/
jquery.jkit.autoload.1.2.16.min.js
10 lines (8 loc) · 12.8 KB
/
jquery.jkit.autoload.1.2.16.min.js
1
2
3
4
5
6
7
8
9
10
// jQuery Plugin: jKit
// A very easy to use, cross platform jQuery UI toolkit that's still small in size, has the features you need and doesn't get in your way.
// Version 1.2.16 - 10. May. 2013
// http://jquery-jkit.com/
//
// by Fredi Bach
// http://fredibach.ch/jquery-plugins/
(function($,undefined){$.jKit=function(element,options,moreoptions){var defaults={prefix:"jkit",dataAttribute:"data-jkit",activeClass:"active",errorClass:"error",successClass:"success",ignoreFocus:!1,ignoreViewport:!1,keyNavigation:!0,touchNavigation:!0,plugins:{},replacements:{},delimiter:",",loadminified:!0,macros:{"hide-if-empty":"binding:selector=this;source=text;mode=css.display","smooth-blink":"loop:speed1=2000;duration1=250;speed2=250;duration2=2000"},commands:{}},plugin=this;plugin.version="1.2.16",plugin.inc=[],plugin.settings={},plugin.commands={},plugin.executions={};var $element=$(element),element=element;if("string"==typeof options){var singlecommand=options;moreoptions==undefined&&(moreoptions={}),options=moreoptions}var startX,startY,windowhasfocus=!0,uid=0,commandkeys={};($.support.htmlSerialize||$.support.opacity)&&$(window).focus(function(){windowhasfocus=!0}).blur(function(){windowhasfocus=!1}),plugin.init=function(a){a==undefined&&(a=$element),plugin.settings=$.extend({},defaults,options);var b=plugin.settings;singlecommand!=undefined?plugin.executeCommand(a,singlecommand,options):a.find("*[rel^=jKit], *["+b.dataAttribute+"]").each(function(){var c=this,d=$(this).attr("rel"),e=plugin.getDataCommands($(this));d=""!=e?$.trim(e).substring(1):$.trim(d).substring(5),d=d.substring(0,d.length-1),d=d.replace(/\]\s+\[/g,"]["),relsplit=d.split("]["),$.each(relsplit,function(d,e){e=e.replace(/\\=/g,"|jkit-eq|").replace(/\\:/g,"|jkit-dp|").replace(/\\;/g,"|jkit-sc|").replace(/\\\[/g,"|jkit-sbo|").replace(/\\\]/g,"|jkit-sbc|").replace(/\\\*/g,"|jkit-st|").replace(/\\ /g,"|jkit-sp|"),e=$.trim(e),b.macros[e]!=undefined&&(e=b.macros[e]);var f=plugin.parseOptions(e);if(b.macros[f.type]!=undefined){var g=plugin.parseOptions(b.macros[f.type]);f.type=g.type,f=$.extend({},g,f)}if("macro"==f.type&&relsplit[d-1]!=undefined)plugin.settings.macros[f.name]=relsplit[d-1];else if("repeat"==f.type&&relsplit[d-1]!=undefined){var h=plugin.parseOptions(relsplit[d-1]);a.on(f.onevent,function(){f.delay==undefined&&(f.delay=0),setTimeout(function(){plugin.executeCommand($(c),h.type,h)},f.delay)})}else if("info"==f.type){var i="jKit version: "+plugin.version+"\n";i+="Included commands: "+plugin.inc.join(", ")+"\n",console.log(i),console.log(a)}else{var j=[];if(f.target!=undefined){var k=f.target.split(".");switch(k=[k.shift(),k.join(".")],k[1]==undefined&&(k[1]="*"),k[0]){case"children":$(c).children(k[1]).each(function(){j.push(this)});break;case"each":$(c).find(k[1]).each(function(){j.push(this)});break;default:j.push(c)}}else j.push(c);$.each(j,function(e,g){var h=plugin.parseDynamicOptions(f);if(h.commandkey==undefined){var i=$(c).attr("id");h.commandkey=i!=undefined?i:b.prefix+"-uid-"+ ++uid}if(h.commandkey!=undefined&&(commandkeys[h.commandkey]={el:g,options:h,execs:0}),h.onevent!==undefined||h.andonevent!==undefined){var j=[];h.onevent!==undefined&&j.push(h.onevent),h.andonevent!==undefined&&j.push(h.andonevent);var k=j.join(" ");a.on(k,function(){b.replacements[h.type]!=undefined&&"function"==typeof b.replacements[h.type]?b.replacements[h.type].call(plugin,g,h.type,h):plugin.executeCommand(g,h.type,h)})}if(h.onevent===undefined)if(relsplit[d-1]!=undefined){var l="";if(relsplit[d-1]!=undefined){var m=plugin.parseOptions(relsplit[d-1]);l=m.type+"."+h.commandkey+".executed"}""!=l&&plugin.executions[m.type+"."+h.commandkey+".executed"]===undefined?a.on(l,function(){b.replacements[h.type]!=undefined&&"function"==typeof b.replacements[h.type]?b.replacements[h.type].call(plugin,g,h.type,h):plugin.executeCommand(g,h.type,h)}):b.replacements[h.type]!=undefined&&"function"==typeof b.replacements[h.type]?b.replacements[h.type].call(plugin,g,h.type,h):plugin.executeCommand(g,h.type,h)}else b.replacements[h.type]!=undefined&&"function"==typeof b.replacements[h.type]?b.replacements[h.type].call(plugin,g,h.type,h):plugin.executeCommand(g,h.type,h)})}})})},plugin.getDataCommands=function(a){for(var b=plugin.settings,c=a.get(0),d="",e=0,f=c.attributes,g=f.length;g>e;e++){var h=f.item(e).nodeName,i=h.split("-");if(i[0]+"-"+i[1]==b.dataAttribute)if(i.length>2){if(i[4]!==undefined&&"height"==i[4])var j=a.height();else var j=a.width();i[2]!==undefined&&i[3]!==undefined&&("gt"==i[2]&&j>parseInt(i[3])||"lt"==i[2]&&parseInt(i[3])>j)&&(d+=a.attr(h))}else d+=a.attr(h)}return d},plugin.applyMacro=function(a,b){var c=plugin.settings;if(c.macros[b]!=undefined){var d=c.macros[b],e=plugin.parseOptions(d);c.replacements[e.type]!=undefined&&"function"==typeof c.replacements[e.type]?c.replacements[e.type].call(plugin,a,e.type,e):plugin.executeCommand(a,e.type,e)}},plugin.parseOptions=function(a){var b=a.split(":"),c=b[0].split("."),d={type:$.trim(c[0])};if(c[1]!==undefined&&(d.commandkey=c[1]),d.execute==undefined&&(d.execute="always"),b.length>1){var e=b[1].split(";");$.each(e,function(a,b){var c=b.split("=");d[$.trim(c[0])]=$.trim(c[1])})}return d},plugin.fixSpeed=function(a){return"fast"!=a&&"slow"!=a&&(a=parseInt(a)),a},plugin.parseDynamicOptions=function(a){var b={};for(index in a){var c=a[index];if(c!==undefined&&c.indexOf("{")>-1&&c.indexOf("|")>0&&c.indexOf("}")>1){for(var d="",e=!1,f="",g=!1,h=0;c.length-1>=h;h++)if(e||"{"!=c.charAt(h)?e&&"}"==c.charAt(h)&&(e=!1,g=!0):e=!0,e||g){if(f+=c.charAt(h),g){f=f.slice(1,-1);var i=f.split("|");if("rand"==i[0]){var j=i[1].split("-");d+=plugin.getRandom(Number(j[0]),Number(j[1]))}g=!1,f=""}}else d+=c.charAt(h);b[index]=d}else b[index]=c}return b},plugin.getRandom=function(a,b){if(a>b)return-1;if(a==b)return a;var c;do c=Math.random();while(1==c);return a+parseInt(c*(b-a+1))},plugin.findElementTag=function(a,b,c,d){var e="";if(c===undefined||isNaN(c)||parseInt(c)!=c){var f={};a.find(b).each(function(a){if(!(25>a))return!1;var b=$(this).prop("tagName");""!=b[0]&&(f[b]!==undefined?f[b]++:f[b]=1)});var g=0,h="";for(var i in f)f[i]>g&&(g=f[i],h=i);e=h}else a.find(b).length>c&&(e=$(a.find(b).get(c)).prop("tagName"));return e!==undefined&&""!=e?e:d},plugin.addDefaults=function(a,b){if(plugin.settings.commands[a]!=undefined){var c=plugin.settings.commands[a];$.each(c,function(a,c){b[a]==undefined&&(b[a]=c),a.indexOf("speed")>-1&&(b[a]=plugin.fixSpeed(b[a]))})}return b},plugin.executeCommand=function(that,type,options){var s=plugin.settings,$that=$(that);if(plugin.commands[type]===undefined&&(plugin.commands[type]=[]),$.isArray(plugin.commands[type])){if(plugin.commands[type].push({el:that,options:options}),s.loadminified)var commandurl="jquery.jkit.commands/"+type+".min.js";else var commandurl="jquery.jkit.commands/"+type+".js";return 1==plugin.commands[type].length&&$.ajax({url:"jquery.jkit.commands/"+type+".js",success:function(data){if(-1!==data.indexOf("plugin.commands.")){var queue=plugin.commands[type];eval(data),$.each(queue,function(a,b){plugin.executeCommand(b.el,type,b.options)})}},dataType:"text"}),$that}return $element.trigger("jkit-commandinit",{element:$that,type:type,options:options}),options.commandkey!==undefined&&(commandkeys[options.commandkey].execs++,"once"==options.execute&&commandkeys[options.commandkey].execs>1||!isNaN(options.execute)&&commandkeys[options.commandkey].execs>options.execute)?$that:(options=plugin.addDefaults(type,options),$.each(options,function(a,b){"string"==typeof b&&(options[a]=b=b.replace(/\|jkit\-eq\|/g,"=").replace(/\|jkit\-dp\|/g,":").replace(/\|jkit\-sc\|/g,";").replace(/\|jkit\-sbo\|/g,"[").replace(/\|jkit\-sbc\|/g,"]").replace(/\|jkit\-st\|/g,"*").replace(/\|jkit\-sp\|/g," ")),"string"==typeof b&&"*"==b.slice(-1)&&(options[a]=window[b.slice(0,-1)],"function"==typeof options[a]&&(options[a]=options[a].call(that)))}),plugin.commands[type].execute($that,options),"remove"!=type&&($element.trigger(type+"."+options.commandkey+".executed",{}),plugin.executions[type+"."+options.commandkey+".executed"]=!0),$that)},plugin.triggerEvent=function(a,b,c){if(c.commandkey!==undefined){var d=a.split(" ");$.each(d,function(a,d){$element.trigger(c.commandkey+"."+d,{element:b,options:c})})}},plugin.cssFromString=function(a){var b=a.split(","),c={};return $.each(b,function(a,b){var d=b.split("(");if(2==d.length){var e=d[0],f=d[1].slice(0,-1);c[e]=f}}),c},plugin.addCommandDefaults=function(a,b){defaults.commands[a]=b,$element.trigger("command."+a+".loaded",{})},plugin.addKeypressEvents=function(a,b){plugin.settings.keyNavigation&&$(document).keydown(function(c){if(this===c.target||!/textarea|select/i.test(c.target.nodeName)&&"text"!==c.target.type){for(var d={8:"backspace",9:"tab",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",191:"/",224:"meta"},e=48;90>=e;e++)d[e]=String.fromCharCode(e).toLowerCase();if($.inArray(c.which,d)){var f="";c.altKey&&(f+="alt+"),c.ctrlKey&&(f+="ctrl+"),c.metaKey&&(f+="meta+"),c.shiftKey&&(f+="shift+");var g=f+d[c.which];g==b&&(a.trigger(f+d[c.which]),c.preventDefault())}}})},plugin.commands.init=function(){var a={};return plugin.addCommandDefaults("init",{}),a.execute=function(a,b){plugin.init(a),plugin.triggerEvent("complete",a,b)},a}();for(x in plugin.commands)"init"!=x&&plugin.inc.push(x);plugin.init()},$.fn.jKit_effect=function(a,b,c,d,e,f){return this.each(function(){f==undefined&&(f=function(){}),e==undefined&&(e=0),"fade"==b?a?$(this).delay(e).fadeTo(c,1,d,f):$(this).delay(e).fadeTo(c,0,d,f):"slide"==b?a?$(this).delay(e).slideDown(c,d,f):$(this).delay(e).slideUp(c,d,f):"none"==b?(a?$(this).delay(e).show():$(this).delay(e).hide(),f()):a?$(this).delay(e).show(c,d,f):$(this).delay(e).hide(c,d,f)})},$.fn.jKit_getUnixtime=function(){var a=new Date,b=a.getTime();return parseInt(b/1e3)},$.fn.jKit_arrayShuffle=function(a){for(var b,c,d=0;a.length>d;d++)c=Math.floor(Math.random()*a.length),b=a[d],a[d]=a[c],a[c]=b;return a},$.fn.jKit_stringOccurrences=function(a,b){for(var c=0,d=0;;){if(d=a.indexOf(b,d),-1==d)break;c++,d+=b.length}return c},$.fn.jKit_emailCheck=function(a){var b=/^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;return b.test(a)},$.fn.jKit_urlCheck=function(a){var b=/^(?:(ftp|http|https):\/\/)?(?:[\w\-]+\.)+[a-z]{2,6}$/i;return b.test(a)},$.fn.jKit_dateCheck=function(a){return $.fn.jKit_regexTests(a,[/^[0-9]{2}\.[0-9]{2}\.[0-9]{2}$/i,/^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{2}$/i,/^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}$/i,/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/i,/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/i,/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/i])},$.fn.jKit_timeCheck=function(a){return $.fn.jKit_regexTests(a,[/^[0-9]{1,2}\:[0-9]{2}$/i,/^[0-9]{1,2}\:[0-9]{2}\:[0-9]{2}$/i])},$.fn.jKit_phoneCheck=function(a){return $.fn.jKit_regexTests(a,[/^(\+|0)([\d ])+(0|\(0\))+[\d ]+(-\d*)?\d$/,/^(\+|0)[\d ]+(-\d*)?\d$/,/^((((\(\d{3}\))|(\d{3}-))\d{3}-\d{4})|(\+?\d{2}((-| )\d{1,8}){1,5}))(( x| ext)\d{1,5}){0,1}$/])},$.fn.jKit_passwordStrength=function(a){var b=0;return 5>a.length?b+=5:a.length>4&&8>a.length?b+=15:a.length>=8&&(b+=30),a.match(/[a-z]/)&&(b+=5),a.match(/[A-Z]/)&&(b+=10),a.match(/\d+/)&&(b+=10),a.match(/(.*[0-9].*[0-9].*[0-9])/)&&(b+=10),a.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)&&(b+=10),a.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)&&(b+=10),a.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)&&(b+=5),a.match(/([a-zA-Z])/)&&a.match(/([0-9])/)&&(b+=5),a.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)&&(b+=5),b},$.fn.jKit_regexTests=function(a,b,c){c===undefined&&(c=!1);var d=0;for(var e in b)b[e].test(a)&&d++;return c&&d==b.length||!c&&d>0},$.fn.jKit_getAttributes=function(){return this.each(function(){for(var a={},b=$(this)[0].attributes,c=b.length,d=0;c>d;d++)a[b[d].name.toLowerCase()]=b[d].value;return a})},$.fn.jKit_setAttributes=function(a){return this.each(function(){$.each(a,function(a,b){try{$(this).attr(a+"",b+"")}catch(c){}})})},$.fn.jKit_iOS=function(){return navigator.userAgent.match(/(iPod|iPhone|iPad)/i)},$.fn.jKit_belowTheFold=function(){var a=$(window).height()+$(window).scrollTop();return $(this).offset().top>=a},$.fn.jKit_aboveTheTop=function(){var a=$(window).scrollTop();return a>=$(this).offset().top+$(this).height()},$.fn.jKit_rightOfScreen=function(){var a=$(window).width()+$(window).scrollLeft();return $(this).offset().left>=a},$.fn.jKit_leftOfScreen=function(){var a=$(window).scrollLeft();return a>=$(this).offset().left+$(this).width()},$.fn.jKit_inViewport=function(){return!($(this).jKit_belowTheFold()||$(this).jKit_aboveTheTop()||$(this).jKit_rightOfScreen()||$(this).jKit_leftOfScreen())},$.fn.jKit=function(a,b){return this.each(function(){var c=new $.jKit(this,a,b);$(this).data("jKit",c)})}})(jQuery);