-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fortunewheel.min.js
1 lines (1 loc) · 5.27 KB
/
jquery.fortunewheel.min.js
1
window.FortuneWheel={getConsoleDebugger:function(){return{clear:function(){console.clear()},log:function(){for(var t=-1,e=arguments.length,n=[],r="console.log(args)";++t<e;)n.push("args["+t+"]");(r=new Function("args",r.replace(/args/,n.join(","))))(arguments)}}},getDebugger:function(t){return{clear:function(){""!=t&&$(t).html("")},log:function(){if(""!=t){var e="";for(var n in arguments)e+=arguments[n].toString(),n<arguments.length-1&&(e+=", ");$(t).append($("<div>").text(e))}}}},init:function(t,e){$(t).fortuneWheel(e)}},function(t,e){function n(t){var e=-1;if(null!=t)for(var n in a)if(null!=a[n]&&t.get(0)==a[n].getElement().get(0)){e=n;break}return e}var r={ua:e.navigator.userAgent.toLowerCase(),isAndroid:function(){return r.ua.indexOf("android")>-1},isIOS:function(){var t=r.ua.match(/(ipad|iphone|ipod)/g)?!0:!1;return t},isOldAndroid:function(){return r.ua.indexOf("android 2.")>-1||r.ua.indexOf("gecko) version/")>-1},isProblematic:function(){return r.isIOS()||r.isOldAndroid()}},a=[],i=function(e,n){function a(e){return"rtl"==t(e).css("direction").toLowerCase()}function i(){var r=null;return null!=n.placeholder&&(r=t(n.placeholder)),r&&0!=r.length||(r=t("<div />"),t(e).before(r)),r.html("").addClass(n.placeholderClass),r}function l(e){return t(e>=0&&e<v.length?v[e]:null)}function s(){t(v).each(function(){var e=t.trim(t(this).val()).replace(/\s/g,"").length,r=parseInt(t(this).attr("maxlength"));t(this).toggleClass(n.filledClass,e>=r)}),g.isFull()?(e.trigger(n.eventFull),"function"==typeof n.full&&n.full(g.getValue())):(e.trigger(n.eventNotFull),"function"==typeof n.partial&&n.partial(g.getValue()))}function o(e){var n=g.getValue();if(n!=e){var r=e.replace(/\s+/g,""),a=0;t(p).each(function(){var e=t(this),n=parseInt(e.prop("maxlength"));e.val(r.substr(a,n)),a+=n})}}function u(){if(t(v).change(function(){var t=g.getValue();t!=e.val()&&e.val(t),s()}).keyup(function(){s()}),r.isOldAndroid()||t(v).keydown(function(e){var i=a(t(this)),s=t(this).data("pos"),o=l(s+1),u=l(s-1);switch(e.keyCode){case 46:if(option.byWords)break;return n.allowBlanks&&t(this).val("").trigger("change"),!1;case 8:if(r.isProblematic())return!0;var c=t(this).val();return n.allowDeleting&&t(this).val(c.substring(0,c.length-1)).trigger("change"),c.length-1<=0&&u.focus(),!1;case 32:if(n.byWords)break;return n.allowBlanks&&(t(this).val(" ").trigger("change"),o.focus()),!1;case 37:return n.byWords?!0:((i?o:u).focus(),!1);case 39:return n.byWords?!0:((i?u:o).focus(),!1)}}).on(r.isAndroid()?"input":"keypress",function(e){var a=t(this).data("pos"),i=l(a+1),s=e.keyCode||e.which||0,o=String.fromCharCode(s),u=t(this).val().length,c=parseInt(t(this).attr("maxlength"));return n.allowNumbers||isNaN(o)?n.restrict&&0!=s&&!new RegExp("["+n.restrict+"]").test(o)?!1:(""!=o&&0!=s&&(n.byWords?t(this).val((t(this).val()+o).substring(0,c)).trigger("change"):t(this).val(o).trigger("change")),u=t(this).val().length,r.isProblematic()||0!=i.length||!n.blurOnLastChar&&0!=s?(r.isAndroid()&&t(this).val(t(this).val().substring(0,c)),r.isAndroid()&&""!=i.val()?t(this).blur():u>=c&&!r.isProblematic()&&i.focus()):t(this).blur(),0!=s?!1:void 0):!1}),r.isAndroid()&&!r.isOldAndroid()&&v.focus(function(){t(this).val("").trigger("change")}),!n.allowBlanks){var i="focus"+Math.floor(1e5*Math.random());t(v).focus(function(){return""!=t(this).val()||t(this).hasClass(i)?(t(this).removeClass(i),!0):void t(v).each(function(){return""==t(this).val()?(t(this).addClass(i).focus(),!1):void 0})})}t(e).change(function(){var e=t(this).val();o(e)})}function c(){var r=[];return r=n.pattern.length>0?n.pattern:t(e).data("pattern"),"object"==typeof r?r:r.toString().split(",")}function h(){var r=!!n.byWords;d.html();var i=c(),l=null;p=[];for(var h in i)if(!isNaN(i[h])){for(var f=r?1:i[h],g=0;f>g;g++){var m=r?"word":"char",b=r?i[h]:1;l=t('<input type="text" data-pos="'+p.length+'" maxlength="'+b+'" class="'+m+'" />'),n.showCaretSymbol||l.attr("readonly","readonly"),d.append(l),l.css({height:n.charSize,width:n.charSize*b,lineHeight:n.charSize+"px"}),p.push(l)}h<i.length-1&&null!=l&&l.addClass(n.spaceClass).css(a(d)?"margin-left":"margin-right",n.wordSpace)}o(e.val()),v=t(p).map(function(){return this.toArray()}),u(),n.hideElem&&e.hide(),s()}this.getElement=function(){return e};var f={placeholder:null,pattern:[],hideElem:!0,wordSpace:15,spaceClass:"word-space",showCaretSymbol:!0,placeholderClass:"fortune-wheel",allowNumbers:!1,trimValue:!0,allowBlanks:!1,allowDeleting:!0,restrict:null,blurOnLastChar:!1,byWords:!1,charSize:30,filledClass:"filled",eventFull:"change-full",eventNotFull:"change-not-full",full:function(){},partial:function(){}},g=this;e.data("fortune_wheel",g);var d=null,v=[],p=[];this.isFull=function(){var e=!0;return t(v).each(function(){var n=t.trim(t(this).val()),r=t(this).attr("maxlength");return n.length<r?(e=!1,!1):void 0}),e},this.getValue=function(){var e="";return t(v).each(function(){var r=t(this).val();e+=""==r?" ":r,t(this).hasClass(n.spaceClass)&&(e+=" ")}),n.trimValue?t.trim(e):e},this.destroy=function(){t(v).remove(),e.show()},n=t.extend(f,n),r.isProblematic()&&(n.byWords=!0),d=i(),h()};i.destroy=function(t){var e=n(t);if(e>-1){var r=a[e];r.destroy(),a[e]=null}},t.fn.fortuneWheel=function(e){return t(this).filter("input[type=text]").each(function(){var r=t(this);if("destroy"==e)i.destroy(r);else{var l=n(r);-1==l&&a.push(new i(r,e))}}),this}}(jQuery,window,document);