1
0
mirror of https://github.com/kidoman/embd synced 2024-11-11 20:18:54 +01:00
embd/js/gumby.min.js
2014-03-31 06:33:08 +05:30

2 lines
8.1 KiB
JavaScript

!function(t){"use strict";function i(){this.$dom=t(document),this.$html=this.$dom.find("html"),this.isOldie=!!this.$html.hasClass("oldie"),this.click="click",this.onReady=this.onOldie=this.onTouch=!1,this.autoInit="false"===t("script[gumby-init]").attr("gumby-init")?!1:!0,this.debugMode=Boolean(t("script[gumby-debug]").length),this.touchDevice=!!(Modernizr.touch||window.navigator.userAgent.indexOf("Windows Phone")>0),this.gumbyTouch=!1,this.touchEvents="js/libs",this.breakpoint=Number(t("script[gumby-breakpoint]").attr("gumby-breakpoint"))||768,this.touchEventsLoaded=!1,this.uiModulesReady=!1,this.uiModules={},this.inits={};var i=t("script[gumby-touch]").attr("gumby-touch"),e=t("script[gumby-path]").attr("gumby-path");"false"===i?this.touchEvents=!1:i?this.touchEvents=i:e&&(this.touchEvents=e),this.touchDevice&&(this.click+=" tap"),this.touchDevice&&t(window).width()<this.breakpoint?(this.$html.addClass("gumby-touch"),this.gumbyTouch=!0):this.$html.addClass("gumby-no-touch"),this.debugMode&&this.debug("Gumby is in debug mode")}i.prototype.init=function(t){var i=this,e=t?t:{};return this.$dom.ready(function(){e.debug&&(i.debugMode=!0),i.debug("Initializing Gumby");var t=e.uiModules?e.uiModules:!1;i.initUIModules(t),i.onReady&&i.onReady(),i.isOldie&&i.onOldie&&i.onOldie(),Modernizr.touch&&i.onTouch&&i.onTouch()}),this},i.prototype.helpers=function(){this.onReady&&this.onReady(),this.isOldie&&this.onOldie&&this.onOldie(),Modernizr.touch&&this.onTouch&&this.onTouch()},i.prototype.ready=function(t){return t&&"function"==typeof t&&(this.onReady=t),this},i.prototype.oldie=function(t){return t&&"function"==typeof t&&(this.onOldie=t),this},i.prototype.touch=function(t){return t&&"function"==typeof t&&(this.onTouch=t),this},i.prototype.console=function(t,i){this.debugMode&&window.console&&console[console[t]?t:"log"](i.length>1?Array.prototype.slice.call(i):i[0])},i.prototype.log=function(){this.console("log",arguments)},i.prototype.debug=function(){this.console("debug",arguments)},i.prototype.warn=function(){this.console("warn",arguments)},i.prototype.error=function(){this.console("error",arguments)},i.prototype.dump=function(){return{$dom:this.$dom,isOldie:this.isOldie,touchEvents:this.touchEvents,debugMode:this.debugMode,autoInit:this.autoInit,uiModules:this.uiModules,click:this.click}},i.prototype.selectAttr=function(){for(var t=0;t<arguments.length;t++){var i=arguments[t],e="data-"+arguments[t],s="gumby-"+arguments[t];if(this.is("["+e+"]"))return this.attr(e)?this.attr(e):!0;if(this.is("["+s+"]"))return this.attr(s)?this.attr(s):!0;if(this.is("["+i+"]"))return this.attr(i)?this.attr(i):!0}return!1},i.prototype.addInitalisation=function(t,i){this.inits[t]=i},i.prototype.initialize=function(t,i){if("object"==typeof t){var e=0;for(e;e<t.length;e++)this.inits[t[e]]&&"function"==typeof this.inits[t[e]]?this.inits[t[e]](i):this.error("Error initializing module: "+t[e])}else this.inits[t]&&"function"==typeof this.inits[t]?this.inits[t](i):this.error("Error initializing module: "+t);return this},i.prototype.UIModule=function(t){var i=t.module;this.uiModules[i]=t},i.prototype.initUIModules=function(t){var i,e,s=this.uiModules;t&&(s=t);for(i in s)e=t?s[i]:i,this.uiModules[e].init()},window.Gumby=new i}(jQuery),!function(t){"use strict";function i(i){this.$el=t(i),this.targets=[],this.on="",this.className="",this.self=!1,this.$el.length&&(Gumby.debug("Initializing Toggle",i),this.init())}function e(i){this.$el=t(i),this.targets=[],this.on="",this.className="",this.self=!1,this.$el.length&&(Gumby.debug("Initializing Switch",i),this.init())}i.prototype.init=function(){var t=this;this.setup(),this.$el.on(this.on,function(i){i.preventDefault(),t.trigger(t.triggered)}).on("gumby.trigger",function(){Gumby.debug("Trigger event triggered",t.$el),t.trigger(t.triggered)}).on("gumby.initialize",function(){Gumby.debug("Re-initializing "+t.constructor,$el),t.setup()})},i.prototype.setup=function(){this.targets=this.parseTargets(),this.on=Gumby.selectAttr.apply(this.$el,["on"])||Gumby.click,this.className=Gumby.selectAttr.apply(this.$el,["classname"])||"active",this.self="false"===Gumby.selectAttr.apply(this.$el,["self"])},i.prototype.parseTargets=function(){var i=Gumby.selectAttr.apply(this.$el,["trigger"]),e=0,s=[];return i?(e=i.indexOf("|"),-1===e?this.checkTargets([i])?[t(i)]:!1:(s=i.split("|"),this.checkTargets(s)?s.length>1?[t(s[0]),t(s[1])]:[t(s[0])]:!1)):!1},i.prototype.checkTargets=function(i){var e=0;for(e;e<i.length;e++)if(i[e]&&!t(i[e]).length)return Gumby.error("Cannot find "+this.constructor.name+" target: "+i[e]),!1;return!0},i.prototype.triggered=function(){Gumby.debug("Triggering onTrigger event",this.$el),this.$el.trigger("gumby.onTrigger",[this.$el.hasClass(this.className)])},e.prototype=new i,e.prototype.constructor=e,i.prototype.trigger=function(t){Gumby.debug("Triggering Toggle",this.$el);var i;this.targets?1==this.targets.length?this.$el.add(this.targets[0]).toggleClass(this.className):this.targets.length>1&&(this.targets[0].hasClass(this.className)?(i=this.targets[0],this.self||(i=i.add(this.$el)),i.removeClass(this.className),this.targets[1].addClass(this.className)):(i=this.targets[0],this.self||(i=i.add(this.$el)),i.addClass(this.className),this.targets[1].removeClass(this.className))):this.$el.toggleClass(this.className),t&&"function"==typeof t&&t.apply(this)},e.prototype.trigger=function(t){Gumby.debug("Triggering Switch",this.$el);var i;this.targets?1==this.targets.length?(i=this.targets[0],this.self||(i=i.add(this.$el)),i.addClass(this.className)):this.targets.length>1&&(i=this.targets[0],this.self||(i=i.add(this.$el)),i.addClass(this.className),this.targets[1].removeClass(this.className)):this.$el.addClass(this.className),t&&"function"==typeof t&&t.apply(this)},Gumby.addInitalisation("toggles",function(e){t(".toggle").each(function(){var s=t(this);return s.data("isToggle")&&!e?!0:(s.data("isToggle")&&e&&s.trigger("gumby.initialize"),s.data("isToggle",!0),new i(s),void 0)})}),Gumby.addInitalisation("switches",function(i){t(".switch").each(function(){var s=t(this);return s.data("isSwitch")&&!i?!0:s.data("isSwitch")&&i?(s.trigger("gumby.initialize"),!0):(s.data("isSwitch",!0),new e(s),void 0)})}),Gumby.UIModule({module:"toggleswitch",events:["initialize","trigger","onTrigger"],init:function(){Gumby.initialize("switches"),Gumby.initialize("toggles")}})}(jQuery),!function(t){"use strict";function i(t,i){Gumby&&Gumby.debug("Initializing Validation",t),this.$this=t,this.$field=this.$this.parents(".field"),this.req=i||function(){return!!this.$this.val().length};var e=this;this.$this.is("[type=checkbox], [type=radio]")?(this.$field=this.$this.parent("label"),this.$field.on("gumby.onChange",function(){e.validate()})):this.$this.is("select")?(this.$field=this.$this.parents(".picker"),this.$field.on("change",function(){e.validate()})):this.$this.on("blur",function(t){9!==t.which&&e.validate()})}i.prototype.validate=function(){var t=this.req(this.$this);return t?this.$field.removeClass("danger").addClass("success"):this.$field.removeClass("success").addClass("danger"),t},t.fn.validation=function(e){var s=t.extend({submit:!1,fail:!1,required:[]},e),n=[];return this.each(function(){if(!s.required.length)return!1;var e,o=t(this),r=s.required.length;for(e=0;r>e;e++)n.push(new i(o.find('[name="'+s.required[e].name+'"]'),s.required[e].validate||!1));o.on("submit",function(t){var i=!1;if(!o.data("passed")){t.preventDefault();var e,r=n.length;for(e=0;r>e;e++)n[e].validate()||(i=!0);if(i){if(s.fail&&"function"==typeof s.fail)return s.fail(),void 0}else{if(s.submit&&"function"==typeof s.submit)return s.submit(o.serializeArray()),void 0;o.data("passed",!0).submit()}}})})}}(jQuery),!function(t){"use strict";Gumby.touchDevice&&Gumby.touchEvents||!Gumby.autoInit?Gumby.touchEvents&&Gumby.touchDevice&&(Gumby.debug("Loading jQuery mobile touch events"),yepnope.errorTimeout=2e3,Modernizr.load({test:Modernizr.touch,yep:Gumby.touchEvents+"/jquery.mobile.custom.min.js",complete:function(){t.mobile||Gumby.error("Error loading jQuery mobile touch events"),Gumby.touchEventsLoaded=!0,Gumby.autoInit?window.Gumby.init():Gumby.uiModulesReady&&Gumby.helpers()}})):window.Gumby.init(),"function"==typeof define&&define.amd&&define(window.Gumby)}(jQuery);
//# sourceMappingURL=gumby.js.map