-
Notifications
You must be signed in to change notification settings - Fork 13
/
jquery.realperson.min.js
6 lines (6 loc) · 5.14 KB
/
jquery.realperson.min.js
1
2
3
4
5
6
/* http://keith-wood.name/realPerson.html
Real Person Form Submission for jQuery v2.0.1.
Written by Keith Wood (kwood{at}iinet.com.au) June 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
(function($){var h='realperson';var k='ABCDEFGHIJKLMNOPQRSTUVWXYZ';var l=k+'0123456789';var m=[[' * ',' * * ',' * * ',' * * ',' ***** ','* *','* *'],['****** ','* *','* *','****** ','* *','* *','****** '],[' ***** ','* *','* ','* ','* ','* *',' ***** '],['****** ','* *','* *','* *','* *','* *','****** '],['*******','* ','* ','**** ','* ','* ','*******'],['*******','* ','* ','**** ','* ','* ','* '],[' ***** ','* *','* ','* ','* ***','* *',' ***** '],['* *','* *','* *','*******','* *','* *','* *'],['*******',' * ',' * ',' * ',' * ',' * ','*******'],[' *',' *',' *',' *',' *','* *',' ***** '],['* *','* ** ','* ** ','** ','* ** ','* ** ','* *'],['* ','* ','* ','* ','* ','* ','*******'],['* *','** **','* * * *','* * *','* *','* *','* *'],['* *','** *','* * *','* * *','* * *','* **','* *'],[' ***** ','* *','* *','* *','* *','* *',' ***** '],['****** ','* *','* *','****** ','* ','* ','* '],[' ***** ','* *','* *','* *','* * *','* * ',' **** *'],['****** ','* *','* *','****** ','* * ','* * ','* *'],[' ***** ','* *','* ',' ***** ',' *','* *',' ***** '],['*******',' * ',' * ',' * ',' * ',' * ',' * '],['* *','* *','* *','* *','* *','* *',' ***** '],['* *','* *',' * * ',' * * ',' * * ',' * * ',' * '],['* *','* *','* *','* * *','* * * *','** **','* *'],['* *',' * * ',' * * ',' * ',' * * ',' * * ','* *'],['* *',' * * ',' * * ',' * ',' * ',' * ',' * '],['*******',' * ',' * ',' * ',' * ',' * ','*******'],[' *** ',' * * ','* * *','* * *','* * *',' * * ',' *** '],[' * ',' ** ',' * * ',' * ',' * ',' * ','*******'],[' ***** ','* *',' *',' * ',' ** ',' ** ','*******'],[' ***** ','* *',' *',' ** ',' *','* *',' ***** '],[' * ',' ** ',' * * ',' * * ','*******',' * ',' * '],['*******','* ','****** ',' *',' *','* *',' ***** '],[' **** ',' * ','* ','****** ','* *','* *',' ***** '],['*******',' * ',' * ',' * ',' * ',' * ','* '],[' ***** ','* *','* *',' ***** ','* *','* *',' ***** '],[' ***** ','* *','* *',' ******',' *',' * ',' **** ']];$.JQPlugin.createPlugin({name:h,alphabetic:k,alphanumeric:l,defaultDots:m,defaultOptions:{length:6,regenerate:'Click to change',hashName:'{n}Hash',dot:'*',dots:m,chars:k},_getters:['getHash'],_challengeClass:h+'-challenge',_disabledClass:h+'-disabled',_hashClass:h+'-hash',_regenerateClass:h+'-regen',_textClass:h+'-text',_optionsChanged:function(c,d,e){$.extend(d.options,e);var f='';for(var i=0;i<d.options.length;i++){f+=d.options.chars.charAt(Math.floor(Math.random()*d.options.chars.length))}d.hash=hash(f+n);var g=this;c.closest('form').off('.'+d.name).on('submit.'+d.name,function(){var a=d.options.hashName.replace(/\{n\}/,c.attr('name'));var b=$(this);b.find('input[name="'+a+'"]').remove();b.append('<input type="hidden" class="'+g._hashClass+'" name="'+a+'" value="'+hash(f+n)+'">');setTimeout(function(){b.find('input[name="'+a+'"]').remove()},0)});c.prevAll('.'+this._challengeClass+',.'+this._hashClass).remove().end().before(this._generateHTML(d,f)).prevAll('div.'+this._challengeClass).click(function(){if(!$(this).hasClass(g._disabledClass)){c.realperson('option',{})}})},enable:function(a){a=$(a);if(!a.hasClass(this._getMarker())){return}a.removeClass(this._disabledClass).prop('disabled',false).prevAll('.'+this._challengeClass).removeClass(this._disabledClass)},disable:function(a){a=$(a);if(!a.hasClass(this._getMarker())){return}a.addClass(this._disabledClass).prop('disabled',true).prevAll('.'+this._challengeClass).addClass(this._disabledClass)},getHash:function(a){var b=this._getInst(a);return b?b.hash:0},_generateHTML:function(a,b){var c='<div class="'+this._challengeClass+'">'+'<div class="'+this._textClass+'">';for(var i=0;i<a.options.dots[0].length;i++){for(var j=0;j<b.length;j++){c+=a.options.dots[a.options.chars.indexOf(b.charAt(j))][i].replace(/ /g,' ').replace(/\*/g,a.options.dot)+'  '}c+='<br>'}c+='</div><div class="'+this._regenerateClass+'">'+a.options.regenerate+'</div></div>';return c},_preDestroy:function(a,b){a.closest('form').off('.'+b.name);a.prevAll('.'+this._challengeClass+',.'+this._hashClass).remove()}});var n=$.salt||'#salt';delete $.salt;$(function(){var a=$(n);if(a.length){n=a.text();a.remove()}if(n==='#salt'){n=''}});function b(a){var b=5381;for(var i=0;i<a.length;i++){b=((b<<5)+b)+a.charCodeAt(i)}return b}})(jQuery);