-
Notifications
You must be signed in to change notification settings - Fork 0
/
lity.min.js
4 lines (4 loc) · 4.58 KB
/
lity.min.js
1
2
3
4
/*! Lity - v1.2.0 - 2015-06-03
* http://sorgalla.com/lity/
* Copyright (c) 2015 Jan Sorgalla; Licensed MIT */
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return b(a,c)}):"object"==typeof module&&"object"==typeof module.exports?module.exports=b(a,require("jquery")):a.lity=b(a,a.jQuery||a.Zepto)}(window,function(a,b){"use strict";function c(a){var c=b.Deferred();return t?(a.one(t,c.resolve),setTimeout(c.resolve,500)):c.resolve(),c.promise()}function d(a,c,d){if(1===arguments.length)return b.extend({},a);if("string"==typeof c){if("undefined"==typeof d)return"undefined"==typeof a[c]?null:a[c];a[c]=d}else b.extend(a,c);return this}function e(){return"file:"===a.location.protocol?"http:":""}function f(a,b){return a+(a.indexOf("?")>-1?"&":"?")+b}function g(a){return b('<span class="lity-error"/>').append(a)}function h(a){if(!n.test(a))return!1;var c=b('<img src="'+a+'">'),d=b.Deferred(),e=function(){d.reject(g("Failed loading image"))};return c.on("load",function(){return 0===this.naturalWidth?e():void d.resolve(c)}).on("error",e),d.promise()}function i(a){var c;try{c=b(a)}catch(d){return!1}if(!c.length)return!1;var e=b('<span style="display:none !important" class="lity-inline-placeholder"/>');return c.after(e).on("lity:ready",function(a,b){b.one("lity:close",function(){e.before(c.addClass("lity-hide")).remove()})})}function j(a){var b,c,d,g=a;return c=o.exec(a),c&&(d=c[1].indexOf("nocookie")>-1?"-nocookie":"",g=e()+"//www.youtube"+d+".com/embed/"+c[3],c[5]&&(g=f(g,"list="+c[5])),g=f(g,"autoplay=1")),a.indexOf("vimeo.")>-1&&a.indexOf("player.vimeo.")<0&&(b=p.exec(a.split("//")[1])[1],g=e()+"//player.vimeo.com/video/"+b+"?autoplay=1"),c=q.exec(a),c&&(g=f(e()+"//www.google."+c[3]+"/maps?"+c[6],"output="+(c[6].indexOf("layer=c")>0?"svembed":"embed"))),'<div class="lity-iframe-container"><iframe frameborder="0" allowfullscreen src="'+g+'"></iframe></div>'}function k(a){function e(a){27===a.keyCode&&j()}function f(){var a=l.documentElement.clientHeight?l.documentElement.clientHeight:Math.round(m.height());o.css("max-height",Math.floor(a)+"px").trigger("lity:resize",[n,k])}function g(a){n&&(o=b(a),m.on("resize",f),f(),n.find(".lity-loader").each(function(){var a=b(this);c(a).always(function(){a.remove()})}),n.removeClass("lity-loading").find(".lity-content").empty().append(o),o.removeClass("lity-hide").trigger("lity:ready",[n,k]),t.resolve())}function h(a,c,d){n=b(u).appendTo("body"),d.esc&&m.one("keyup",e),setTimeout(function(){n.addClass("lity-opened lity-"+a).on("click","[data-lity-close]",function(a){b(a.target).is("[data-lity-close]")&&j()}).trigger("lity:open",[n,k]),b.when(c).always(g)},0)}function i(a,c){var d,e;if(c.handler&&q[c.handler])e=q[c.handler](a,instance,k),d=c.handler;else{var f=b.extend({},q),g={};b.each(["inline","iframe"],function(a,b){f[b]&&(g[b]=f[b]),delete f[b]});var i=function(b,c){return c?(e=c(a,k),e?(d=b,!1):void 0):!0};b.each(f,i),d||b.each(g,i)}return e&&(t=b.Deferred(),b.when(j()).done(b.proxy(h,null,d,e,c))),!!e}function j(){if(n){var a=b.Deferred();return t.done(function(){m.off("resize",f).off("keyup",e),o&&o.trigger("lity:close",[n,k]),n.removeClass("lity-opened").addClass("lity-closed");var b=n;n=null,o=null,c(b).always(function(){b.remove(),a.resolve()})}),a.promise()}}function k(a){if(!a.preventDefault)return k.open(a);var c=b(this),d=c.data("lity-target")||c.attr("href")||c.attr("src");if(d){var e=b.extend({},p,c.data("lity-options")||c.data("lity"));i(d,e)&&a.preventDefault()}}var n,o,p=b.extend({},s),q=b.extend({},r),t=b.Deferred().resolve();return k.handlers=b.proxy(d,k,q),k.options=b.proxy(d,k,p),k.open=function(a){return i(a,p),k},k.close=function(){return j(),k},k.options(a)}var l=a.document,m=b(a),n=/\.(png|jpg|jpeg|gif|tiff|bmp)(\?\S*)?$/i,o=/(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})([&|\?]+list=([^&]+))?.*/i,p=/\/([^\?&]+)$/,q=/((maps|www)\.)?google\.([^\/\?]+)\/?((maps\/?)?\?)(.*)/i,r={image:h,inline:i,iframe:j},s={esc:!0,handler:null},t=function(){var a=l.createElement("div"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return b[c];return!1}(),u='<div class="lity lity-loading" tabindex="-1"><div class="lity-wrap" data-lity-close><div class="lity-loader">Loading...</div><div class="lity-container"><div class="lity-content"></div><button class="lity-close" type="button" title="Close (Esc)" data-lity-close>×</button></div></div></div>';return k.version="1.2.0",k.handlers=b.proxy(d,k,r),k.options=b.proxy(d,k,s),b(l).on("click","[data-lity]",k()),k});