meta-lightbox/dist/js/app.js

2 lines
11 KiB
JavaScript

/*! For license information please see app.js.LICENSE.txt */
!function(){"use strict";var t={n:function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,{a:o}),o},d:function(e,o){for(var a in o)t.o(o,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:o[a]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}},e=jQuery,o="ajax-load",a="back-online",n="load";function _typeof(t){return(_typeof="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function _typeof(t){return typeof t}:function _typeof(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _defineProperties(t,e){for(var o=0;o<e.length;o++){var a=e[o];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}!function($){var t=window,e=$(t),i=document,c=$("body"),l="MetaLightboxUI",r='<div class="meta-lightbox-error"><div class="alert alert-error alert-danger">Connection failure.</div></div>',s=function(){function MetaLightboxUI(){!function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,MetaLightboxUI)}return function _createClass(t,e,o){return e&&_defineProperties(t.prototype,e),o&&_defineProperties(t,o),t}(MetaLightboxUI,null,[{key:"init",value:function init(){console.log("".concat(l,": init ..."));var t=this;t.isMSIE=0;try{t.isHidpi=t.is_hdpi()}catch(e){console.log("".concat(l,": catch"))}$(".js".concat(l,',[data-toggle="lightbox"],[data-lightbox-gallery]')).on("click",(function(e){e.preventDefault(),e.stopPropagation();var o=$(e.currentTarget);t.show(o)})),$(".js".concat(l,"-close-inline")).on("click",(function(t){$(t.currentTarget).parents(".meta-lightbox-overlay").removeClass("meta-lightbox-open")}))}},{key:"is_hdpi",value:function is_hdpi(){console.log("".concat(l,": isHidpi"));return t.devicePixelRatio>1||t.matchMedia&&t.matchMedia("(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)").matches}},{key:"show",value:function show(t){console.log("".concat(l,": show"));var e=this;if(e.constructLightbox()){var o=e.$content;if(o){if(c.addClass("meta-lightbox-body-effect-fade"),e.process(o,t),t.data("lightbox-gallery")){var a=$('[data-lightbox-gallery="'.concat(t.data("lightbox-gallery"),'"]'));1===a.length?$(".meta-lightbox-nav").hide():$(".meta-lightbox-nav").show(),$(".meta-lightbox-prev").off("click").on("click",(function(o){o.preventDefault();var n=a.index(t),i=a.eq(n-1);i.length||(i=a.last()),setTimeout((function(){e.show(i)}),10)})),$(".meta-lightbox-next").off("click").on("click",(function(o){o.preventDefault();var n=a.index(t),i=a.eq(n+1);i.length||(i=a.first()),setTimeout((function(){e.show(i)}),10)}))}setTimeout((function(){e.$overlay.addClass("meta-lightbox-open")}),1)}}}},{key:"constructLightbox",value:function constructLightbox(){console.log("".concat(l,": constructLightbox"));var t=this,e=$("<div>",{class:"meta-lightbox-overlay meta-lightbox-theme-default meta-lightbox-effect-fade"}),o=$("<div>",{class:"meta-lightbox-wrap"}),a=$("<div>",{class:"meta-lightbox-content"}),n=$('<a href="#" class="meta-lightbox-nav meta-lightbox-prev"><i class="fas fa fa-chevron-left"></i> <span class="sr-only">Previous</span></a><a href="#" class="meta-lightbox-nav meta-lightbox-next"><i class="fa fas fa-chevron-right"></i> <span class="sr-only">Next</span></a>'),i=$('<a href="#" class="meta-lightbox-close fas fa fa-times" title="Close"><span class="sr-only">Close</span></a>'),r=$("<div>",{class:"meta-lightbox-title-wrap"});return t.$overlay||(t.isMSIE&&e.addClass("meta-lightbox-ie"),o.append(a),o.append(r),e.append(o),e.append(n),e.append(i),c.append(e),e.on("click",(function(e){e.preventDefault(),t.hide()})),i.on("click",(function(e){e.preventDefault(),t.hide()})),t.$overlay=e,t.$content=a,t.$title=r),t.$overlay}},{key:"setTitle",value:function setTitle(t){this.$title.html(t)}},{key:"process",value:function process(o,a){console.log("".concat(l,": process"));var n=this,c=a.attr("href")&&a.attr("href").length?a.attr("href"):a.data("href");n.$content.attr("class","meta-lightbox-content"),n.$content.addClass(a.data("lightbox-class")),c.length||(console.log(a),console.error("".concat(l,": href(attr/data) is missing")));var s=$("#PageLoading .loading-spinner"),f=s.length?s.clone():"";if(n.$content.append(f).addClass("meta-lightbox-loading"),c.match(/\.(jpeg|jpg|gif|png|svg)$/i)||"image"===a.data("force")){$.ajax({url:c,success:function success(){var t=$("<img>",{src:c}),a=$('<div class="meta-lightbox-image"></div>'),i=$('<span class="meta-lightbox-zoom-wrapper"></span>');i.append(t),a.append(i),a.css({"line-height":"".concat(o.height(),"px"),height:"".concat(o.height(),"px")}),e.resize((function(){a.css({"line-height":"".concat(o.height(),"px"),height:"".concat(o.height(),"px")})})),"undefined"!==typeof i.zoom?i.zoom():i.addClass("no-zoom"),n.$content.html(a),n.contentLoaded()},error:function error(t,e){var o=$(r);n.$content.html(o),n.contentLoaded()}});var d=a.data("title")?a.data("title"):a.attr("title");n.setTitle(d),"function"===typeof ga&&ga("send","event","meta","Image Click",c)}else if(c.match(/(youtube|youtube-nocookie|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/)||"youtube"===a.data("force")||"vimeo"===a.data("force")){var h,g=c.match(/(youtube|youtube-nocookie|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/),u="meta-lightbox-video";if("youtube"==g[1]&&(h="https://www.youtube.com/embed/".concat(g[4]),u="".concat(u," meta-lightbox-youtube")),"youtu"==g[1]&&(h="https://www.youtube.com/embed/".concat(g[3]),u="".concat(u," meta-lightbox-youtube")),"youtube-nocookie"==g[1]&&(h="https://www.youtube-nocookie.com/embed/".concat(g[4]),u="".concat(u," meta-lightbox-youtube")),"vimeo"==g[1]&&(h="https://player.vimeo.com/video/".concat(g[3]),u="".concat(u," meta-lightbox-vimeo")),!h)return console.warn("".concat(l,": Video loading bad URL")),!1;if(!n.loadIframe(h,u))return a.addClass("meta-offline"),!1;a.removeClass("meta-offline");var m=a.data("title")?a.data("title"):a.attr("title");n.setTitle(m),"function"===typeof ga&&ga("send","event","meta","Video Click",g)}else if("#"==c.substring(0,1)||"inline"===a.data("force"))$(c).length?(wrap=$('<div class="meta-lightbox-inline" />'),wrap.append($(c).clone().show()),wrap.outerHeight()<n.$content.height()&&wrap.css({position:"relative",top:"50%","margin-top":"".concat(-wrap.outerHeight()/2,"px")}),e.resize((function(){wrap.outerHeight()<n.$content.height()&&wrap.css({position:"relative",top:"50%","margin-top":"".concat(-wrap.outerHeight()/2,"px")})})),n.$content.html(wrap),n.contentLoaded()):(wrap=$(r),n.$content.html(wrap),n.contentLoaded()),$(".meta-lightbox-title-wrap").html(""),"function"===typeof ga&&ga("send","event","meta","inline HTML click",c);else{if(a.data("force-iframe")||"iframe"===a.data("force"))return console.log("".concat(l,": IFrame forced")),n.loadIframe(c,"meta-lightbox-iframe-content")?(a.removeClass("meta-offline"),!0):(a.addClass("meta-offline"),!1);console.log("".concat(l,": loading AJAX")),$.ajax({sync:!1,async:!0,url:c,dataType:"html",method:"GET",cache:!1,statusCode:{404:function _(){console.log("".concat(l,": page not found")),t.location.href=url},302:function _(){console.log("".concat(l,": redirect 302")),t.location.href=url}},error:function error(t,e){console.log("".concat(l,": AJAX request failure.").concat(t.statusText));var o=$(r);n.$content.html(o),n.contentLoaded(),"function"===typeof ga&&ga("send","event","error","AJAX ERROR",t.statusText)},success:function success(e,o,a){console.log("".concat(l,": AJAX success"));try{var c=$.parseJSON(e);if("object"===_typeof(c)){if(console.log("".concat(l,": AJAX JSON")),"object"===_typeof(c.regions)&&"undefinded"!==typeof c.regions.LayoutAjax){var r=$('<div class="meta-lightbox-ajax" />');r.html(c.regions.LayoutAjax),n.$content.html(r),n.contentLoaded()}var s=a.getResponseHeader("X-Title"),f=a.getResponseHeader("X-Link");s&&s.length&&f&&f.length&&f!==t.location.href&&f.substring(0,f.indexOf("#"))!==t.location.href.replace($("base").attr("href"),"/")&&($(".meta-lightbox-ajax").data("curr-title",i.title),$(".meta-lightbox-ajax").data("curr-link",t.location.href),"undefined"!==typeof t.localStorage&&"/"!==f&&t.localStorage.setItem("current-page",f),i.URL!==f&&i.URL!==$("base").attr("href")+f&&i.URL!=="".concat($("base").attr("href"),"/").concat(f)&&t.history.pushState({title:s,page:f,ajax:"true"},s,f),$(".meta-lightbox-title-wrap").html(""),"function"===typeof ga&&(ga("set",{page:f.replace($("base").attr("href"),""),title:s}),ga("send","pageview")))}}catch(h){console.log("".concat(l,": AJAX HTML"));var d=$('<div class="meta-lightbox-ajax" />');d.append(e),n.$content.html(d),n.contentLoaded()}n.contentLoaded()}})}}},{key:"loadIframe",value:function loadIframe(t,e){var o=this,a=$("<iframe>",{src:t,class:e,frameborder:0,vspace:0,hspace:0,scrolling:"auto",allowtransparency:"true"});return console.log("".concat(l,": loading iframe")),c.append('<div id="MetaIFramePreload" class="hidden d-none iframe-preload" style="display:none"></div>'),$("#MetaIFramePreload").html(a),a.on("load",(function(){if(c.hasClass("is-offline"))return console.warn("".concat(l,": Unable to load iframe offline")),!1;o.finishIFrameLoading()})),a}},{key:"finishIFrameLoading",value:function finishIFrameLoading(){var t=this,e=$("#MetaIFramePreload");if(!e.length)return console.warn("".concat(l,": iframe preload not found")),!1;var o=e.find("iframe");if(!o.length)return console.warn("".concat(l,": iframe preload > iframe not found")),!1;console.log("".concat(l,": the iframe was loaded")),e.html(""),e.remove(),t.$content.addClass("iframe-delay"),t.$content.html(o),t.contentLoaded(),setTimeout((function(){t.$content.removeClass("iframe-delay")}),1e3)}},{key:"contentLoaded",value:function contentLoaded(){var t=this;t.$content.removeClass("meta-lightbox-loading"),$(".meta-lightbox-content .js".concat(l,',.meta-lightbox-content [data-toggle="lightbox"],.meta-lightbox-content [data-lightbox-gallery]')).on("click",(function(e){e.preventDefault(),e.stopPropagation();var o=$(e.currentTarget);t.show(o)})),$(".js".concat(l,"-close")).on("click",(function(e){e.preventDefault(),t.hide()})),setTimeout((function(){e.trigger("meta-lightbox-loaded")}),1),setTimeout((function(){c.addClass("meta-lightbox-body-effect-fade")}),600)}},{key:"hide",value:function hide(e){var o=this.$overlay,a=$(".meta-lightbox-ajax").data("curr-title"),n=$(".meta-lightbox-ajax").data("curr-link");a&&n&&("undefined"!==typeof t.localStorage&&"/"!==n&&t.localStorage.setItem("current-page",n),i.URL!==n&&i.URL!==$("base").attr("href")+n&&i.URL!=="".concat($("base").attr("href"),"/").concat(n)&&t.history.replaceState({title:a,page:n,ajax:"true"},a,n)),o.removeClass("meta-lightbox-open"),c.removeClass("meta-lightbox-body-effect-fade"),$(".meta-lightbox-content .meta-lightbox-zoom-wrapper").trigger("zoom.destroy"),this.isMSIE&&(o.find("iframe").attr("src"," "),o.find("iframe").remove()),$(".meta-lightbox-prev").off("click"),$(".meta-lightbox-next").off("click"),$(".meta-lightbox-content").empty(),c.removeClass("meta-lightbox-body-effect-fade")}}]),MetaLightboxUI}();e.on("MetaLightboxUI.init ".concat(o," ").concat(n),(function(){s.init()})),e.on("".concat(a),(function(){$(".meta-offline").removeClass("meta-offline"),console.log("".concat(l,": reloading iframe")),s.finishIFrameLoading();var t=$(".meta-lightbox-content iframe");t.length&&t.attr("src",t.attr("src"))})),t.MetaLightboxUI=s}(t.n(e)())}();