scratch – Blame information for rev 115
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | /* |
2 | * blueimp Gallery JS |
||
3 | * https://github.com/blueimp/Gallery |
||
4 | * |
||
5 | * Copyright 2013, Sebastian Tschan |
||
6 | * https://blueimp.net |
||
7 | * |
||
8 | * Swipe implementation based on |
||
9 | * https://github.com/bradbirdsall/Swipe |
||
10 | * |
||
11 | * Licensed under the MIT license: |
||
12 | * https://opensource.org/licenses/MIT |
||
13 | */ |
||
14 | |||
15 | /* global define, window, document, DocumentTouch */ |
||
16 | |||
17 | ;(function (factory) { |
||
18 | 'use strict' |
||
19 | if (typeof define === 'function' && define.amd) { |
||
20 | // Register as an anonymous AMD module: |
||
21 | define(['./blueimp-helper'], factory) |
||
22 | } else { |
||
23 | // Browser globals: |
||
24 | window.blueimp = window.blueimp || {} |
||
25 | window.blueimp.Gallery = factory( |
||
26 | window.blueimp.helper || window.jQuery |
||
27 | ) |
||
28 | } |
||
29 | }(function ($) { |
||
30 | 'use strict' |
||
31 | |||
32 | function Gallery (list, options) { |
||
33 | if (document.body.style.maxHeight === undefined) { |
||
34 | // document.body.style.maxHeight is undefined on IE6 and lower |
||
35 | return null |
||
36 | } |
||
37 | if (!this || this.options !== Gallery.prototype.options) { |
||
38 | // Called as function instead of as constructor, |
||
39 | // so we simply return a new instance: |
||
40 | return new Gallery(list, options) |
||
41 | } |
||
42 | if (!list || !list.length) { |
||
43 | this.console.log( |
||
44 | 'blueimp Gallery: No or empty list provided as first argument.', |
||
45 | list |
||
46 | ) |
||
47 | return |
||
48 | } |
||
49 | this.list = list |
||
50 | this.num = list.length |
||
51 | this.initOptions(options) |
||
52 | this.initialize() |
||
53 | } |
||
54 | |||
55 | $.extend(Gallery.prototype, { |
||
56 | options: { |
||
57 | // The Id, element or querySelector of the gallery widget: |
||
58 | container: '#blueimp-gallery', |
||
59 | // The tag name, Id, element or querySelector of the slides container: |
||
60 | slidesContainer: 'div', |
||
61 | // The tag name, Id, element or querySelector of the title element: |
||
62 | titleElement: 'h3', |
||
63 | // The class to add when the gallery is visible: |
||
64 | displayClass: 'blueimp-gallery-display', |
||
65 | // The class to add when the gallery controls are visible: |
||
66 | controlsClass: 'blueimp-gallery-controls', |
||
67 | // The class to add when the gallery only displays one element: |
||
68 | singleClass: 'blueimp-gallery-single', |
||
69 | // The class to add when the left edge has been reached: |
||
70 | leftEdgeClass: 'blueimp-gallery-left', |
||
71 | // The class to add when the right edge has been reached: |
||
72 | rightEdgeClass: 'blueimp-gallery-right', |
||
73 | // The class to add when the automatic slideshow is active: |
||
74 | playingClass: 'blueimp-gallery-playing', |
||
75 | // The class for all slides: |
||
76 | slideClass: 'slide', |
||
77 | // The slide class for loading elements: |
||
78 | slideLoadingClass: 'slide-loading', |
||
79 | // The slide class for elements that failed to load: |
||
80 | slideErrorClass: 'slide-error', |
||
81 | // The class for the content element loaded into each slide: |
||
82 | slideContentClass: 'slide-content', |
||
83 | // The class for the "toggle" control: |
||
84 | toggleClass: 'toggle', |
||
85 | // The class for the "prev" control: |
||
86 | prevClass: 'prev', |
||
87 | // The class for the "next" control: |
||
88 | nextClass: 'next', |
||
89 | // The class for the "close" control: |
||
90 | closeClass: 'close', |
||
91 | // The class for the "play-pause" toggle control: |
||
92 | playPauseClass: 'play-pause', |
||
93 | // The list object property (or data attribute) with the object type: |
||
94 | typeProperty: 'type', |
||
95 | // The list object property (or data attribute) with the object title: |
||
96 | titleProperty: 'title', |
||
97 | // The list object property (or data attribute) with the object URL: |
||
98 | urlProperty: 'href', |
||
99 | // The list object property (or data attribute) with the object srcset URL(s): |
||
100 | srcsetProperty: 'urlset', |
||
101 | // The gallery listens for transitionend events before triggering the |
||
102 | // opened and closed events, unless the following option is set to false: |
||
103 | displayTransition: true, |
||
104 | // Defines if the gallery slides are cleared from the gallery modal, |
||
105 | // or reused for the next gallery initialization: |
||
106 | clearSlides: true, |
||
107 | // Defines if images should be stretched to fill the available space, |
||
108 | // while maintaining their aspect ratio (will only be enabled for browsers |
||
109 | // supporting background-size="contain", which excludes IE < 9). |
||
110 | // Set to "cover", to make images cover all available space (requires |
||
111 | // support for background-size="cover", which excludes IE < 9): |
||
112 | stretchImages: false, |
||
113 | // Toggle the controls on pressing the Return key: |
||
114 | toggleControlsOnReturn: true, |
||
115 | // Toggle the controls on slide click: |
||
116 | toggleControlsOnSlideClick: true, |
||
117 | // Toggle the automatic slideshow interval on pressing the Space key: |
||
118 | toggleSlideshowOnSpace: true, |
||
119 | // Navigate the gallery by pressing left and right on the keyboard: |
||
120 | enableKeyboardNavigation: true, |
||
121 | // Close the gallery on pressing the Esc key: |
||
122 | closeOnEscape: true, |
||
123 | // Close the gallery when clicking on an empty slide area: |
||
124 | closeOnSlideClick: true, |
||
125 | // Close the gallery by swiping up or down: |
||
126 | closeOnSwipeUpOrDown: true, |
||
127 | // Emulate touch events on mouse-pointer devices such as desktop browsers: |
||
128 | emulateTouchEvents: true, |
||
129 | // Stop touch events from bubbling up to ancestor elements of the Gallery: |
||
130 | stopTouchEventsPropagation: false, |
||
131 | // Hide the page scrollbars: |
||
132 | hidePageScrollbars: true, |
||
133 | // Stops any touches on the container from scrolling the page: |
||
134 | disableScroll: true, |
||
135 | // Carousel mode (shortcut for carousel specific options): |
||
136 | carousel: false, |
||
137 | // Allow continuous navigation, moving from last to first |
||
138 | // and from first to last slide: |
||
139 | continuous: true, |
||
140 | // Remove elements outside of the preload range from the DOM: |
||
141 | unloadElements: true, |
||
142 | // Start with the automatic slideshow: |
||
143 | startSlideshow: false, |
||
144 | // Delay in milliseconds between slides for the automatic slideshow: |
||
145 | slideshowInterval: 5000, |
||
146 | // The starting index as integer. |
||
147 | // Can also be an object of the given list, |
||
148 | // or an equal object with the same url property: |
||
149 | index: 0, |
||
150 | // The number of elements to load around the current index: |
||
151 | preloadRange: 2, |
||
152 | // The transition speed between slide changes in milliseconds: |
||
153 | transitionSpeed: 400, |
||
154 | // The transition speed for automatic slide changes, set to an integer |
||
155 | // greater 0 to override the default transition speed: |
||
156 | slideshowTransitionSpeed: undefined, |
||
157 | // The event object for which the default action will be canceled |
||
158 | // on Gallery initialization (e.g. the click event to open the Gallery): |
||
159 | event: undefined, |
||
160 | // Callback function executed when the Gallery is initialized. |
||
161 | // Is called with the gallery instance as "this" object: |
||
162 | onopen: undefined, |
||
163 | // Callback function executed when the Gallery has been initialized |
||
164 | // and the initialization transition has been completed. |
||
165 | // Is called with the gallery instance as "this" object: |
||
166 | onopened: undefined, |
||
167 | // Callback function executed on slide change. |
||
168 | // Is called with the gallery instance as "this" object and the |
||
169 | // current index and slide as arguments: |
||
170 | onslide: undefined, |
||
171 | // Callback function executed after the slide change transition. |
||
172 | // Is called with the gallery instance as "this" object and the |
||
173 | // current index and slide as arguments: |
||
174 | onslideend: undefined, |
||
175 | // Callback function executed on slide content load. |
||
176 | // Is called with the gallery instance as "this" object and the |
||
177 | // slide index and slide element as arguments: |
||
178 | onslidecomplete: undefined, |
||
179 | // Callback function executed when the Gallery is about to be closed. |
||
180 | // Is called with the gallery instance as "this" object: |
||
181 | onclose: undefined, |
||
182 | // Callback function executed when the Gallery has been closed |
||
183 | // and the closing transition has been completed. |
||
184 | // Is called with the gallery instance as "this" object: |
||
185 | onclosed: undefined |
||
186 | }, |
||
187 | |||
188 | carouselOptions: { |
||
189 | hidePageScrollbars: false, |
||
190 | toggleControlsOnReturn: false, |
||
191 | toggleSlideshowOnSpace: false, |
||
192 | enableKeyboardNavigation: false, |
||
193 | closeOnEscape: false, |
||
194 | closeOnSlideClick: false, |
||
195 | closeOnSwipeUpOrDown: false, |
||
196 | disableScroll: false, |
||
197 | startSlideshow: true |
||
198 | }, |
||
199 | |||
200 | console: window.console && typeof window.console.log === 'function' |
||
201 | ? window.console |
||
202 | : {log: function () {}}, |
||
203 | |||
204 | // Detect touch, transition, transform and background-size support: |
||
205 | support: (function (element) { |
||
206 | var support = { |
||
207 | touch: window.ontouchstart !== undefined || |
||
208 | (window.DocumentTouch && document instanceof DocumentTouch) |
||
209 | } |
||
210 | var transitions = { |
||
211 | webkitTransition: { |
||
212 | end: 'webkitTransitionEnd', |
||
213 | prefix: '-webkit-' |
||
214 | }, |
||
215 | MozTransition: { |
||
216 | end: 'transitionend', |
||
217 | prefix: '-moz-' |
||
218 | }, |
||
219 | OTransition: { |
||
220 | end: 'otransitionend', |
||
221 | prefix: '-o-' |
||
222 | }, |
||
223 | transition: { |
||
224 | end: 'transitionend', |
||
225 | prefix: '' |
||
226 | } |
||
227 | } |
||
228 | var prop |
||
229 | for (prop in transitions) { |
||
230 | if (transitions.hasOwnProperty(prop) && |
||
231 | element.style[prop] !== undefined) { |
||
232 | support.transition = transitions[prop] |
||
233 | support.transition.name = prop |
||
234 | break |
||
235 | } |
||
236 | } |
||
237 | function elementTests () { |
||
238 | var transition = support.transition |
||
239 | var prop |
||
240 | var translateZ |
||
241 | document.body.appendChild(element) |
||
242 | if (transition) { |
||
243 | prop = transition.name.slice(0, -9) + 'ransform' |
||
244 | if (element.style[prop] !== undefined) { |
||
245 | element.style[prop] = 'translateZ(0)' |
||
246 | translateZ = window.getComputedStyle(element) |
||
247 | .getPropertyValue(transition.prefix + 'transform') |
||
248 | support.transform = { |
||
249 | prefix: transition.prefix, |
||
250 | name: prop, |
||
251 | translate: true, |
||
252 | translateZ: !!translateZ && translateZ !== 'none' |
||
253 | } |
||
254 | } |
||
255 | } |
||
256 | if (element.style.backgroundSize !== undefined) { |
||
257 | support.backgroundSize = {} |
||
258 | element.style.backgroundSize = 'contain' |
||
259 | support.backgroundSize.contain = window |
||
260 | .getComputedStyle(element) |
||
261 | .getPropertyValue('background-size') === 'contain' |
||
262 | element.style.backgroundSize = 'cover' |
||
263 | support.backgroundSize.cover = window |
||
264 | .getComputedStyle(element) |
||
265 | .getPropertyValue('background-size') === 'cover' |
||
266 | } |
||
267 | document.body.removeChild(element) |
||
268 | } |
||
269 | if (document.body) { |
||
270 | elementTests() |
||
271 | } else { |
||
272 | $(document).on('DOMContentLoaded', elementTests) |
||
273 | } |
||
274 | return support |
||
275 | // Test element, has to be standard HTML and must not be hidden |
||
276 | // for the CSS3 tests using window.getComputedStyle to be applicable: |
||
277 | }(document.createElement('div'))), |
||
278 | |||
279 | requestAnimationFrame: window.requestAnimationFrame || |
||
280 | window.webkitRequestAnimationFrame || |
||
281 | window.mozRequestAnimationFrame, |
||
282 | |||
283 | initialize: function () { |
||
284 | this.initStartIndex() |
||
285 | if (this.initWidget() === false) { |
||
286 | return false |
||
287 | } |
||
288 | this.initEventListeners() |
||
289 | // Load the slide at the given index: |
||
290 | this.onslide(this.index) |
||
291 | // Manually trigger the slideend event for the initial slide: |
||
292 | this.ontransitionend() |
||
293 | // Start the automatic slideshow if applicable: |
||
294 | if (this.options.startSlideshow) { |
||
295 | this.play() |
||
296 | } |
||
297 | }, |
||
298 | |||
299 | slide: function (to, speed) { |
||
300 | window.clearTimeout(this.timeout) |
||
301 | var index = this.index |
||
302 | var direction |
||
303 | var naturalDirection |
||
304 | var diff |
||
305 | if (index === to || this.num === 1) { |
||
306 | return |
||
307 | } |
||
308 | if (!speed) { |
||
309 | speed = this.options.transitionSpeed |
||
310 | } |
||
311 | if (this.support.transform) { |
||
312 | if (!this.options.continuous) { |
||
313 | to = this.circle(to) |
||
314 | } |
||
315 | // 1: backward, -1: forward: |
||
316 | direction = Math.abs(index - to) / (index - to) |
||
317 | // Get the actual position of the slide: |
||
318 | if (this.options.continuous) { |
||
319 | naturalDirection = direction |
||
320 | direction = -this.positions[this.circle(to)] / this.slideWidth |
||
321 | // If going forward but to < index, use to = slides.length + to |
||
322 | // If going backward but to > index, use to = -slides.length + to |
||
323 | if (direction !== naturalDirection) { |
||
324 | to = -direction * this.num + to |
||
325 | } |
||
326 | } |
||
327 | diff = Math.abs(index - to) - 1 |
||
328 | // Move all the slides between index and to in the right direction: |
||
329 | while (diff) { |
||
330 | diff -= 1 |
||
331 | this.move( |
||
332 | this.circle((to > index ? to : index) - diff - 1), |
||
333 | this.slideWidth * direction, |
||
334 | |||
335 | ) |
||
336 | } |
||
337 | to = this.circle(to) |
||
338 | this.move(index, this.slideWidth * direction, speed) |
||
339 | this.move(to, 0, speed) |
||
340 | if (this.options.continuous) { |
||
341 | this.move( |
||
342 | this.circle(to - direction), |
||
343 | -(this.slideWidth * direction), |
||
344 | |||
345 | ) |
||
346 | } |
||
347 | } else { |
||
348 | to = this.circle(to) |
||
349 | this.animate(index * -this.slideWidth, to * -this.slideWidth, speed) |
||
350 | } |
||
351 | this.onslide(to) |
||
352 | }, |
||
353 | |||
354 | getIndex: function () { |
||
355 | return this.index |
||
356 | }, |
||
357 | |||
358 | getNumber: function () { |
||
359 | return this.num |
||
360 | }, |
||
361 | |||
362 | prev: function () { |
||
363 | if (this.options.continuous || this.index) { |
||
364 | this.slide(this.index - 1) |
||
365 | } |
||
366 | }, |
||
367 | |||
368 | next: function () { |
||
369 | if (this.options.continuous || this.index < this.num - 1) { |
||
370 | this.slide(this.index + 1) |
||
371 | } |
||
372 | }, |
||
373 | |||
374 | play: function (time) { |
||
375 | var that = this |
||
376 | window.clearTimeout(this.timeout) |
||
377 | this.interval = time || this.options.slideshowInterval |
||
378 | if (this.elements[this.index] > 1) { |
||
379 | this.timeout = this.setTimeout( |
||
380 | (!this.requestAnimationFrame && this.slide) || function (to, speed) { |
||
381 | that.animationFrameId = that.requestAnimationFrame.call( |
||
382 | window, |
||
383 | function () { |
||
384 | that.slide(to, speed) |
||
385 | } |
||
386 | ) |
||
387 | }, |
||
388 | [this.index + 1, this.options.slideshowTransitionSpeed], |
||
389 | this.interval |
||
390 | ) |
||
391 | } |
||
392 | this.container.addClass(this.options.playingClass) |
||
393 | }, |
||
394 | |||
395 | pause: function () { |
||
396 | window.clearTimeout(this.timeout) |
||
397 | this.interval = null |
||
398 | this.container.removeClass(this.options.playingClass) |
||
399 | }, |
||
400 | |||
401 | add: function (list) { |
||
402 | var i |
||
403 | if (!list.concat) { |
||
404 | // Make a real array out of the list to add: |
||
405 | list = Array.prototype.slice.call(list) |
||
406 | } |
||
407 | if (!this.list.concat) { |
||
408 | // Make a real array out of the Gallery list: |
||
409 | this.list = Array.prototype.slice.call(this.list) |
||
410 | } |
||
411 | this.list = this.list.concat(list) |
||
412 | this.num = this.list.length |
||
413 | if (this.num > 2 && this.options.continuous === null) { |
||
414 | this.options.continuous = true |
||
415 | this.container.removeClass(this.options.leftEdgeClass) |
||
416 | } |
||
417 | this.container |
||
418 | .removeClass(this.options.rightEdgeClass) |
||
419 | .removeClass(this.options.singleClass) |
||
420 | for (i = this.num - list.length; i < this.num; i += 1) { |
||
421 | this.addSlide(i) |
||
422 | this.positionSlide(i) |
||
423 | } |
||
424 | this.positions.length = this.num |
||
425 | this.initSlides(true) |
||
426 | }, |
||
427 | |||
428 | resetSlides: function () { |
||
429 | this.slidesContainer.empty() |
||
430 | this.unloadAllSlides() |
||
431 | this.slides = [] |
||
432 | }, |
||
433 | |||
434 | handleClose: function () { |
||
435 | var options = this.options |
||
436 | this.destroyEventListeners() |
||
437 | // Cancel the slideshow: |
||
438 | this.pause() |
||
439 | this.container[0].style.display = 'none' |
||
440 | this.container |
||
441 | .removeClass(options.displayClass) |
||
442 | .removeClass(options.singleClass) |
||
443 | .removeClass(options.leftEdgeClass) |
||
444 | .removeClass(options.rightEdgeClass) |
||
445 | if (options.hidePageScrollbars) { |
||
446 | document.body.style.overflow = this.bodyOverflowStyle |
||
447 | } |
||
448 | if (this.options.clearSlides) { |
||
449 | this.resetSlides() |
||
450 | } |
||
451 | if (this.options.onclosed) { |
||
452 | this.options.onclosed.call(this) |
||
453 | } |
||
454 | }, |
||
455 | |||
456 | close: function () { |
||
457 | var that = this |
||
458 | function closeHandler (event) { |
||
459 | if (event.target === that.container[0]) { |
||
460 | that.container.off( |
||
461 | that.support.transition.end, |
||
462 | closeHandler |
||
463 | ) |
||
464 | that.handleClose() |
||
465 | } |
||
466 | } |
||
467 | if (this.options.onclose) { |
||
468 | this.options.onclose.call(this) |
||
469 | } |
||
470 | if (this.support.transition && this.options.displayTransition) { |
||
471 | this.container.on( |
||
472 | this.support.transition.end, |
||
473 | closeHandler |
||
474 | ) |
||
475 | this.container.removeClass(this.options.displayClass) |
||
476 | } else { |
||
477 | this.handleClose() |
||
478 | } |
||
479 | }, |
||
480 | |||
481 | circle: function (index) { |
||
482 | // Always return a number inside of the slides index range: |
||
483 | return (this.num + (index % this.num)) % this.num |
||
484 | }, |
||
485 | |||
486 | move: function (index, dist, speed) { |
||
487 | this.translateX(index, dist, speed) |
||
488 | this.positions[index] = dist |
||
489 | }, |
||
490 | |||
491 | translate: function (index, x, y, speed) { |
||
492 | var style = this.slides[index].style |
||
493 | var transition = this.support.transition |
||
494 | var transform = this.support.transform |
||
495 | style[transition.name + 'Duration'] = speed + 'ms' |
||
496 | style[transform.name] = 'translate(' + x + 'px, ' + y + 'px)' + |
||
497 | (transform.translateZ ? ' translateZ(0)' : '') |
||
498 | }, |
||
499 | |||
500 | translateX: function (index, x, speed) { |
||
501 | this.translate(index, x, 0, speed) |
||
502 | }, |
||
503 | |||
504 | translateY: function (index, y, speed) { |
||
505 | this.translate(index, 0, y, speed) |
||
506 | }, |
||
507 | |||
508 | animate: function (from, to, speed) { |
||
509 | if (!speed) { |
||
510 | this.slidesContainer[0].style.left = to + 'px' |
||
511 | return |
||
512 | } |
||
513 | var that = this |
||
514 | var start = new Date().getTime() |
||
515 | var timer = window.setInterval(function () { |
||
516 | var timeElap = new Date().getTime() - start |
||
517 | if (timeElap > speed) { |
||
518 | that.slidesContainer[0].style.left = to + 'px' |
||
519 | that.ontransitionend() |
||
520 | window.clearInterval(timer) |
||
521 | return |
||
522 | } |
||
523 | that.slidesContainer[0].style.left = (((to - from) * |
||
524 | (Math.floor((timeElap / speed) * 100) / 100)) + |
||
525 | from) + 'px' |
||
526 | }, 4) |
||
527 | }, |
||
528 | |||
529 | preventDefault: function (event) { |
||
530 | if (event.preventDefault) { |
||
531 | event.preventDefault() |
||
532 | } else { |
||
533 | event.returnValue = false |
||
534 | } |
||
535 | }, |
||
536 | |||
537 | stopPropagation: function (event) { |
||
538 | if (event.stopPropagation) { |
||
539 | event.stopPropagation() |
||
540 | } else { |
||
541 | event.cancelBubble = true |
||
542 | } |
||
543 | }, |
||
544 | |||
545 | onresize: function () { |
||
546 | this.initSlides(true) |
||
547 | }, |
||
548 | |||
549 | onmousedown: function (event) { |
||
550 | // Trigger on clicks of the left mouse button only |
||
551 | // and exclude video elements: |
||
552 | if (event.which && event.which === 1 && |
||
553 | event.target.nodeName !== 'VIDEO') { |
||
554 | // Preventing the default mousedown action is required |
||
555 | // to make touch emulation work with Firefox: |
||
556 | event.preventDefault() |
||
557 | ;(event.originalEvent || event).touches = [{ |
||
558 | pageX: event.pageX, |
||
559 | pageY: event.pageY |
||
560 | }] |
||
561 | this.ontouchstart(event) |
||
562 | } |
||
563 | }, |
||
564 | |||
565 | onmousemove: function (event) { |
||
566 | if (this.touchStart) { |
||
567 | (event.originalEvent || event).touches = [{ |
||
568 | pageX: event.pageX, |
||
569 | pageY: event.pageY |
||
570 | }] |
||
571 | this.ontouchmove(event) |
||
572 | } |
||
573 | }, |
||
574 | |||
575 | onmouseup: function (event) { |
||
576 | if (this.touchStart) { |
||
577 | this.ontouchend(event) |
||
578 | delete this.touchStart |
||
579 | } |
||
580 | }, |
||
581 | |||
582 | onmouseout: function (event) { |
||
583 | if (this.touchStart) { |
||
584 | var target = event.target |
||
585 | var related = event.relatedTarget |
||
586 | if (!related || (related !== target && |
||
587 | !$.contains(target, related))) { |
||
588 | this.onmouseup(event) |
||
589 | } |
||
590 | } |
||
591 | }, |
||
592 | |||
593 | ontouchstart: function (event) { |
||
594 | if (this.options.stopTouchEventsPropagation) { |
||
595 | this.stopPropagation(event) |
||
596 | } |
||
597 | // jQuery doesn't copy touch event properties by default, |
||
598 | // so we have to access the originalEvent object: |
||
599 | var touches = (event.originalEvent || event).touches[0] |
||
600 | this.touchStart = { |
||
601 | // Remember the initial touch coordinates: |
||
602 | x: touches.pageX, |
||
603 | y: touches.pageY, |
||
604 | // Store the time to determine touch duration: |
||
605 | time: Date.now() |
||
606 | } |
||
607 | // Helper variable to detect scroll movement: |
||
608 | this.isScrolling = undefined |
||
609 | // Reset delta values: |
||
610 | this.touchDelta = {} |
||
611 | }, |
||
612 | |||
613 | ontouchmove: function (event) { |
||
614 | if (this.options.stopTouchEventsPropagation) { |
||
615 | this.stopPropagation(event) |
||
616 | } |
||
617 | // jQuery doesn't copy touch event properties by default, |
||
618 | // so we have to access the originalEvent object: |
||
619 | var touches = (event.originalEvent || event).touches[0] |
||
620 | var scale = (event.originalEvent || event).scale |
||
621 | var index = this.index |
||
622 | var touchDeltaX |
||
623 | var indices |
||
624 | // Ensure this is a one touch swipe and not, e.g. a pinch: |
||
625 | if (touches.length > 1 || (scale && scale !== 1)) { |
||
626 | return |
||
627 | } |
||
628 | if (this.options.disableScroll) { |
||
629 | event.preventDefault() |
||
630 | } |
||
631 | // Measure change in x and y coordinates: |
||
632 | this.touchDelta = { |
||
633 | x: touches.pageX - this.touchStart.x, |
||
634 | y: touches.pageY - this.touchStart.y |
||
635 | } |
||
636 | touchDeltaX = this.touchDelta.x |
||
637 | // Detect if this is a vertical scroll movement (run only once per touch): |
||
638 | if (this.isScrolling === undefined) { |
||
639 | this.isScrolling = this.isScrolling || |
||
640 | Math.abs(touchDeltaX) < Math.abs(this.touchDelta.y) |
||
641 | } |
||
642 | if (!this.isScrolling) { |
||
643 | // Always prevent horizontal scroll: |
||
644 | event.preventDefault() |
||
645 | // Stop the slideshow: |
||
646 | window.clearTimeout(this.timeout) |
||
647 | if (this.options.continuous) { |
||
648 | indices = [ |
||
649 | this.circle(index + 1), |
||
650 | index, |
||
651 | this.circle(index - 1) |
||
652 | ] |
||
653 | } else { |
||
654 | // Increase resistance if first slide and sliding left |
||
655 | // or last slide and sliding right: |
||
656 | this.touchDelta.x = touchDeltaX = |
||
657 | touchDeltaX / |
||
658 | ( |
||
659 | ((!index && touchDeltaX > 0) || |
||
660 | (index === this.num - 1 && touchDeltaX < 0))> |
||
661 | < 0)) ? (Math.abs(touchDeltaX) / this.slideWidth + 1)> |
||
662 | < 0)) : 1> |
||
663 | < 0)) )> |
||
664 | < 0)) indices = [index]> |
||
665 | < 0)) if (index) {> |
||
666 | < 0)) indices.push(index - 1)> |
||
667 | < 0)) }> |
||
668 | < 0)) if (index < this.num - 1) {> |
||
669 | < 0)) indices.unshift(index + 1)> |
||
670 | < 0)) }> |
||
671 | < 0)) }> |
||
672 | < 0)) while (indices.length) {> |
||
673 | < 0)) index = indices.pop()> |
||
674 | < 0)) this.translateX(index, touchDeltaX + this.positions[index], 0)> |
||
675 | < 0)) }> |
||
676 | < 0)) } else {> |
||
677 | < 0)) this.translateY(index, this.touchDelta.y + this.positions[index], 0)> |
||
678 | < 0)) }> |
||
679 | < 0)) },> |
||
680 | |||
681 | < 0)) ontouchend: function (event) {> |
||
682 | < 0)) if (this.options.stopTouchEventsPropagation) {> |
||
683 | < 0)) this.stopPropagation(event)> |
||
684 | < 0)) }> |
||
685 | < 0)) var index = this.index> |
||
686 | < 0)) var speed = this.options.transitionSpeed> |
||
687 | < 0)) var slideWidth = this.slideWidth> |
||
688 | < 0)) var isShortDuration = Number(Date.now() - this.touchStart.time) < 250> |
||
689 | < 0)) // Determine if slide attempt triggers next/prev slide:> |
||
690 | < 0)) var isValidSlide => |
||
691 | < 0)) (isShortDuration && Math.abs(this.touchDelta.x) > 20) ||> |
||
692 | < 0)) Math.abs(this.touchDelta.x) > slideWidth / 2> |
||
693 | < 0)) // Determine if slide attempt is past start or end:> |
||
694 | < 0)) var isPastBounds = (!index && this.touchDelta.x > 0) ||> |
||
695 | < 0)) (index === this.num - 1 && this.touchDelta.x < 0)>> |
||
696 | < 0))< 0) var isValidClose = !isValidSlide && this.options.closeOnSwipeUpOrDown &&>> |
||
697 | < 0))< 0) ((isShortDuration && Math.abs(this.touchDelta.y) > 20) ||>> |
||
698 | < 0))< 0) Math.abs(this.touchDelta.y) > this.slideHeight / 2)>> |
||
699 | < 0))< 0) var direction>> |
||
700 | < 0))< 0) var indexForward>> |
||
701 | < 0))< 0) var indexBackward>> |
||
702 | < 0))< 0) var distanceForward>> |
||
703 | < 0))< 0) var distanceBackward>> |
||
704 | < 0))< 0) if (this.options.continuous) {>> |
||
705 | < 0))< 0) isPastBounds = false>> |
||
706 | < 0))< 0) }>> |
||
707 | < 0))< 0) // Determine direction of swipe (true: right, false: left):>> |
||
708 | < 0))< 0) direction = this.touchDelta.x < 0 ? -1 : 1>> |
||
709 | < 0))< 0) if (!this.isScrolling) {>> |
||
710 | < 0))< 0) if (isValidSlide && !isPastBounds) {>> |
||
711 | < 0))< 0) indexForward = index + direction>> |
||
712 | < 0))< 0) indexBackward = index - direction>> |
||
713 | < 0))< 0) distanceForward = slideWidth * direction>> |
||
714 | < 0))< 0) distanceBackward = -slideWidth * direction>> |
||
715 | < 0))< 0) if (this.options.continuous) {>> |
||
716 | < 0))< 0) this.move(this.circle(indexForward), distanceForward, 0)>> |
||
717 | < 0))< 0) this.move(this.circle(index - 2 * direction), distanceBackward, 0)>> |
||
718 | < 0))< 0) } else if (indexForward >= 0 &&>> |
||
719 | < 0))< 0) indexForward < this.num) {>> |
||
720 | < 0))< 0) this.move(indexForward, distanceForward, 0)>> |
||
721 | < 0))< 0) }>> |
||
722 | < 0))< 0) this.move(index, this.positions[index] + distanceForward, speed)>> |
||
723 | < 0))< 0) this.move(>> |
||
724 | < 0))< 0) this.circle(indexBackward),>> |
||
725 | < 0))< 0) this.positions[this.circle(indexBackward)] + distanceForward,>> |
||
726 | < 0))< 0) speed>> |
||
727 | < 0))< 0) )>> |
||
728 | < 0))< 0) index = this.circle(indexBackward)>> |
||
729 | < 0))< 0) this.onslide(index)>> |
||
730 | < 0))< 0) } else {>> |
||
731 | < 0))< 0) // Move back into position>> |
||
732 | < 0))< 0) if (this.options.continuous) {>> |
||
733 | < 0))< 0) this.move(this.circle(index - 1), -slideWidth, speed)>> |
||
734 | < 0))< 0) this.move(index, 0, speed)>> |
||
735 | < 0))< 0) this.move(this.circle(index + 1), slideWidth, speed)>> |
||
736 | < 0))< 0) } else {>> |
||
737 | < 0))< 0) if (index) {>> |
||
738 | < 0))< 0) this.move(index - 1, -slideWidth, speed)>> |
||
739 | < 0))< 0) }>> |
||
740 | < 0))< 0) this.move(index, 0, speed)>> |
||
741 | < 0))< 0) if (index < this.num - 1) {>> |
||
742 | < 0))< 0) this.move(index + 1, slideWidth, speed)>> |
||
743 | < 0))< 0) }>> |
||
744 | < 0))< 0) }>> |
||
745 | < 0))< 0) }>> |
||
746 | < 0))< 0) } else {>> |
||
747 | < 0))< 0) if (isValidClose) {>> |
||
748 | < 0))< 0) this.close()>> |
||
749 | < 0))< 0) } else {>> |
||
750 | < 0))< 0) // Move back into position>> |
||
751 | < 0))< 0) this.translateY(index, 0, speed)>> |
||
752 | < 0))< 0) }>> |
||
753 | < 0))< 0) }>> |
||
754 | < 0))< 0) },>> |
||
755 | |||
756 | < 0))< 0) ontouchcancel: function (event) {>> |
||
757 | < 0))< 0) if (this.touchStart) {>> |
||
758 | < 0))< 0) this.ontouchend(event)>> |
||
759 | < 0))< 0) delete this.touchStart>> |
||
760 | < 0))< 0) }>> |
||
761 | < 0))< 0) },>> |
||
762 | |||
763 | < 0))< 0) ontransitionend: function (event) {>> |
||
764 | < 0))< 0) var slide = this.slides[this.index]>> |
||
765 | < 0))< 0) if (!event || slide === event.target) {>> |
||
766 | < 0))< 0) if (this.interval) {>> |
||
767 | < 0))< 0) this.play()>> |
||
768 | < 0))< 0) }>> |
||
769 | < 0))< 0) this.setTimeout(>> |
||
770 | < 0))< 0) this.options.onslideend,>> |
||
771 | < 0))< 0) [this.index, slide]>> |
||
772 | < 0))< 0) )>> |
||
773 | < 0))< 0) }>> |
||
774 | < 0))< 0) },>> |
||
775 | |||
776 | < 0))< 0) oncomplete: function (event) {>> |
||
777 | < 0))< 0) var target = event.target || event.srcElement>> |
||
778 | < 0))< 0) var parent = target && target.parentNode>> |
||
779 | < 0))< 0) var index>> |
||
780 | < 0))< 0) if (!target || !parent) {>> |
||
781 | < 0))< 0) return>> |
||
782 | < 0))< 0) }>> |
||
783 | < 0))< 0) index = this.getNodeIndex(parent)>> |
||
784 | < 0))< 0) $(parent).removeClass(this.options.slideLoadingClass)>> |
||
785 | < 0))< 0) if (event.type === 'error') {>> |
||
786 | < 0))< 0) $(parent).addClass(this.options.slideErrorClass)>> |
||
787 | < 0))< 0) this.elements[index] = 3 // Fail>> |
||
788 | < 0))< 0) } else {>> |
||
789 | < 0))< 0) this.elements[index] = 2 // Done>> |
||
790 | < 0))< 0) }>> |
||
791 | < 0))< 0) // Fix for IE7's lack of support for percentage max-height:>> |
||
792 | < 0))< 0) if (target.clientHeight > this.container[0].clientHeight) {>> |
||
793 | < 0))< 0) target.style.maxHeight = this.container[0].clientHeight>> |
||
794 | < 0))< 0) }>> |
||
795 | < 0))< 0) if (this.interval && this.slides[this.index] === parent) {>> |
||
796 | < 0))< 0) this.play()>> |
||
797 | < 0))< 0) }>> |
||
798 | < 0))< 0) this.setTimeout(>> |
||
799 | < 0))< 0) this.options.onslidecomplete,>> |
||
800 | < 0))< 0) [index, parent]>> |
||
801 | < 0))< 0) )>> |
||
802 | < 0))< 0) },>> |
||
803 | |||
804 | < 0))< 0) onload: function (event) {>> |
||
805 | < 0))< 0) this.oncomplete(event)>> |
||
806 | < 0))< 0) },>> |
||
807 | |||
808 | < 0))< 0) onerror: function (event) {>> |
||
809 | < 0))< 0) this.oncomplete(event)>> |
||
810 | < 0))< 0) },>> |
||
811 | |||
812 | < 0))< 0) onkeydown: function (event) {>> |
||
813 | < 0))< 0) switch (event.which || event.keyCode) {>> |
||
814 | < 0))< 0) case 13: // Return>> |
||
815 | < 0))< 0) if (this.options.toggleControlsOnReturn) {>> |
||
816 | < 0))< 0) this.preventDefault(event)>> |
||
817 | < 0))< 0) this.toggleControls()>> |
||
818 | < 0))< 0) }>> |
||
819 | < 0))< 0) break>> |
||
820 | < 0))< 0) case 27: // Esc>> |
||
821 | < 0))< 0) if (this.options.closeOnEscape) {>> |
||
822 | < 0))< 0) this.close()>> |
||
823 | < 0))< 0) // prevent Esc from closing other things>> |
||
824 | < 0))< 0) event.stopImmediatePropagation()>> |
||
825 | < 0))< 0) }>> |
||
826 | < 0))< 0) break>> |
||
827 | < 0))< 0) case 32: // Space>> |
||
828 | < 0))< 0) if (this.options.toggleSlideshowOnSpace) {>> |
||
829 | < 0))< 0) this.preventDefault(event)>> |
||
830 | < 0))< 0) this.toggleSlideshow()>> |
||
831 | < 0))< 0) }>> |
||
832 | < 0))< 0) break>> |
||
833 | < 0))< 0) case 37: // Left>> |
||
834 | < 0))< 0) if (this.options.enableKeyboardNavigation) {>> |
||
835 | < 0))< 0) this.preventDefault(event)>> |
||
836 | < 0))< 0) this.prev()>> |
||
837 | < 0))< 0) }>> |
||
838 | < 0))< 0) break>> |
||
839 | < 0))< 0) case 39: // Right>> |
||
840 | < 0))< 0) if (this.options.enableKeyboardNavigation) {>> |
||
841 | < 0))< 0) this.preventDefault(event)>> |
||
842 | < 0))< 0) this.next()>> |
||
843 | < 0))< 0) }>> |
||
844 | < 0))< 0) break>> |
||
845 | < 0))< 0) }>> |
||
846 | < 0))< 0) },>> |
||
847 | |||
848 | < 0))< 0) handleClick: function (event) {>> |
||
849 | < 0))< 0) var options = this.options>> |
||
850 | < 0))< 0) var target = event.target || event.srcElement>> |
||
851 | < 0))< 0) var parent = target.parentNode>> |
||
852 | < 0))< 0) function isTarget (className) {>> |
||
853 | < 0))< 0) return $(target).hasClass(className) ||>> |
||
854 | < 0))< 0) $(parent).hasClass(className)>> |
||
855 | < 0))< 0) }>> |
||
856 | < 0))< 0) if (isTarget(options.toggleClass)) {>> |
||
857 | < 0))< 0) // Click on "toggle" control>> |
||
858 | < 0))< 0) this.preventDefault(event)>> |
||
859 | < 0))< 0) this.toggleControls()>> |
||
860 | < 0))< 0) } else if (isTarget(options.prevClass)) {>> |
||
861 | < 0))< 0) // Click on "prev" control>> |
||
862 | < 0))< 0) this.preventDefault(event)>> |
||
863 | < 0))< 0) this.prev()>> |
||
864 | < 0))< 0) } else if (isTarget(options.nextClass)) {>> |
||
865 | < 0))< 0) // Click on "next" control>> |
||
866 | < 0))< 0) this.preventDefault(event)>> |
||
867 | < 0))< 0) this.next()>> |
||
868 | < 0))< 0) } else if (isTarget(options.closeClass)) {>> |
||
869 | < 0))< 0) // Click on "close" control>> |
||
870 | < 0))< 0) this.preventDefault(event)>> |
||
871 | < 0))< 0) this.close()>> |
||
872 | < 0))< 0) } else if (isTarget(options.playPauseClass)) {>> |
||
873 | < 0))< 0) // Click on "play-pause" control>> |
||
874 | < 0))< 0) this.preventDefault(event)>> |
||
875 | < 0))< 0) this.toggleSlideshow()>> |
||
876 | < 0))< 0) } else if (parent === this.slidesContainer[0]) {>> |
||
877 | < 0))< 0) // Click on slide background>> |
||
878 | < 0))< 0) if (options.closeOnSlideClick) {>> |
||
879 | < 0))< 0) this.preventDefault(event)>> |
||
880 | < 0))< 0) this.close()>> |
||
881 | < 0))< 0) } else if (options.toggleControlsOnSlideClick) {>> |
||
882 | < 0))< 0) this.preventDefault(event)>> |
||
883 | < 0))< 0) this.toggleControls()>> |
||
884 | < 0))< 0) }>> |
||
885 | < 0))< 0) } else if (parent.parentNode &&>> |
||
886 | < 0))< 0) parent.parentNode === this.slidesContainer[0]) {>> |
||
887 | < 0))< 0) // Click on displayed element>> |
||
888 | < 0))< 0) if (options.toggleControlsOnSlideClick) {>> |
||
889 | < 0))< 0) this.preventDefault(event)>> |
||
890 | < 0))< 0) this.toggleControls()>> |
||
891 | < 0))< 0) }>> |
||
892 | < 0))< 0) }>> |
||
893 | < 0))< 0) },>> |
||
894 | |||
895 | < 0))< 0) onclick: function (event) {>> |
||
896 | < 0))< 0) if (this.options.emulateTouchEvents &&>> |
||
897 | < 0))< 0) this.touchDelta && (Math.abs(this.touchDelta.x) > 20 ||>> |
||
898 | < 0))< 0) Math.abs(this.touchDelta.y) > 20)) {>> |
||
899 | < 0))< 0) delete this.touchDelta>> |
||
900 | < 0))< 0) return>> |
||
901 | < 0))< 0) }>> |
||
902 | < 0))< 0) return this.handleClick(event)>> |
||
903 | < 0))< 0) },>> |
||
904 | |||
905 | < 0))< 0) updateEdgeClasses: function (index) {>> |
||
906 | < 0))< 0) if (!index) {>> |
||
907 | < 0))< 0) this.container.addClass(this.options.leftEdgeClass)>> |
||
908 | < 0))< 0) } else {>> |
||
909 | < 0))< 0) this.container.removeClass(this.options.leftEdgeClass)>> |
||
910 | < 0))< 0) }>> |
||
911 | < 0))< 0) if (index === this.num - 1) {>> |
||
912 | < 0))< 0) this.container.addClass(this.options.rightEdgeClass)>> |
||
913 | < 0))< 0) } else {>> |
||
914 | < 0))< 0) this.container.removeClass(this.options.rightEdgeClass)>> |
||
915 | < 0))< 0) }>> |
||
916 | < 0))< 0) },>> |
||
917 | |||
918 | < 0))< 0) handleSlide: function (index) {>> |
||
919 | < 0))< 0) if (!this.options.continuous) {>> |
||
920 | < 0))< 0) this.updateEdgeClasses(index)>> |
||
921 | < 0))< 0) }>> |
||
922 | < 0))< 0) this.loadElements(index)>> |
||
923 | < 0))< 0) if (this.options.unloadElements) {>> |
||
924 | < 0))< 0) this.unloadElements(index)>> |
||
925 | < 0))< 0) }>> |
||
926 | < 0))< 0) this.setTitle(index)>> |
||
927 | < 0))< 0) },>> |
||
928 | |||
929 | < 0))< 0) onslide: function (index) {>> |
||
930 | < 0))< 0) this.index = index>> |
||
931 | < 0))< 0) this.handleSlide(index)>> |
||
932 | < 0))< 0) this.setTimeout(this.options.onslide, [index, this.slides[index]])>> |
||
933 | < 0))< 0) },>> |
||
934 | |||
935 | < 0))< 0) setTitle: function (index) {>> |
||
936 | < 0))< 0) var text = this.slides[index].firstChild.title>> |
||
937 | < 0))< 0) var titleElement = this.titleElement>> |
||
938 | < 0))< 0) if (titleElement.length) {>> |
||
939 | < 0))< 0) this.titleElement.empty()>> |
||
940 | < 0))< 0) if (text) {>> |
||
941 | < 0))< 0) titleElement[0].appendChild(document.createTextNode(text))>> |
||
942 | < 0))< 0) }>> |
||
943 | < 0))< 0) }>> |
||
944 | < 0))< 0) },>> |
||
945 | |||
946 | < 0))< 0) setTimeout: function (func, args, wait) {>> |
||
947 | < 0))< 0) var that = this>> |
||
948 | < 0))< 0) return func && window.setTimeout(function () {>> |
||
949 | < 0))< 0) func.apply(that, args || [])>> |
||
950 | < 0))< 0) }, wait || 0)>> |
||
951 | < 0))< 0) },>> |
||
952 | |||
953 | < 0))< 0) imageFactory: function (obj, callback) {>> |
||
954 | < 0))< 0) var that = this>> |
||
955 | < 0))< 0) var img = this.imagePrototype.cloneNode(false)>> |
||
956 | < 0))< 0) var url = obj>> |
||
957 | < 0))< 0) var backgroundSize = this.options.stretchImages>> |
||
958 | < 0))< 0) var called>> |
||
959 | < 0))< 0) var element>> |
||
960 | < 0))< 0) var title>> |
||
961 | < 0))< 0) function callbackWrapper (event) {>> |
||
962 | < 0))< 0) if (!called) {>> |
||
963 | < 0))< 0) event = {>> |
||
964 | < 0))< 0) type: event.type,>> |
||
965 | < 0))< 0) target: element>> |
||
966 | < 0))< 0) }>> |
||
967 | < 0))< 0) if (!element.parentNode) {>> |
||
968 | < 0))< 0) // Fix for IE7 firing the load event for>> |
||
969 | < 0))< 0) // cached images before the element could>> |
||
970 | < 0))< 0) // be added to the DOM:>> |
||
971 | < 0))< 0) return that.setTimeout(callbackWrapper, [event])>> |
||
972 | < 0))< 0) }>> |
||
973 | < 0))< 0) called = true>> |
||
974 | < 0))< 0) $(img).off('load error', callbackWrapper)>> |
||
975 | < 0))< 0) if (backgroundSize) {>> |
||
976 | < 0))< 0) if (event.type === 'load') {>> |
||
977 | < 0))< 0) element.style.background = 'url("' + url +>> |
||
978 | < 0))< 0) '") center no-repeat'>> |
||
979 | < 0))< 0) element.style.backgroundSize = backgroundSize>> |
||
980 | < 0))< 0) }>> |
||
981 | < 0))< 0) }>> |
||
982 | < 0))< 0) callback(event)>> |
||
983 | < 0))< 0) }>> |
||
984 | < 0))< 0) }>> |
||
985 | < 0))< 0) if (typeof url !== 'string') {>> |
||
986 | < 0))< 0) url = this.getItemProperty(obj, this.options.urlProperty)>> |
||
987 | < 0))< 0) title = this.getItemProperty(obj, this.options.titleProperty)>> |
||
988 | < 0))< 0) }>> |
||
989 | < 0))< 0) if (backgroundSize === true) {>> |
||
990 | < 0))< 0) backgroundSize = 'contain'>> |
||
991 | < 0))< 0) }>> |
||
992 | < 0))< 0) backgroundSize = this.support.backgroundSize &&>> |
||
993 | < 0))< 0) this.support.backgroundSize[backgroundSize] && backgroundSize>> |
||
994 | < 0))< 0) if (backgroundSize) {>> |
||
995 | < 0))< 0) element = this.elementPrototype.cloneNode(false)>> |
||
996 | < 0))< 0) } else {>> |
||
997 | < 0))< 0) element = img>> |
||
998 | < 0))< 0) img.draggable = false>> |
||
999 | < 0))< 0) }>> |
||
1000 | < 0))< 0) if (title) {>> |
||
1001 | < 0))< 0) element.title = title>> |
||
1002 | < 0))< 0) }>> |
||
1003 | < 0))< 0) $(img).on('load error', callbackWrapper)>> |
||
1004 | < 0))< 0) img.src = url>> |
||
1005 | < 0))< 0) return element>> |
||
1006 | < 0))< 0) },>> |
||
1007 | |||
1008 | < 0))< 0) createElement: function (obj, callback) {>> |
||
1009 | < 0))< 0) var type = obj && this.getItemProperty(obj, this.options.typeProperty)>> |
||
1010 | < 0))< 0) var factory = (type && this[type.split('/')[0] + 'Factory']) ||>> |
||
1011 | < 0))< 0) this.imageFactory>> |
||
1012 | < 0))< 0) var element = obj && factory.call(this, obj, callback)>> |
||
1013 | < 0))< 0) var srcset = this.getItemProperty(obj, this.options.srcsetProperty)>> |
||
1014 | < 0))< 0) if (!element) {>> |
||
1015 | < 0))< 0) element = this.elementPrototype.cloneNode(false)>> |
||
1016 | < 0))< 0) this.setTimeout(callback, [{>> |
||
1017 | < 0))< 0) type: 'error',>> |
||
1018 | < 0))< 0) target: element>> |
||
1019 | < 0))< 0) }])>> |
||
1020 | < 0))< 0) }>> |
||
1021 | < 0))< 0) if (srcset) {>> |
||
1022 | < 0))< 0) element.setAttribute('srcset', srcset)>> |
||
1023 | < 0))< 0) }>> |
||
1024 | < 0))< 0) $(element).addClass(this.options.slideContentClass)>> |
||
1025 | < 0))< 0) return element>> |
||
1026 | < 0))< 0) },>> |
||
1027 | |||
1028 | < 0))< 0) loadElement: function (index) {>> |
||
1029 | < 0))< 0) if (!this.elements[index]) {>> |
||
1030 | < 0))< 0) if (this.slides[index].firstChild) {>> |
||
1031 | < 0))< 0) this.elements[index] = $(this.slides[index])>> |
||
1032 | < 0))< 0) .hasClass(this.options.slideErrorClass) ? 3 : 2>> |
||
1033 | < 0))< 0) } else {>> |
||
1034 | < 0))< 0) this.elements[index] = 1 // Loading>> |
||
1035 | < 0))< 0) $(this.slides[index]).addClass(this.options.slideLoadingClass)>> |
||
1036 | < 0))< 0) this.slides[index].appendChild(this.createElement(>> |
||
1037 | < 0))< 0) this.list[index],>> |
||
1038 | < 0))< 0) this.proxyListener>> |
||
1039 | < 0))< 0) ))>> |
||
1040 | < 0))< 0) }>> |
||
1041 | < 0))< 0) }>> |
||
1042 | < 0))< 0) },>> |
||
1043 | |||
1044 | < 0))< 0) loadElements: function (index) {>> |
||
1045 | < 0))< 0) var limit = Math.min(this.num, this.options.preloadRange * 2 + 1)>> |
||
1046 | < 0))< 0) var j = index>> |
||
1047 | < 0))< 0) var i>> |
||
1048 | < 0))< 0) for (i = 0; i < limit; i += 1) {>> |
||
1049 | < 0))< 0) // First load the current slide element (0),>> |
||
1050 | < 0))< 0) // then the next one (+1),>> |
||
1051 | < 0))< 0) // then the previous one (-2),>> |
||
1052 | < 0))< 0) // then the next after next (+2), etc.:>> |
||
1053 | < 0))< 0) j += i * (i % 2 === 0 ? -1 : 1)>> |
||
1054 | < 0))< 0) // Connect the ends of the list to load slide elements for>> |
||
1055 | < 0))< 0) // continuous navigation:>> |
||
1056 | < 0))< 0) j = this.circle(j)>> |
||
1057 | < 0))< 0) this.loadElement(j)>> |
||
1058 | < 0))< 0) }>> |
||
1059 | < 0))< 0) },>> |
||
1060 | |||
1061 | < 0))< 0) unloadElements: function (index) {>> |
||
1062 | < 0))< 0) var i,>> |
||
1063 | < 0))< 0) diff>> |
||
1064 | < 0))< 0) for (i in this.elements) {>> |
||
1065 | < 0))< 0) if (this.elements.hasOwnProperty(i)) {>> |
||
1066 | < 0))< 0) diff = Math.abs(index - i)>> |
||
1067 | < 0))< 0) if (diff > this.options.preloadRange &&>> |
||
1068 | < 0))< 0) diff + this.options.preloadRange < this.num) {>> |
||
1069 | < 0))< 0) this.unloadSlide(i)>> |
||
1070 | < 0))< 0) delete this.elements[i]>> |
||
1071 | < 0))< 0) }>> |
||
1072 | < 0))< 0) }>> |
||
1073 | < 0))< 0) }>> |
||
1074 | < 0))< 0) },>> |
||
1075 | |||
1076 | < 0))< 0) addSlide: function (index) {>> |
||
1077 | < 0))< 0) var slide = this.slidePrototype.cloneNode(false)>> |
||
1078 | < 0))< 0) slide.setAttribute('data-index', index)>> |
||
1079 | < 0))< 0) this.slidesContainer[0].appendChild(slide)>> |
||
1080 | < 0))< 0) this.slides.push(slide)>> |
||
1081 | < 0))< 0) },>> |
||
1082 | |||
1083 | < 0))< 0) positionSlide: function (index) {>> |
||
1084 | < 0))< 0) var slide = this.slides[index]>> |
||
1085 | < 0))< 0) slide.style.width = this.slideWidth + 'px'>> |
||
1086 | < 0))< 0) if (this.support.transform) {>> |
||
1087 | < 0))< 0) slide.style.left = (index * -this.slideWidth) + 'px'>> |
||
1088 | < 0))< 0) this.move(>> |
||
1089 | < 0))< 0) index, this.index > index>> |
||
1090 | < 0))< 0) ? -this.slideWidth>> |
||
1091 | < 0))< 0) : (this.index < index ? this.slideWidth : 0),>> |
||
1092 | |||
1093 | < 0))< 0) )>> |
||
1094 | < 0))< 0) }>> |
||
1095 | < 0))< 0) },>> |
||
1096 | |||
1097 | < 0))< 0) initSlides: function (reload) {>> |
||
1098 | < 0))< 0) var clearSlides,>> |
||
1099 | < 0))< 0) i>> |
||
1100 | < 0))< 0) if (!reload) {>> |
||
1101 | < 0))< 0) this.positions = []>> |
||
1102 | < 0))< 0) this.positions.length = this.num>> |
||
1103 | < 0))< 0) this.elements = {}>> |
||
1104 | < 0))< 0) this.imagePrototype = document.createElement('img')>> |
||
1105 | < 0))< 0) this.elementPrototype = document.createElement('div')>> |
||
1106 | < 0))< 0) this.slidePrototype = document.createElement('div')>> |
||
1107 | < 0))< 0) $(this.slidePrototype).addClass(this.options.slideClass)>> |
||
1108 | < 0))< 0) this.slides = this.slidesContainer[0].children>> |
||
1109 | < 0))< 0) clearSlides = this.options.clearSlides ||>> |
||
1110 | < 0))< 0) this.slides.length !== this.num>> |
||
1111 | < 0))< 0) }>> |
||
1112 | < 0))< 0) this.slideWidth = this.container[0].offsetWidth>> |
||
1113 | < 0))< 0) this.slideHeight = this.container[0].offsetHeight>> |
||
1114 | < 0))< 0) this.slidesContainer[0].style.width =>> |
||
1115 | < 0))< 0) (this.num * this.slideWidth) + 'px'>> |
||
1116 | < 0))< 0) if (clearSlides) {>> |
||
1117 | < 0))< 0) this.resetSlides()>> |
||
1118 | < 0))< 0) }>> |
||
1119 | < 0))< 0) for (i = 0; i < this.num; i += 1) {>> |
||
1120 | < 0))< 0) if (clearSlides) {>> |
||
1121 | < 0))< 0) this.addSlide(i)>> |
||
1122 | < 0))< 0) }>> |
||
1123 | < 0))< 0) this.positionSlide(i)>> |
||
1124 | < 0))< 0) }>> |
||
1125 | < 0))< 0) // Reposition the slides before and after the given index:>> |
||
1126 | < 0))< 0) if (this.options.continuous && this.support.transform) {>> |
||
1127 | < 0))< 0) this.move(this.circle(this.index - 1), -this.slideWidth, 0)>> |
||
1128 | < 0))< 0) this.move(this.circle(this.index + 1), this.slideWidth, 0)>> |
||
1129 | < 0))< 0) }>> |
||
1130 | < 0))< 0) if (!this.support.transform) {>> |
||
1131 | < 0))< 0) this.slidesContainer[0].style.left =>> |
||
1132 | < 0))< 0) (this.index * -this.slideWidth) + 'px'>> |
||
1133 | < 0))< 0) }>> |
||
1134 | < 0))< 0) },>> |
||
1135 | |||
1136 | < 0))< 0) unloadSlide: function (index) {>> |
||
1137 | < 0))< 0) var slide,>> |
||
1138 | < 0))< 0) firstChild>> |
||
1139 | < 0))< 0) slide = this.slides[index]>> |
||
1140 | < 0))< 0) firstChild = slide.firstChild>> |
||
1141 | < 0))< 0) if (firstChild !== null) {>> |
||
1142 | < 0))< 0) slide.removeChild(firstChild)>> |
||
1143 | < 0))< 0) }>> |
||
1144 | < 0))< 0) },>> |
||
1145 | |||
1146 | < 0))< 0) unloadAllSlides: function () {>> |
||
1147 | < 0))< 0) var i,>> |
||
1148 | < 0))< 0) len>> |
||
1149 | < 0))< 0) for (i = 0, len = this.slides.length; i < len; i++) {>> |
||
1150 | < 0))< 0) this.unloadSlide(i)>> |
||
1151 | < 0))< 0) }>> |
||
1152 | < 0))< 0) },>> |
||
1153 | |||
1154 | < 0))< 0) toggleControls: function () {>> |
||
1155 | < 0))< 0) var controlsClass = this.options.controlsClass>> |
||
1156 | < 0))< 0) if (this.container.hasClass(controlsClass)) {>> |
||
1157 | < 0))< 0) this.container.removeClass(controlsClass)>> |
||
1158 | < 0))< 0) } else {>> |
||
1159 | < 0))< 0) this.container.addClass(controlsClass)>> |
||
1160 | < 0))< 0) }>> |
||
1161 | < 0))< 0) },>> |
||
1162 | |||
1163 | < 0))< 0) toggleSlideshow: function () {>> |
||
1164 | < 0))< 0) if (!this.interval) {>> |
||
1165 | < 0))< 0) this.play()>> |
||
1166 | < 0))< 0) } else {>> |
||
1167 | < 0))< 0) this.pause()>> |
||
1168 | < 0))< 0) }>> |
||
1169 | < 0))< 0) },>> |
||
1170 | |||
1171 | < 0))< 0) getNodeIndex: function (element) {>> |
||
1172 | < 0))< 0) return parseInt(element.getAttribute('data-index'), 10)>> |
||
1173 | < 0))< 0) },>> |
||
1174 | |||
1175 | < 0))< 0) getNestedProperty: function (obj, property) {>> |
||
1176 | < 0))< 0) property.replace(>> |
||
1177 | < 0))< 0) // Matches native JavaScript notation in a String,>> |
||
1178 | < 0))< 0) // e.g. '["doubleQuoteProp"].dotProp[2]'>> |
||
1179 | < 0))< 0) // eslint-disable-next-line no-useless-escape>> |
||
1180 | < 0))< 0) /\[(?:'([^']+)'|"([^"]+)"|(\d+))\]|(?:(?:^|\.)([^\.\[]+))/g,>> |
||
1181 | < 0))< 0) function (str, singleQuoteProp, doubleQuoteProp, arrayIndex, dotProp) {>> |
||
1182 | < 0))< 0) var prop = dotProp || singleQuoteProp || doubleQuoteProp ||>> |
||
1183 | < 0))< 0) (arrayIndex && parseInt(arrayIndex, 10))>> |
||
1184 | < 0))< 0) if (str && obj) {>> |
||
1185 | < 0))< 0) obj = obj[prop]>> |
||
1186 | < 0))< 0) }>> |
||
1187 | < 0))< 0) }>> |
||
1188 | < 0))< 0) )>> |
||
1189 | < 0))< 0) return obj>> |
||
1190 | < 0))< 0) },>> |
||
1191 | |||
1192 | < 0))< 0) getDataProperty: function (obj, property) {>> |
||
1193 | < 0))< 0) var prop>> |
||
1194 | < 0))< 0) if (obj.dataset) {>> |
||
1195 | < 0))< 0) // eslint-disable-next-line standard/computed-property-even-spacing>> |
||
1196 | < 0))< 0) prop = obj.dataset[property.replace(/-([a-z])/g, function (_, b) {>> |
||
1197 | < 0))< 0) return b.toUpperCase()>> |
||
1198 | < 0))< 0) })]>> |
||
1199 | < 0))< 0) } else if (obj.getAttribute) {>> |
||
1200 | < 0))< 0) prop = obj.getAttribute('data-' +>> |
||
1201 | < 0))< 0) property.replace(/([A-Z])/g, '-$1').toLowerCase())>> |
||
1202 | < 0))< 0) }>> |
||
1203 | < 0))< 0) if (typeof prop === 'string') {>> |
||
1204 | < 0))< 0) // eslint-disable-next-line no-useless-escape>> |
||
1205 | < 0))< 0) if (/^(true|false|null|-?\d+(\.\d+)?|\{[\s\S]*\}|\[[\s\S]*\])$/>> |
||
1206 | < 0))< 0) .test(prop)) {>> |
||
1207 | < 0))< 0) try {>> |
||
1208 | < 0))< 0) return $.parseJSON(prop)>> |
||
1209 | < 0))< 0) } catch (ignore) {}>> |
||
1210 | < 0))< 0) }>> |
||
1211 | < 0))< 0) return prop>> |
||
1212 | < 0))< 0) }>> |
||
1213 | < 0))< 0) },>> |
||
1214 | |||
1215 | < 0))< 0) getItemProperty: function (obj, property) {>> |
||
1216 | < 0))< 0) var prop = this.getDataProperty(obj, property)>> |
||
1217 | < 0))< 0) if (prop === undefined) {>> |
||
1218 | < 0))< 0) prop = obj[property]>> |
||
1219 | < 0))< 0) }>> |
||
1220 | < 0))< 0) if (prop === undefined) {>> |
||
1221 | < 0))< 0) prop = this.getNestedProperty(obj, property)>> |
||
1222 | < 0))< 0) }>> |
||
1223 | < 0))< 0) return prop>> |
||
1224 | < 0))< 0) },>> |
||
1225 | |||
1226 | < 0))< 0) initStartIndex: function () {>> |
||
1227 | < 0))< 0) var index = this.options.index>> |
||
1228 | < 0))< 0) var urlProperty = this.options.urlProperty>> |
||
1229 | < 0))< 0) var i>> |
||
1230 | < 0))< 0) // Check if the index is given as a list object:>> |
||
1231 | < 0))< 0) if (index && typeof index !== 'number') {>> |
||
1232 | < 0))< 0) for (i = 0; i < this.num; i += 1) {>> |
||
1233 | < 0))< 0) if (this.list[i] === index ||>> |
||
1234 | < 0))< 0) this.getItemProperty(this.list[i], urlProperty) ===>> |
||
1235 | < 0))< 0) this.getItemProperty(index, urlProperty)) {>> |
||
1236 | < 0))< 0) index = i>> |
||
1237 | < 0))< 0) break>> |
||
1238 | < 0))< 0) }>> |
||
1239 | < 0))< 0) }>> |
||
1240 | < 0))< 0) }>> |
||
1241 | < 0))< 0) // Make sure the index is in the list range:>> |
||
1242 | < 0))< 0) this.index = this.circle(parseInt(index, 10) || 0)>> |
||
1243 | < 0))< 0) },>> |
||
1244 | |||
1245 | < 0))< 0) initEventListeners: function () {>> |
||
1246 | < 0))< 0) var that = this>> |
||
1247 | < 0))< 0) var slidesContainer = this.slidesContainer>> |
||
1248 | < 0))< 0) function proxyListener (event) {>> |
||
1249 | < 0))< 0) var type = that.support.transition &&>> |
||
1250 | < 0))< 0) that.support.transition.end === event.type>> |
||
1251 | < 0))< 0) ? 'transitionend'>> |
||
1252 | < 0))< 0) : event.type>> |
||
1253 | < 0))< 0) that['on' + type](event)>> |
||
1254 | < 0))< 0) }>> |
||
1255 | < 0))< 0) $(window).on('resize', proxyListener)>> |
||
1256 | < 0))< 0) $(document.body).on('keydown', proxyListener)>> |
||
1257 | < 0))< 0) this.container.on('click', proxyListener)>> |
||
1258 | < 0))< 0) if (this.support.touch) {>> |
||
1259 | < 0))< 0) slidesContainer>> |
||
1260 | < 0))< 0) .on('touchstart touchmove touchend touchcancel', proxyListener)>> |
||
1261 | < 0))< 0) } else if (this.options.emulateTouchEvents &&>> |
||
1262 | < 0))< 0) this.support.transition) {>> |
||
1263 | < 0))< 0) slidesContainer>> |
||
1264 | < 0))< 0) .on('mousedown mousemove mouseup mouseout', proxyListener)>> |
||
1265 | < 0))< 0) }>> |
||
1266 | < 0))< 0) if (this.support.transition) {>> |
||
1267 | < 0))< 0) slidesContainer.on(>> |
||
1268 | < 0))< 0) this.support.transition.end,>> |
||
1269 | < 0))< 0) proxyListener>> |
||
1270 | < 0))< 0) )>> |
||
1271 | < 0))< 0) }>> |
||
1272 | < 0))< 0) this.proxyListener = proxyListener>> |
||
1273 | < 0))< 0) },>> |
||
1274 | |||
1275 | < 0))< 0) destroyEventListeners: function () {>> |
||
1276 | < 0))< 0) var slidesContainer = this.slidesContainer>> |
||
1277 | < 0))< 0) var proxyListener = this.proxyListener>> |
||
1278 | < 0))< 0) $(window).off('resize', proxyListener)>> |
||
1279 | < 0))< 0) $(document.body).off('keydown', proxyListener)>> |
||
1280 | < 0))< 0) this.container.off('click', proxyListener)>> |
||
1281 | < 0))< 0) if (this.support.touch) {>> |
||
1282 | < 0))< 0) slidesContainer>> |
||
1283 | < 0))< 0) .off('touchstart touchmove touchend touchcancel', proxyListener)>> |
||
1284 | < 0))< 0) } else if (this.options.emulateTouchEvents &&>> |
||
1285 | < 0))< 0) this.support.transition) {>> |
||
1286 | < 0))< 0) slidesContainer>> |
||
1287 | < 0))< 0) .off('mousedown mousemove mouseup mouseout', proxyListener)>> |
||
1288 | < 0))< 0) }>> |
||
1289 | < 0))< 0) if (this.support.transition) {>> |
||
1290 | < 0))< 0) slidesContainer.off(>> |
||
1291 | < 0))< 0) this.support.transition.end,>> |
||
1292 | < 0))< 0) proxyListener>> |
||
1293 | < 0))< 0) )>> |
||
1294 | < 0))< 0) }>> |
||
1295 | < 0))< 0) },>> |
||
1296 | |||
1297 | < 0))< 0) handleOpen: function () {>> |
||
1298 | < 0))< 0) if (this.options.onopened) {>> |
||
1299 | < 0))< 0) this.options.onopened.call(this)>> |
||
1300 | < 0))< 0) }>> |
||
1301 | < 0))< 0) },>> |
||
1302 | |||
1303 | < 0))< 0) initWidget: function () {>> |
||
1304 | < 0))< 0) var that = this>> |
||
1305 | < 0))< 0) function openHandler (event) {>> |
||
1306 | < 0))< 0) if (event.target === that.container[0]) {>> |
||
1307 | < 0))< 0) that.container.off(>> |
||
1308 | < 0))< 0) that.support.transition.end,>> |
||
1309 | < 0))< 0) openHandler>> |
||
1310 | < 0))< 0) )>> |
||
1311 | < 0))< 0) that.handleOpen()>> |
||
1312 | < 0))< 0) }>> |
||
1313 | < 0))< 0) }>> |
||
1314 | < 0))< 0) this.container = $(this.options.container)>> |
||
1315 | < 0))< 0) if (!this.container.length) {>> |
||
1316 | < 0))< 0) this.console.log(>> |
||
1317 | < 0))< 0) 'blueimp Gallery: Widget container not found.',>> |
||
1318 | < 0))< 0) this.options.container>> |
||
1319 | < 0))< 0) )>> |
||
1320 | < 0))< 0) return false>> |
||
1321 | < 0))< 0) }>> |
||
1322 | < 0))< 0) this.slidesContainer = this.container.find(>> |
||
1323 | < 0))< 0) this.options.slidesContainer>> |
||
1324 | < 0))< 0) ).first()>> |
||
1325 | < 0))< 0) if (!this.slidesContainer.length) {>> |
||
1326 | < 0))< 0) this.console.log(>> |
||
1327 | < 0))< 0) 'blueimp Gallery: Slides container not found.',>> |
||
1328 | < 0))< 0) this.options.slidesContainer>> |
||
1329 | < 0))< 0) )>> |
||
1330 | < 0))< 0) return false>> |
||
1331 | < 0))< 0) }>> |
||
1332 | < 0))< 0) this.titleElement = this.container.find(>> |
||
1333 | < 0))< 0) this.options.titleElement>> |
||
1334 | < 0))< 0) ).first()>> |
||
1335 | < 0))< 0) if (this.num === 1) {>> |
||
1336 | < 0))< 0) this.container.addClass(this.options.singleClass)>> |
||
1337 | < 0))< 0) }>> |
||
1338 | < 0))< 0) if (this.options.onopen) {>> |
||
1339 | < 0))< 0) this.options.onopen.call(this)>> |
||
1340 | < 0))< 0) }>> |
||
1341 | < 0))< 0) if (this.support.transition && this.options.displayTransition) {>> |
||
1342 | < 0))< 0) this.container.on(>> |
||
1343 | < 0))< 0) this.support.transition.end,>> |
||
1344 | < 0))< 0) openHandler>> |
||
1345 | < 0))< 0) )>> |
||
1346 | < 0))< 0) } else {>> |
||
1347 | < 0))< 0) this.handleOpen()>> |
||
1348 | < 0))< 0) }>> |
||
1349 | < 0))< 0) if (this.options.hidePageScrollbars) {>> |
||
1350 | < 0))< 0) // Hide the page scrollbars:>> |
||
1351 | < 0))< 0) this.bodyOverflowStyle = document.body.style.overflow>> |
||
1352 | < 0))< 0) document.body.style.overflow = 'hidden'>> |
||
1353 | < 0))< 0) }>> |
||
1354 | < 0))< 0) this.container[0].style.display = 'block'>> |
||
1355 | < 0))< 0) this.initSlides()>> |
||
1356 | < 0))< 0) this.container.addClass(this.options.displayClass)>> |
||
1357 | < 0))< 0) },>> |
||
1358 | |||
1359 | < 0))< 0) initOptions: function (options) {>> |
||
1360 | < 0))< 0) // Create a copy of the prototype options:>> |
||
1361 | < 0))< 0) this.options = $.extend({}, this.options)>> |
||
1362 | < 0))< 0) // Check if carousel mode is enabled:>> |
||
1363 | < 0))< 0) if ((options && options.carousel) ||>> |
||
1364 | < 0))< 0) (this.options.carousel && (!options || options.carousel !== false))) {>> |
||
1365 | < 0))< 0) $.extend(this.options, this.carouselOptions)>> |
||
1366 | < 0))< 0) }>> |
||
1367 | < 0))< 0) // Override any given options:>> |
||
1368 | < 0))< 0) $.extend(this.options, options)>> |
||
1369 | < 0))< 0) if (this.num < 3) {>> |
||
1370 | < 0))< 0) // 1 or 2 slides cannot be displayed continuous,>> |
||
1371 | < 0))< 0) // remember the original option by setting to null instead of false:>> |
||
1372 | < 0))< 0) this.options.continuous = this.options.continuous ? null : false>> |
||
1373 | < 0))< 0) }>> |
||
1374 | < 0))< 0) if (!this.support.transition) {>> |
||
1375 | < 0))< 0) this.options.emulateTouchEvents = false>> |
||
1376 | < 0))< 0) }>> |
||
1377 | < 0))< 0) if (this.options.event) {>> |
||
1378 | < 0))< 0) this.preventDefault(this.options.event)>> |
||
1379 | < 0))< 0) }>> |
||
1380 | < 0))< 0) }>> |
||
1381 | |||
1382 | < 0))< 0) })>> |
||
1383 | |||
1384 | < 0))< 0) return Gallery>> |
||
1385 | < 0))< 0)}))>> |