nextend-litebox.min.js 7.54 KB
!function(t,e){function o(){return null!=navigator.userAgent.match(/iPhone/i)||null!=navigator.userAgent.match(/iPod/i)}function i(){return null!=navigator.userAgent.match(/iPad/i)&&!o()}function n(e,o){this.timeout=!1,this.clickTimeout=!1,this.element=e,this.$element=t(this.element),this.options=t.extend({},r,o),this._defaults=r,this._name=s,this.init()}function l(){return window.innerHeight?window.innerHeight:t(window).height()}function a(e){t(e).each(function(){var e=new Image;e.src=this,e.width>0&&t("<img />").attr("src",this).addClass("litebox-preload").appendTo("body").hide()})}var s="liteBox",r={revealSpeed:400,background:"rgba(0,0,0,.8)",overlayClose:!0,escKey:!0,navKey:!0,closeTip:"tip-l-fade",closeTipText:"Close",prevTip:"tip-t-fade",prevTipText:"Previous",nextTip:"tip-t-fade",nextTipText:"Next",autoplay:!1,callbackInit:function(){},callbackBeforeOpen:function(){},callbackAfterOpen:function(){},callbackBeforeClose:function(){},callbackAfterClose:function(){},callbackError:function(){},callbackPrev:function(){},callbackNext:function(){},errorMessage:"Error loading content."};n.prototype={init:function(){var t=this;this.$element.on("click n2click",function(e){nextend.shouldPreventClick||t.clickTimeout===!1&&(e.preventDefault(),t.openLitebox(),t.clickTimeout=setTimeout(function(){t.clickTimeout=!1},300))}),this.options.callbackInit.call(this)},openLitebox:function(){var e=this;this.options.callbackBeforeOpen.call(this),e.buildLitebox();var n=this.$element;if(e.populateLitebox(n),e.options.overlayClose&&$litebox.on("click",function(o){e.clickTimeout===!1&&(o.target===this||t(o.target).hasClass("litebox-container")||t(o.target).hasClass("litebox-error"))&&e.closeLitebox()}),$close.on("click",function(){e.clickTimeout===!1&&e.closeLitebox()}),this.$element.attr("data-litebox-group")){var e=this,l=this.$element.attr("data-litebox-group"),s=t('[data-litebox-group="'+this.$element.attr("data-litebox-group")+'"]'),r=[];t('[data-litebox-group="'+l+'"]').each(function(){var e=t(this).attr("href")||t(this).data("href");r.push(e)}),a(r),t(".litebox-nav").show(),$prevNav.off("click").on("click",function(){e.options.callbackPrev.call(this);var o=s.index(n);n=s.eq(o-1),t(n).length||(n=s.last()),e.populateLitebox(n)}),$nextNav.off("click").on("click",function(){e.options.callbackNext.call(this);var o=s.index(n);n=s.eq(o+1),t(n).length||(n=s.first()),e.populateLitebox(n),e.startAutoplay()})}var c=27,p=37,d=39;t("body").on("keydown.litebox",function(o){e.options.escKey&&o.keyCode==c&&(o.stopImmediatePropagation(),e.closeLitebox()),e.options.navKey&&o.keyCode==p&&(o.stopImmediatePropagation(),t(".litebox-prev").trigger("click")),e.options.navKey&&o.keyCode==d&&(o.stopImmediatePropagation(),t(".litebox-next").trigger("click"))}),this.startAutoplay(),this.options.callbackAfterOpen.call(this),(i()||o())&&t(".litebox-container").addClass("litebox-iframe-holder")},startAutoplay:function(){if(this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.options.autoplay){this.timeout=setTimeout(function(){t(".litebox-next").trigger("click")},this.options.autoplay)}},buildLitebox:function(){$litebox=t("<div>",{"class":"litebox-overlay"}),$close=t("<div>",{"class":"litebox-close "+this.options.closeTip,"data-tooltip":this.options.closeTipText}),$text=t("<div>",{"class":"litebox-text"}),$error=t('<div class="litebox-error"><span>'+this.options.errorMessage+"</span></div>"),$prevNav=t("<div>",{"class":"litebox-nav litebox-prev "+this.options.prevTip,"data-tooltip":this.options.prevTipText}),$nextNav=t("<div>",{"class":"litebox-nav litebox-next "+this.options.nextTip,"data-tooltip":this.options.nextTipText}),$container=t("<div>",{"class":"litebox-container"}),$loader=t("<div>",{"class":"litebox-loader"}),t(document.fullscreenElement||document.msFullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.body).prepend($litebox.css({"background-color":this.options.background})),$litebox.append($close,$text,$prevNav,$nextNav,$container),$litebox.fadeIn(this.options.revealSpeed)},populateLitebox:function(e){var o=this,i=e.attr("href")||e.data("href"),n=t(".litebox-content");this.options.autoplay=e.data("autoplay")||this.options.autoplay,$litebox.append($loader);var l=e.data("title");if("undefined"==typeof l||""==l)t(".litebox-text").removeClass("active"),t(".litebox-text").html();else{l="<b>"+l+"</b>";var a=e.data("description");"undefined"!=typeof a&&""!=a&&(l+=" - "+a),t(".litebox-text").html(l),t(".litebox-text").addClass("active")}if(null!==i.match(/\.(jpeg|jpg|gif|png|bmp)/i)){var s=t("<img>",{src:i,"class":"litebox-content"});o.transitionContent("image",n,s),t("img.litebox-content").n2imagesLoaded(function(){$loader.remove()}),s.error(function(){o.liteboxError(),$loader.remove()})}else if(videoURL=i.match(/(youtube|youtu|vimeo|dailymotion|kickstarter)\.(com|be)\/((watch\?v=([-\w]+))|(video\/([-\w]+))|(projects\/([-\w]+)\/([-\w]+))|([-\w]+))/)){var r="";if("youtube"==videoURL[1]&&(r="https://www.youtube.com/embed/"+videoURL[5]+"?fs=1&amp;wmode=opaque&amp;autoplay=1;rel=0"),"youtu"==videoURL[1]&&(r="https://www.youtube.com/embed/"+videoURL[3]+"?fs=1&amp;wmode=opaque&amp;autoplay=1;rel=0"),"vimeo"==videoURL[1]&&(r="https://player.vimeo.com/video/"+videoURL[3]+"?autoplay=1"),"dailymotion"==videoURL[1]&&(r="https://www.dailymotion.com/embed/video/"+videoURL[7]),"kickstarter"==videoURL[1]&&(r="https://www.kickstarter.com/projects/"+videoURL[9]+"/"+videoURL[10]+"/widget/video.html"),r){var c=t("<iframe>",{frameborder:"0",vspace:"0",hspace:"0",scrolling:"no",allowfullscreen:"","class":"litebox-content",style:"background: #000",seamless:"seamless",sandbox:"allow-forms allow-popups allow-scripts allow-same-origin allow-presentation"});o.transitionContent("embed",n,c),c.attr("src",r),c.on("load",function(){$loader.remove()})}}else if("#"==i.substring(0,1))t(i).length?($html=t("<div>",{"class":"litebox-content litebox-inline-html"}),$html.append(t(i).clone()),o.transitionContent("inline",n,$html)):o.liteboxError(),$loader.remove();else{var p=i.split(".").pop();if("mp4"==p){var c=t("<video autoplay controls />",{src:i,"class":"litebox-content"}).append('<source src="'+i+'" type="video/mp4">');o.transitionContent("video",n,c),$loader.remove()}else{var c=t("<iframe>",{src:i,frameborder:"0",vspace:"0",hspace:"0",scrolling:n2const.isIOS?"no":"auto","class":"litebox-content",allowfullscreen:""});o.transitionContent("iframe",n,c),c.on("load",function(){$loader.remove()})}}},transitionContent:function(e,o,i){var n=this;"inline"!=e&&$container.removeClass("litebox-scroll"),o.remove(),$container.append(i),"inline"==e&&$container.addClass("litebox-scroll"),n.centerContent(),t(window).on("resize",function(){n.centerContent()})},centerContent:function(){$litebox.css({height:l()}),$container.css({"line-height":$container.height()+"px"}),"undefined"!=typeof $html&&t(".litebox-inline-html").outerHeight()<$container.height()&&t(".litebox-inline-html").css({"margin-top":"-"+t(".litebox-inline-html").outerHeight()/2+"px",top:"50%"})},closeLitebox:function(){this.options.callbackBeforeClose.call(this),this.timeout&&(clearTimeout(this.timeout),this.timeout=null),$litebox.fadeOut(this.options.revealSpeed,function(){t(".litebox-nav").hide(),$litebox.empty().remove(),t(".litebox-preload").remove()}),t(".tipsy").fadeOut(this.options.revealSpeed,function(){t(this).remove()}),t(".litebox-prev").off("click"),t(".litebox-next").off("click"),t("body").off(".litebox"),this.options.callbackAfterClose.call(this)},liteboxError:function(){this.options.callbackError.call(this),$container.append($error)}},t.fn[s]=function(e){return this.each(function(){t.data(this,s)||t.data(this,s,new n(this,e))})}}(n2);