vendor: 14,207 bytes, lines 1-441
1/*! lg-thumbnail - v1.1.0 - 2017-08-08 2* http://sachinchoolur.github.io/lightGallery 3* Copyright (c) 2017 Sachin N; Licensed GPLv3 */ 4 5(function (root, factory) { 6 if (typeof define === 'function' && define.amd) { 7 // AMD. Register as an anonymous module unless amdModuleId is set 8 define(['jquery'], function (a0) { 9 return (factory(a0)); 10 }); 11 } else if (typeof exports === 'object') { 12 // Node. Does not work with strict CommonJS, but 13 // only CommonJS-like environments that support module.exports, 14 // like Node. 15 module.exports = factory(require('jquery')); 16 } else { 17 factory(jQuery); 18 } 19}(this, function ($) { 20 21(function() { 22 23 'use strict'; 24 25 var defaults = { 26 thumbnail: true, 27 28 animateThumb: true, 29 currentPagerPosition: 'middle', 30 31 thumbWidth: 100, 32 thumbHeight: '80px', 33 thumbContHeight: 100, 34 thumbMargin: 5, 35 36 exThumbImage: false, 37 showThumbByDefault: true, 38 toogleThumb: true, 39 pullCaptionUp: true, 40 41 enableThumbDrag: true, 42 enableThumbSwipe: true, 43 swipeThreshold: 50, 44 45 loadYoutubeThumbnail: true, 46 youtubeThumbSize: 1, 47 48 loadVimeoThumbnail: true, 49 vimeoThumbSize: 'thumbnail_small', 50 51 loadDailymotionThumbnail: true 52 }; 53 54 var Thumbnail = function(element) { 55 56 // get lightGallery core plugin data 57 this.core = $(element).data('lightGallery'); 58 59 // extend module default settings with lightGallery core settings 60 this.core.s = $.extend({}, defaults, this.core.s); 61 62 this.$el = $(element); 63 this.$thumbOuter = null; 64 this.thumbOuterWidth = 0; 65 this.thumbTotalWidth = (this.core.$items.length * (this.core.s.thumbWidth + this.core.s.thumbMargin)); 66 this.thumbIndex = this.core.index; 67 68 if (this.core.s.animateThumb) { 69 this.core.s.thumbHeight = '100%'; 70 } 71 72 // Thumbnail animation value 73 this.left = 0; 74 75 this.init(); 76 77 return this; 78 }; 79 80 Thumbnail.prototype.init = function() { 81 var _this = this; 82 if (this.core.s.thumbnail && this.core.$items.length > 1) { 83 if (this.core.s.showThumbByDefault) { 84 setTimeout(function(){ 85 _this.core.$outer.addClass('lg-thumb-open'); 86 }, 700); 87 } 88 89 if (this.core.s.pullCaptionUp) { 90 this.core.$outer.addClass('lg-pull-caption-up'); 91 } 92 93 this.build(); 94 if (this.core.s.animateThumb && this.core.doCss()) { 95 if (this.core.s.enableThumbDrag) { 96 this.enableThumbDrag(); 97 } 98 99 if (this.core.s.enableThumbSwipe) { 100 this.enableThumbSwipe(); 101 } 102 103 this.thumbClickable = false; 104 } else { 105 this.thumbClickable = true; 106 } 107 108 this.toogle(); 109 this.thumbkeyPress(); 110 } 111 }; 112 113 Thumbnail.prototype.build = function() { 114 var _this = this; 115 var thumbList = ''; 116 var vimeoErrorThumbSize = ''; 117 var $thumb; 118 var html = '<div class="lg-thumb-outer">' + 119 '<div class="lg-thumb lg-group">' + 120 '</div>' + 121 '</div>'; 122 123 switch (this.core.s.vimeoThumbSize) { 124 case 'thumbnail_large': 125 vimeoErrorThumbSize = '640'; 126 break; 127 case 'thumbnail_medium': 128 vimeoErrorThumbSize = '200x150'; 129 break; 130 case 'thumbnail_small': 131 vimeoErrorThumbSize = '100x75'; 132 } 133 134 _this.core.$outer.addClass('lg-has-thumb'); 135 136 _this.core.$outer.find('.lg-inner').after(html); 137 138 _this.$thumbOuter = _this.core.$outer.find('.lg-thumb-outer'); 139 _this.thumbOuterWidth = _this.$thumbOuter.width(); 140 141 if (_this.core.s.animateThumb) { 142 _this.core.$outer.find('.lg-thumb').css({ 143 width: _this.thumbTotalWidth + 'px', 144 position: 'relative' 145 }); 146 } 147 148 if (this.core.s.animateThumb) { 149 _this.$thumbOuter.css('height', _this.core.s.thumbContHeight + 'px'); 150 } 151 152 function getThumb(src, thumb, index) { 153 var isVideo = _this.core.isVideo(src, index) || {}; 154 var thumbImg; 155 var vimeoId = ''; 156 157 thumbImg = thumb; 158 159 thumbList += '<div data-vimeo-id="' + vimeoId + '" class="lg-thumb-item" style="width:' + _this.core.s.thumbWidth + 'px; height: ' + _this.core.s.thumbHeight + '; margin-right: ' + _this.core.s.thumbMargin + 'px"><img src="' + thumbImg + '" /></div>'; 160 vimeoId = ''; 161 } 162 163 if (_this.core.s.dynamic) { 164 for (var i = 0; i < _this.core.s.dynamicEl.length; i++) { 165 getThumb(_this.core.s.dynamicEl[i].src, _this.core.s.dynamicEl[i].thumb, i); 166 } 167 } else { 168 _this.core.$items.each(function(i) { 169 170 if (!_this.core.s.exThumbImage) { 171 getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).find('img').attr('src'), i); 172 } else { 173 getThumb($(this).attr('href') || $(this).attr('data-src'), $(this).attr(_this.core.s.exThumbImage), i); 174 } 175 176 }); 177 } 178 179 _this.core.$outer.find('.lg-thumb').html(thumbList); 180 181 $thumb = _this.core.$outer.find('.lg-thumb-item'); 182 183 // manage active class for thumbnail 184 $thumb.eq(_this.core.index).addClass('active'); 185 _this.core.$el.on('onBeforeSlide.lg.tm', function() { 186 $thumb.removeClass('active'); 187 $thumb.eq(_this.core.index).addClass('active'); 188 }); 189 190 $thumb.on('click.lg touchend.lg', function() { 191 var _$this = $(this); 192 setTimeout(function() { 193 194 // In IE9 and bellow touch does not support 195 // Go to slide if browser does not support css transitions 196 if ((_this.thumbClickable && !_this.core.lgBusy) || !_this.core.doCss()) { 197 _this.core.index = _$this.index(); 198 _this.core.slide(_this.core.index, false, true, false); 199 } 200 }, 50); 201 }); 202 203 _this.core.$el.on('onBeforeSlide.lg.tm', function() { 204 _this.animateThumb(_this.core.index); 205 }); 206 207 $(window).on('resize.lg.thumb orientationchange.lg.thumb', function() { 208 setTimeout(function() { 209 _this.animateThumb(_this.core.index); 210 _this.thumbOuterWidth = _this.$thumbOuter.width(); 211 }, 200); 212 }); 213 214 }; 215 216 Thumbnail.prototype.setTranslate = function(value) { 217 // jQuery supports Automatic CSS prefixing since jQuery 1.8.0 218 this.core.$outer.find('.lg-thumb').css({ 219 transform: 'translate3d(-' + (value) + 'px, 0px, 0px)' 220 }); 221 }; 222 223 Thumbnail.prototype.animateThumb = function(index) { 224 var $thumb = this.core.$outer.find('.lg-thumb'); 225 if (this.core.s.animateThumb) { 226 var position; 227 switch (this.core.s.currentPagerPosition) { 228 case 'left': 229 position = 0; 230 break; 231 case 'middle': 232 position = (this.thumbOuterWidth / 2) - (this.core.s.thumbWidth / 2); 233 break; 234 case 'right': 235 position = this.thumbOuterWidth - this.core.s.thumbWidth; 236 } 237 this.left = ((this.core.s.thumbWidth + this.core.s.thumbMargin) * index - 1) - position; 238 if (this.left > (this.thumbTotalWidth - this.thumbOuterWidth)) { 239 this.left = this.thumbTotalWidth - this.thumbOuterWidth; 240 } 241 242 if (this.left < 0) { 243 this.left = 0; 244 } 245 246 if (this.core.lGalleryOn) { 247 if (!$thumb.hasClass('on')) { 248 this.core.$outer.find('.lg-thumb').css('transition-duration', this.core.s.speed + 'ms'); 249 } 250 251 if (!this.core.doCss()) { 252 $thumb.animate({ 253 left: -this.left + 'px' 254 }, this.core.s.speed); 255 } 256 } else { 257 if (!this.core.doCss()) { 258 $thumb.css('left', -this.left + 'px'); 259 } 260 } 261 262 this.setTranslate(this.left); 263 264 } 265 }; 266 267 // Enable thumbnail dragging and swiping 268 Thumbnail.prototype.enableThumbDrag = function() { 269 270 var _this = this; 271 var startCoords = 0; 272 var endCoords = 0; 273 var isDraging = false; 274 var isMoved = false; 275 var tempLeft = 0; 276 277 _this.$thumbOuter.addClass('lg-grab'); 278 279 _this.core.$outer.find('.lg-thumb').on('mousedown.lg.thumb', function(e) { 280 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 281 // execute only on .lg-object 282 e.preventDefault(); 283 startCoords = e.pageX; 284 isDraging = true; 285 286 // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723 287 _this.core.$outer.scrollLeft += 1; 288 _this.core.$outer.scrollLeft -= 1; 289 290 // * 291 _this.thumbClickable = false; 292 _this.$thumbOuter.removeClass('lg-grab').addClass('lg-grabbing'); 293 } 294 }); 295 296 $(window).on('mousemove.lg.thumb', function(e) { 297 if (isDraging) { 298 tempLeft = _this.left; 299 isMoved = true; 300 endCoords = e.pageX; 301 302 _this.$thumbOuter.addClass('lg-dragging'); 303 304 tempLeft = tempLeft - (endCoords - startCoords); 305 306 if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) { 307 tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth; 308 } 309 310 if (tempLeft < 0) { 311 tempLeft = 0; 312 } 313 314 // move current slide 315 _this.setTranslate(tempLeft); 316 317 } 318 }); 319 320 $(window).on('mouseup.lg.thumb', function() { 321 if (isMoved) { 322 isMoved = false; 323 _this.$thumbOuter.removeClass('lg-dragging'); 324 325 _this.left = tempLeft; 326 327 if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) { 328 _this.thumbClickable = true; 329 } 330 331 } else { 332 _this.thumbClickable = true; 333 } 334 335 if (isDraging) { 336 isDraging = false; 337 _this.$thumbOuter.removeClass('lg-grabbing').addClass('lg-grab'); 338 } 339 }); 340 341 }; 342 343 Thumbnail.prototype.enableThumbSwipe = function() { 344 var _this = this; 345 var startCoords = 0; 346 var endCoords = 0; 347 var isMoved = false; 348 var tempLeft = 0; 349 350 _this.core.$outer.find('.lg-thumb').on('touchstart.lg', function(e) { 351 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 352 e.preventDefault(); 353 startCoords = e.originalEvent.targetTouches[0].pageX; 354 _this.thumbClickable = false; 355 } 356 }); 357 358 _this.core.$outer.find('.lg-thumb').on('touchmove.lg', function(e) { 359 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 360 e.preventDefault(); 361 endCoords = e.originalEvent.targetTouches[0].pageX; 362 isMoved = true; 363 364 _this.$thumbOuter.addClass('lg-dragging'); 365 366 tempLeft = _this.left; 367 368 tempLeft = tempLeft - (endCoords - startCoords); 369 370 if (tempLeft > (_this.thumbTotalWidth - _this.thumbOuterWidth)) { 371 tempLeft = _this.thumbTotalWidth - _this.thumbOuterWidth; 372 } 373 374 if (tempLeft < 0) { 375 tempLeft = 0; 376 } 377 378 // move current slide 379 _this.setTranslate(tempLeft); 380 381 } 382 }); 383 384 _this.core.$outer.find('.lg-thumb').on('touchend.lg', function() { 385 if (_this.thumbTotalWidth > _this.thumbOuterWidth) { 386 387 if (isMoved) { 388 isMoved = false; 389 _this.$thumbOuter.removeClass('lg-dragging'); 390 if (Math.abs(endCoords - startCoords) < _this.core.s.swipeThreshold) { 391 _this.thumbClickable = true; 392 } 393 394 _this.left = tempLeft; 395 } else { 396 _this.thumbClickable = true; 397 } 398 } else { 399 _this.thumbClickable = true; 400 } 401 }); 402 403 }; 404 405 Thumbnail.prototype.toogle = function() { 406 var _this = this; 407 if (_this.core.s.toogleThumb) { 408 _this.core.$outer.addClass('lg-can-toggle'); 409 _this.$thumbOuter.append('<span class="lg-toogle-thumb lg-icon"></span>'); 410 _this.core.$outer.find('.lg-toogle-thumb').on('click.lg', function() { 411 _this.core.$outer.toggleClass('lg-thumb-open'); 412 }); 413 } 414 }; 415 416 Thumbnail.prototype.thumbkeyPress = function() { 417 var _this = this; 418 $(window).on('keydown.lg.thumb', function(e) { 419 if (e.keyCode === 38) { 420 e.preventDefault(); 421 _this.core.$outer.addClass('lg-thumb-open'); 422 } else if (e.keyCode === 40) { 423 e.preventDefault(); 424 _this.core.$outer.removeClass('lg-thumb-open'); 425 } 426 }); 427 }; 428 429 Thumbnail.prototype.destroy = function() { 430 if (this.core.s.thumbnail && this.core.$items.length > 1) { 431 $(window).off('resize.lg.thumb orientationchange.lg.thumb keydown.lg.thumb'); 432 this.$thumbOuter.remove(); 433 this.core.$outer.removeClass('lg-has-thumb'); 434 } 435 }; 436 437 $.fn.lightGallery.modules.Thumbnail = Thumbnail; 438 439})(); 440 441}));
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.