1/* 2 * blueimp Gallery Indicator JS 3 * https://github.com/blueimp/Gallery 4 * 5 * Copyright 2013, Sebastian Tschan 6 * https://blueimp.net 7 * 8 * Licensed under the MIT license: 9 * https://opensource.org/licenses/MIT 10 */ 11 12/* global define, window, document */ 13 14;(function (factory) { 15 'use strict' 16 if (typeof define === 'function' && define.amd) { 17 // Register as an anonymous AMD module: 18 define(['./blueimp-helper', './blueimp-gallery'], factory) 19 } else { 20 // Browser globals: 21 factory(window.blueimp.helper || window.jQuery, window.blueimp.Gallery) 22 } 23})(function ($, Gallery) { 24 'use strict' 25 26 $.extend(Gallery.prototype.options, { 27 // The tag name, Id, element or querySelector of the indicator container: 28 indicatorContainer: 'ol', 29 // The class for the active indicator: 30 activeIndicatorClass: 'active', 31 // The list object property (or data attribute) with the thumbnail URL, 32 // used as alternative to a thumbnail child element: 33 thumbnailProperty: 'thumbnail', 34 // Defines if the gallery indicators should display a thumbnail: 35 thumbnailIndicators: true 36 }) 37 38 var initSlides = Gallery.prototype.initSlides 39 var addSlide = Gallery.prototype.addSlide 40 var resetSlides = Gallery.prototype.resetSlides 41 var handleClick = Gallery.prototype.handleClick 42 var handleSlide = Gallery.prototype.handleSlide 43 var handleClose = Gallery.prototype.handleClose 44 45 $.extend(Gallery.prototype, { 46 createIndicator: function (obj) { 47 var indicator = this.indicatorPrototype.cloneNode(false) 48 var title = this.getItemProperty(obj, this.options.titleProperty) 49 var thumbnailProperty = this.options.thumbnailProperty 50 var thumbnailUrl 51 var thumbnail 52 if (this.options.thumbnailIndicators) { 53 if (thumbnailProperty) { 54 thumbnailUrl = this.getItemProperty(obj, thumbnailProperty) 55 } 56 if (thumbnailUrl === undefined) { 57 thumbnail = obj.getElementsByTagName && $(obj).find('img')[0] 58 if (thumbnail) { 59 thumbnailUrl = thumbnail.src 60 } 61 } 62 if (thumbnailUrl) { 63 indicator.style.backgroundImage = 'url("' + thumbnailUrl + '")' 64 } 65 } 66 if (title) { 67 indicator.title = title 68 } 69 return indicator 70 }, 71 72 addIndicator: function (index) { 73 if (this.indicatorContainer.length) { 74 var indicator = this.createIndicator(this.list[index]) 75 indicator.setAttribute('data-index', index) 76 this.indicatorContainer[0].appendChild(indicator) 77 this.indicators.push(indicator) 78 } 79 }, 80 81 setActiveIndicator: function (index) { 82 if (this.indicators) { 83 if (this.activeIndicator) { 84 this.activeIndicator.removeClass(this.options.activeIndicatorClass) 85 } 86 this.activeIndicator = $(this.indicators[index]) 87 this.activeIndicator.addClass(this.options.activeIndicatorClass) 88 } 89 }, 90 91 initSlides: function (reload) { 92 if (!reload) { 93 this.indicatorContainer = this.container.find( 94 this.options.indicatorContainer 95 ) 96 if (this.indicatorContainer.length) { 97 this.indicatorPrototype = document.createElement('li') 98 this.indicators = this.indicatorContainer[0].children 99 } 100 } 101 initSlides.call(this, reload) 102 }, 103 104 addSlide: function (index) { 105 addSlide.call(this, index) 106 this.addIndicator(index) 107 }, 108 109 resetSlides: function () { 110 resetSlides.call(this) 111 this.indicatorContainer.empty() 112 this.indicators = [] 113 }, 114 115 handleClick: function (event) { 116 var target = event.target || event.srcElement 117 var parent = target.parentNode 118 if (parent === this.indicatorContainer[0]) { 119 // Click on indicator element 120 this.preventDefault(event) 121 this.slide(this.getNodeIndex(target)) 122 } else if (parent.parentNode === this.indicatorContainer[0]) { 123 // Click on indicator child element 124 this.preventDefault(event) 125 this.slide(this.getNodeIndex(parent)) 126 } else { 127 return handleClick.call(this, event) 128 } 129 }, 130 131 handleSlide: function (index) { 132 handleSlide.call(this, index) 133 this.setActiveIndicator(index) 134 }, 135 136 handleClose: function () { 137 if (this.activeIndicator) { 138 this.activeIndicator.removeClass(this.options.activeIndicatorClass) 139 } 140 handleClose.call(this) 141 } 142 }) 143 144 return Gallery 145})
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.