File size: 1.93Kb
jQuery.QapTcha = {
build : function(options)
{
var defaults = {
txtLock : 'Переместите ползунок вправо',
txtUnlock : 'Успешно',
disabledSubmit : true,
autoRevert : true,
PHPfile : '/wu-engine/wu-actions/captcha.php',
autoSubmit : false
};
if(this.length>0)
return jQuery(this).each(function(i) {
var
opts = $.extend(defaults, options),
$this = $(this),
form = $('form').has($this),
Clr = jQuery('<div>',{'class':'clr'}),
bgSlider = jQuery('<div>',{'class':'bgSlider'}),
Slider = jQuery('<div>',{'class':'Slider'}),
TxtStatus = jQuery('<div>',{'class':' TxtStatus dropError',text:opts.txtLock}),
inputQapTcha = jQuery('<input>',{name:generatePass(32),value:generatePass(7),type:'hidden'});
if(opts.disabledSubmit) form.find('input[type=\'submit\']').attr('disabled','disabled');
bgSlider.appendTo($this);
Clr.insertAfter(bgSlider);
TxtStatus.insertAfter(Clr);
inputQapTcha.appendTo($this);
Slider.appendTo(bgSlider);
$this.show();
Slider.draggable({
revert: function(){
if(opts.autoRevert)
{
if(parseInt(Slider.css("left")) > (bgSlider.width()-Slider.width()-10)) return false;
else return true;
}
},
containment: bgSlider,
axis:'x',
stop: function(event,ui){
if(ui.position.left > (bgSlider.width()-Slider.width()-10))
{
$.post(opts.PHPfile,{
action : 'qaptcha',
qaptcha_key : inputQapTcha.attr('name')
},
function(data) {
if(!data.error)
{
Slider.draggable('disable').css('cursor','default');
inputQapTcha.val('');
TxtStatus.text(opts.txtUnlock).addClass('dropSuccess').removeClass('dropError');
form.find('input[type=\'submit\']').removeAttr('disabled');
if(opts.autoSubmit) form.find('input[type=\'submit\']').trigger('click');
}
},'json');
}
}
});
function generatePass(nb) {
var chars = 'azertyupqsdfghjkmwxcvbn23456789AZERTYUPQSDFGHJKMWXCVBN_-#@';
var pass = '';
for(i=0;i<nb;i++){
var wpos = Math.round(Math.random()*chars.length);
pass += chars.substring(wpos,wpos+1);
}
return pass;
}
});
}
}; jQuery.fn.QapTcha = jQuery.QapTcha.build;