1(function ($, window) { 2 3 /** 4 * Enable thumbnail support for Swiper 5 * @param swiper (pass swiper element) 6 * @param settings (pass custom options) 7 */ 8 window.swiperThumbs = function (swiper, settings) { 9 10 /** 11 * Loop over swiper instances 12 */ 13 $(swiper).each(function () { 14 15 var _this = this; 16 17 /** 18 * Default settings 19 */ 20 var options = { 21 element: 'swiper-thumbnails', 22 activeClass: 'is-active' 23 } 24 25 /** 26 * Merge user settings and default settings 27 */ 28 $.extend(options, settings); 29 30 /** 31 * Helper vars 32 */ 33 var element = $('.' + options.element); 34 35 /** 36 * Get real activeIndex 37 * @returns {*} 38 */ 39 var realIndex = function (index) { 40 // if index doesn't exist set index to activeIndex of swiper 41 if (index === undefined) index = _this.activeIndex; 42 43 // Check if swiper instance has loop before getting real index 44 if (_this.params.loop) { 45 return parseInt(_this.slides.eq(index).attr('data-swiper-slide-index')); 46 } else { 47 return index; 48 } 49 } 50 51 var app = { 52 53 init: function () { 54 app.bindUIevents(); 55 app.updateActiveClasses(realIndex(_this.activeIndex)); 56 }, 57 58 bindUIevents: function () { 59 /** 60 * Bind click events to thumbs 61 */ 62 element.children().each(function () { 63 $(this).on('click', function () { 64 65 // Get clicked index 66 var index = parseInt($(this).index()); 67 68 // Get difference between item clicked and current real active index. 69 var difference = (index - realIndex()); 70 71 // Move to slide that makes sense for the user by 72 // checking what the current active slide is and adding the difference 73 // this makes sure the swiper moves to a natural direction the user expects. 74 app.moveToSlide(_this.activeIndex + difference); 75 }) 76 }) 77 78 /** 79 * Update thumbs on slideChange 80 */ 81 _this.on('slideChangeStart', function (swiper) { 82 app.updateActiveClasses(realIndex()) 83 }); 84 }, 85 86 moveToSlide: function (index) { 87 _this.slideTo(index); 88 }, 89 90 updateActiveClasses: function (index) { 91 element.children().removeClass(options.activeClass); 92 element.children().eq(index).addClass(options.activeClass); 93 } 94 } 95 96 app.init(); 97 98 }); 99 100 }; 101 102}(jQuery, window));
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.