forked from compact/angular-bootstrap-lightbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-bootstrap-lightbox.min.js
2 lines (2 loc) · 6.37 KB
/
angular-bootstrap-lightbox.min.js
1
2
/*! angular-bootstrap-lightbox */
angular.module("bootstrapLightbox",["ui.bootstrap"]);try{angular.module("angular-loading-bar"),angular.module("bootstrapLightbox").requires.push("angular-loading-bar")}catch(e){}try{angular.module("ngTouch"),angular.module("bootstrapLightbox").requires.push("ngTouch")}catch(e){}try{angular.module("videosharing-embed"),angular.module("bootstrapLightbox").requires.push("videosharing-embed")}catch(e){}angular.module("bootstrapLightbox").run(["$templateCache",function(a){"use strict";a.put("lightbox.html",'<div class=modal-body ng-swipe-left=Lightbox.nextImage() ng-swipe-right=Lightbox.prevImage()><div class=lightbox-nav><button class=close aria-hidden=true ng-click=$dismiss()>×</button><div class=btn-group ng-if="Lightbox.images.length > 1"><a class="btn btn-xs btn-default" ng-click=Lightbox.prevImage()>‹ Previous</a> <a ng-href={{Lightbox.imageUrl}} target=_blank class="btn btn-xs btn-default" title="Open in new tab">Open image in new tab</a> <a class="btn btn-xs btn-default" ng-click=Lightbox.nextImage()>Next ›</a></div></div><div class=lightbox-image-container><div class=lightbox-image-caption><span>{{Lightbox.imageCaption}}</span></div><img ng-if=!Lightbox.isVideo(Lightbox.image) lightbox-src={{Lightbox.imageUrl}}><div ng-if=Lightbox.isVideo(Lightbox.image) class="embed-responsive embed-responsive-16by9"><video ng-if=!Lightbox.isSharedVideo(Lightbox.image) lightbox-src={{Lightbox.imageUrl}} controls autoplay></video><embed-video ng-if=Lightbox.isSharedVideo(Lightbox.image) lightbox-src={{Lightbox.imageUrl}} ng-href={{Lightbox.imageUrl}} iframe-id=lightbox-video class=embed-responsive-item><a ng-href={{Lightbox.imageUrl}}>Watch video</a></embed-video></div></div></div>')}]),angular.module("bootstrapLightbox").service("ImageLoader",["$q",function(a){this.load=function(b){var c=a.defer(),d=new Image;return d.onload=function(){("boolean"==typeof this.complete&&this.complete===!1||"number"==typeof this.naturalWidth&&0===this.naturalWidth)&&c.reject(),c.resolve(d)},d.onerror=function(){c.reject()},d.src=b,c.promise}}]),angular.module("bootstrapLightbox").provider("Lightbox",function(){this.templateUrl="lightbox.html",this.fullScreenMode=!1,this.getImageUrl=function(a){return"string"==typeof a?a:a.url},this.getImageCaption=function(a){return a.caption},this.calculateImageDimensionLimits=function(a){return a.windowWidth>=768?{maxWidth:a.windowWidth-92,maxHeight:a.windowHeight-126}:{maxWidth:a.windowWidth-52,maxHeight:a.windowHeight-86}},this.calculateModalDimensions=function(a){var b=Math.max(400,a.imageDisplayWidth+32),c=Math.max(200,a.imageDisplayHeight+66);return(b>=a.windowWidth-20||a.windowWidth<768)&&(b="auto"),c>=a.windowHeight&&(c="auto"),{width:b,height:c}},this.isVideo=function(a){return"object"==typeof a&&a&&a.type?"video"===a.type:!1},this.isSharedVideo=function(a){return this.isVideo(a)&&!this.getImageUrl(a).match(/\.(mp4|ogg|webm)$/)},this.$get=["$document","$injector","$uibModal","$timeout","ImageLoader",function(a,b,c,d,e){var f=b.has("cfpLoadingBar")?b.get("cfpLoadingBar"):null,g={};return g.images=[],g.index=-1,g.templateUrl=this.templateUrl,g.fullScreenMode=this.fullScreenMode,g.getImageUrl=this.getImageUrl,g.getImageCaption=this.getImageCaption,g.calculateImageDimensionLimits=this.calculateImageDimensionLimits,g.calculateModalDimensions=this.calculateModalDimensions,g.isVideo=this.isVideo,g.isSharedVideo=this.isSharedVideo,g.keyboardNavEnabled=!1,g.image={},g.modalInstance=null,g.loading=!1,g.openModal=function(a,b,d){return g.images=a,g.setImage(b),g.modalInstance=c.open(angular.extend({templateUrl:g.templateUrl,controller:["$scope",function(a){a.Lightbox=g,g.keyboardNavEnabled=!0}],windowClass:"lightbox-modal"},d||{})),g.modalInstance.result["finally"](function(){g.images=[],g.index=1,g.image={},g.imageUrl=null,g.imageCaption=null,g.keyboardNavEnabled=!1,f&&f.complete()}),g.modalInstance},g.closeModal=function(a){return g.modalInstance.close(a)},g.setImage=function(a){if(!(a in g.images))throw"Invalid image.";g.loading=!0,f&&f.start();var b=g.images[a],c=g.getImageUrl(b),d=function(d){d=d||{},g.index=d.index||a,g.image=d.image||b,g.imageUrl=d.imageUrl||c,g.imageCaption=d.imageCaption||g.getImageCaption(b),g.loading=!1,f&&f.complete()};g.isVideo(b)?d():e.load(c).then(function(){d()},function(){d({imageUrl:"//:0",imageCaption:"Failed to load image"})})},g.firstImage=function(){g.setImage(0)},g.prevImage=function(){g.setImage((g.index-1+g.images.length)%g.images.length)},g.nextImage=function(){g.setImage((g.index+1)%g.images.length)},g.lastImage=function(){g.setImage(g.images.length-1)},g.setImages=function(a){g.images=a,g.setImage(g.index)},a.bind("keydown",function(a){if(g.keyboardNavEnabled){var b=null;switch(a.which){case 39:b="nextImage";break;case 37:b="prevImage"}null!==b&&-1===["input","textarea"].indexOf(a.target.tagName.toLowerCase())&&(d(function(){g[b]()}),a.preventDefault())}}),g}]}),angular.module("bootstrapLightbox").directive("lightboxSrc",["$window","ImageLoader","Lightbox",function(a,b,c){var d=function(a,b){var c=a.width,d=a.height,e=a.minWidth,f=a.minHeight,g=a.maxWidth,h=a.maxHeight,i=c,j=d;if(b){var k=Math.min(g/c,h/d),l=Math.round(c*k),m=Math.round(d*k);i=Math.max(e,l),j=Math.max(f,m)}else e>c&&f>d?c/d>g/h?(j=f,i=Math.round(c*f/d)):(i=e,j=Math.round(d*e/c)):e>c?(i=e,j=Math.round(d*e/c)):f>d&&(j=f,i=Math.round(c*f/d)),c>g&&d>h?c/d>g/h?(i=g,j=Math.round(d*g/c)):(j=h,i=Math.round(c*h/d)):c>g?(i=g,j=Math.round(d*g/c)):d>h&&(j=h,i=Math.round(c*h/d));return{width:i||0,height:j||0}},e=function(a){return"number"==typeof a?a+"px":a},f=0,g=0;return{link:function(h,i,j){var k=function(){var b=a.innerWidth,h=a.innerHeight,j=c.calculateImageDimensionLimits({windowWidth:b,windowHeight:h,imageWidth:f,imageHeight:g}),k=d(angular.extend({width:f,height:g,minWidth:1,minHeight:1,maxWidth:3e3,maxHeight:3e3},j),c.fullScreenMode),l=c.calculateModalDimensions({windowWidth:b,windowHeight:h,imageDisplayWidth:k.width,imageDisplayHeight:k.height});i.css({width:k.width+"px",height:k.height+"px"}),angular.element(document.querySelector(".lightbox-modal .modal-dialog")).css({width:e(l.width)}),angular.element(document.querySelector(".lightbox-modal .modal-content")).css({height:e(l.height)})};h.$watch(function(){return j.lightboxSrc},function(a){c.isVideo(c.image)?(f=1280,g=720,k(),i[0].src=a):(i[0].src="//:0",b.load(a).then(function(b){f=b.naturalWidth,g=b.naturalHeight,k(),i[0].src=a},function(){f=0,g=0,k()}))}),angular.element(a).on("resize",k)}}}]);