diff options
Diffstat (limited to 'gum/static/js/libs/gumby.min.js')
-rw-r--r-- | gum/static/js/libs/gumby.min.js | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/gum/static/js/libs/gumby.min.js b/gum/static/js/libs/gumby.min.js new file mode 100644 index 0000000..da25e72 --- /dev/null +++ b/gum/static/js/libs/gumby.min.js @@ -0,0 +1 @@ +!function(){"use strict";function Gumby(){this.$dom=$(document);this.isOldie=!!this.$dom.find("html").hasClass("oldie");this.click="click";this.onReady=this.onOldie=this.onTouch=false;this.uiModules={};this.inits={}}Gumby.prototype.init=function(){this.initUIModules();var scope=this;this.$dom.ready(function(){if(scope.onReady){scope.onReady()}if(scope.isOldie&&scope.onOldie){scope.onOldie()}if(Modernizr.touch&&scope.onTouch){scope.onTouch()}})};Gumby.prototype.ready=function(code){if(code&&typeof code==="function"){this.onReady=code}};Gumby.prototype.oldie=function(code){if(code&&typeof code==="function"){this.onOldie=code}};Gumby.prototype.touch=function(code){if(code&&typeof code==="function"){this.onTouch=code}};Gumby.prototype.debug=function(){return{$dom:this.$dom,isOldie:this.isOldie,uiModules:this.uiModules,click:this.click}};Gumby.prototype.selectAttr=function(){var i=0;for(;i<arguments.length;i++){var attr=arguments[i],dataAttr="data-"+arguments[i],gumbyAttr="gumby-"+arguments[i];if(this.attr(dataAttr)){return this.attr(dataAttr)}else if(this.attr(gumbyAttr)){return this.attr(gumbyAttr)}else if(this.attr(attr)){return this.attr(attr)}}return false};Gumby.prototype.addInitalisation=function(ref,code){this.inits[ref]=code};Gumby.prototype.initialize=function(ref){if(this.inits[ref]&&typeof this.inits[ref]==="function"){this.inits[ref]()}};Gumby.prototype.UIModule=function(data){var module=data.module;this.uiModules[module]=data};Gumby.prototype.initUIModules=function(){var x;for(x in this.uiModules){this.uiModules[x].init()}};window.Gumby=new Gumby}();!function(){"use strict";function Checkbox($el){this.$el=$el;var scope=this;this.$el.on(Gumby.click,function(e){scope.click(e)}).on("gumby.check",function(){scope.update(true)}).on("gumby.uncheck",function(){scope.update(false)});if(scope.$el.hasClass("checked")){scope.update(true)}}Checkbox.prototype.click=function(e){var $target=$(e.target);e.stopPropagation();e.preventDefault();if(this.$el.hasClass("checked")){this.update(false)}else{this.update(true)}};Checkbox.prototype.update=function(check){if(check){this.$el.find("input").prop("checked",true).end().addClass("checked").append('<i class="icon-check" />').trigger("gumby.onCheck").trigger("gumby.onChange")}else{this.$el.find("input").prop("checked",false).end().find("i").remove().end().removeClass("checked").trigger("gumby.onUncheck").trigger("gumby.onChange")}};Gumby.addInitalisation("checkboxes",function(){$(".checkbox").each(function(){var $this=$(this);if($this.data("isCheckbox")){return true}$this.data("isCheckbox",true);new Checkbox($this)})});Gumby.UIModule({module:"checkbox",events:["onCheck","onUncheck","onChange","check","uncheck"],init:function(){Gumby.initialize("checkboxes")}})}();!function(){"use strict";function Fixed($el){this.$el=$el;this.$holder=Gumby.selectAttr.apply(this.$el,["holder"]);this.fixedPoint=Gumby.selectAttr.apply(this.$el,["fixed"]);this.unfixPoint=false;if(this.$holder){this.$holder=$(this.$holder)}else{this.$holder=$(window)}if(this.fixedPoint.indexOf("|")>-1){var points=this.fixedPoint.split("|");this.fixedPoint=points[0];this.unfixPoint=points[1]}this.fixedPoint=this.parseAttrValue(this.fixedPoint);if(this.unfixPoint){this.unfixPoint=this.parseAttrValue(this.unfixPoint)}var scope=this;this.$holder.scroll(function(){scope.scroll()})}Fixed.prototype.scroll=function(){var offset=this.$holder.scrollTop(),fixedPoint=this.fixedPoint,unfixPoint=this.unfixPoint,endPoint=this.endPoint;fixedPoint=fixedPoint instanceof jQuery?this.fixedPoint.offset().top:this.fixedPoint;unfixPoint=unfixPoint instanceof jQuery?this.unfixPoint.offset().top:this.unfixPoint;if(!unfixPoint){unfixPoint=offset*2}if(offset>=fixedPoint&&offset<unfixPoint&&!this.$el.hasClass("fixed")){this.$el.addClass("fixed").trigger("gumby.onFixed")}else if(offset<=fixedPoint&&this.$el.hasClass("fixed")){this.$el.removeClass("fixed").trigger("gumby.onUnfixed",0)}if(unfixPoint&&offset>=unfixPoint&&this.$el.hasClass("fixed")){this.$el.removeClass("fixed").trigger("gumby.onUnfixed",1)}};Fixed.prototype.parseAttrValue=function(attr){if($.isNumeric(attr)){return Number(attr)}else if(attr==="top"){return this.$el.offset().top}else{var $el=$(attr);return $el.length?$el:false}};Gumby.addInitalisation("fixed",function(){$("[data-fixed],[gumby-fixed],[fixed]").each(function(){var $this=$(this);if($this.data("isFixed")){return true}$this.data("isFixed",true);new Fixed($this)})});Gumby.UIModule({module:"fixed",events:["onFixed","onUnfixed"],init:function(){Gumby.initialize("fixed")}})}();!function(){"use strict";if(!Modernizr.touch){return}function Navbar($el){this.$el=$el;var scope=this;this.$el.find("li").on(Gumby.click,function(e){var $this=$(this);e.stopPropagation();if(this.href==="#"){e.preventDefault()}scope.dropdown($this)})}Navbar.prototype.dropdown=function($this){if($this.children(".dropdown").length){if($this.hasClass("active")){$this.removeClass("active")}else{$this.addClass("active")}}else{this.$items.removeClass("active")}};Gumby.addInitalisation("navbars",function(){$(".navbar").each(function(){var $this=$(this);if($this.data("isNavbar")){return true}$this.data("isNavbar",true);new Navbar($this)})});Gumby.UIModule({module:"navbar",events:[],init:function(){Gumby.initialize("navbars")}})}();!function(){"use strict";function RadioBtn($el){this.$el=$el;var scope=this;this.$el.on(Gumby.click,function(e){scope.click(e)}).on("gumby.check",function(){scope.update()});if(scope.$el.hasClass("checked")){scope.update()}}RadioBtn.prototype.click=function(e){var $target=$(e.target);e.stopPropagation();e.preventDefault();this.update()};RadioBtn.prototype.update=function(){var $input=this.$el.find("input[type=radio]"),group='input[name="'+$input.attr("name")+'"]';$(".radio").has(group).removeClass("checked").find("input").prop("checked",false).end().find("i").remove();$input.prop("checked",true);this.$el.append('<i class="icon-dot" />').addClass("checked").trigger("gumby.onChange")};Gumby.addInitalisation("radiobtns",function(){$(".radio").each(function(){var $this=$(this);if($this.data("isRadioBtn")){return true}$this.data("isRadioBtn",true);new RadioBtn($this)})});Gumby.UIModule({module:"radiobtn",events:["onChange","check"],init:function(){Gumby.initialize("radiobtns")}})}();!function(){"use strict";function Retina($el){this.$el=$el;this.imageSrc=this.$el.attr("src");this.retinaSrc=this.fetchRetinaImage();this.$retinaImg=$(new Image);var scope=this;if(!this.retinaSrc){return false}this.$retinaImg.attr("src",this.retinaSrc).load(function(){scope.retinaImageLoaded()})}Retina.prototype.fetchRetinaImage=function(){var imgSrc=this.imageSrc,index=this.imageSrc.search(/(\.|\/)(gif|jpe?g|png)$/i);if(index<0){return false}return imgSrc.substr(0,index)+"@2x"+imgSrc.substr(index,imgSrc.length)};Retina.prototype.retinaImageLoaded=function(){this.$el.attr("src",this.$retinaImg.attr("src")).trigger("gumby.onRetina")};Gumby.addInitalisation("retina",function(){if(!window.devicePixelRatio||window.devicePixelRatio<=1){return}$("img[data-retina],img[gumby-retina],img[retina]").each(function(){var $this=$(this);if($this.data("isRetina")){return true}$this.data("isRetina",true);new Retina($this)})});Gumby.UIModule({module:"retina",events:["onRetina"],init:function(){Gumby.initialize("retina")}})}();!function(){"use strict";function SkipLink($el){this.$el=$el;this.targetPos=0;this.duration=Number(Gumby.selectAttr.apply(this.$el,["duration"]))||200;this.offset=Gumby.selectAttr.apply(this.$el,["offset"])||false;this.easing=Gumby.selectAttr.apply(this.$el,["easing"])||"swing";var scope=this;this.$el.on(Gumby.click+" gumby.skip",function(e){e.preventDefault();scope.calculateTarget()})}SkipLink.prototype.calculateTarget=function(){var scope=this,target=Gumby.selectAttr.apply(this.$el,["goto"]),$target;if(target=="top"){this.targetPos=0}else if($.isNumeric(target)){this.targetPos=Number(target)}else{$target=$(target);if(!$target){return false}this.targetPos=$target.offset().top}this.skipTo()};SkipLink.prototype.skipTo=function(){var scope=this;$("html,body").animate({scrollTop:this.calculateOffset()},this.duration,this.easing).promise().done(function(){scope.$el.trigger("gumby.onComplete")})};SkipLink.prototype.calculateOffset=function(){if(!this.offset){return this.targetPos}var op=this.offset.substr(0,1),off=Number(this.offset.substr(1,this.offset.length));if(op==="-"){return this.targetPos-off}else if(op==="+"){return this.targetPos+off}};Gumby.addInitalisation("skiplinks",function(){$(".skiplink > a, .skip").each(function(){var $this=$(this);if($this.data("isSkipLink")){return true}$this.data("isSkipLink",true);new SkipLink($this)})});Gumby.UIModule({module:"skiplink",events:["onComplete","skip"],init:function(){Gumby.initialize("skiplinks")}})}();!function(){"use strict";function Tabs($el){this.$el=$el;this.$nav=this.$el.find("ul.tab-nav > li");this.$content=this.$el.find(".tab-content");var scope=this;this.$nav.children("a").on(Gumby.click,function(e){e.preventDefault();scope.click($(this))});this.$el.on("gumby.set",function(e,index){scope.set(e,index)})}Tabs.prototype.click=function($this){var index=$this.parent().index();this.$nav.add(this.$content).removeClass("active");this.$nav.eq(index).add(this.$content.eq(index)).addClass("active");this.$el.trigger("gumby.onChange",index)};Tabs.prototype.set=function(e,index){this.$nav.eq(index).find("a").trigger(Gumby.click)};Gumby.addInitalisation("tabs",function(){$(".tabs").each(function(){var $this=$(this);if($this.data("isTabs")){return true}$this.data("isTabs",true);new Tabs($this)})});Gumby.UIModule({module:"tabs",events:["onChange","set"],init:function(){Gumby.initialize("tabs")}})}();!function(){"use strict";function Toggle($el){this.$el=$($el);this.targets=[];this.on="";if(this.$el.length){this.init()}}function Switch($el){this.$el=$($el);this.targets=[];this.on="";if(this.$el.length){this.init()}}Toggle.prototype.init=function(){this.targets=this.parseTargets();this.on=Gumby.selectAttr.apply(this.$el,["on"])||Gumby.click;var scope=this;this.$el.on(this.on,function(e){if($(this).prop("tagName")==="A"){e.preventDefault()}e.stopPropagation();scope.trigger(scope.triggered)}).on("gumby.trigger",function(){scope.trigger(scope.triggered)})};Toggle.prototype.parseTargets=function(){var targetStr=Gumby.selectAttr.apply(this.$el,["trigger"]),secondaryTargets=0,targets=[];if(!targetStr){return false}secondaryTargets=targetStr.indexOf("|");if(secondaryTargets===-1){return[$(targetStr)]}targets=targetStr.split("|");return targets.length>1?[$(targets[0]),$(targets[1])]:[$(targets[0])]};Toggle.prototype.triggered=function(){this.$el.trigger("gumby.onTrigger",[this.$el.hasClass("active")])};Switch.prototype=new Toggle;Toggle.prototype.trigger=function(cb){if(!this.targets){this.$el.toggleClass("active")}else if(this.targets.length==1){this.$el.add(this.targets[0]).toggleClass("active")}else if(this.targets.length>1){if(this.targets[0].hasClass("active")){this.$el.add(this.targets[0]).removeClass("active");this.targets[1].addClass("active")}else{this.targets[1].removeClass("active");this.$el.add(this.targets[0]).addClass("active")}}if(cb&&typeof cb==="function"){cb.apply(this)}};Switch.prototype.trigger=function(cb){if(!this.targets){this.$el.addClass("active")}else if(this.targets.length==1){this.$el.add(this.targets[0]).addClass("active")}else if(this.targets.length>1){this.$el.add(this.targets[0]).addClass("active");this.targets[1].removeClass("active")}if(cb&&typeof cb==="function"){cb.apply(this)}};Gumby.addInitalisation("toggles",function(){$(".toggle").each(function(){var $this=$(this);if($this.data("isToggle")){return true}$this.data("isToggle",true);new Toggle($this)})});Gumby.addInitalisation("switches",function(){$(".switch").each(function(){var $this=$(this);if($this.data("isSwitch")){return true}$this.data("isSwitch",true);new Switch($this)})});Gumby.UIModule({module:"toggleswitch",events:["trigger","onTrigger"],init:function(){Gumby.initialize("switches");Gumby.initialize("toggles")}})}();!function($){"use strict";function Validation($this,req){this.$this=$this;this.$field=this.$this.parents(".field");this.req=req||function(){return!!this.$this.val().length};var scope=this;if(this.$this.is("[type=checkbox], [type=radio]")){this.$field=this.$this.parent("label");this.$field.on("gumby.onChange",function(){scope.validate()})}else if(this.$this.is("select")){this.$field=this.$this.parents(".picker");this.$field.on("change",function(){scope.validate()})}else{this.$this.on("blur",function(e){if(e.which!==9){scope.validate()}})}}Validation.prototype.validate=function(){var result=this.req(this.$this);if(!result){this.$field.removeClass("success").addClass("danger")}else{this.$field.removeClass("danger").addClass("success")}return result};$.fn.validation=function(options){var settings=$.extend({submit:false,fail:false,required:[]},options),validations=[];return this.each(function(){if(!settings.required.length){return false}var $this=$(this),reqLength=settings.required.length,i;for(i=0;i<reqLength;i++){validations.push(new Validation($this.find('[name="'+settings.required[i].name+'"]'),settings.required[i].validate||false))}$this.on("submit",function(e){var failed=false;if(!$this.data("passed")){e.preventDefault();var reqLength=validations.length,i;for(i=0;i<reqLength;i++){if(!validations[i].validate()){failed=true}}if(!failed){if(settings.submit&&typeof settings.submit==="function"){settings.submit($this.serializeArray());return}$this.data("passed",true).submit()}else{if(settings.fail&&typeof settings.fail==="function"){settings.fail();return}}}})})}}(jQuery);Modernizr.load({test:Modernizr.touch,yep:"js/libs/jquery.mobile.custom.min.js",callback:function(url,result,key){if($.mobile){window.Gumby.click="tap"}},complete:function(){window.Gumby.init();if(typeof define=="function"&&define.amd){define(window.Gumby)}}});
\ No newline at end of file |