12345678 |
- /**
- * Featherlight - ultra slim jQuery lightbox
- * Version 0.4.9 - http://noelboss.github.io/featherlight/
- *
- * Copyright 2014, Noël Raoul Bossart (http://www.noelboss.com)
- * MIT Licensed.
- **/
- !function(a){"use strict";if("undefined"==typeof a)return void("console"in window&&window.console.info("Too much lightness, Featherlight needs jQuery."));var b=a.featherlight=function(c,d){if(this.constructor===b)this.id=b.id++;else{if("string"==typeof c||!1!=c instanceof a){var e=(new b).setup(c,d);return e.config.open.call(e),e}d=a.extend({},b.defaults,c||{}),a(d.selector,d.context).featherlight()}},c=function(a){if(27===a.keyCode&&!a.isDefaultPrevented()){var c=b.current();c&&c.config.closeOnEsc&&(c.$instance.find("."+c.config.namespace+"-close:first").click(),a.preventDefault())}};a.extend(b,{id:0,defaults:{autostart:!0,namespace:"featherlight",selector:"[data-featherlight]",context:"body",type:{image:!1,ajax:!1},targetAttr:"data-featherlight",variant:null,resetCss:!1,background:null,openTrigger:"click",closeTrigger:"click",openSpeed:250,closeSpeed:250,closeOnClick:"background",closeOnEsc:!0,closeIcon:"✕",beforeOpen:a.noop,beforeClose:a.noop,afterOpen:a.noop,afterClose:a.noop,contentFilters:["jquery","image","html","ajax"],open:function(a){var b=this.config.beforeOpen.call(this,a);return!1!==b&&(b=this.open(a)),!1!==b&&this.config.afterOpen.call(this,a),b},close:function(a){var b=this.config.beforeClose.call(this,a);!1!==b&&this.close(a)}},methods:{setup:function(c,d){"object"!=typeof c||c instanceof a!=!1||d||(d=c,c=void 0),d=a.extend({},b.defaults,d);var e=d.resetCss?d.namespace+"-reset":d.namespace,f=a(d.background||'<div class="'+e+'"><div class="'+e+'-content"><span class="'+e+"-close-icon "+d.namespace+'-close">'+d.closeIcon+"</span></div></div>"),g=this;return a.extend(g,{config:d,target:c,$instance:f.clone().addClass(d.variant)}),g.$instance.on(d.closeTrigger+"."+d.namespace,function(b){var c=a(b.target);("background"===d.closeOnClick&&c.is("."+d.namespace)||"anywhere"===d.closeOnClick||c.is("."+d.namespace+"-close"))&&(b.preventDefault(),d.close.call(g))}),this},attach:function(b,c,d){var e={};return a.each(b[0].attributes,function(){var b=this.name.match(/^data-featherlight-(.*)/);if(b){var c=this.value;try{c=a.parseJSON(c)}catch(d){}e[a.camelCase(b[1])]=c}}),this.$elm=b,this.setup(c,a.extend(e,d)),b.on(this.config.openTrigger+"."+this.config.namespace,a.proxy(this.config.open,this)),this},getContent:function(){var c,d=this,e=d.target||d.$elm.attr(d.config.targetAttr)||"";for(var f in d.config.type)d.config.type[f]===!0&&(c=b.contentFilters[f]);if(!c&&e in b.contentFilters&&(c=b.contentFilters[e],e=d.target&&d.$elm.attr(d.config.targetAttr)),e=e||d.$elm.attr("href")||"",!c){var g=e;if(e=null,a.each(d.config.contentFilters,function(){return c=b.contentFilters[this],c.test&&(e=c.test(g)),!e&&c.regex&&g.match&&g.match(c.regex)&&(e=g),!e}),!e)return"console"in window&&window.console.error("Featherlight: no content filter found "+(g?' for "'+g+'"':" (no target specified)")),!1}return c.process.call(d,e)},setContent:function(b){var c=this;(b.is("iframe")||a("iframe",b).length>0)&&c.$instance.addClass(c.config.namespace+"-iframe"),c.$content=b.clone().addClass(c.config.namespace+"-inner"),c.$instance.find("."+c.config.namespace+"-inner").remove(),c.$instance.find("."+c.config.namespace+"-content").append(c.$content)},open:function(d){var e=this;d&&d.preventDefault();var f=this.getContent();return f?(e.constructor._opened.add(e._openedCallback=function(a){e.$instance.closest("body").length>0&&(a.currentFeatherlight=e)}),this.config.closeOnEsc&&c&&(a(document).bind("keyup."+b.defaults.namespace,c),c=null),this.setContent(f),this.$instance.appendTo("body").fadeIn(this.config.openSpeed),void 0):!1},close:function(a){var b=this;b.constructor._opened.remove(b._openedCallback),b.$instance.fadeOut(b.config.closeSpeed,function(){b.$instance.detach(),b.config.afterClose.call(b,a)})}},contentFilters:{jquery:{regex:/^[#.]\w/,test:function(b){return b instanceof a&&b},process:function(b){return a(b)}},image:{regex:/\.(png|jpg|jpeg|gif|tiff|bmp)(\?\S*)?$/i,process:function(b){return a('<img src="'+b+'" alt="" class="'+this.config.namespace+'-image" />')}},html:{regex:/^\s*<[\w!][^<]*>/,process:function(b){return a(b)}},ajax:{regex:/./,process:function(b){var c=this,d=a("<div></div>").load(b,function(b,e){"error"!==e&&a.featherlight(d.html(),a.extend({},c.config,{type:{html:!0}}))})}}},current:function(){var a={};return this._opened.fire(a),a.currentFeatherlight},close:function(){var a=b.current();a&&a.config.close.call(a)},_opened:a.Callbacks()}),b.prototype=a.extend({constructor:b},b.methods),a.fn.featherlight=function(c,d){return this.each(function(){(new b).attach(a(this),d,c)}),this},a(document).ready(function(){var c=b.defaults;c.autostart&&a(c.selector,c.context).featherlight()})}(jQuery);
|