(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS 瑙勮寖
module.exports = mod;
else if (typeof define == "function" && define.amd) // AMD 瑙勮寖
return define(['jquery','tools'], mod);
else // Plain browser env 娴忚鍣
mod($,tools);
})(function($,tools) {
// var $ = require(['jquery']);
// var tools = require(['tools']);
// 瀵瑰垎椤电殑閾炬帴娣诲姞澶勭悊
if (!tools.isEmptyValue($('.pagination').toArray())) {
$('.pagination>a ').each(function(index, el) {
if ($(el).attr('href') != "#") {
el.href += location.search;
}
});
}
// 楠岃瘉鐮
$('input[name="captcha"]').one('focusin', function(e) {
var img = $(this).nextAll('img.captcha');
if (tools.isEmptyValue(img)) {
var imgStr = '';
} else {
imgStr += ' style="cursor:pointer"/>';
}
$(this).after(imgStr);
} else {
if ($(img).attr('src') === "" || $(img).attr('src') === "#" || RegExp('blank.png').test($(img).attr('src'))) {
$(img).attr('src', SITE_URL + 'service/captcha?t=' + Math.random() * 10);
}
}
});
// 楠岃瘉鐮佺殑瀹炴椂楠岃瘉
// 璁╁墠绔瀹 input[name="captcha"] 鐨 .success 鍜 .error 鐨勬牱寮
$('input[name="captcha"]').on('keyup', function(e) {
var _self = $(this);
var code = _self.val();
// 闀垮害搴旇 == 4
if (code.length > 3 && code.length < 8 && !_self.attr('readonly')) {
$.ajax({
url: SITE_URL + 'service/captcha_ajax',
type: 'GET',
dataType: 'json',
data: {
code: code
}
})
.done(function(data) {
console.log("success");
if (data.status) {
_self.removeClass('error').addClass('success');
_self.next('img').remove();
_self.attr('readonly', true);
_self.nextAll('.captcha_no').remove();
//_self.after('√');
} else {
_self.removeClass('success').addClass('error');
_self.nextAll('.captcha_ok').remove();
_self.nextAll('.captcha_no').remove();
//_self.next().after('×');
}
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
}
});
// 榛樿鍔犺浇楠岃瘉鐮
function pic(){
var imgStr = ''
: imgStr += ' style="cursor:pointer"/>';
$("#captcha").after(imgStr);
}
pic();
// 鍒锋柊楠岃瘉鐮
$(document).delegate('input[name="captcha"] ~ img.captcha', 'click', function(event) {
$(this).attr('src', SITE_URL + 'service/captcha?t=' + Math.random() * 10);
});
});