当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 61

blueslan/clicaptcha
关闭

forked from Hooray/clicaptcha
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
clicaptcha.js 3.35 KB
一键复制 编辑 原始数据 按行查看 历史
(function($){
$.fn.extend({
'clicaptcha': function(options){
var opts = $.extend({}, defaluts, options); //使用jQuery.extend覆盖插件默认参数
var $this = this;
if(!$('#clicaptcha-container').length){
$('body').append('<div id="clicaptcha-container">'+
'<div class="clicaptcha-imgbox">'+
'<img class="clicaptcha-img" alt="验证码加载失败,请点击刷新按钮">'+
'</div>'+
'<div class="clicaptcha-title"></div>'+
'<div class="clicaptcha-refresh-box">'+
'<div class="clicaptcha-refresh-line clicaptcha-refresh-line-left"></div>'+
'<a href="javascript:;" class="clicaptcha-refresh-btn" title="刷新"></a>'+
'<div class="clicaptcha-refresh-line clicaptcha-refresh-line-right"></div>'+
'</div>'+
'</div>');
$('body').append('<div id="clicaptcha-mask"></div>');
$('#clicaptcha-mask').click(function(){
$('#clicaptcha-container').hide();
$(this).hide();
});
$('#clicaptcha-container .clicaptcha-refresh-btn').click(function(){
$this.clicaptcha(opts);
});
}
$('#clicaptcha-container, #clicaptcha-mask').show();
$('#clicaptcha-container .clicaptcha-imgbox .step').remove();
$('#clicaptcha-container .clicaptcha-imgbox .clicaptcha-img').attr('src', opts.src + '?' + new Date().getTime()).on('load', function(){
var thisObj = $(this);
var text = Cookies.get('clicaptcha_text').split(',');
var title = '请依次点击';
var t = [];
for(var i = 0; i < text.length; i++){
t.push('“<span>'+text[i]+'</span>”');
}
title += t.join('');
$('#clicaptcha-container .clicaptcha-title').html(title);
var xyArr = [];
thisObj.off('mousedown').on('mousedown', function(e){
e.preventDefault();
thisObj.off('mouseup').on('mouseup', function(e){
$('#clicaptcha-container .clicaptcha-title span:eq('+xyArr.length+')').addClass('clicaptcha-clicked');
xyArr.push(e.offsetX + ',' + e.offsetY);
$('#clicaptcha-container .clicaptcha-imgbox').append('<span class="step" style="left:' + (e.offsetX - 13) + 'px;top:' + (e.offsetY - 13) + 'px">' + xyArr.length + '</span>')
if(xyArr.length == text.length){
var captchainfo = [xyArr.join('-'), thisObj.width(), thisObj.height()].join(';');
$.ajax({
type: 'POST',
url: opts.src,
data: {
do : 'check',
info : captchainfo
}
}).done(function(cb){
if(cb == 1){
$this.val(captchainfo).data('ischeck', true);
$('#clicaptcha-container .clicaptcha-title').html(opts.success_tip);
setTimeout(function(){
$('#clicaptcha-container, #clicaptcha-mask').hide();
opts.callback();
}, 1500);
}else{
$('#clicaptcha-container .clicaptcha-title').html(opts.error_tip);
setTimeout(function(){
$this.clicaptcha(opts);
}, 1500);
}
});
}
});
});
});
return this;
},
'clicaptchaCheck': function(){
var ischeck = false;
if(this.data('ischeck') == true){
ischeck = true;
}
return ischeck;
},
'clicaptchaReset': function(){
this.val('').removeData('ischeck');
return this;
}
});
//默认参数
var defaluts = {
src: 'clicaptcha/clicaptcha.php',
success_tip: '验证成功!',
error_tip: '未点中正确区域,请重试!',
callback: function(){}
};
})(window.jQuery);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/blueslan/clicaptcha.git
git@gitee.com:blueslan/clicaptcha.git
blueslan
clicaptcha
clicaptcha
master

搜索帮助