1(function($) { 2 var BootstrapLightBox = function($element, options) 3 { 4 this.init($element, options) 5 } 6 7 BootstrapLightBox.DEFAULTS = { 8 gallery: true, 9 caption: true 10 } 11 12 BootstrapLightBox.prototype.getOptions = function ($element, options) 13 { 14 options = $.extend({}, BootstrapLightBox.DEFAULTS, $element.data(), options) 15 16 if (options.fontSet === undefined) { 17 options.fontSet = this.getFontSet(); 18 } 19 return options 20 } 21 22 BootstrapLightBox.prototype.init = function($input, options) 23 { 24 var t = this; 25 26 // get options 27 this.options = this.getOptions($input, options); 28 29 if ($('#bootstrap-media-lightbox').length == 0) { 30 31 // close button 32 if (this.options.fontSet === "fa" ) { 33 var closeButton = '<div id="bootstrap-media-lightbox-close">'+ 34 '<span class="fa-stack fa-lg">'+ 35 '<i class="fa fa-square fa-stack-2x"></i>'+ 36 '<i class="fa fa-times fa-stack-1x fa-inverse" data-dismiss="modal" aria-hidden="true"></i>'+ 37 '</span>'+ 38 '</div>' 39 var backwardButton = '<i class="fa fa-chevron-circle-left"></i>'; 40 var forwardButton = '<i class="fa fa-chevron-circle-right"></i>'; 41 } else { 42 var closeButton = '<div id="bootstrap-media-lightbox-close">'+ 43 '<i class="glyphicon glyphicon-remove-circle" data-dismiss="modal" aria-hidden="true"></i>'+ 44 '</div>' 45 var backwardButton = '<i class="glyphicon glyphicon-chevron-left"></i>'; 46 var forwardButton = '<i class="glyphicon glyphicon-chevron-right"></i>'; 47 } 48 49 $(document.body).append( 50 '<div class="modal fade" id="bootstrap-media-lightbox" tabindex="-1" role="dialog" aria-labelledby="bootstrap-media-lightbox-label" aria-hidden="true">'+ 51 closeButton+ 52 '<div id="bootstrap-media-lightbox-content-container" data-dismiss="modal"></div>'+ 53 54 '<div id="bootstrap-media-lightbox-backward">'+backwardButton+'</div>'+ 55 56 '<div id="bootstrap-media-lightbox-forward">'+forwardButton+'</div>'+ 57 58 '<div id="bootstrap-media-lightbox-caption-container">'+ 59 '<div id="bootstrap-media-lightbox-caption"></div>'+ 60 '</div>'+ 61 '</div>' 62 ); 63 } 64 65 $($input).each(function(index) { 66 $(this).on("click", function(event){ 67 event.preventDefault(); 68 t.updatePictureInLightbox($(this), $input, index); 69 $('#bootstrap-media-lightbox').modal('show'); 70 }); 71 }); 72 } 73 74 BootstrapLightBox.prototype.updatePictureInLightbox = function($a, $input, index) 75 { 76 var t = this; 77 78 if (this.options.gallery === false || $input.size() < 2) { 79 $('#bootstrap-media-lightbox-backward').hide(); 80 $('#bootstrap-media-lightbox-forward').hide(); 81 } else if (index == 0) { 82 $('#bootstrap-media-lightbox-backward').hide(); 83 $('#bootstrap-media-lightbox-forward').show(); 84 } else if (index == $input.size() - 1) { 85 $('#bootstrap-media-lightbox-backward').show(); 86 $('#bootstrap-media-lightbox-forward').hide(); 87 } else { 88 $('#bootstrap-media-lightbox-backward').show(); 89 $('#bootstrap-media-lightbox-forward').show(); 90 } 91 92 // add content to the lightbox 93 var target = $a.attr('href'); 94 var supportedImageFormats = [ "jpe", "png", "jpg", "jpeg", "bmp" ] 95 var extension = target.split('.').pop().toLowerCase(); 96 if ($a.data('target') !== undefined) { 97 98 } 99 if ($.inArray(extension, supportedImageFormats) > -1) { 100 console.log('en el arreglo'); 101 this.addImage(target); 102 } else if (target.substr(0, 22) == "http://www.youtube.com") { 103 this.addYoutubeVideo(target); 104 } else if (target.substr(0, 16) == "http://vimeo.com") { 105 this.addVimeoVideo(target); 106 } else if (target.substr(0, 4) == "http") { 107 this.addIframe(target); 108 } 109 110 this.addCaption($a); 111 112 $( "#bootstrap-media-lightbox-forward").unbind( "click" ); 113 $('#bootstrap-media-lightbox-forward').click(function() { 114 t.updatePictureInLightbox($input.eq(index+1), $input, index+1) 115 }); 116 $( "#bootstrap-media-lightbox-backward").unbind( "click" ); 117 $('#bootstrap-media-lightbox-backward').click(function() { 118 t.updatePictureInLightbox($input.eq(index-1), $input, index-1) 119 }); 120 121 $('#bootstrap-media-lightbox-close').click(function() { 122 $('#bootstrap-media-lightbox-iframe').attr("src", ""); 123 }); 124 125 } 126 127 BootstrapLightBox.prototype.addImage = function(target) 128 { 129 var t = this; 130 131 var preloader = new Image(); 132 preloader.onload = function() { 133 134 // set default size if size is undefined 135 if (t.options.width === undefined && t.options.height === undefined) { 136 t.contentWidth = preloader.width; // original imagel width 137 t.contentHeight = preloader.height; // originalImagelHeight 138 } else if (t.options.width === undefined) { 139 t.contentWidth = t.options.height/preloader.height*preloader.width; // originalImagelHeight 140 t.contentHeight = t.options.height; 141 } else if (t.options.height === undefined) { 142 t.contentHeight = t.options.width/preloader.width*preloader.height; // originalImagelHeight 143 t.contentWidth = t.options.width; 144 } 145 146 t.validateSize(); 147 148 var $contentContainer = $('#bootstrap-media-lightbox-content-container'); 149 $contentContainer.html('<img width="'+t.contentWidth+'" height="'+t.contentHeight+'" src="'+target+'" />'); 150 151 t.setMargins($contentContainer); 152 }; 153 preloader.src = target; 154 } 155 156 BootstrapLightBox.prototype.addIframe = function(target) 157 { 158 // set default size if size is undefined 159 if (this.options.width === undefined && this.options.height === undefined) { 160 this.contentWidth = 420; 161 this.contentHeight = 315; 162 } else if (this.options.width === undefined) { 163 this.contentWidth = 420/(315/this.options.height); 164 this.contentHeight = this.options.height; 165 } else if (this.options.height === undefined) { 166 this.contentHeight = 315/(420/this.options.width); 167 this.contentWidth = this.options.width; 168 } 169 170 var $contentContainer = $('#bootstrap-media-lightbox-content-container'); 171 var content = '<iframe id="bootstrap-media-lightbox-iframe" style="background-color: white" width="'+this.contentWidth+'" height="'+this.contentHeight+'" src="'+target+'" frameborder="0" allowfullscreen></iframe>'; 172 this.setMargins($contentContainer); 173 $contentContainer.html(content); 174 } 175 176 177 BootstrapLightBox.prototype.addYoutubeVideo = function(target) 178 { 179 // set default size if size is undefined 180 if (this.options.width === undefined && this.options.height === undefined) { 181 this.contentWidth = 420; 182 this.contentHeight = 315; 183 } else if (this.options.width === undefined) { 184 this.contentWidth = 420/(315/this.options.height); 185 this.contentHeight = this.options.height; 186 } else if (this.options.height === undefined) { 187 this.contentHeight = 315/(420/this.options.width); 188 this.contentWidth = this.options.width; 189 } 190 this.validateSize(); 191 192 var $contentContainer = $('#bootstrap-media-lightbox-content-container'); 193 var videoId = target.substr(31) 194 var content = '<iframe id="bootstrap-media-lightbox-iframe" width="'+this.contentWidth+'" height="'+this.contentHeight+'" src="http://www.youtube-nocookie.com/embed/'+videoId+'" frameborder="0" allowfullscreen></iframe>'; 195 $contentContainer.html(content); 196 197 this.setMargins($contentContainer); 198 } 199 200 BootstrapLightBox.prototype.addVimeoVideo = function(target) 201 { 202 // set default size if size is undefined 203 if (this.options.width === undefined && this.options.height === undefined) { 204 this.contentWidth = 420; 205 this.contentHeight = 315; 206 } else if (this.options.width === undefined) { 207 this.contentWidth= 420/(315/this.options.height); 208 this.contentHeight = this.options.height; 209 } else if (this.options.height === undefined) { 210 this.contentHeight = 315/(420/this.options.width); 211 this.contentWidth = this.options.width; 212 } 213 this.validateSize(); 214 215 var $contentContainer = $('#bootstrap-media-lightbox-content-container'); 216 var videoId = target.substr(17) 217 var content = '<iframe id="bootstrap-media-lightbox-iframe" width="'+this.contentWidth+'" height="'+this.contentHeight+'" src="http://player.vimeo.com/video/'+videoId+'" frameborder="0" allowfullscreen></iframe>'; 218 $contentContainer.html(content); 219 220 this.setMargins($contentContainer); 221 } 222 223 BootstrapLightBox.prototype.addCaption = function($a) 224 { 225 var caption = $a.attr('title'); 226 227 if (caption !== "" && caption !== undefined && this.options.caption === true) { 228 // below it will affect the height of the image with the caption or without it 229 this.caption = true; 230 $('#bootstrap-media-lightbox-caption-container').show(); 231 $('#bootstrap-media-lightbox-caption').text(caption); 232 } else { 233 this.caption = false;
234 $('#bootstrap-media-lightbox-caption-container').hide(); 235 } 236 } 237 238 BootstrapLightBox.prototype.getFontSet = function() 239 { 240 var $fontAwesomeTest = $('<i class="fa"></i>'); 241 if ($fontAwesomeTest.css('font-family') === "FontAwesome") { 242 return "fa" 243 } 244 245 return "glyphicon"; 246 } 247 248 BootstrapLightBox.prototype.validateSize = function(target) 249 { 250 var windowHeight = $( window ).height(); 251 var windowWidth = $( window ).width(); 252 var offsetHeight = this.caption?80:30; 253 254 if (this.contentWidth + 50 > windowWidth) { 255 var oldWith = this.contentWidth; 256 this.contentWidth = windowWidth - 50; 257 this.contentHeight = this.contentHeight * this.contentWidth / oldWith; 258 } 259 260 if (this.contentHeight + offsetHeight > windowHeight) { 261 var oldHeight = this.contentHeight; 262 this.contentHeight = windowHeight - offsetHeight; 263 this.contentWidth = this.contentWidth * this.contentHeight / oldHeight; 264 } 265 } 266 267 BootstrapLightBox.prototype.setMargins = function($element) 268 { 269 var windowHeight = $( window ).height(); 270 var windowWidth = $( window ).width(); 271 var offsetHeight = this.caption?50:0; 272 273 $element.css({"margin-top": (windowHeight - offsetHeight - this.contentHeight)/2}); 274 $element.css({"margin-left": (windowWidth - this.contentWidth - 16)/2}); 275 } 276 277 $.fn.lightbox = function(options) 278 { 279 new BootstrapLightBox($(this), options); 280 }; 281 282 $('.lightbox').lightbox(); 283 284})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.