You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

7 lines
11 KiB

/*!
* Lightbox for Bootstrap 3 by @ashleydw
* https://github.com/ashleydw/lightbox
*
* License: https://github.com/ashleydw/lightbox/blob/master/LICENSE
*/
(function(){"use strict";var n,t;n=jQuery;t=function(t,i){var e,u,f,r=this;return this.options=n.extend({title:null,footer:null,remote:null},n.fn.ekkoLightbox.defaults,i||{}),this.$element=n(t),e="",this.modal_id=this.options.modal_id?this.options.modal_id:"ekkoLightbox-"+Math.floor(1e3*Math.random()+1),f='<div class="modal-header"'+(this.options.title||this.options.always_show_close?"":' style="display:none"')+'><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;<\/button><h4 class="modal-title">'+(this.options.title||"&nbsp;")+"<\/h4><\/div>",u='<div class="modal-footer"'+(this.options.footer?"":' style="display:none"')+">"+this.options.footer+"<\/div>",n(document.body).append('<div id="'+this.modal_id+'" class="ekko-lightbox modal fade" tabindex="-1"><div class="modal-dialog"><div class="modal-content">'+f+'<div class="modal-body"><div class="ekko-lightbox-container"><div><\/div><\/div><\/div>'+u+"<\/div><\/div><\/div>"),this.modal=n("#"+this.modal_id),this.modal_dialog=this.modal.find(".modal-dialog").first(),this.modal_content=this.modal.find(".modal-content").first(),this.modal_body=this.modal.find(".modal-body").first(),this.lightbox_container=this.modal_body.find(".ekko-lightbox-container").first(),this.lightbox_body=this.lightbox_container.find("> div:first-child").first(),this.showLoading(),this.modal_arrows=null,this.border={top:parseFloat(this.modal_dialog.css("border-top-width"))+parseFloat(this.modal_content.css("border-top-width"))+parseFloat(this.modal_body.css("border-top-width")),right:parseFloat(this.modal_dialog.css("border-right-width"))+parseFloat(this.modal_content.css("border-right-width"))+parseFloat(this.modal_body.css("border-right-width")),bottom:parseFloat(this.modal_dialog.css("border-bottom-width"))+parseFloat(this.modal_content.css("border-bottom-width"))+parseFloat(this.modal_body.css("border-bottom-width")),left:parseFloat(this.modal_dialog.css("border-left-width"))+parseFloat(this.modal_content.css("border-left-width"))+parseFloat(this.modal_body.css("border-left-width"))},this.padding={top:parseFloat(this.modal_dialog.css("padding-top"))+parseFloat(this.modal_content.css("padding-top"))+parseFloat(this.modal_body.css("padding-top")),right:parseFloat(this.modal_dialog.css("padding-right"))+parseFloat(this.modal_content.css("padding-right"))+parseFloat(this.modal_body.css("padding-right")),bottom:parseFloat(this.modal_dialog.css("padding-bottom"))+parseFloat(this.modal_content.css("padding-bottom"))+parseFloat(this.modal_body.css("padding-bottom")),left:parseFloat(this.modal_dialog.css("padding-left"))+parseFloat(this.modal_content.css("padding-left"))+parseFloat(this.modal_body.css("padding-left"))},this.modal.on("show.bs.modal",this.options.onShow.bind(this)).on("shown.bs.modal",function(){return r.modal_shown(),r.options.onShown.call(r)}).on("hide.bs.modal",this.options.onHide.bind(this)).on("hidden.bs.modal",function(){return r.gallery&&n(document).off("keydown.ekkoLightbox"),r.modal.remove(),r.options.onHidden.call(r)}).modal("show",i),this.modal};t.prototype={modal_shown:function(){var t,i=this;return this.options.remote?(this.gallery=this.$element.data("gallery"),this.gallery&&(this.gallery_items="document.body"===this.options.gallery_parent_selector||""===this.options.gallery_parent_selector?n(document.body).find('*[data-toggle="lightbox"][data-gallery="'+this.gallery+'"]'):this.$element.parents(this.options.gallery_parent_selector).first().find('*[data-toggle="lightbox"][data-gallery="'+this.gallery+'"]'),this.gallery_index=this.gallery_items.index(this.$element),n(document).on("keydown.ekkoLightbox",this.navigate.bind(this)),this.options.directional_arrows&&this.gallery_items.length>1&&(this.lightbox_container.append('<div class="ekko-lightbox-nav-overlay"><a href="#" class="'+this.strip_stops(this.options.left_arrow_class)+'"><\/a><a href="#" class="'+this.strip_stops(this.options.right_arrow_class)+'"><\/a><\/div>'),this.modal_arrows=this.lightbox_container.find("div.ekko-lightbox-nav-overlay").first(),this.lightbox_container.find("a"+this.strip_spaces(this.options.left_arrow_class)).on("click",function(n){return n.preventDefault(),i.navigate_left()}),this.lightbox_container.find("a"+this.strip_spaces(this.options.right_arrow_class)).on("click",function(n){return n.preventDefault(),i.navigate_right()}))),this.options.type?"image"===this.options.type?this.preloadImage(this.options.remote,!0):"youtube"===this.options.type&&(t=this.getYoutubeId(this.options.remote))?this.showYoutubeVideo(t):"vimeo"===this.options.type?this.showVimeoVideo(this.options.remote):"instagram"===this.options.type?this.showInstagramVideo(this.options.remote):"url"===this.options.type?this.loadRemoteContent(this.options.remote):"video"===this.options.type?this.showVideoIframe(this.options.remote):this.error('Could not detect remote target type. Force the type using data-type="image|youtube|vimeo|instagram|url|video"'):this.detectRemoteType(this.options.remote)):this.error("No remote target given")},strip_stops:function(n){return n.replace(/\./g,"")},strip_spaces:function(n){return n.replace(/\s/g,"")},isImage:function(n){return n.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i)},isSwf:function(n){return n.match(/\.(swf)((\?|#).*)?$/i)},getYoutubeId:function(n){var t;return t=n.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/),t&&11===t[2].length?t[2]:!1},getVimeoId:function(n){return n.indexOf("vimeo")>0?n:!1},getInstagramId:function(n){return n.indexOf("instagram")>0?n:!1},navigate:function(n){if(n=n||window.event,39===n.keyCode||37===n.keyCode){if(39===n.keyCode)return this.navigate_right();if(37===n.keyCode)return this.navigate_left()}},navigateTo:function(t){var r,i;return 0>t||t>this.gallery_items.length-1?this:(this.showLoading(),this.gallery_index=t,this.$element=n(this.gallery_items.get(this.gallery_index)),this.updateTitleAndFooter(),i=this.$element.attr("data-remote")||this.$element.attr("href"),this.detectRemoteType(i,this.$element.attr("data-type")||!1),this.gallery_index+1<this.gallery_items.length&&(r=n(this.gallery_items.get(this.gallery_index+1),!1),i=r.attr("data-remote")||r.attr("href"),"image"===r.attr("data-type")||this.isImage(i))?this.preloadImage(i,!1):void 0)},navigate_left:function(){if(1!==this.gallery_items.length)return(0===this.gallery_index?this.gallery_index=this.gallery_items.length-1:this.gallery_index--,this.options.onNavigate.call(this,"left",this.gallery_index),this.navigateTo(this.gallery_index))},navigate_right:function(){if(1!==this.gallery_items.length)return(this.gallery_index===this.gallery_items.length-1?this.gallery_index=0:this.gallery_index++,this.options.onNavigate.call(this,"right",this.gallery_index),this.navigateTo(this.gallery_index))},detectRemoteType:function(n,t){var i;return t=t||!1,"image"===t||this.isImage(n)?(this.options.type="image",this.preloadImage(n,!0)):"youtube"===t||(i=this.getYoutubeId(n))?(this.options.type="youtube",this.showYoutubeVideo(i)):"vimeo"===t||(i=this.getVimeoId(n))?(this.options.type="vimeo",this.showVimeoVideo(i)):"instagram"===t||(i=this.getInstagramId(n))?(this.options.type="instagram",this.showInstagramVideo(i)):"video"===t?(this.options.type="video",this.showVideoIframe(i)):(this.options.type="url",this.loadRemoteContent(n))},updateTitleAndFooter:function(){var n,t,i,r;return i=this.modal_content.find(".modal-header"),t=this.modal_content.find(".modal-footer"),r=this.$element.data("title")||"",n=this.$element.data("footer")||"",r||this.options.always_show_close?i.css("display","").find(".modal-title").html(r||"&nbsp;"):i.css("display","none"),n?t.css("display","").html(n):t.css("display","none"),this},showLoading:function(){return this.lightbox_body.html('<div class="modal-loading">'+this.options.loadingMessage+"<\/div>"),this},showYoutubeVideo:function(n){var i,t;return t=this.checkDimensions(this.$element.data("width")||560),i=t/(560/315),this.showVideoIframe("//www.youtube.com/embed/"+n+"?badge=0&autoplay=1&html5=1",t,i)},showVimeoVideo:function(n){var i,t;return t=this.checkDimensions(this.$element.data("width")||560),i=t/(500/281),this.showVideoIframe(n+"?autoplay=1",t,i)},showInstagramVideo:function(n){var i,t;return t=this.checkDimensions(this.$element.data("width")||612),this.resize(t),i=t+80,this.lightbox_body.html('<iframe width="'+t+'" height="'+i+'" src="'+this.addTrailingSlash(n)+'embed/" frameborder="0" allowfullscreen><\/iframe>'),this.options.onContentLoaded.call(this),this.modal_arrows?this.modal_arrows.css("display","none"):void 0},showVideoIframe:function(n,t,i){return i=i||t,this.resize(t),this.lightbox_body.html('<div class="embed-responsive embed-responsive-16by9"><iframe width="'+t+'" height="'+i+'" src="'+n+'" frameborder="0" allowfullscreenclass="embed-responsive-item"><\/iframe><\/div>'),this.options.onContentLoaded.call(this),this.modal_arrows&&this.modal_arrows.css("display","none"),this},loadRemoteContent:function(t){var r,i,u=this;return i=this.$element.data("width")||560,this.resize(i),r=this.$element.data("disableExternalCheck")||!1,r||this.isExternal(t)?(this.lightbox_body.html('<iframe width="'+i+'" height="'+i+'" src="'+t+'" frameborder="0" allowfullscreen><\/iframe>'),this.options.onContentLoaded.call(this)):this.lightbox_body.load(t,n.proxy(function(){return u.$element.trigger("loaded.bs.modal")})),this.modal_arrows&&this.modal_arrows.css("display","none"),this},isExternal:function(n){var t;return t=n.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/),"string"==typeof t[1]&&t[1].length>0&&t[1].toLowerCase()!==location.protocol?!0:"string"==typeof t[2]&&t[2].length>0&&t[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"),"")!==location.host?!0:!1},error:function(n){return this.lightbox_body.html(n),this},preloadImage:function(t,i){var r,u=this;return r=new Image,(null==i||i===!0)&&(r.onload=function(){var t;return t=n("<img />"),t.attr("src",r.src),t.addClass("img-responsive"),u.lightbox_body.html(t),u.modal_arrows&&u.modal_arrows.css("display","block"),u.resize(r.width),u.options.onContentLoaded.call(u)},r.onerror=function(){return u.error("Failed to load image: "+t)}),r.src=t,r},resize:function(t){var i;return i=t+this.border.left+this.padding.left+this.padding.right+this.border.right,this.modal_dialog.css("width","auto").css("max-width",i),this.lightbox_container.find("a").css("line-height",function(){return n(this).parent().height()+"px"}),this},checkDimensions:function(n){var t,i;return i=n+this.border.left+this.padding.left+this.padding.right+this.border.right,t=document.body.clientWidth,i>t&&(n=this.modal_body.width()),n},close:function(){return this.modal.modal("hide")},addTrailingSlash:function(n){return"/"!==n.substr(-1)&&(n+="/"),n}};n.fn.ekkoLightbox=function(i){return this.each(function(){var r;return r=n(this),i=n.extend({remote:r.attr("data-remote")||r.attr("href"),gallery_parent_selector:r.attr("data-parent"),type:r.attr("data-type")},i,r.data()),new t(this,i),this})};n.fn.ekkoLightbox.defaults={gallery_parent_selector:"document.body",left_arrow_class:".glyphicon .glyphicon-chevron-left",right_arrow_class:".glyphicon .glyphicon-chevron-right",directional_arrows:!0,type:null,always_show_close:!0,loadingMessage:"Loading...",onShow:function(){},onShown:function(){},onHide:function(){},onHidden:function(){},onNavigate:function(){},onContentLoaded:function(){}}}).call(this);