1'use strict';
vendor: 16,407 bytes, lines 2-354
2 3(function ($) { 4 var SlickLightbox, defaults; 5 SlickLightbox = function () { 6 /* 7 The core class. 8 */ 9 function SlickLightbox(element, options1) { 10 var slickLightbox; 11 this.options = options1; 12 /* Binds the plugin. */ 13 this.$element = $(element); 14 this.didInit = false; 15 slickLightbox = this; 16 this.$element.on('click.slickLightbox', this.options.itemSelector, function (e) { 17 var $clickedItem, $items; 18 e.preventDefault(); 19 $clickedItem = $(this); 20 $clickedItem.blur(); 21 if (typeof slickLightbox.options.shouldOpen === 'function') { 22 if (!slickLightbox.options.shouldOpen(slickLightbox, $clickedItem, e)) { 23 return; 24 } 25 } 26 $items = slickLightbox.$element.find(slickLightbox.options.itemSelector); 27 if (slickLightbox.elementIsSlick()) { 28 $items = slickLightbox.filterOutSlickClones($items); 29 $clickedItem = slickLightbox.handlePossibleCloneClick($clickedItem, $items); 30 } 31 return slickLightbox.init($items.index($clickedItem)); 32 }); 33 } 34 SlickLightbox.prototype.init = function (index) { 35 /* Creates the lightbox, opens it, binds events and calls `slick`. Accepts `index` of the element, that triggered it (so that we know, on which slide to start slick). */ 36 this.didInit = true; 37 this.detectIE(); 38 this.createModal(); 39 this.bindEvents(); 40 this.initSlick(index); 41 return this.open(); 42 }; 43 SlickLightbox.prototype.createModalItems = function () { 44 /* Creates individual slides to be used with slick. If `options.images` array is specified, it uses it's contents, otherwise loops through elements' `options.itemSelector`. */ 45 var $items, createItem, itemTemplate, lazyPlaceholder, length, links; 46 lazyPlaceholder = this.options.lazyPlaceholder || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; 47 itemTemplate = function (source, caption, lazy) { 48 var imgSourceParams; 49 if (lazy === true) { 50 imgSourceParams = ' data-lazy="' + source + '" src="' + lazyPlaceholder + '" '; 51 } else { 52 imgSourceParams = ' src="' + source + '" '; 53 } 54 return '<div class="slick-lightbox-slick-item">\n <div class="slick-lightbox-slick-item-inner">\n <img class="slick-lightbox-slick-img" ' + imgSourceParams + ' />\n ' + caption + '\n </div>\n</div>'; 55 }; 56 if (this.options.images) { 57 links = $.map(this.options.images, function (_this) { 58 return function (img) { 59 return itemTemplate(img, _this.options.lazy); 60 }; 61 }(this)); 62 } else { 63 $items = this.filterOutSlickClones(this.$element.find(this.options.itemSelector)); 64 length = $items.length; 65 createItem = function (_this) { 66 return function (el, index) { 67 var caption, info, src; 68 info = { 69 index: index, 70 length: length 71 }; 72 caption = _this.getElementCaption(el, info); 73 src = _this.getElementSrc(el); 74 return itemTemplate(src, caption, _this.options.lazy); 75 }; 76 }(this); 77 links = $.map($items, createItem); 78 } 79 return links; 80 }; 81 SlickLightbox.prototype.createModal = function () { 82 /* Creates a `slick`-friendly modal. */ 83 var html, links; 84 links = this.createModalItems(); 85 html = '<div class="slick-lightbox slick-lightbox-hide-init' + (this.isIE ? ' slick-lightbox-ie' : '') + '" style="background: ' + this.options.background + ';">\n <div class="slick-lightbox-inner">\n <div class="slick-lightbox-slick slick-caption-' + this.options.captionPosition + '">' + links.join('') + '</div>\n <div>\n<div>'; 86 this.$modalElement = $(html); 87 this.$parts = {}; 88 this.$parts['closeButton'] = $(this.options.layouts.closeButton); 89 this.$modalElement.find('.slick-lightbox-inner').append(this.$parts['closeButton']); 90 return $('body').append(this.$modalElement); 91 }; 92 SlickLightbox.prototype.initSlick = function (index) { 93 /* Runs slick by default, using `options.slick` if provided. If `options.slick` is a function, it gets fired instead of us initializing slick. Merges in initialSlide option. */ 94 var additional; 95 additional = { initialSlide: index }; 96 if (this.options.lazy) { 97 additional.lazyLoad = 'ondemand'; 98 } 99 if (this.options.slick != null) { 100 if (typeof this.options.slick === 'function') { 101 this.slick = this.options.slick(this.$modalElement); 102 } else { 103 this.slick = this.$modalElement.find('.slick-lightbox-slick').slick($.extend({}, this.options.slick, additional)); 104 } 105 } else { 106 this.slick = this.$modalElement.find('.slick-lightbox-slick').slick(additional); 107 } 108 return this.$modalElement.trigger('init.slickLightbox'); 109 }; 110 SlickLightbox.prototype.open = function () { 111 /* Opens the lightbox. */ 112 if (this.options.useHistoryApi) { 113 this.writeHistory(); 114 } 115 this.$element.trigger('show.slickLightbox'); 116 setTimeout(function (_this) { 117 return function () { 118 return _this.$element.trigger('shown.slickLightbox'); 119 }; 120 }(this), this.getTransitionDuration()); 121 return this.$modalElement.removeClass('slick-lightbox-hide-init'); 122 }; 123 SlickLightbox.prototype.close = function () { 124 /* Closes the lightbox and destroys it, maintaining the original element bindings. */ 125 this.$element.trigger('hide.slickLightbox'); 126 setTimeout(function (_this) { 127 return function () { 128 return _this.$element.trigger('hidden.slickLightbox'); 129 }; 130 }(this), this.getTransitionDuration()); 131 this.$modalElement.addClass('slick-lightbox-hide'); 132 return this.destroy(); 133 }; 134 SlickLightbox.prototype.bindEvents = function () { 135 /* Binds global events. */ 136 var resizeSlides; 137 resizeSlides = function (_this) { 138 return function () { 139 var h; 140 h = _this.$modalElement.find('.slick-lightbox-inner').height(); 141 _this.$modalElement.find('.slick-lightbox-slick-item').height(h); 142 return _this.$modalElement.find('.slick-lightbox-slick-img, .slick-lightbox-slick-item-inner').css('max-height', Math.round(_this.options.imageMaxHeight * h)); 143 }; 144 }(this); 145 $(window).on('orientationchange.slickLightbox resize.slickLightbox', resizeSlides); 146 if (this.options.useHistoryApi) { 147 $(window).on('popstate.slickLightbox', function (_this) { 148 return function () { 149 return _this.close(); 150 }; 151 }(this)); 152 } 153 this.$modalElement.on('init.slickLightbox', resizeSlides); 154 this.$modalElement.on('destroy.slickLightbox', function (_this) { 155 return function () { 156 return _this.destroy(); 157 }; 158 }(this)); 159 this.$element.on('destroy.slickLightbox', function (_this) { 160 return function () { 161 return _this.destroy(true); 162 }; 163 }(this)); 164 this.$parts['closeButton'].on('click.slickLightbox touchstart.slickLightbox', function (_this) { 165 return function (e) { 166 e.preventDefault(); 167 return _this.close(); 168 }; 169 }(this)); 170 if (this.options.closeOnEscape || this.options.navigateByKeyboard) { 171 $(document).on('keydown.slickLightbox', function (_this) { 172 return function (e) { 173 var code; 174 code = e.keyCode ? e.keyCode : e.which; 175 if (_this.options.navigateByKeyboard) { 176 if (code === 37) { 177 _this.slideSlick('left'); 178 } else if (code === 39) { 179 _this.slideSlick('right'); 180 } 181 } 182 if (_this.options.closeOnEscape) { 183 if (code === 27) { 184 return _this.close(); 185 } 186 } 187 }; 188 }(this)); 189 } 190 if (this.options.closeOnBackdropClick) { 191 this.$modalElement.on('click.slickLightbox touchstart.slickLightbox', '.slick-lightbox-slick-img', function (e) { 192 return e.stopPropagation(); 193 }); 194 return this.$modalElement.on('click.slickLightbox', '.slick-lightbox-slick-item', function (_this) { 195 return function (e) { 196 e.preventDefault(); 197 return _this.close(); 198 }; 199 }(this)); 200 } 201 }; 202 SlickLightbox.prototype.slideSlick = function (direction) { 203 /* Moves the slick prev or next. */ 204 if (direction === 'left') { 205 return this.slick.slick('slickPrev'); 206 } else { 207 return this.slick.slick('slickNext'); 208 } 209 }; 210 SlickLightbox.prototype.detectIE = function () { 211 /* Detects usage of IE8 and lower. */ 212 var ieversion; 213 this.isIE = false; 214 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { 215 ieversion = new Number(RegExp.$1); 216 if (ieversion < 9) { 217 return this.isIE = true; 218 } 219 } 220 }; 221 SlickLightbox.prototype.getElementCaption = function (el, info) { 222 /* Returns caption for each slide based on the type of `options.caption`. */ 223 var c; 224 if (!this.options.caption) { 225 return ''; 226 } 227 c = function () { 228 switch (typeof this.options.caption) { 229 case 'function': 230 return this.options.caption(el, info); 231 case 'string': 232 return $(el).data(this.options.caption); 233 } 234 }.call(this); 235 return '<span class="slick-lightbox-slick-caption">' + c + '</span>'; 236 }; 237 SlickLightbox.prototype.getElementSrc = function (el) { 238 /* Returns src for each slide image based on the type of `options.src`. */ 239 switch (typeof this.options.src) { 240 case 'function': 241 return this.options.src(el); 242 case 'string': 243 return $(el).attr(this.options.src); 244 default: 245 return el.href; 246 } 247 }; 248 SlickLightbox.prototype.unbindEvents = function () { 249 /* Unbinds global events. */ 250 $(window).off('.slickLightbox'); 251 $(document).off('.slickLightbox'); 252 return this.$modalElement.off('.slickLightbox'); 253 }; 254 SlickLightbox.prototype.destroy = function (unbindAnchors) { 255 if (unbindAnchors == null) { 256 unbindAnchors = false; 257 } 258 /* Destroys the lightbox and unbinds global events. If `true` is passed as an argument, unbinds the original element as well. */ 259 if (this.didInit) { 260 this.unbindEvents(); 261 setTimeout(function (_this) { 262 return function () { 263 return _this.$modalElement.remove(); 264 }; 265 }(this), this.options.destroyTimeout); 266 } 267 if (unbindAnchors) { 268 this.$element.off('.slickLightbox'); 269 return this.$element.off('.slickLightbox', this.options.itemSelector); 270 } 271 }; 272 SlickLightbox.prototype.destroyPrevious = function () { 273 /* Destroys lightboxes currently in DOM. */ 274 return $('body').children('.slick-lightbox').trigger('destroy.slickLightbox'); 275 }; 276 SlickLightbox.prototype.getTransitionDuration = function () { 277 /* Detects the transition duration to know when to remove stuff from DOM etc. */ 278 var duration; 279 if (this.transitionDuration) { 280 return this.transitionDuration; 281 } 282 duration = this.$modalElement.css('transition-duration'); 283 if (typeof duration === 'undefined') { 284 return this.transitionDuration = 500; 285 } else { 286 return this.transitionDuration = duration.indexOf('ms') > -1 ? parseFloat(duration) : parseFloat(duration) * 1000; 287 } 288 }; 289 SlickLightbox.prototype.writeHistory = function () { 290 /* Writes an empty state to the history API if supported. */ 291 return typeof history !== 'undefined' && history !== null ? typeof history.pushState === 'function' ? history.pushState(null, null, '') : void 0 : void 0; 292 }; 293 SlickLightbox.prototype.filterOutSlickClones = function ($items) { 294 /* Removes all slick clones from the set of elements. Only does so, if the target element is a slick slider. */ 295 if (!this.elementIsSlick()) { 296 return $items; 297 } 298 return $items = $items.filter(function () { 299 var $item; 300 $item = $(this); 301 return !$item.hasClass('slick-cloned') && $item.parents('.slick-cloned').length === 0; 302 }); 303 }; 304 SlickLightbox.prototype.handlePossibleCloneClick = function ($clickedItem, $items) { 305 var href; 306 if (!this.elementIsSlick()) { 307 return $clickedItem; 308 } 309 if (!$clickedItem.closest('.slick-slide').hasClass('slick-cloned')) { 310 return $clickedItem; 311 } 312 href = $clickedItem.attr('href'); 313 return $items.filter(function () { 314 return $(this).attr('href') === href; 315 }).first(); 316 }; 317 SlickLightbox.prototype.elementIsSlick = function () { 318 return this.$element.hasClass('slick-slider'); 319 }; 320 return SlickLightbox; 321 }(); 322 defaults = { 323 background: 'rgba(0,0,0,.8)', 324 closeOnEscape: true, 325 closeOnBackdropClick: true, 326 destroyTimeout: 500, 327 itemSelector: 'a', 328 navigateByKeyboard: true, 329 src: false, 330 caption: false, 331 captionPosition: 'dynamic', 332 images: false, 333 slick: {}, 334 useHistoryApi: false, 335 layouts: { closeButton: '<button type="button" class="slick-lightbox-close"></button>' }, 336 shouldOpen: null, 337 imageMaxHeight: 0.9, 338 lazy: false 339 }; 340 $.fn.slickLightbox = function (options) { 341 /* Fires the plugin. */ 342 options = $.extend({}, defaults, options); 343 $(this).each(function () { 344 return this.slickLightbox = new SlickLightbox(this, options); 345 }); 346 return this; 347 }; 348 $.fn.unslickLightbox = function () { 349 /* Removes everything. */ 350 return $(this).trigger('destroy.slickLightbox').each(function () { 351 return this.slickLightbox = null; 352 }); 353 }; 354}(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.