@tarsis/toolkit 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3969 +0,0 @@
1
- 'use strict';
2
-
3
- const index$2 = require('./index-CZ4lcB3k.cjs');
4
-
5
- function _mergeNamespaces(n, m) {
6
- for (var i = 0; i < m.length; i++) {
7
- const e = m[i];
8
- if (typeof e !== 'string' && !Array.isArray(e)) { for (const k in e) {
9
- if (k !== 'default' && !(k in n)) {
10
- const d = Object.getOwnPropertyDescriptor(e, k);
11
- if (d) {
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: () => e[k]
15
- });
16
- }
17
- }
18
- } }
19
- }
20
- return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' }));
21
- }
22
-
23
- var js = {exports: {}};
24
-
25
- var flickity = {exports: {}};
26
-
27
- var evEmitter = {exports: {}};
28
-
29
- /**
30
- * EvEmitter v1.1.0
31
- * Lil' event emitter
32
- * MIT License
33
- */
34
-
35
- var hasRequiredEvEmitter;
36
-
37
- function requireEvEmitter () {
38
- if (hasRequiredEvEmitter) return evEmitter.exports;
39
- hasRequiredEvEmitter = 1;
40
- (function (module) {
41
- /* jshint unused: true, undef: true, strict: true */
42
-
43
- ( function( global, factory ) {
44
- // universal module definition
45
- /* jshint strict: false */ /* globals define, module, window */
46
- if ( module.exports ) {
47
- // CommonJS - Browserify, Webpack
48
- module.exports = factory();
49
- } else {
50
- // Browser globals
51
- global.EvEmitter = factory();
52
- }
53
-
54
- }( typeof window != 'undefined' ? window : index$2.commonjsGlobal, function() {
55
-
56
- function EvEmitter() {}
57
-
58
- var proto = EvEmitter.prototype;
59
-
60
- proto.on = function( eventName, listener ) {
61
- if ( !eventName || !listener ) {
62
- return;
63
- }
64
- // set events hash
65
- var events = this._events = this._events || {};
66
- // set listeners array
67
- var listeners = events[ eventName ] = events[ eventName ] || [];
68
- // only add once
69
- if ( listeners.indexOf( listener ) == -1 ) {
70
- listeners.push( listener );
71
- }
72
-
73
- return this;
74
- };
75
-
76
- proto.once = function( eventName, listener ) {
77
- if ( !eventName || !listener ) {
78
- return;
79
- }
80
- // add event
81
- this.on( eventName, listener );
82
- // set once flag
83
- // set onceEvents hash
84
- var onceEvents = this._onceEvents = this._onceEvents || {};
85
- // set onceListeners object
86
- var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
87
- // set flag
88
- onceListeners[ listener ] = true;
89
-
90
- return this;
91
- };
92
-
93
- proto.off = function( eventName, listener ) {
94
- var listeners = this._events && this._events[ eventName ];
95
- if ( !listeners || !listeners.length ) {
96
- return;
97
- }
98
- var index = listeners.indexOf( listener );
99
- if ( index != -1 ) {
100
- listeners.splice( index, 1 );
101
- }
102
-
103
- return this;
104
- };
105
-
106
- proto.emitEvent = function( eventName, args ) {
107
- var listeners = this._events && this._events[ eventName ];
108
- if ( !listeners || !listeners.length ) {
109
- return;
110
- }
111
- // copy over to avoid interference if .off() in listener
112
- listeners = listeners.slice(0);
113
- args = args || [];
114
- // once stuff
115
- var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
116
-
117
- for ( var i=0; i < listeners.length; i++ ) {
118
- var listener = listeners[i];
119
- var isOnce = onceListeners && onceListeners[ listener ];
120
- if ( isOnce ) {
121
- // remove listener
122
- // remove before trigger to prevent recursion
123
- this.off( eventName, listener );
124
- // unset once flag
125
- delete onceListeners[ listener ];
126
- }
127
- // trigger listener
128
- listener.apply( this, args );
129
- }
130
-
131
- return this;
132
- };
133
-
134
- proto.allOff = function() {
135
- delete this._events;
136
- delete this._onceEvents;
137
- };
138
-
139
- return EvEmitter;
140
-
141
- }));
142
- } (evEmitter));
143
- return evEmitter.exports;
144
- }
145
-
146
- var getSize = {exports: {}};
147
-
148
- /*!
149
- * getSize v2.0.3
150
- * measure size of elements
151
- * MIT license
152
- */
153
-
154
- var hasRequiredGetSize;
155
-
156
- function requireGetSize () {
157
- if (hasRequiredGetSize) return getSize.exports;
158
- hasRequiredGetSize = 1;
159
- (function (module) {
160
- /* jshint browser: true, strict: true, undef: true, unused: true */
161
- /* globals console: false */
162
-
163
- ( function( window, factory ) {
164
- /* jshint strict: false */ /* globals define, module */
165
- if ( module.exports ) {
166
- // CommonJS
167
- module.exports = factory();
168
- } else {
169
- // browser global
170
- window.getSize = factory();
171
- }
172
-
173
- })( window, function factory() {
174
-
175
- // -------------------------- helpers -------------------------- //
176
-
177
- // get a number from a string, not a percentage
178
- function getStyleSize( value ) {
179
- var num = parseFloat( value );
180
- // not a percent like '100%', and a number
181
- var isValid = value.indexOf('%') == -1 && !isNaN( num );
182
- return isValid && num;
183
- }
184
-
185
- function noop() {}
186
-
187
- var logError = typeof console == 'undefined' ? noop :
188
- function( message ) {
189
- console.error( message );
190
- };
191
-
192
- // -------------------------- measurements -------------------------- //
193
-
194
- var measurements = [
195
- 'paddingLeft',
196
- 'paddingRight',
197
- 'paddingTop',
198
- 'paddingBottom',
199
- 'marginLeft',
200
- 'marginRight',
201
- 'marginTop',
202
- 'marginBottom',
203
- 'borderLeftWidth',
204
- 'borderRightWidth',
205
- 'borderTopWidth',
206
- 'borderBottomWidth'
207
- ];
208
-
209
- var measurementsLength = measurements.length;
210
-
211
- function getZeroSize() {
212
- var size = {
213
- width: 0,
214
- height: 0,
215
- innerWidth: 0,
216
- innerHeight: 0,
217
- outerWidth: 0,
218
- outerHeight: 0
219
- };
220
- for ( var i=0; i < measurementsLength; i++ ) {
221
- var measurement = measurements[i];
222
- size[ measurement ] = 0;
223
- }
224
- return size;
225
- }
226
-
227
- // -------------------------- getStyle -------------------------- //
228
-
229
- /**
230
- * getStyle, get style of element, check for Firefox bug
231
- * https://bugzilla.mozilla.org/show_bug.cgi?id=548397
232
- */
233
- function getStyle( elem ) {
234
- var style = getComputedStyle( elem );
235
- if ( !style ) {
236
- logError( 'Style returned ' + style +
237
- '. Are you running this code in a hidden iframe on Firefox? ' +
238
- 'See https://bit.ly/getsizebug1' );
239
- }
240
- return style;
241
- }
242
-
243
- // -------------------------- setup -------------------------- //
244
-
245
- var isSetup = false;
246
-
247
- var isBoxSizeOuter;
248
-
249
- /**
250
- * setup
251
- * check isBoxSizerOuter
252
- * do on first getSize() rather than on page load for Firefox bug
253
- */
254
- function setup() {
255
- // setup once
256
- if ( isSetup ) {
257
- return;
258
- }
259
- isSetup = true;
260
-
261
- // -------------------------- box sizing -------------------------- //
262
-
263
- /**
264
- * Chrome & Safari measure the outer-width on style.width on border-box elems
265
- * IE11 & Firefox<29 measures the inner-width
266
- */
267
- var div = document.createElement('div');
268
- div.style.width = '200px';
269
- div.style.padding = '1px 2px 3px 4px';
270
- div.style.borderStyle = 'solid';
271
- div.style.borderWidth = '1px 2px 3px 4px';
272
- div.style.boxSizing = 'border-box';
273
-
274
- var body = document.body || document.documentElement;
275
- body.appendChild( div );
276
- var style = getStyle( div );
277
- // round value for browser zoom. desandro/masonry#928
278
- isBoxSizeOuter = Math.round( getStyleSize( style.width ) ) == 200;
279
- getSize.isBoxSizeOuter = isBoxSizeOuter;
280
-
281
- body.removeChild( div );
282
- }
283
-
284
- // -------------------------- getSize -------------------------- //
285
-
286
- function getSize( elem ) {
287
- setup();
288
-
289
- // use querySeletor if elem is string
290
- if ( typeof elem == 'string' ) {
291
- elem = document.querySelector( elem );
292
- }
293
-
294
- // do not proceed on non-objects
295
- if ( !elem || typeof elem != 'object' || !elem.nodeType ) {
296
- return;
297
- }
298
-
299
- var style = getStyle( elem );
300
-
301
- // if hidden, everything is 0
302
- if ( style.display == 'none' ) {
303
- return getZeroSize();
304
- }
305
-
306
- var size = {};
307
- size.width = elem.offsetWidth;
308
- size.height = elem.offsetHeight;
309
-
310
- var isBorderBox = size.isBorderBox = style.boxSizing == 'border-box';
311
-
312
- // get all measurements
313
- for ( var i=0; i < measurementsLength; i++ ) {
314
- var measurement = measurements[i];
315
- var value = style[ measurement ];
316
- var num = parseFloat( value );
317
- // any 'auto', 'medium' value will be 0
318
- size[ measurement ] = !isNaN( num ) ? num : 0;
319
- }
320
-
321
- var paddingWidth = size.paddingLeft + size.paddingRight;
322
- var paddingHeight = size.paddingTop + size.paddingBottom;
323
- var marginWidth = size.marginLeft + size.marginRight;
324
- var marginHeight = size.marginTop + size.marginBottom;
325
- var borderWidth = size.borderLeftWidth + size.borderRightWidth;
326
- var borderHeight = size.borderTopWidth + size.borderBottomWidth;
327
-
328
- var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
329
-
330
- // overwrite width and height if we can get it from style
331
- var styleWidth = getStyleSize( style.width );
332
- if ( styleWidth !== false ) {
333
- size.width = styleWidth +
334
- // add padding and border unless it's already including it
335
- ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
336
- }
337
-
338
- var styleHeight = getStyleSize( style.height );
339
- if ( styleHeight !== false ) {
340
- size.height = styleHeight +
341
- // add padding and border unless it's already including it
342
- ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
343
- }
344
-
345
- size.innerWidth = size.width - ( paddingWidth + borderWidth );
346
- size.innerHeight = size.height - ( paddingHeight + borderHeight );
347
-
348
- size.outerWidth = size.width + marginWidth;
349
- size.outerHeight = size.height + marginHeight;
350
-
351
- return size;
352
- }
353
-
354
- return getSize;
355
-
356
- });
357
- } (getSize));
358
- return getSize.exports;
359
- }
360
-
361
- var utils = {exports: {}};
362
-
363
- var matchesSelector = {exports: {}};
364
-
365
- /**
366
- * matchesSelector v2.0.2
367
- * matchesSelector( element, '.selector' )
368
- * MIT license
369
- */
370
-
371
- var hasRequiredMatchesSelector;
372
-
373
- function requireMatchesSelector () {
374
- if (hasRequiredMatchesSelector) return matchesSelector.exports;
375
- hasRequiredMatchesSelector = 1;
376
- (function (module) {
377
- /*jshint browser: true, strict: true, undef: true, unused: true */
378
-
379
- ( function( window, factory ) {
380
- // universal module definition
381
- if ( module.exports ) {
382
- // CommonJS
383
- module.exports = factory();
384
- } else {
385
- // browser global
386
- window.matchesSelector = factory();
387
- }
388
-
389
- }( window, function factory() {
390
-
391
- var matchesMethod = ( function() {
392
- var ElemProto = window.Element.prototype;
393
- // check for the standard method name first
394
- if ( ElemProto.matches ) {
395
- return 'matches';
396
- }
397
- // check un-prefixed
398
- if ( ElemProto.matchesSelector ) {
399
- return 'matchesSelector';
400
- }
401
- // check vendor prefixes
402
- var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
403
-
404
- for ( var i=0; i < prefixes.length; i++ ) {
405
- var prefix = prefixes[i];
406
- var method = prefix + 'MatchesSelector';
407
- if ( ElemProto[ method ] ) {
408
- return method;
409
- }
410
- }
411
- })();
412
-
413
- return function matchesSelector( elem, selector ) {
414
- return elem[ matchesMethod ]( selector );
415
- };
416
-
417
- }));
418
- } (matchesSelector));
419
- return matchesSelector.exports;
420
- }
421
-
422
- /**
423
- * Fizzy UI utils v2.0.7
424
- * MIT license
425
- */
426
-
427
- var hasRequiredUtils;
428
-
429
- function requireUtils () {
430
- if (hasRequiredUtils) return utils.exports;
431
- hasRequiredUtils = 1;
432
- (function (module) {
433
- /*jshint browser: true, undef: true, unused: true, strict: true */
434
-
435
- ( function( window, factory ) {
436
- // universal module definition
437
- /*jshint strict: false */ /*globals define, module, require */
438
-
439
- if ( module.exports ) {
440
- // CommonJS
441
- module.exports = factory(
442
- window,
443
- requireMatchesSelector()
444
- );
445
- } else {
446
- // browser global
447
- window.fizzyUIUtils = factory(
448
- window,
449
- window.matchesSelector
450
- );
451
- }
452
-
453
- }( window, function factory( window, matchesSelector ) {
454
-
455
- var utils = {};
456
-
457
- // ----- extend ----- //
458
-
459
- // extends objects
460
- utils.extend = function( a, b ) {
461
- for ( var prop in b ) {
462
- a[ prop ] = b[ prop ];
463
- }
464
- return a;
465
- };
466
-
467
- // ----- modulo ----- //
468
-
469
- utils.modulo = function( num, div ) {
470
- return ( ( num % div ) + div ) % div;
471
- };
472
-
473
- // ----- makeArray ----- //
474
-
475
- var arraySlice = Array.prototype.slice;
476
-
477
- // turn element or nodeList into an array
478
- utils.makeArray = function( obj ) {
479
- if ( Array.isArray( obj ) ) {
480
- // use object if already an array
481
- return obj;
482
- }
483
- // return empty array if undefined or null. #6
484
- if ( obj === null || obj === undefined ) {
485
- return [];
486
- }
487
-
488
- var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
489
- if ( isArrayLike ) {
490
- // convert nodeList to array
491
- return arraySlice.call( obj );
492
- }
493
-
494
- // array of single index
495
- return [ obj ];
496
- };
497
-
498
- // ----- removeFrom ----- //
499
-
500
- utils.removeFrom = function( ary, obj ) {
501
- var index = ary.indexOf( obj );
502
- if ( index != -1 ) {
503
- ary.splice( index, 1 );
504
- }
505
- };
506
-
507
- // ----- getParent ----- //
508
-
509
- utils.getParent = function( elem, selector ) {
510
- while ( elem.parentNode && elem != document.body ) {
511
- elem = elem.parentNode;
512
- if ( matchesSelector( elem, selector ) ) {
513
- return elem;
514
- }
515
- }
516
- };
517
-
518
- // ----- getQueryElement ----- //
519
-
520
- // use element as selector string
521
- utils.getQueryElement = function( elem ) {
522
- if ( typeof elem == 'string' ) {
523
- return document.querySelector( elem );
524
- }
525
- return elem;
526
- };
527
-
528
- // ----- handleEvent ----- //
529
-
530
- // enable .ontype to trigger from .addEventListener( elem, 'type' )
531
- utils.handleEvent = function( event ) {
532
- var method = 'on' + event.type;
533
- if ( this[ method ] ) {
534
- this[ method ]( event );
535
- }
536
- };
537
-
538
- // ----- filterFindElements ----- //
539
-
540
- utils.filterFindElements = function( elems, selector ) {
541
- // make array of elems
542
- elems = utils.makeArray( elems );
543
- var ffElems = [];
544
-
545
- elems.forEach( function( elem ) {
546
- // check that elem is an actual element
547
- if ( !( elem instanceof HTMLElement ) ) {
548
- return;
549
- }
550
- // add elem if no selector
551
- if ( !selector ) {
552
- ffElems.push( elem );
553
- return;
554
- }
555
- // filter & find items if we have a selector
556
- // filter
557
- if ( matchesSelector( elem, selector ) ) {
558
- ffElems.push( elem );
559
- }
560
- // find children
561
- var childElems = elem.querySelectorAll( selector );
562
- // concat childElems to filterFound array
563
- for ( var i=0; i < childElems.length; i++ ) {
564
- ffElems.push( childElems[i] );
565
- }
566
- });
567
-
568
- return ffElems;
569
- };
570
-
571
- // ----- debounceMethod ----- //
572
-
573
- utils.debounceMethod = function( _class, methodName, threshold ) {
574
- threshold = threshold || 100;
575
- // original method
576
- var method = _class.prototype[ methodName ];
577
- var timeoutName = methodName + 'Timeout';
578
-
579
- _class.prototype[ methodName ] = function() {
580
- var timeout = this[ timeoutName ];
581
- clearTimeout( timeout );
582
-
583
- var args = arguments;
584
- var _this = this;
585
- this[ timeoutName ] = setTimeout( function() {
586
- method.apply( _this, args );
587
- delete _this[ timeoutName ];
588
- }, threshold );
589
- };
590
- };
591
-
592
- // ----- docReady ----- //
593
-
594
- utils.docReady = function( callback ) {
595
- var readyState = document.readyState;
596
- if ( readyState == 'complete' || readyState == 'interactive' ) {
597
- // do async to allow for other scripts to run. metafizzy/flickity#441
598
- setTimeout( callback );
599
- } else {
600
- document.addEventListener( 'DOMContentLoaded', callback );
601
- }
602
- };
603
-
604
- // ----- htmlInit ----- //
605
-
606
- // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
607
- utils.toDashed = function( str ) {
608
- return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
609
- return $1 + '-' + $2;
610
- }).toLowerCase();
611
- };
612
-
613
- var console = window.console;
614
- /**
615
- * allow user to initialize classes via [data-namespace] or .js-namespace class
616
- * htmlInit( Widget, 'widgetName' )
617
- * options are parsed from data-namespace-options
618
- */
619
- utils.htmlInit = function( WidgetClass, namespace ) {
620
- utils.docReady( function() {
621
- var dashedNamespace = utils.toDashed( namespace );
622
- var dataAttr = 'data-' + dashedNamespace;
623
- var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
624
- var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
625
- var elems = utils.makeArray( dataAttrElems )
626
- .concat( utils.makeArray( jsDashElems ) );
627
- var dataOptionsAttr = dataAttr + '-options';
628
- var jQuery = window.jQuery;
629
-
630
- elems.forEach( function( elem ) {
631
- var attr = elem.getAttribute( dataAttr ) ||
632
- elem.getAttribute( dataOptionsAttr );
633
- var options;
634
- try {
635
- options = attr && JSON.parse( attr );
636
- } catch ( error ) {
637
- // log error, do not initialize
638
- if ( console ) {
639
- console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
640
- ': ' + error );
641
- }
642
- return;
643
- }
644
- // initialize
645
- var instance = new WidgetClass( elem, options );
646
- // make available via $().data('namespace')
647
- if ( jQuery ) {
648
- jQuery.data( elem, namespace, instance );
649
- }
650
- });
651
-
652
- });
653
- };
654
-
655
- // ----- ----- //
656
-
657
- return utils;
658
-
659
- }));
660
- } (utils));
661
- return utils.exports;
662
- }
663
-
664
- var cell = {exports: {}};
665
-
666
- var hasRequiredCell;
667
-
668
- function requireCell () {
669
- if (hasRequiredCell) return cell.exports;
670
- hasRequiredCell = 1;
671
- (function (module) {
672
- // Flickity.Cell
673
- ( function( window, factory ) {
674
- // universal module definition
675
- /* jshint strict: false */
676
- if ( module.exports ) {
677
- // CommonJS
678
- module.exports = factory(
679
- window,
680
- requireGetSize()
681
- );
682
- } else {
683
- // browser global
684
- window.Flickity = window.Flickity || {};
685
- window.Flickity.Cell = factory(
686
- window,
687
- window.getSize
688
- );
689
- }
690
-
691
- }( window, function factory( window, getSize ) {
692
-
693
- function Cell( elem, parent ) {
694
- this.element = elem;
695
- this.parent = parent;
696
-
697
- this.create();
698
- }
699
-
700
- var proto = Cell.prototype;
701
-
702
- proto.create = function() {
703
- this.element.style.position = 'absolute';
704
- this.x = 0;
705
- this.shift = 0;
706
- };
707
-
708
- proto.destroy = function() {
709
- // reset style
710
- this.element.style.position = '';
711
- var side = this.parent.originSide;
712
- this.element.style[ side ] = '';
713
- };
714
-
715
- proto.getSize = function() {
716
- this.size = getSize( this.element );
717
- };
718
-
719
- proto.setPosition = function( x ) {
720
- this.x = x;
721
- this.updateTarget();
722
- this.renderPosition( x );
723
- };
724
-
725
- // setDefaultTarget v1 method, backwards compatibility, remove in v3
726
- proto.updateTarget = proto.setDefaultTarget = function() {
727
- var marginProperty = this.parent.originSide == 'left' ? 'marginLeft' : 'marginRight';
728
- this.target = this.x + this.size[ marginProperty ] +
729
- this.size.width * this.parent.cellAlign;
730
- };
731
-
732
- proto.renderPosition = function( x ) {
733
- // render position of cell with in slider
734
- var side = this.parent.originSide;
735
- this.element.style[ side ] = this.parent.getPositionValue( x );
736
- };
737
-
738
- /**
739
- * @param {Integer} factor - 0, 1, or -1
740
- **/
741
- proto.wrapShift = function( shift ) {
742
- this.shift = shift;
743
- this.renderPosition( this.x + this.parent.slideableWidth * shift );
744
- };
745
-
746
- proto.remove = function() {
747
- this.element.parentNode.removeChild( this.element );
748
- };
749
-
750
- return Cell;
751
-
752
- }));
753
- } (cell));
754
- return cell.exports;
755
- }
756
-
757
- var slide = {exports: {}};
758
-
759
- var hasRequiredSlide;
760
-
761
- function requireSlide () {
762
- if (hasRequiredSlide) return slide.exports;
763
- hasRequiredSlide = 1;
764
- (function (module) {
765
- // slide
766
- ( function( window, factory ) {
767
- // universal module definition
768
- /* jshint strict: false */
769
- if ( module.exports ) {
770
- // CommonJS
771
- module.exports = factory();
772
- } else {
773
- // browser global
774
- window.Flickity = window.Flickity || {};
775
- window.Flickity.Slide = factory();
776
- }
777
-
778
- }( window, function factory() {
779
-
780
- function Slide( parent ) {
781
- this.parent = parent;
782
- this.isOriginLeft = parent.originSide == 'left';
783
- this.cells = [];
784
- this.outerWidth = 0;
785
- this.height = 0;
786
- }
787
-
788
- var proto = Slide.prototype;
789
-
790
- proto.addCell = function( cell ) {
791
- this.cells.push( cell );
792
- this.outerWidth += cell.size.outerWidth;
793
- this.height = Math.max( cell.size.outerHeight, this.height );
794
- // first cell stuff
795
- if ( this.cells.length == 1 ) {
796
- this.x = cell.x; // x comes from first cell
797
- var beginMargin = this.isOriginLeft ? 'marginLeft' : 'marginRight';
798
- this.firstMargin = cell.size[ beginMargin ];
799
- }
800
- };
801
-
802
- proto.updateTarget = function() {
803
- var endMargin = this.isOriginLeft ? 'marginRight' : 'marginLeft';
804
- var lastCell = this.getLastCell();
805
- var lastMargin = lastCell ? lastCell.size[ endMargin ] : 0;
806
- var slideWidth = this.outerWidth - ( this.firstMargin + lastMargin );
807
- this.target = this.x + this.firstMargin + slideWidth * this.parent.cellAlign;
808
- };
809
-
810
- proto.getLastCell = function() {
811
- return this.cells[ this.cells.length - 1 ];
812
- };
813
-
814
- proto.select = function() {
815
- this.changeSelectedClass('add');
816
- };
817
-
818
- proto.unselect = function() {
819
- this.changeSelectedClass('remove');
820
- };
821
-
822
- proto.changeSelectedClass = function( method ) {
823
- this.cells.forEach( function( cell ) {
824
- cell.element.classList[ method ]('is-selected');
825
- });
826
- };
827
-
828
- proto.getCellElements = function() {
829
- return this.cells.map( function( cell ) {
830
- return cell.element;
831
- });
832
- };
833
-
834
- return Slide;
835
-
836
- }));
837
- } (slide));
838
- return slide.exports;
839
- }
840
-
841
- var animate = {exports: {}};
842
-
843
- var hasRequiredAnimate;
844
-
845
- function requireAnimate () {
846
- if (hasRequiredAnimate) return animate.exports;
847
- hasRequiredAnimate = 1;
848
- (function (module) {
849
- // animate
850
- ( function( window, factory ) {
851
- // universal module definition
852
- /* jshint strict: false */
853
- if ( module.exports ) {
854
- // CommonJS
855
- module.exports = factory(
856
- window,
857
- requireUtils()
858
- );
859
- } else {
860
- // browser global
861
- window.Flickity = window.Flickity || {};
862
- window.Flickity.animatePrototype = factory(
863
- window,
864
- window.fizzyUIUtils
865
- );
866
- }
867
-
868
- }( window, function factory( window, utils ) {
869
-
870
- // -------------------------- requestAnimationFrame -------------------------- //
871
-
872
- // get rAF, prefixed, if present
873
- var requestAnimationFrame = window.requestAnimationFrame ||
874
- window.webkitRequestAnimationFrame;
875
-
876
- // fallback to setTimeout
877
- var lastTime = 0;
878
- if ( !requestAnimationFrame ) {
879
- requestAnimationFrame = function( callback ) {
880
- var currTime = new Date().getTime();
881
- var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
882
- var id = setTimeout( callback, timeToCall );
883
- lastTime = currTime + timeToCall;
884
- return id;
885
- };
886
- }
887
-
888
- // -------------------------- animate -------------------------- //
889
-
890
- var proto = {};
891
-
892
- proto.startAnimation = function() {
893
- if ( this.isAnimating ) {
894
- return;
895
- }
896
-
897
- this.isAnimating = true;
898
- this.restingFrames = 0;
899
- this.animate();
900
- };
901
-
902
- proto.animate = function() {
903
- this.applyDragForce();
904
- this.applySelectedAttraction();
905
-
906
- var previousX = this.x;
907
-
908
- this.integratePhysics();
909
- this.positionSlider();
910
- this.settle( previousX );
911
- // animate next frame
912
- if ( this.isAnimating ) {
913
- var _this = this;
914
- requestAnimationFrame( function animateFrame() {
915
- _this.animate();
916
- });
917
- }
918
- };
919
-
920
-
921
- var transformProperty = ( function () {
922
- var style = document.documentElement.style;
923
- if ( typeof style.transform == 'string' ) {
924
- return 'transform';
925
- }
926
- return 'WebkitTransform';
927
- })();
928
-
929
- proto.positionSlider = function() {
930
- var x = this.x;
931
- // wrap position around
932
- if ( this.options.wrapAround && this.cells.length > 1 ) {
933
- x = utils.modulo( x, this.slideableWidth );
934
- x = x - this.slideableWidth;
935
- this.shiftWrapCells( x );
936
- }
937
-
938
- x = x + this.cursorPosition;
939
- // reverse if right-to-left and using transform
940
- x = this.options.rightToLeft && transformProperty ? -x : x;
941
- var value = this.getPositionValue( x );
942
- // use 3D tranforms for hardware acceleration on iOS
943
- // but use 2D when settled, for better font-rendering
944
- this.slider.style[ transformProperty ] = this.isAnimating ?
945
- 'translate3d(' + value + ',0,0)' : 'translateX(' + value + ')';
946
-
947
- // scroll event
948
- var firstSlide = this.slides[0];
949
- if ( firstSlide ) {
950
- var positionX = -this.x - firstSlide.target;
951
- var progress = positionX / this.slidesWidth;
952
- this.dispatchEvent( 'scroll', null, [ progress, positionX ] );
953
- }
954
- };
955
-
956
- proto.positionSliderAtSelected = function() {
957
- if ( !this.cells.length ) {
958
- return;
959
- }
960
- this.x = -this.selectedSlide.target;
961
- this.positionSlider();
962
- };
963
-
964
- proto.getPositionValue = function( position ) {
965
- if ( this.options.percentPosition ) {
966
- // percent position, round to 2 digits, like 12.34%
967
- return ( Math.round( ( position / this.size.innerWidth ) * 10000 ) * 0.01 )+ '%';
968
- } else {
969
- // pixel positioning
970
- return Math.round( position ) + 'px';
971
- }
972
- };
973
-
974
- proto.settle = function( previousX ) {
975
- // keep track of frames where x hasn't moved
976
- if ( !this.isPointerDown && Math.round( this.x * 100 ) == Math.round( previousX * 100 ) ) {
977
- this.restingFrames++;
978
- }
979
- // stop animating if resting for 3 or more frames
980
- if ( this.restingFrames > 2 ) {
981
- this.isAnimating = false;
982
- delete this.isFreeScrolling;
983
- // render position with translateX when settled
984
- this.positionSlider();
985
- this.dispatchEvent('settle');
986
- }
987
- };
988
-
989
- proto.shiftWrapCells = function( x ) {
990
- // shift before cells
991
- var beforeGap = this.cursorPosition + x;
992
- this._shiftCells( this.beforeShiftCells, beforeGap, -1 );
993
- // shift after cells
994
- var afterGap = this.size.innerWidth - ( x + this.slideableWidth + this.cursorPosition );
995
- this._shiftCells( this.afterShiftCells, afterGap, 1 );
996
- };
997
-
998
- proto._shiftCells = function( cells, gap, shift ) {
999
- for ( var i=0; i < cells.length; i++ ) {
1000
- var cell = cells[i];
1001
- var cellShift = gap > 0 ? shift : 0;
1002
- cell.wrapShift( cellShift );
1003
- gap -= cell.size.outerWidth;
1004
- }
1005
- };
1006
-
1007
- proto._unshiftCells = function( cells ) {
1008
- if ( !cells || !cells.length ) {
1009
- return;
1010
- }
1011
- for ( var i=0; i < cells.length; i++ ) {
1012
- cells[i].wrapShift( 0 );
1013
- }
1014
- };
1015
-
1016
- // -------------------------- physics -------------------------- //
1017
-
1018
- proto.integratePhysics = function() {
1019
- this.x += this.velocity;
1020
- this.velocity *= this.getFrictionFactor();
1021
- };
1022
-
1023
- proto.applyForce = function( force ) {
1024
- this.velocity += force;
1025
- };
1026
-
1027
- proto.getFrictionFactor = function() {
1028
- return 1 - this.options[ this.isFreeScrolling ? 'freeScrollFriction' : 'friction' ];
1029
- };
1030
-
1031
- proto.getRestingPosition = function() {
1032
- // my thanks to Steven Wittens, who simplified this math greatly
1033
- return this.x + this.velocity / ( 1 - this.getFrictionFactor() );
1034
- };
1035
-
1036
- proto.applyDragForce = function() {
1037
- if ( !this.isPointerDown ) {
1038
- return;
1039
- }
1040
- // change the position to drag position by applying force
1041
- var dragVelocity = this.dragX - this.x;
1042
- var dragForce = dragVelocity - this.velocity;
1043
- this.applyForce( dragForce );
1044
- };
1045
-
1046
- proto.applySelectedAttraction = function() {
1047
- // do not attract if pointer down or no cells
1048
- if ( this.isPointerDown || this.isFreeScrolling || !this.cells.length ) {
1049
- return;
1050
- }
1051
- var distance = this.selectedSlide.target * -1 - this.x;
1052
- var force = distance * this.options.selectedAttraction;
1053
- this.applyForce( force );
1054
- };
1055
-
1056
- return proto;
1057
-
1058
- }));
1059
- } (animate));
1060
- return animate.exports;
1061
- }
1062
-
1063
- var hasRequiredFlickity;
1064
-
1065
- function requireFlickity () {
1066
- if (hasRequiredFlickity) return flickity.exports;
1067
- hasRequiredFlickity = 1;
1068
- (function (module) {
1069
- // Flickity main
1070
- ( function( window, factory ) {
1071
- // universal module definition
1072
- /* jshint strict: false */
1073
- if ( module.exports ) {
1074
- // CommonJS
1075
- module.exports = factory(
1076
- window,
1077
- requireEvEmitter(),
1078
- requireGetSize(),
1079
- requireUtils(),
1080
- requireCell(),
1081
- requireSlide(),
1082
- requireAnimate()
1083
- );
1084
- } else {
1085
- // browser global
1086
- var _Flickity = window.Flickity;
1087
-
1088
- window.Flickity = factory(
1089
- window,
1090
- window.EvEmitter,
1091
- window.getSize,
1092
- window.fizzyUIUtils,
1093
- _Flickity.Cell,
1094
- _Flickity.Slide,
1095
- _Flickity.animatePrototype
1096
- );
1097
- }
1098
-
1099
- }( window, function factory( window, EvEmitter, getSize,
1100
- utils, Cell, Slide, animatePrototype ) {
1101
-
1102
- // vars
1103
- var jQuery = window.jQuery;
1104
- var getComputedStyle = window.getComputedStyle;
1105
- var console = window.console;
1106
-
1107
- function moveElements( elems, toElem ) {
1108
- elems = utils.makeArray( elems );
1109
- while ( elems.length ) {
1110
- toElem.appendChild( elems.shift() );
1111
- }
1112
- }
1113
-
1114
- // -------------------------- Flickity -------------------------- //
1115
-
1116
- // globally unique identifiers
1117
- var GUID = 0;
1118
- // internal store of all Flickity intances
1119
- var instances = {};
1120
-
1121
- function Flickity( element, options ) {
1122
- var queryElement = utils.getQueryElement( element );
1123
- if ( !queryElement ) {
1124
- if ( console ) {
1125
- console.error( 'Bad element for Flickity: ' + ( queryElement || element ) );
1126
- }
1127
- return;
1128
- }
1129
- this.element = queryElement;
1130
- // do not initialize twice on same element
1131
- if ( this.element.flickityGUID ) {
1132
- var instance = instances[ this.element.flickityGUID ];
1133
- instance.option( options );
1134
- return instance;
1135
- }
1136
-
1137
- // add jQuery
1138
- if ( jQuery ) {
1139
- this.$element = jQuery( this.element );
1140
- }
1141
- // options
1142
- this.options = utils.extend( {}, this.constructor.defaults );
1143
- this.option( options );
1144
-
1145
- // kick things off
1146
- this._create();
1147
- }
1148
-
1149
- Flickity.defaults = {
1150
- accessibility: true,
1151
- // adaptiveHeight: false,
1152
- cellAlign: 'center',
1153
- // cellSelector: undefined,
1154
- // contain: false,
1155
- freeScrollFriction: 0.075, // friction when free-scrolling
1156
- friction: 0.28, // friction when selecting
1157
- namespaceJQueryEvents: true,
1158
- // initialIndex: 0,
1159
- percentPosition: true,
1160
- resize: true,
1161
- selectedAttraction: 0.025,
1162
- setGallerySize: true
1163
- // watchCSS: false,
1164
- // wrapAround: false
1165
- };
1166
-
1167
- // hash of methods triggered on _create()
1168
- Flickity.createMethods = [];
1169
-
1170
- var proto = Flickity.prototype;
1171
- // inherit EventEmitter
1172
- utils.extend( proto, EvEmitter.prototype );
1173
-
1174
- proto._create = function() {
1175
- // add id for Flickity.data
1176
- var id = this.guid = ++GUID;
1177
- this.element.flickityGUID = id; // expando
1178
- instances[ id ] = this; // associate via id
1179
- // initial properties
1180
- this.selectedIndex = 0;
1181
- // how many frames slider has been in same position
1182
- this.restingFrames = 0;
1183
- // initial physics properties
1184
- this.x = 0;
1185
- this.velocity = 0;
1186
- this.originSide = this.options.rightToLeft ? 'right' : 'left';
1187
- // create viewport & slider
1188
- this.viewport = document.createElement('div');
1189
- this.viewport.className = 'flickity-viewport';
1190
- this._createSlider();
1191
-
1192
- if ( this.options.resize || this.options.watchCSS ) {
1193
- window.addEventListener( 'resize', this );
1194
- }
1195
-
1196
- Flickity.createMethods.forEach( function( method ) {
1197
- this[ method ]();
1198
- }, this );
1199
-
1200
- if ( this.options.watchCSS ) {
1201
- this.watchCSS();
1202
- } else {
1203
- this.activate();
1204
- }
1205
-
1206
- };
1207
-
1208
- /**
1209
- * set options
1210
- * @param {Object} opts
1211
- */
1212
- proto.option = function( opts ) {
1213
- utils.extend( this.options, opts );
1214
- };
1215
-
1216
- proto.activate = function() {
1217
- if ( this.isActive ) {
1218
- return;
1219
- }
1220
- this.isActive = true;
1221
- this.element.classList.add('flickity-enabled');
1222
- if ( this.options.rightToLeft ) {
1223
- this.element.classList.add('flickity-rtl');
1224
- }
1225
-
1226
- this.getSize();
1227
- // move initial cell elements so they can be loaded as cells
1228
- var cellElems = this._filterFindCellElements( this.element.children );
1229
- moveElements( cellElems, this.slider );
1230
- this.viewport.appendChild( this.slider );
1231
- this.element.appendChild( this.viewport );
1232
- // get cells from children
1233
- this.reloadCells();
1234
-
1235
- if ( this.options.accessibility ) {
1236
- // allow element to focusable
1237
- this.element.tabIndex = 0;
1238
- // listen for key presses
1239
- this.element.addEventListener( 'keydown', this );
1240
- }
1241
-
1242
- this.emitEvent('activate');
1243
-
1244
- var index;
1245
- var initialIndex = this.options.initialIndex;
1246
- if ( this.isInitActivated ) {
1247
- index = this.selectedIndex;
1248
- } else if ( initialIndex !== undefined ) {
1249
- index = this.cells[ initialIndex ] ? initialIndex : 0;
1250
- } else {
1251
- index = 0;
1252
- }
1253
- // select instantly
1254
- this.select( index, false, true );
1255
- // flag for initial activation, for using initialIndex
1256
- this.isInitActivated = true;
1257
- };
1258
-
1259
- // slider positions the cells
1260
- proto._createSlider = function() {
1261
- // slider element does all the positioning
1262
- var slider = document.createElement('div');
1263
- slider.className = 'flickity-slider';
1264
- slider.style[ this.originSide ] = 0;
1265
- this.slider = slider;
1266
- };
1267
-
1268
- proto._filterFindCellElements = function( elems ) {
1269
- return utils.filterFindElements( elems, this.options.cellSelector );
1270
- };
1271
-
1272
- // goes through all children
1273
- proto.reloadCells = function() {
1274
- // collection of item elements
1275
- this.cells = this._makeCells( this.slider.children );
1276
- this.positionCells();
1277
- this._getWrapShiftCells();
1278
- this.setGallerySize();
1279
- };
1280
-
1281
- /**
1282
- * turn elements into Flickity.Cells
1283
- * @param {Array or NodeList or HTMLElement} elems
1284
- * @returns {Array} items - collection of new Flickity Cells
1285
- */
1286
- proto._makeCells = function( elems ) {
1287
- var cellElems = this._filterFindCellElements( elems );
1288
-
1289
- // create new Flickity for collection
1290
- var cells = cellElems.map( function( cellElem ) {
1291
- return new Cell( cellElem, this );
1292
- }, this );
1293
-
1294
- return cells;
1295
- };
1296
-
1297
- proto.getLastCell = function() {
1298
- return this.cells[ this.cells.length - 1 ];
1299
- };
1300
-
1301
- proto.getLastSlide = function() {
1302
- return this.slides[ this.slides.length - 1 ];
1303
- };
1304
-
1305
- // positions all cells
1306
- proto.positionCells = function() {
1307
- // size all cells
1308
- this._sizeCells( this.cells );
1309
- // position all cells
1310
- this._positionCells( 0 );
1311
- };
1312
-
1313
- /**
1314
- * position certain cells
1315
- * @param {Integer} index - which cell to start with
1316
- */
1317
- proto._positionCells = function( index ) {
1318
- index = index || 0;
1319
- // also measure maxCellHeight
1320
- // start 0 if positioning all cells
1321
- this.maxCellHeight = index ? this.maxCellHeight || 0 : 0;
1322
- var cellX = 0;
1323
- // get cellX
1324
- if ( index > 0 ) {
1325
- var startCell = this.cells[ index - 1 ];
1326
- cellX = startCell.x + startCell.size.outerWidth;
1327
- }
1328
- var len = this.cells.length;
1329
- for ( var i=index; i < len; i++ ) {
1330
- var cell = this.cells[i];
1331
- cell.setPosition( cellX );
1332
- cellX += cell.size.outerWidth;
1333
- this.maxCellHeight = Math.max( cell.size.outerHeight, this.maxCellHeight );
1334
- }
1335
- // keep track of cellX for wrap-around
1336
- this.slideableWidth = cellX;
1337
- // slides
1338
- this.updateSlides();
1339
- // contain slides target
1340
- this._containSlides();
1341
- // update slidesWidth
1342
- this.slidesWidth = len ? this.getLastSlide().target - this.slides[0].target : 0;
1343
- };
1344
-
1345
- /**
1346
- * cell.getSize() on multiple cells
1347
- * @param {Array} cells
1348
- */
1349
- proto._sizeCells = function( cells ) {
1350
- cells.forEach( function( cell ) {
1351
- cell.getSize();
1352
- });
1353
- };
1354
-
1355
- // -------------------------- -------------------------- //
1356
-
1357
- proto.updateSlides = function() {
1358
- this.slides = [];
1359
- if ( !this.cells.length ) {
1360
- return;
1361
- }
1362
-
1363
- var slide = new Slide( this );
1364
- this.slides.push( slide );
1365
- var isOriginLeft = this.originSide == 'left';
1366
- var nextMargin = isOriginLeft ? 'marginRight' : 'marginLeft';
1367
-
1368
- var canCellFit = this._getCanCellFit();
1369
-
1370
- this.cells.forEach( function( cell, i ) {
1371
- // just add cell if first cell in slide
1372
- if ( !slide.cells.length ) {
1373
- slide.addCell( cell );
1374
- return;
1375
- }
1376
-
1377
- var slideWidth = ( slide.outerWidth - slide.firstMargin ) +
1378
- ( cell.size.outerWidth - cell.size[ nextMargin ] );
1379
-
1380
- if ( canCellFit.call( this, i, slideWidth ) ) {
1381
- slide.addCell( cell );
1382
- } else {
1383
- // doesn't fit, new slide
1384
- slide.updateTarget();
1385
-
1386
- slide = new Slide( this );
1387
- this.slides.push( slide );
1388
- slide.addCell( cell );
1389
- }
1390
- }, this );
1391
- // last slide
1392
- slide.updateTarget();
1393
- // update .selectedSlide
1394
- this.updateSelectedSlide();
1395
- };
1396
-
1397
- proto._getCanCellFit = function() {
1398
- var groupCells = this.options.groupCells;
1399
- if ( !groupCells ) {
1400
- return function() {
1401
- return false;
1402
- };
1403
- } else if ( typeof groupCells == 'number' ) {
1404
- // group by number. 3 -> [0,1,2], [3,4,5], ...
1405
- var number = parseInt( groupCells, 10 );
1406
- return function( i ) {
1407
- return ( i % number ) !== 0;
1408
- };
1409
- }
1410
- // default, group by width of slide
1411
- // parse '75%
1412
- var percentMatch = typeof groupCells == 'string' &&
1413
- groupCells.match(/^(\d+)%$/);
1414
- var percent = percentMatch ? parseInt( percentMatch[1], 10 ) / 100 : 1;
1415
- return function( i, slideWidth ) {
1416
- return slideWidth <= ( this.size.innerWidth + 1 ) * percent;
1417
- };
1418
- };
1419
-
1420
- // alias _init for jQuery plugin .flickity()
1421
- proto._init =
1422
- proto.reposition = function() {
1423
- this.positionCells();
1424
- this.positionSliderAtSelected();
1425
- };
1426
-
1427
- proto.getSize = function() {
1428
- this.size = getSize( this.element );
1429
- this.setCellAlign();
1430
- this.cursorPosition = this.size.innerWidth * this.cellAlign;
1431
- };
1432
-
1433
- var cellAlignShorthands = {
1434
- // cell align, then based on origin side
1435
- center: {
1436
- left: 0.5,
1437
- right: 0.5
1438
- },
1439
- left: {
1440
- left: 0,
1441
- right: 1
1442
- },
1443
- right: {
1444
- right: 0,
1445
- left: 1
1446
- }
1447
- };
1448
-
1449
- proto.setCellAlign = function() {
1450
- var shorthand = cellAlignShorthands[ this.options.cellAlign ];
1451
- this.cellAlign = shorthand ? shorthand[ this.originSide ] : this.options.cellAlign;
1452
- };
1453
-
1454
- proto.setGallerySize = function() {
1455
- if ( this.options.setGallerySize ) {
1456
- var height = this.options.adaptiveHeight && this.selectedSlide ?
1457
- this.selectedSlide.height : this.maxCellHeight;
1458
- this.viewport.style.height = height + 'px';
1459
- }
1460
- };
1461
-
1462
- proto._getWrapShiftCells = function() {
1463
- // only for wrap-around
1464
- if ( !this.options.wrapAround ) {
1465
- return;
1466
- }
1467
- // unshift previous cells
1468
- this._unshiftCells( this.beforeShiftCells );
1469
- this._unshiftCells( this.afterShiftCells );
1470
- // get before cells
1471
- // initial gap
1472
- var gapX = this.cursorPosition;
1473
- var cellIndex = this.cells.length - 1;
1474
- this.beforeShiftCells = this._getGapCells( gapX, cellIndex, -1 );
1475
- // get after cells
1476
- // ending gap between last cell and end of gallery viewport
1477
- gapX = this.size.innerWidth - this.cursorPosition;
1478
- // start cloning at first cell, working forwards
1479
- this.afterShiftCells = this._getGapCells( gapX, 0, 1 );
1480
- };
1481
-
1482
- proto._getGapCells = function( gapX, cellIndex, increment ) {
1483
- // keep adding cells until the cover the initial gap
1484
- var cells = [];
1485
- while ( gapX > 0 ) {
1486
- var cell = this.cells[ cellIndex ];
1487
- if ( !cell ) {
1488
- break;
1489
- }
1490
- cells.push( cell );
1491
- cellIndex += increment;
1492
- gapX -= cell.size.outerWidth;
1493
- }
1494
- return cells;
1495
- };
1496
-
1497
- // ----- contain ----- //
1498
-
1499
- // contain cell targets so no excess sliding
1500
- proto._containSlides = function() {
1501
- if ( !this.options.contain || this.options.wrapAround || !this.cells.length ) {
1502
- return;
1503
- }
1504
- var isRightToLeft = this.options.rightToLeft;
1505
- var beginMargin = isRightToLeft ? 'marginRight' : 'marginLeft';
1506
- var endMargin = isRightToLeft ? 'marginLeft' : 'marginRight';
1507
- var contentWidth = this.slideableWidth - this.getLastCell().size[ endMargin ];
1508
- // content is less than gallery size
1509
- var isContentSmaller = contentWidth < this.size.innerWidth;
1510
- // bounds
1511
- var beginBound = this.cursorPosition + this.cells[0].size[ beginMargin ];
1512
- var endBound = contentWidth - this.size.innerWidth * ( 1 - this.cellAlign );
1513
- // contain each cell target
1514
- this.slides.forEach( function( slide ) {
1515
- if ( isContentSmaller ) {
1516
- // all cells fit inside gallery
1517
- slide.target = contentWidth * this.cellAlign;
1518
- } else {
1519
- // contain to bounds
1520
- slide.target = Math.max( slide.target, beginBound );
1521
- slide.target = Math.min( slide.target, endBound );
1522
- }
1523
- }, this );
1524
- };
1525
-
1526
- // ----- ----- //
1527
-
1528
- /**
1529
- * emits events via eventEmitter and jQuery events
1530
- * @param {String} type - name of event
1531
- * @param {Event} event - original event
1532
- * @param {Array} args - extra arguments
1533
- */
1534
- proto.dispatchEvent = function( type, event, args ) {
1535
- var emitArgs = event ? [ event ].concat( args ) : args;
1536
- this.emitEvent( type, emitArgs );
1537
-
1538
- if ( jQuery && this.$element ) {
1539
- // default trigger with type if no event
1540
- type += this.options.namespaceJQueryEvents ? '.flickity' : '';
1541
- var $event = type;
1542
- if ( event ) {
1543
- // create jQuery event
1544
- var jQEvent = jQuery.Event( event );
1545
- jQEvent.type = type;
1546
- $event = jQEvent;
1547
- }
1548
- this.$element.trigger( $event, args );
1549
- }
1550
- };
1551
-
1552
- // -------------------------- select -------------------------- //
1553
-
1554
- /**
1555
- * @param {Integer} index - index of the slide
1556
- * @param {Boolean} isWrap - will wrap-around to last/first if at the end
1557
- * @param {Boolean} isInstant - will immediately set position at selected cell
1558
- */
1559
- proto.select = function( index, isWrap, isInstant ) {
1560
- if ( !this.isActive ) {
1561
- return;
1562
- }
1563
- index = parseInt( index, 10 );
1564
- this._wrapSelect( index );
1565
-
1566
- if ( this.options.wrapAround || isWrap ) {
1567
- index = utils.modulo( index, this.slides.length );
1568
- }
1569
- // bail if invalid index
1570
- if ( !this.slides[ index ] ) {
1571
- return;
1572
- }
1573
- this.selectedIndex = index;
1574
- this.updateSelectedSlide();
1575
- if ( isInstant ) {
1576
- this.positionSliderAtSelected();
1577
- } else {
1578
- this.startAnimation();
1579
- }
1580
- if ( this.options.adaptiveHeight ) {
1581
- this.setGallerySize();
1582
- }
1583
-
1584
- this.dispatchEvent('select');
1585
- // old v1 event name, remove in v3
1586
- this.dispatchEvent('cellSelect');
1587
- };
1588
-
1589
- // wraps position for wrapAround, to move to closest slide. #113
1590
- proto._wrapSelect = function( index ) {
1591
- var len = this.slides.length;
1592
- var isWrapping = this.options.wrapAround && len > 1;
1593
- if ( !isWrapping ) {
1594
- return index;
1595
- }
1596
- var wrapIndex = utils.modulo( index, len );
1597
- // go to shortest
1598
- var delta = Math.abs( wrapIndex - this.selectedIndex );
1599
- var backWrapDelta = Math.abs( ( wrapIndex + len ) - this.selectedIndex );
1600
- var forewardWrapDelta = Math.abs( ( wrapIndex - len ) - this.selectedIndex );
1601
- if ( !this.isDragSelect && backWrapDelta < delta ) {
1602
- index += len;
1603
- } else if ( !this.isDragSelect && forewardWrapDelta < delta ) {
1604
- index -= len;
1605
- }
1606
- // wrap position so slider is within normal area
1607
- if ( index < 0 ) {
1608
- this.x -= this.slideableWidth;
1609
- } else if ( index >= len ) {
1610
- this.x += this.slideableWidth;
1611
- }
1612
- };
1613
-
1614
- proto.previous = function( isWrap, isInstant ) {
1615
- this.select( this.selectedIndex - 1, isWrap, isInstant );
1616
- };
1617
-
1618
- proto.next = function( isWrap, isInstant ) {
1619
- this.select( this.selectedIndex + 1, isWrap, isInstant );
1620
- };
1621
-
1622
- proto.updateSelectedSlide = function() {
1623
- var slide = this.slides[ this.selectedIndex ];
1624
- // selectedIndex could be outside of slides, if triggered before resize()
1625
- if ( !slide ) {
1626
- return;
1627
- }
1628
- // unselect previous selected slide
1629
- this.unselectSelectedSlide();
1630
- // update new selected slide
1631
- this.selectedSlide = slide;
1632
- slide.select();
1633
- this.selectedCells = slide.cells;
1634
- this.selectedElements = slide.getCellElements();
1635
- // HACK: selectedCell & selectedElement is first cell in slide, backwards compatibility
1636
- // Remove in v3?
1637
- this.selectedCell = slide.cells[0];
1638
- this.selectedElement = this.selectedElements[0];
1639
- };
1640
-
1641
- proto.unselectSelectedSlide = function() {
1642
- if ( this.selectedSlide ) {
1643
- this.selectedSlide.unselect();
1644
- }
1645
- };
1646
-
1647
- /**
1648
- * select slide from number or cell element
1649
- * @param {Element or Number} elem
1650
- */
1651
- proto.selectCell = function( value, isWrap, isInstant ) {
1652
- // get cell
1653
- var cell;
1654
- if ( typeof value == 'number' ) {
1655
- cell = this.cells[ value ];
1656
- } else {
1657
- // use string as selector
1658
- if ( typeof value == 'string' ) {
1659
- value = this.element.querySelector( value );
1660
- }
1661
- // get cell from element
1662
- cell = this.getCell( value );
1663
- }
1664
- // select slide that has cell
1665
- for ( var i=0; cell && i < this.slides.length; i++ ) {
1666
- var slide = this.slides[i];
1667
- var index = slide.cells.indexOf( cell );
1668
- if ( index != -1 ) {
1669
- this.select( i, isWrap, isInstant );
1670
- return;
1671
- }
1672
- }
1673
- };
1674
-
1675
- // -------------------------- get cells -------------------------- //
1676
-
1677
- /**
1678
- * get Flickity.Cell, given an Element
1679
- * @param {Element} elem
1680
- * @returns {Flickity.Cell} item
1681
- */
1682
- proto.getCell = function( elem ) {
1683
- // loop through cells to get the one that matches
1684
- for ( var i=0; i < this.cells.length; i++ ) {
1685
- var cell = this.cells[i];
1686
- if ( cell.element == elem ) {
1687
- return cell;
1688
- }
1689
- }
1690
- };
1691
-
1692
- /**
1693
- * get collection of Flickity.Cells, given Elements
1694
- * @param {Element, Array, NodeList} elems
1695
- * @returns {Array} cells - Flickity.Cells
1696
- */
1697
- proto.getCells = function( elems ) {
1698
- elems = utils.makeArray( elems );
1699
- var cells = [];
1700
- elems.forEach( function( elem ) {
1701
- var cell = this.getCell( elem );
1702
- if ( cell ) {
1703
- cells.push( cell );
1704
- }
1705
- }, this );
1706
- return cells;
1707
- };
1708
-
1709
- /**
1710
- * get cell elements
1711
- * @returns {Array} cellElems
1712
- */
1713
- proto.getCellElements = function() {
1714
- return this.cells.map( function( cell ) {
1715
- return cell.element;
1716
- });
1717
- };
1718
-
1719
- /**
1720
- * get parent cell from an element
1721
- * @param {Element} elem
1722
- * @returns {Flickit.Cell} cell
1723
- */
1724
- proto.getParentCell = function( elem ) {
1725
- // first check if elem is cell
1726
- var cell = this.getCell( elem );
1727
- if ( cell ) {
1728
- return cell;
1729
- }
1730
- // try to get parent cell elem
1731
- elem = utils.getParent( elem, '.flickity-slider > *' );
1732
- return this.getCell( elem );
1733
- };
1734
-
1735
- /**
1736
- * get cells adjacent to a slide
1737
- * @param {Integer} adjCount - number of adjacent slides
1738
- * @param {Integer} index - index of slide to start
1739
- * @returns {Array} cells - array of Flickity.Cells
1740
- */
1741
- proto.getAdjacentCellElements = function( adjCount, index ) {
1742
- if ( !adjCount ) {
1743
- return this.selectedSlide.getCellElements();
1744
- }
1745
- index = index === undefined ? this.selectedIndex : index;
1746
-
1747
- var len = this.slides.length;
1748
- if ( 1 + ( adjCount * 2 ) >= len ) {
1749
- return this.getCellElements();
1750
- }
1751
-
1752
- var cellElems = [];
1753
- for ( var i = index - adjCount; i <= index + adjCount ; i++ ) {
1754
- var slideIndex = this.options.wrapAround ? utils.modulo( i, len ) : i;
1755
- var slide = this.slides[ slideIndex ];
1756
- if ( slide ) {
1757
- cellElems = cellElems.concat( slide.getCellElements() );
1758
- }
1759
- }
1760
- return cellElems;
1761
- };
1762
-
1763
- // -------------------------- events -------------------------- //
1764
-
1765
- proto.uiChange = function() {
1766
- this.emitEvent('uiChange');
1767
- };
1768
-
1769
- proto.childUIPointerDown = function( event ) {
1770
- this.emitEvent( 'childUIPointerDown', [ event ] );
1771
- };
1772
-
1773
- // ----- resize ----- //
1774
-
1775
- proto.onresize = function() {
1776
- this.watchCSS();
1777
- this.resize();
1778
- };
1779
-
1780
- utils.debounceMethod( Flickity, 'onresize', 150 );
1781
-
1782
- proto.resize = function() {
1783
- if ( !this.isActive ) {
1784
- return;
1785
- }
1786
- this.getSize();
1787
- // wrap values
1788
- if ( this.options.wrapAround ) {
1789
- this.x = utils.modulo( this.x, this.slideableWidth );
1790
- }
1791
- this.positionCells();
1792
- this._getWrapShiftCells();
1793
- this.setGallerySize();
1794
- this.emitEvent('resize');
1795
- // update selected index for group slides, instant
1796
- // TODO: position can be lost between groups of various numbers
1797
- var selectedElement = this.selectedElements && this.selectedElements[0];
1798
- this.selectCell( selectedElement, false, true );
1799
- };
1800
-
1801
- // watches the :after property, activates/deactivates
1802
- proto.watchCSS = function() {
1803
- var watchOption = this.options.watchCSS;
1804
- if ( !watchOption ) {
1805
- return;
1806
- }
1807
-
1808
- var afterContent = getComputedStyle( this.element, ':after' ).content;
1809
- // activate if :after { content: 'flickity' }
1810
- if ( afterContent.indexOf('flickity') != -1 ) {
1811
- this.activate();
1812
- } else {
1813
- this.deactivate();
1814
- }
1815
- };
1816
-
1817
- // ----- keydown ----- //
1818
-
1819
- // go previous/next if left/right keys pressed
1820
- proto.onkeydown = function( event ) {
1821
- // only work if element is in focus
1822
- if ( !this.options.accessibility ||
1823
- ( document.activeElement && document.activeElement != this.element ) ) {
1824
- return;
1825
- }
1826
-
1827
- if ( event.keyCode == 37 ) {
1828
- // go left
1829
- var leftMethod = this.options.rightToLeft ? 'next' : 'previous';
1830
- this.uiChange();
1831
- this[ leftMethod ]();
1832
- } else if ( event.keyCode == 39 ) {
1833
- // go right
1834
- var rightMethod = this.options.rightToLeft ? 'previous' : 'next';
1835
- this.uiChange();
1836
- this[ rightMethod ]();
1837
- }
1838
- };
1839
-
1840
- // -------------------------- destroy -------------------------- //
1841
-
1842
- // deactivate all Flickity functionality, but keep stuff available
1843
- proto.deactivate = function() {
1844
- if ( !this.isActive ) {
1845
- return;
1846
- }
1847
- this.element.classList.remove('flickity-enabled');
1848
- this.element.classList.remove('flickity-rtl');
1849
- // destroy cells
1850
- this.cells.forEach( function( cell ) {
1851
- cell.destroy();
1852
- });
1853
- this.unselectSelectedSlide();
1854
- this.element.removeChild( this.viewport );
1855
- // move child elements back into element
1856
- moveElements( this.slider.children, this.element );
1857
- if ( this.options.accessibility ) {
1858
- this.element.removeAttribute('tabIndex');
1859
- this.element.removeEventListener( 'keydown', this );
1860
- }
1861
- // set flags
1862
- this.isActive = false;
1863
- this.emitEvent('deactivate');
1864
- };
1865
-
1866
- proto.destroy = function() {
1867
- this.deactivate();
1868
- window.removeEventListener( 'resize', this );
1869
- this.emitEvent('destroy');
1870
- if ( jQuery && this.$element ) {
1871
- jQuery.removeData( this.element, 'flickity' );
1872
- }
1873
- delete this.element.flickityGUID;
1874
- delete instances[ this.guid ];
1875
- };
1876
-
1877
- // -------------------------- prototype -------------------------- //
1878
-
1879
- utils.extend( proto, animatePrototype );
1880
-
1881
- // -------------------------- extras -------------------------- //
1882
-
1883
- /**
1884
- * get Flickity instance from element
1885
- * @param {Element} elem
1886
- * @returns {Flickity}
1887
- */
1888
- Flickity.data = function( elem ) {
1889
- elem = utils.getQueryElement( elem );
1890
- var id = elem && elem.flickityGUID;
1891
- return id && instances[ id ];
1892
- };
1893
-
1894
- utils.htmlInit( Flickity, 'flickity' );
1895
-
1896
- if ( jQuery && jQuery.bridget ) {
1897
- jQuery.bridget( 'flickity', Flickity );
1898
- }
1899
-
1900
- // set internal jQuery, for Webpack + jQuery v3, #478
1901
- Flickity.setJQuery = function( jq ) {
1902
- jQuery = jq;
1903
- };
1904
-
1905
- Flickity.Cell = Cell;
1906
-
1907
- return Flickity;
1908
-
1909
- }));
1910
- } (flickity));
1911
- return flickity.exports;
1912
- }
1913
-
1914
- var drag = {exports: {}};
1915
-
1916
- var unidragger = {exports: {}};
1917
-
1918
- var unipointer = {exports: {}};
1919
-
1920
- /*!
1921
- * Unipointer v2.4.0
1922
- * base class for doing one thing with pointer event
1923
- * MIT license
1924
- */
1925
-
1926
- var hasRequiredUnipointer;
1927
-
1928
- function requireUnipointer () {
1929
- if (hasRequiredUnipointer) return unipointer.exports;
1930
- hasRequiredUnipointer = 1;
1931
- (function (module) {
1932
- /*jshint browser: true, undef: true, unused: true, strict: true */
1933
-
1934
- ( function( window, factory ) {
1935
- // universal module definition
1936
- /* jshint strict: false */ /*global define, module, require */
1937
- if ( module.exports ) {
1938
- // CommonJS
1939
- module.exports = factory(
1940
- window,
1941
- requireEvEmitter()
1942
- );
1943
- } else {
1944
- // browser global
1945
- window.Unipointer = factory(
1946
- window,
1947
- window.EvEmitter
1948
- );
1949
- }
1950
-
1951
- }( window, function factory( window, EvEmitter ) {
1952
-
1953
- function noop() {}
1954
-
1955
- function Unipointer() {}
1956
-
1957
- // inherit EvEmitter
1958
- var proto = Unipointer.prototype = Object.create( EvEmitter.prototype );
1959
-
1960
- proto.bindStartEvent = function( elem ) {
1961
- this._bindStartEvent( elem, true );
1962
- };
1963
-
1964
- proto.unbindStartEvent = function( elem ) {
1965
- this._bindStartEvent( elem, false );
1966
- };
1967
-
1968
- /**
1969
- * Add or remove start event
1970
- * @param {Boolean} isAdd - remove if falsey
1971
- */
1972
- proto._bindStartEvent = function( elem, isAdd ) {
1973
- // munge isAdd, default to true
1974
- isAdd = isAdd === undefined ? true : isAdd;
1975
- var bindMethod = isAdd ? 'addEventListener' : 'removeEventListener';
1976
-
1977
- // default to mouse events
1978
- var startEvent = 'mousedown';
1979
- if ( 'ontouchstart' in window ) {
1980
- // HACK prefer Touch Events as you can preventDefault on touchstart to
1981
- // disable scroll in iOS & mobile Chrome metafizzy/flickity#1177
1982
- startEvent = 'touchstart';
1983
- } else if ( window.PointerEvent ) {
1984
- // Pointer Events
1985
- startEvent = 'pointerdown';
1986
- }
1987
- elem[ bindMethod ]( startEvent, this );
1988
- };
1989
-
1990
- // trigger handler methods for events
1991
- proto.handleEvent = function( event ) {
1992
- var method = 'on' + event.type;
1993
- if ( this[ method ] ) {
1994
- this[ method ]( event );
1995
- }
1996
- };
1997
-
1998
- // returns the touch that we're keeping track of
1999
- proto.getTouch = function( touches ) {
2000
- for ( var i=0; i < touches.length; i++ ) {
2001
- var touch = touches[i];
2002
- if ( touch.identifier == this.pointerIdentifier ) {
2003
- return touch;
2004
- }
2005
- }
2006
- };
2007
-
2008
- // ----- start event ----- //
2009
-
2010
- proto.onmousedown = function( event ) {
2011
- // dismiss clicks from right or middle buttons
2012
- var button = event.button;
2013
- if ( button && ( button !== 0 && button !== 1 ) ) {
2014
- return;
2015
- }
2016
- this._pointerDown( event, event );
2017
- };
2018
-
2019
- proto.ontouchstart = function( event ) {
2020
- this._pointerDown( event, event.changedTouches[0] );
2021
- };
2022
-
2023
- proto.onpointerdown = function( event ) {
2024
- this._pointerDown( event, event );
2025
- };
2026
-
2027
- /**
2028
- * pointer start
2029
- * @param {Event} event
2030
- * @param {Event or Touch} pointer
2031
- */
2032
- proto._pointerDown = function( event, pointer ) {
2033
- // dismiss right click and other pointers
2034
- // button = 0 is okay, 1-4 not
2035
- if ( event.button || this.isPointerDown ) {
2036
- return;
2037
- }
2038
-
2039
- this.isPointerDown = true;
2040
- // save pointer identifier to match up touch events
2041
- this.pointerIdentifier = pointer.pointerId !== undefined ?
2042
- // pointerId for pointer events, touch.indentifier for touch events
2043
- pointer.pointerId : pointer.identifier;
2044
-
2045
- this.pointerDown( event, pointer );
2046
- };
2047
-
2048
- proto.pointerDown = function( event, pointer ) {
2049
- this._bindPostStartEvents( event );
2050
- this.emitEvent( 'pointerDown', [ event, pointer ] );
2051
- };
2052
-
2053
- // hash of events to be bound after start event
2054
- var postStartEvents = {
2055
- mousedown: [ 'mousemove', 'mouseup' ],
2056
- touchstart: [ 'touchmove', 'touchend', 'touchcancel' ],
2057
- pointerdown: [ 'pointermove', 'pointerup', 'pointercancel' ],
2058
- };
2059
-
2060
- proto._bindPostStartEvents = function( event ) {
2061
- if ( !event ) {
2062
- return;
2063
- }
2064
- // get proper events to match start event
2065
- var events = postStartEvents[ event.type ];
2066
- // bind events to node
2067
- events.forEach( function( eventName ) {
2068
- window.addEventListener( eventName, this );
2069
- }, this );
2070
- // save these arguments
2071
- this._boundPointerEvents = events;
2072
- };
2073
-
2074
- proto._unbindPostStartEvents = function() {
2075
- // check for _boundEvents, in case dragEnd triggered twice (old IE8 bug)
2076
- if ( !this._boundPointerEvents ) {
2077
- return;
2078
- }
2079
- this._boundPointerEvents.forEach( function( eventName ) {
2080
- window.removeEventListener( eventName, this );
2081
- }, this );
2082
-
2083
- delete this._boundPointerEvents;
2084
- };
2085
-
2086
- // ----- move event ----- //
2087
-
2088
- proto.onmousemove = function( event ) {
2089
- this._pointerMove( event, event );
2090
- };
2091
-
2092
- proto.onpointermove = function( event ) {
2093
- if ( event.pointerId == this.pointerIdentifier ) {
2094
- this._pointerMove( event, event );
2095
- }
2096
- };
2097
-
2098
- proto.ontouchmove = function( event ) {
2099
- var touch = this.getTouch( event.changedTouches );
2100
- if ( touch ) {
2101
- this._pointerMove( event, touch );
2102
- }
2103
- };
2104
-
2105
- /**
2106
- * pointer move
2107
- * @param {Event} event
2108
- * @param {Event or Touch} pointer
2109
- * @private
2110
- */
2111
- proto._pointerMove = function( event, pointer ) {
2112
- this.pointerMove( event, pointer );
2113
- };
2114
-
2115
- // public
2116
- proto.pointerMove = function( event, pointer ) {
2117
- this.emitEvent( 'pointerMove', [ event, pointer ] );
2118
- };
2119
-
2120
- // ----- end event ----- //
2121
-
2122
-
2123
- proto.onmouseup = function( event ) {
2124
- this._pointerUp( event, event );
2125
- };
2126
-
2127
- proto.onpointerup = function( event ) {
2128
- if ( event.pointerId == this.pointerIdentifier ) {
2129
- this._pointerUp( event, event );
2130
- }
2131
- };
2132
-
2133
- proto.ontouchend = function( event ) {
2134
- var touch = this.getTouch( event.changedTouches );
2135
- if ( touch ) {
2136
- this._pointerUp( event, touch );
2137
- }
2138
- };
2139
-
2140
- /**
2141
- * pointer up
2142
- * @param {Event} event
2143
- * @param {Event or Touch} pointer
2144
- * @private
2145
- */
2146
- proto._pointerUp = function( event, pointer ) {
2147
- this._pointerDone();
2148
- this.pointerUp( event, pointer );
2149
- };
2150
-
2151
- // public
2152
- proto.pointerUp = function( event, pointer ) {
2153
- this.emitEvent( 'pointerUp', [ event, pointer ] );
2154
- };
2155
-
2156
- // ----- pointer done ----- //
2157
-
2158
- // triggered on pointer up & pointer cancel
2159
- proto._pointerDone = function() {
2160
- this._pointerReset();
2161
- this._unbindPostStartEvents();
2162
- this.pointerDone();
2163
- };
2164
-
2165
- proto._pointerReset = function() {
2166
- // reset properties
2167
- this.isPointerDown = false;
2168
- delete this.pointerIdentifier;
2169
- };
2170
-
2171
- proto.pointerDone = noop;
2172
-
2173
- // ----- pointer cancel ----- //
2174
-
2175
- proto.onpointercancel = function( event ) {
2176
- if ( event.pointerId == this.pointerIdentifier ) {
2177
- this._pointerCancel( event, event );
2178
- }
2179
- };
2180
-
2181
- proto.ontouchcancel = function( event ) {
2182
- var touch = this.getTouch( event.changedTouches );
2183
- if ( touch ) {
2184
- this._pointerCancel( event, touch );
2185
- }
2186
- };
2187
-
2188
- /**
2189
- * pointer cancel
2190
- * @param {Event} event
2191
- * @param {Event or Touch} pointer
2192
- * @private
2193
- */
2194
- proto._pointerCancel = function( event, pointer ) {
2195
- this._pointerDone();
2196
- this.pointerCancel( event, pointer );
2197
- };
2198
-
2199
- // public
2200
- proto.pointerCancel = function( event, pointer ) {
2201
- this.emitEvent( 'pointerCancel', [ event, pointer ] );
2202
- };
2203
-
2204
- // ----- ----- //
2205
-
2206
- // utility function for getting x/y coords from event
2207
- Unipointer.getPointerPoint = function( pointer ) {
2208
- return {
2209
- x: pointer.pageX,
2210
- y: pointer.pageY
2211
- };
2212
- };
2213
-
2214
- // ----- ----- //
2215
-
2216
- return Unipointer;
2217
-
2218
- }));
2219
- } (unipointer));
2220
- return unipointer.exports;
2221
- }
2222
-
2223
- /*!
2224
- * Unidragger v2.4.0
2225
- * Draggable base class
2226
- * MIT license
2227
- */
2228
-
2229
- var hasRequiredUnidragger;
2230
-
2231
- function requireUnidragger () {
2232
- if (hasRequiredUnidragger) return unidragger.exports;
2233
- hasRequiredUnidragger = 1;
2234
- (function (module) {
2235
- /*jshint browser: true, unused: true, undef: true, strict: true */
2236
-
2237
- ( function( window, factory ) {
2238
- // universal module definition
2239
- /*jshint strict: false */ /*globals define, module, require */
2240
-
2241
- if ( module.exports ) {
2242
- // CommonJS
2243
- module.exports = factory(
2244
- window,
2245
- requireUnipointer()
2246
- );
2247
- } else {
2248
- // browser global
2249
- window.Unidragger = factory(
2250
- window,
2251
- window.Unipointer
2252
- );
2253
- }
2254
-
2255
- }( window, function factory( window, Unipointer ) {
2256
-
2257
- // -------------------------- Unidragger -------------------------- //
2258
-
2259
- function Unidragger() {}
2260
-
2261
- // inherit Unipointer & EvEmitter
2262
- var proto = Unidragger.prototype = Object.create( Unipointer.prototype );
2263
-
2264
- // ----- bind start ----- //
2265
-
2266
- proto.bindHandles = function() {
2267
- this._bindHandles( true );
2268
- };
2269
-
2270
- proto.unbindHandles = function() {
2271
- this._bindHandles( false );
2272
- };
2273
-
2274
- /**
2275
- * Add or remove start event
2276
- * @param {Boolean} isAdd
2277
- */
2278
- proto._bindHandles = function( isAdd ) {
2279
- // munge isAdd, default to true
2280
- isAdd = isAdd === undefined ? true : isAdd;
2281
- // bind each handle
2282
- var bindMethod = isAdd ? 'addEventListener' : 'removeEventListener';
2283
- var touchAction = isAdd ? this._touchActionValue : '';
2284
- for ( var i=0; i < this.handles.length; i++ ) {
2285
- var handle = this.handles[i];
2286
- this._bindStartEvent( handle, isAdd );
2287
- handle[ bindMethod ]( 'click', this );
2288
- // touch-action: none to override browser touch gestures. metafizzy/flickity#540
2289
- if ( window.PointerEvent ) {
2290
- handle.style.touchAction = touchAction;
2291
- }
2292
- }
2293
- };
2294
-
2295
- // prototype so it can be overwriteable by Flickity
2296
- proto._touchActionValue = 'none';
2297
-
2298
- // ----- start event ----- //
2299
-
2300
- /**
2301
- * pointer start
2302
- * @param {Event} event
2303
- * @param {Event or Touch} pointer
2304
- */
2305
- proto.pointerDown = function( event, pointer ) {
2306
- var isOkay = this.okayPointerDown( event );
2307
- if ( !isOkay ) {
2308
- return;
2309
- }
2310
- // track start event position
2311
- // Safari 9 overrides pageX and pageY. These values needs to be copied. flickity#842
2312
- this.pointerDownPointer = {
2313
- pageX: pointer.pageX,
2314
- pageY: pointer.pageY,
2315
- };
2316
-
2317
- event.preventDefault();
2318
- this.pointerDownBlur();
2319
- // bind move and end events
2320
- this._bindPostStartEvents( event );
2321
- this.emitEvent( 'pointerDown', [ event, pointer ] );
2322
- };
2323
-
2324
- // nodes that have text fields
2325
- var cursorNodes = {
2326
- TEXTAREA: true,
2327
- INPUT: true,
2328
- SELECT: true,
2329
- OPTION: true,
2330
- };
2331
-
2332
- // input types that do not have text fields
2333
- var clickTypes = {
2334
- radio: true,
2335
- checkbox: true,
2336
- button: true,
2337
- submit: true,
2338
- image: true,
2339
- file: true,
2340
- };
2341
-
2342
- // dismiss inputs with text fields. flickity#403, flickity#404
2343
- proto.okayPointerDown = function( event ) {
2344
- var isCursorNode = cursorNodes[ event.target.nodeName ];
2345
- var isClickType = clickTypes[ event.target.type ];
2346
- var isOkay = !isCursorNode || isClickType;
2347
- if ( !isOkay ) {
2348
- this._pointerReset();
2349
- }
2350
- return isOkay;
2351
- };
2352
-
2353
- // kludge to blur previously focused input
2354
- proto.pointerDownBlur = function() {
2355
- var focused = document.activeElement;
2356
- // do not blur body for IE10, metafizzy/flickity#117
2357
- var canBlur = focused && focused.blur && focused != document.body;
2358
- if ( canBlur ) {
2359
- focused.blur();
2360
- }
2361
- };
2362
-
2363
- // ----- move event ----- //
2364
-
2365
- /**
2366
- * drag move
2367
- * @param {Event} event
2368
- * @param {Event or Touch} pointer
2369
- */
2370
- proto.pointerMove = function( event, pointer ) {
2371
- var moveVector = this._dragPointerMove( event, pointer );
2372
- this.emitEvent( 'pointerMove', [ event, pointer, moveVector ] );
2373
- this._dragMove( event, pointer, moveVector );
2374
- };
2375
-
2376
- // base pointer move logic
2377
- proto._dragPointerMove = function( event, pointer ) {
2378
- var moveVector = {
2379
- x: pointer.pageX - this.pointerDownPointer.pageX,
2380
- y: pointer.pageY - this.pointerDownPointer.pageY
2381
- };
2382
- // start drag if pointer has moved far enough to start drag
2383
- if ( !this.isDragging && this.hasDragStarted( moveVector ) ) {
2384
- this._dragStart( event, pointer );
2385
- }
2386
- return moveVector;
2387
- };
2388
-
2389
- // condition if pointer has moved far enough to start drag
2390
- proto.hasDragStarted = function( moveVector ) {
2391
- return Math.abs( moveVector.x ) > 3 || Math.abs( moveVector.y ) > 3;
2392
- };
2393
-
2394
- // ----- end event ----- //
2395
-
2396
- /**
2397
- * pointer up
2398
- * @param {Event} event
2399
- * @param {Event or Touch} pointer
2400
- */
2401
- proto.pointerUp = function( event, pointer ) {
2402
- this.emitEvent( 'pointerUp', [ event, pointer ] );
2403
- this._dragPointerUp( event, pointer );
2404
- };
2405
-
2406
- proto._dragPointerUp = function( event, pointer ) {
2407
- if ( this.isDragging ) {
2408
- this._dragEnd( event, pointer );
2409
- } else {
2410
- // pointer didn't move enough for drag to start
2411
- this._staticClick( event, pointer );
2412
- }
2413
- };
2414
-
2415
- // -------------------------- drag -------------------------- //
2416
-
2417
- // dragStart
2418
- proto._dragStart = function( event, pointer ) {
2419
- this.isDragging = true;
2420
- // prevent clicks
2421
- this.isPreventingClicks = true;
2422
- this.dragStart( event, pointer );
2423
- };
2424
-
2425
- proto.dragStart = function( event, pointer ) {
2426
- this.emitEvent( 'dragStart', [ event, pointer ] );
2427
- };
2428
-
2429
- // dragMove
2430
- proto._dragMove = function( event, pointer, moveVector ) {
2431
- // do not drag if not dragging yet
2432
- if ( !this.isDragging ) {
2433
- return;
2434
- }
2435
-
2436
- this.dragMove( event, pointer, moveVector );
2437
- };
2438
-
2439
- proto.dragMove = function( event, pointer, moveVector ) {
2440
- event.preventDefault();
2441
- this.emitEvent( 'dragMove', [ event, pointer, moveVector ] );
2442
- };
2443
-
2444
- // dragEnd
2445
- proto._dragEnd = function( event, pointer ) {
2446
- // set flags
2447
- this.isDragging = false;
2448
- // re-enable clicking async
2449
- setTimeout( function() {
2450
- delete this.isPreventingClicks;
2451
- }.bind( this ) );
2452
-
2453
- this.dragEnd( event, pointer );
2454
- };
2455
-
2456
- proto.dragEnd = function( event, pointer ) {
2457
- this.emitEvent( 'dragEnd', [ event, pointer ] );
2458
- };
2459
-
2460
- // ----- onclick ----- //
2461
-
2462
- // handle all clicks and prevent clicks when dragging
2463
- proto.onclick = function( event ) {
2464
- if ( this.isPreventingClicks ) {
2465
- event.preventDefault();
2466
- }
2467
- };
2468
-
2469
- // ----- staticClick ----- //
2470
-
2471
- // triggered after pointer down & up with no/tiny movement
2472
- proto._staticClick = function( event, pointer ) {
2473
- // ignore emulated mouse up clicks
2474
- if ( this.isIgnoringMouseUp && event.type == 'mouseup' ) {
2475
- return;
2476
- }
2477
-
2478
- this.staticClick( event, pointer );
2479
-
2480
- // set flag for emulated clicks 300ms after touchend
2481
- if ( event.type != 'mouseup' ) {
2482
- this.isIgnoringMouseUp = true;
2483
- // reset flag after 300ms
2484
- setTimeout( function() {
2485
- delete this.isIgnoringMouseUp;
2486
- }.bind( this ), 400 );
2487
- }
2488
- };
2489
-
2490
- proto.staticClick = function( event, pointer ) {
2491
- this.emitEvent( 'staticClick', [ event, pointer ] );
2492
- };
2493
-
2494
- // ----- utils ----- //
2495
-
2496
- Unidragger.getPointerPoint = Unipointer.getPointerPoint;
2497
-
2498
- // ----- ----- //
2499
-
2500
- return Unidragger;
2501
-
2502
- }));
2503
- } (unidragger));
2504
- return unidragger.exports;
2505
- }
2506
-
2507
- var hasRequiredDrag;
2508
-
2509
- function requireDrag () {
2510
- if (hasRequiredDrag) return drag.exports;
2511
- hasRequiredDrag = 1;
2512
- (function (module) {
2513
- // drag
2514
- ( function( window, factory ) {
2515
- // universal module definition
2516
- /* jshint strict: false */
2517
- if ( module.exports ) {
2518
- // CommonJS
2519
- module.exports = factory(
2520
- window,
2521
- requireFlickity(),
2522
- requireUnidragger(),
2523
- requireUtils()
2524
- );
2525
- } else {
2526
- // browser global
2527
- window.Flickity = factory(
2528
- window,
2529
- window.Flickity,
2530
- window.Unidragger,
2531
- window.fizzyUIUtils
2532
- );
2533
- }
2534
-
2535
- }( window, function factory( window, Flickity, Unidragger, utils ) {
2536
-
2537
- // ----- defaults ----- //
2538
-
2539
- utils.extend( Flickity.defaults, {
2540
- draggable: true,
2541
- dragThreshold: 3,
2542
- });
2543
-
2544
- // ----- create ----- //
2545
-
2546
- Flickity.createMethods.push('_createDrag');
2547
-
2548
- // -------------------------- drag prototype -------------------------- //
2549
-
2550
- var proto = Flickity.prototype;
2551
- utils.extend( proto, Unidragger.prototype );
2552
- proto._touchActionValue = 'pan-y';
2553
-
2554
- // -------------------------- -------------------------- //
2555
-
2556
- var isTouch = 'createTouch' in document;
2557
- var isTouchmoveScrollCanceled = false;
2558
-
2559
- proto._createDrag = function() {
2560
- this.on( 'activate', this.bindDrag );
2561
- this.on( 'uiChange', this._uiChangeDrag );
2562
- this.on( 'childUIPointerDown', this._childUIPointerDownDrag );
2563
- this.on( 'deactivate', this.unbindDrag );
2564
- // HACK - add seemingly innocuous handler to fix iOS 10 scroll behavior
2565
- // #457, RubaXa/Sortable#973
2566
- if ( isTouch && !isTouchmoveScrollCanceled ) {
2567
- window.addEventListener( 'touchmove', function() {});
2568
- isTouchmoveScrollCanceled = true;
2569
- }
2570
- };
2571
-
2572
- proto.bindDrag = function() {
2573
- if ( !this.options.draggable || this.isDragBound ) {
2574
- return;
2575
- }
2576
- this.element.classList.add('is-draggable');
2577
- this.handles = [ this.viewport ];
2578
- this.bindHandles();
2579
- this.isDragBound = true;
2580
- };
2581
-
2582
- proto.unbindDrag = function() {
2583
- if ( !this.isDragBound ) {
2584
- return;
2585
- }
2586
- this.element.classList.remove('is-draggable');
2587
- this.unbindHandles();
2588
- delete this.isDragBound;
2589
- };
2590
-
2591
- proto._uiChangeDrag = function() {
2592
- delete this.isFreeScrolling;
2593
- };
2594
-
2595
- proto._childUIPointerDownDrag = function( event ) {
2596
- event.preventDefault();
2597
- this.pointerDownFocus( event );
2598
- };
2599
-
2600
- // -------------------------- pointer events -------------------------- //
2601
-
2602
- // nodes that have text fields
2603
- var cursorNodes = {
2604
- TEXTAREA: true,
2605
- INPUT: true,
2606
- OPTION: true,
2607
- };
2608
-
2609
- // input types that do not have text fields
2610
- var clickTypes = {
2611
- radio: true,
2612
- checkbox: true,
2613
- button: true,
2614
- submit: true,
2615
- image: true,
2616
- file: true,
2617
- };
2618
-
2619
- proto.pointerDown = function( event, pointer ) {
2620
- // dismiss inputs with text fields. #403, #404
2621
- var isCursorInput = cursorNodes[ event.target.nodeName ] &&
2622
- !clickTypes[ event.target.type ];
2623
- if ( isCursorInput ) {
2624
- // reset pointerDown logic
2625
- this.isPointerDown = false;
2626
- delete this.pointerIdentifier;
2627
- return;
2628
- }
2629
-
2630
- this._dragPointerDown( event, pointer );
2631
-
2632
- // kludge to blur focused inputs in dragger
2633
- var focused = document.activeElement;
2634
- if ( focused && focused.blur && focused != this.element &&
2635
- // do not blur body for IE9 & 10, #117
2636
- focused != document.body ) {
2637
- focused.blur();
2638
- }
2639
- this.pointerDownFocus( event );
2640
- // stop if it was moving
2641
- this.dragX = this.x;
2642
- this.viewport.classList.add('is-pointer-down');
2643
- // bind move and end events
2644
- this._bindPostStartEvents( event );
2645
- // track scrolling
2646
- this.pointerDownScroll = getScrollPosition();
2647
- window.addEventListener( 'scroll', this );
2648
-
2649
- this.dispatchEvent( 'pointerDown', event, [ pointer ] );
2650
- };
2651
-
2652
- proto.pointerDownFocus = function( event ) {
2653
- // focus element, if not touch, and its not an input or select
2654
- var canPointerDown = getCanPointerDown( event );
2655
- if ( !this.options.accessibility || canPointerDown ) {
2656
- return;
2657
- }
2658
- var prevScrollY = window.pageYOffset;
2659
- this.element.focus();
2660
- // hack to fix scroll jump after focus, #76
2661
- if ( window.pageYOffset != prevScrollY ) {
2662
- window.scrollTo( window.pageXOffset, prevScrollY );
2663
- }
2664
- };
2665
-
2666
- var focusNodes = {
2667
- INPUT: true,
2668
- SELECT: true,
2669
- };
2670
-
2671
- function getCanPointerDown( event ) {
2672
- var isTouchStart = event.type == 'touchstart';
2673
- var isTouchPointer = event.pointerType == 'touch';
2674
- var isFocusNode = focusNodes[ event.target.nodeName ];
2675
- return isTouchStart || isTouchPointer || isFocusNode;
2676
- }
2677
-
2678
- proto.canPreventDefaultOnPointerDown = function( event ) {
2679
- // prevent default, unless touchstart or input
2680
- var canPointerDown = getCanPointerDown( event );
2681
- return !canPointerDown;
2682
- };
2683
-
2684
- // ----- move ----- //
2685
-
2686
- proto.hasDragStarted = function( moveVector ) {
2687
- return Math.abs( moveVector.x ) > this.options.dragThreshold;
2688
- };
2689
-
2690
- // ----- up ----- //
2691
-
2692
- proto.pointerUp = function( event, pointer ) {
2693
- delete this.isTouchScrolling;
2694
- this.viewport.classList.remove('is-pointer-down');
2695
- this.dispatchEvent( 'pointerUp', event, [ pointer ] );
2696
- this._dragPointerUp( event, pointer );
2697
- };
2698
-
2699
- proto.pointerDone = function() {
2700
- window.removeEventListener( 'scroll', this );
2701
- delete this.pointerDownScroll;
2702
- };
2703
-
2704
- // -------------------------- dragging -------------------------- //
2705
-
2706
- proto.dragStart = function( event, pointer ) {
2707
- this.dragStartPosition = this.x;
2708
- this.startAnimation();
2709
- window.removeEventListener( 'scroll', this );
2710
- this.dispatchEvent( 'dragStart', event, [ pointer ] );
2711
- };
2712
-
2713
- proto.pointerMove = function( event, pointer ) {
2714
- var moveVector = this._dragPointerMove( event, pointer );
2715
- this.dispatchEvent( 'pointerMove', event, [ pointer, moveVector ] );
2716
- this._dragMove( event, pointer, moveVector );
2717
- };
2718
-
2719
- proto.dragMove = function( event, pointer, moveVector ) {
2720
- event.preventDefault();
2721
-
2722
- this.previousDragX = this.dragX;
2723
- // reverse if right-to-left
2724
- var direction = this.options.rightToLeft ? -1 : 1;
2725
- var dragX = this.dragStartPosition + moveVector.x * direction;
2726
-
2727
- if ( !this.options.wrapAround && this.slides.length ) {
2728
- // slow drag
2729
- var originBound = Math.max( -this.slides[0].target, this.dragStartPosition );
2730
- dragX = dragX > originBound ? ( dragX + originBound ) * 0.5 : dragX;
2731
- var endBound = Math.min( -this.getLastSlide().target, this.dragStartPosition );
2732
- dragX = dragX < endBound ? ( dragX + endBound ) * 0.5 : dragX;
2733
- }
2734
-
2735
- this.dragX = dragX;
2736
-
2737
- this.dragMoveTime = new Date();
2738
- this.dispatchEvent( 'dragMove', event, [ pointer, moveVector ] );
2739
- };
2740
-
2741
- proto.dragEnd = function( event, pointer ) {
2742
- if ( this.options.freeScroll ) {
2743
- this.isFreeScrolling = true;
2744
- }
2745
- // set selectedIndex based on where flick will end up
2746
- var index = this.dragEndRestingSelect();
2747
-
2748
- if ( this.options.freeScroll && !this.options.wrapAround ) {
2749
- // if free-scroll & not wrap around
2750
- // do not free-scroll if going outside of bounding slides
2751
- // so bounding slides can attract slider, and keep it in bounds
2752
- var restingX = this.getRestingPosition();
2753
- this.isFreeScrolling = -restingX > this.slides[0].target &&
2754
- -restingX < this.getLastSlide().target;
2755
- } else if ( !this.options.freeScroll && index == this.selectedIndex ) {
2756
- // boost selection if selected index has not changed
2757
- index += this.dragEndBoostSelect();
2758
- }
2759
- delete this.previousDragX;
2760
- // apply selection
2761
- // TODO refactor this, selecting here feels weird
2762
- // HACK, set flag so dragging stays in correct direction
2763
- this.isDragSelect = this.options.wrapAround;
2764
- this.select( index );
2765
- delete this.isDragSelect;
2766
- this.dispatchEvent( 'dragEnd', event, [ pointer ] );
2767
- };
2768
-
2769
- proto.dragEndRestingSelect = function() {
2770
- var restingX = this.getRestingPosition();
2771
- // how far away from selected slide
2772
- var distance = Math.abs( this.getSlideDistance( -restingX, this.selectedIndex ) );
2773
- // get closet resting going up and going down
2774
- var positiveResting = this._getClosestResting( restingX, distance, 1 );
2775
- var negativeResting = this._getClosestResting( restingX, distance, -1 );
2776
- // use closer resting for wrap-around
2777
- var index = positiveResting.distance < negativeResting.distance ?
2778
- positiveResting.index : negativeResting.index;
2779
- return index;
2780
- };
2781
-
2782
- /**
2783
- * given resting X and distance to selected cell
2784
- * get the distance and index of the closest cell
2785
- * @param {Number} restingX - estimated post-flick resting position
2786
- * @param {Number} distance - distance to selected cell
2787
- * @param {Integer} increment - +1 or -1, going up or down
2788
- * @returns {Object} - { distance: {Number}, index: {Integer} }
2789
- */
2790
- proto._getClosestResting = function( restingX, distance, increment ) {
2791
- var index = this.selectedIndex;
2792
- var minDistance = Infinity;
2793
- var condition = this.options.contain && !this.options.wrapAround ?
2794
- // if contain, keep going if distance is equal to minDistance
2795
- function( d, md ) { return d <= md; } : function( d, md ) { return d < md; };
2796
- while ( condition( distance, minDistance ) ) {
2797
- // measure distance to next cell
2798
- index += increment;
2799
- minDistance = distance;
2800
- distance = this.getSlideDistance( -restingX, index );
2801
- if ( distance === null ) {
2802
- break;
2803
- }
2804
- distance = Math.abs( distance );
2805
- }
2806
- return {
2807
- distance: minDistance,
2808
- // selected was previous index
2809
- index: index - increment
2810
- };
2811
- };
2812
-
2813
- /**
2814
- * measure distance between x and a slide target
2815
- * @param {Number} x
2816
- * @param {Integer} index - slide index
2817
- */
2818
- proto.getSlideDistance = function( x, index ) {
2819
- var len = this.slides.length;
2820
- // wrap around if at least 2 slides
2821
- var isWrapAround = this.options.wrapAround && len > 1;
2822
- var slideIndex = isWrapAround ? utils.modulo( index, len ) : index;
2823
- var slide = this.slides[ slideIndex ];
2824
- if ( !slide ) {
2825
- return null;
2826
- }
2827
- // add distance for wrap-around slides
2828
- var wrap = isWrapAround ? this.slideableWidth * Math.floor( index / len ) : 0;
2829
- return x - ( slide.target + wrap );
2830
- };
2831
-
2832
- proto.dragEndBoostSelect = function() {
2833
- // do not boost if no previousDragX or dragMoveTime
2834
- if ( this.previousDragX === undefined || !this.dragMoveTime ||
2835
- // or if drag was held for 100 ms
2836
- new Date() - this.dragMoveTime > 100 ) {
2837
- return 0;
2838
- }
2839
-
2840
- var distance = this.getSlideDistance( -this.dragX, this.selectedIndex );
2841
- var delta = this.previousDragX - this.dragX;
2842
- if ( distance > 0 && delta > 0 ) {
2843
- // boost to next if moving towards the right, and positive velocity
2844
- return 1;
2845
- } else if ( distance < 0 && delta < 0 ) {
2846
- // boost to previous if moving towards the left, and negative velocity
2847
- return -1;
2848
- }
2849
- return 0;
2850
- };
2851
-
2852
- // ----- staticClick ----- //
2853
-
2854
- proto.staticClick = function( event, pointer ) {
2855
- // get clickedCell, if cell was clicked
2856
- var clickedCell = this.getParentCell( event.target );
2857
- var cellElem = clickedCell && clickedCell.element;
2858
- var cellIndex = clickedCell && this.cells.indexOf( clickedCell );
2859
- this.dispatchEvent( 'staticClick', event, [ pointer, cellElem, cellIndex ] );
2860
- };
2861
-
2862
- // ----- scroll ----- //
2863
-
2864
- proto.onscroll = function() {
2865
- var scroll = getScrollPosition();
2866
- var scrollMoveX = this.pointerDownScroll.x - scroll.x;
2867
- var scrollMoveY = this.pointerDownScroll.y - scroll.y;
2868
- // cancel click/tap if scroll is too much
2869
- if ( Math.abs( scrollMoveX ) > 3 || Math.abs( scrollMoveY ) > 3 ) {
2870
- this._pointerDone();
2871
- }
2872
- };
2873
-
2874
- // ----- utils ----- //
2875
-
2876
- function getScrollPosition() {
2877
- return {
2878
- x: window.pageXOffset,
2879
- y: window.pageYOffset
2880
- };
2881
- }
2882
-
2883
- // ----- ----- //
2884
-
2885
- return Flickity;
2886
-
2887
- }));
2888
- } (drag));
2889
- return drag.exports;
2890
- }
2891
-
2892
- var prevNextButton = {exports: {}};
2893
-
2894
- var tapListener = {exports: {}};
2895
-
2896
- /*!
2897
- * Tap listener v2.0.0
2898
- * listens to taps
2899
- * MIT license
2900
- */
2901
-
2902
- var hasRequiredTapListener;
2903
-
2904
- function requireTapListener () {
2905
- if (hasRequiredTapListener) return tapListener.exports;
2906
- hasRequiredTapListener = 1;
2907
- (function (module) {
2908
- /*jshint browser: true, unused: true, undef: true, strict: true */
2909
-
2910
- ( function( window, factory ) {
2911
- // universal module definition
2912
- /*jshint strict: false*/ /*globals define, module, require */
2913
-
2914
- if ( module.exports ) {
2915
- // CommonJS
2916
- module.exports = factory(
2917
- window,
2918
- requireUnipointer()
2919
- );
2920
- } else {
2921
- // browser global
2922
- window.TapListener = factory(
2923
- window,
2924
- window.Unipointer
2925
- );
2926
- }
2927
-
2928
- }( window, function factory( window, Unipointer ) {
2929
-
2930
- // -------------------------- TapListener -------------------------- //
2931
-
2932
- function TapListener( elem ) {
2933
- this.bindTap( elem );
2934
- }
2935
-
2936
- // inherit Unipointer & EventEmitter
2937
- var proto = TapListener.prototype = Object.create( Unipointer.prototype );
2938
-
2939
- /**
2940
- * bind tap event to element
2941
- * @param {Element} elem
2942
- */
2943
- proto.bindTap = function( elem ) {
2944
- if ( !elem ) {
2945
- return;
2946
- }
2947
- this.unbindTap();
2948
- this.tapElement = elem;
2949
- this._bindStartEvent( elem, true );
2950
- };
2951
-
2952
- proto.unbindTap = function() {
2953
- if ( !this.tapElement ) {
2954
- return;
2955
- }
2956
- this._bindStartEvent( this.tapElement, true );
2957
- delete this.tapElement;
2958
- };
2959
-
2960
- /**
2961
- * pointer up
2962
- * @param {Event} event
2963
- * @param {Event or Touch} pointer
2964
- */
2965
- proto.pointerUp = function( event, pointer ) {
2966
- // ignore emulated mouse up clicks
2967
- if ( this.isIgnoringMouseUp && event.type == 'mouseup' ) {
2968
- return;
2969
- }
2970
-
2971
- var pointerPoint = Unipointer.getPointerPoint( pointer );
2972
- var boundingRect = this.tapElement.getBoundingClientRect();
2973
- var scrollX = window.pageXOffset;
2974
- var scrollY = window.pageYOffset;
2975
- // calculate if pointer is inside tapElement
2976
- var isInside = pointerPoint.x >= boundingRect.left + scrollX &&
2977
- pointerPoint.x <= boundingRect.right + scrollX &&
2978
- pointerPoint.y >= boundingRect.top + scrollY &&
2979
- pointerPoint.y <= boundingRect.bottom + scrollY;
2980
- // trigger callback if pointer is inside element
2981
- if ( isInside ) {
2982
- this.emitEvent( 'tap', [ event, pointer ] );
2983
- }
2984
-
2985
- // set flag for emulated clicks 300ms after touchend
2986
- if ( event.type != 'mouseup' ) {
2987
- this.isIgnoringMouseUp = true;
2988
- // reset flag after 300ms
2989
- var _this = this;
2990
- setTimeout( function() {
2991
- delete _this.isIgnoringMouseUp;
2992
- }, 400 );
2993
- }
2994
- };
2995
-
2996
- proto.destroy = function() {
2997
- this.pointerDone();
2998
- this.unbindTap();
2999
- };
3000
-
3001
- // ----- ----- //
3002
-
3003
- return TapListener;
3004
-
3005
- }));
3006
- } (tapListener));
3007
- return tapListener.exports;
3008
- }
3009
-
3010
- var hasRequiredPrevNextButton;
3011
-
3012
- function requirePrevNextButton () {
3013
- if (hasRequiredPrevNextButton) return prevNextButton.exports;
3014
- hasRequiredPrevNextButton = 1;
3015
- (function (module) {
3016
- // prev/next buttons
3017
- ( function( window, factory ) {
3018
- // universal module definition
3019
- /* jshint strict: false */
3020
- if ( module.exports ) {
3021
- // CommonJS
3022
- module.exports = factory(
3023
- window,
3024
- requireFlickity(),
3025
- requireTapListener(),
3026
- requireUtils()
3027
- );
3028
- } else {
3029
- // browser global
3030
- factory(
3031
- window,
3032
- window.Flickity,
3033
- window.TapListener,
3034
- window.fizzyUIUtils
3035
- );
3036
- }
3037
-
3038
- }( window, function factory( window, Flickity, TapListener, utils ) {
3039
-
3040
- var svgURI = 'http://www.w3.org/2000/svg';
3041
-
3042
- // -------------------------- PrevNextButton -------------------------- //
3043
-
3044
- function PrevNextButton( direction, parent ) {
3045
- this.direction = direction;
3046
- this.parent = parent;
3047
- this._create();
3048
- }
3049
-
3050
- PrevNextButton.prototype = new TapListener();
3051
-
3052
- PrevNextButton.prototype._create = function() {
3053
- // properties
3054
- this.isEnabled = true;
3055
- this.isPrevious = this.direction == -1;
3056
- var leftDirection = this.parent.options.rightToLeft ? 1 : -1;
3057
- this.isLeft = this.direction == leftDirection;
3058
-
3059
- var element = this.element = document.createElement('button');
3060
- element.className = 'flickity-prev-next-button';
3061
- element.className += this.isPrevious ? ' previous' : ' next';
3062
- // prevent button from submitting form http://stackoverflow.com/a/10836076/182183
3063
- element.setAttribute( 'type', 'button' );
3064
- // init as disabled
3065
- this.disable();
3066
-
3067
- element.setAttribute( 'aria-label', this.isPrevious ? 'previous' : 'next' );
3068
-
3069
- // create arrow
3070
- var svg = this.createSVG();
3071
- element.appendChild( svg );
3072
- // events
3073
- this.on( 'tap', this.onTap );
3074
- this.parent.on( 'select', this.update.bind( this ) );
3075
- this.on( 'pointerDown', this.parent.childUIPointerDown.bind( this.parent ) );
3076
- };
3077
-
3078
- PrevNextButton.prototype.activate = function() {
3079
- this.bindTap( this.element );
3080
- // click events from keyboard
3081
- this.element.addEventListener( 'click', this );
3082
- // add to DOM
3083
- this.parent.element.appendChild( this.element );
3084
- };
3085
-
3086
- PrevNextButton.prototype.deactivate = function() {
3087
- // remove from DOM
3088
- this.parent.element.removeChild( this.element );
3089
- // do regular TapListener destroy
3090
- TapListener.prototype.destroy.call( this );
3091
- // click events from keyboard
3092
- this.element.removeEventListener( 'click', this );
3093
- };
3094
-
3095
- PrevNextButton.prototype.createSVG = function() {
3096
- var svg = document.createElementNS( svgURI, 'svg');
3097
- svg.setAttribute( 'viewBox', '0 0 100 100' );
3098
- var path = document.createElementNS( svgURI, 'path');
3099
- var pathMovements = getArrowMovements( this.parent.options.arrowShape );
3100
- path.setAttribute( 'd', pathMovements );
3101
- path.setAttribute( 'class', 'arrow' );
3102
- // rotate arrow
3103
- if ( !this.isLeft ) {
3104
- path.setAttribute( 'transform', 'translate(100, 100) rotate(180) ' );
3105
- }
3106
- svg.appendChild( path );
3107
- return svg;
3108
- };
3109
-
3110
- // get SVG path movmement
3111
- function getArrowMovements( shape ) {
3112
- // use shape as movement if string
3113
- if ( typeof shape == 'string' ) {
3114
- return shape;
3115
- }
3116
- // create movement string
3117
- return 'M ' + shape.x0 + ',50' +
3118
- ' L ' + shape.x1 + ',' + ( shape.y1 + 50 ) +
3119
- ' L ' + shape.x2 + ',' + ( shape.y2 + 50 ) +
3120
- ' L ' + shape.x3 + ',50 ' +
3121
- ' L ' + shape.x2 + ',' + ( 50 - shape.y2 ) +
3122
- ' L ' + shape.x1 + ',' + ( 50 - shape.y1 ) +
3123
- ' Z';
3124
- }
3125
-
3126
- PrevNextButton.prototype.onTap = function() {
3127
- if ( !this.isEnabled ) {
3128
- return;
3129
- }
3130
- this.parent.uiChange();
3131
- var method = this.isPrevious ? 'previous' : 'next';
3132
- this.parent[ method ]();
3133
- };
3134
-
3135
- PrevNextButton.prototype.handleEvent = utils.handleEvent;
3136
-
3137
- PrevNextButton.prototype.onclick = function() {
3138
- // only allow clicks from keyboard
3139
- var focused = document.activeElement;
3140
- if ( focused && focused == this.element ) {
3141
- this.onTap();
3142
- }
3143
- };
3144
-
3145
- // ----- ----- //
3146
-
3147
- PrevNextButton.prototype.enable = function() {
3148
- if ( this.isEnabled ) {
3149
- return;
3150
- }
3151
- this.element.disabled = false;
3152
- this.isEnabled = true;
3153
- };
3154
-
3155
- PrevNextButton.prototype.disable = function() {
3156
- if ( !this.isEnabled ) {
3157
- return;
3158
- }
3159
- this.element.disabled = true;
3160
- this.isEnabled = false;
3161
- };
3162
-
3163
- PrevNextButton.prototype.update = function() {
3164
- // index of first or last slide, if previous or next
3165
- var slides = this.parent.slides;
3166
- // enable is wrapAround and at least 2 slides
3167
- if ( this.parent.options.wrapAround && slides.length > 1 ) {
3168
- this.enable();
3169
- return;
3170
- }
3171
- var lastIndex = slides.length ? slides.length - 1 : 0;
3172
- var boundIndex = this.isPrevious ? 0 : lastIndex;
3173
- var method = this.parent.selectedIndex == boundIndex ? 'disable' : 'enable';
3174
- this[ method ]();
3175
- };
3176
-
3177
- PrevNextButton.prototype.destroy = function() {
3178
- this.deactivate();
3179
- };
3180
-
3181
- // -------------------------- Flickity prototype -------------------------- //
3182
-
3183
- utils.extend( Flickity.defaults, {
3184
- prevNextButtons: true,
3185
- arrowShape: {
3186
- x0: 10,
3187
- x1: 60, y1: 50,
3188
- x2: 70, y2: 40,
3189
- x3: 30
3190
- }
3191
- });
3192
-
3193
- Flickity.createMethods.push('_createPrevNextButtons');
3194
- var proto = Flickity.prototype;
3195
-
3196
- proto._createPrevNextButtons = function() {
3197
- if ( !this.options.prevNextButtons ) {
3198
- return;
3199
- }
3200
-
3201
- this.prevButton = new PrevNextButton( -1, this );
3202
- this.nextButton = new PrevNextButton( 1, this );
3203
-
3204
- this.on( 'activate', this.activatePrevNextButtons );
3205
- };
3206
-
3207
- proto.activatePrevNextButtons = function() {
3208
- this.prevButton.activate();
3209
- this.nextButton.activate();
3210
- this.on( 'deactivate', this.deactivatePrevNextButtons );
3211
- };
3212
-
3213
- proto.deactivatePrevNextButtons = function() {
3214
- this.prevButton.deactivate();
3215
- this.nextButton.deactivate();
3216
- this.off( 'deactivate', this.deactivatePrevNextButtons );
3217
- };
3218
-
3219
- // -------------------------- -------------------------- //
3220
-
3221
- Flickity.PrevNextButton = PrevNextButton;
3222
-
3223
- return Flickity;
3224
-
3225
- }));
3226
- } (prevNextButton));
3227
- return prevNextButton.exports;
3228
- }
3229
-
3230
- var pageDots = {exports: {}};
3231
-
3232
- var hasRequiredPageDots;
3233
-
3234
- function requirePageDots () {
3235
- if (hasRequiredPageDots) return pageDots.exports;
3236
- hasRequiredPageDots = 1;
3237
- (function (module) {
3238
- // page dots
3239
- ( function( window, factory ) {
3240
- // universal module definition
3241
- /* jshint strict: false */
3242
- if ( module.exports ) {
3243
- // CommonJS
3244
- module.exports = factory(
3245
- window,
3246
- requireFlickity(),
3247
- requireTapListener(),
3248
- requireUtils()
3249
- );
3250
- } else {
3251
- // browser global
3252
- factory(
3253
- window,
3254
- window.Flickity,
3255
- window.TapListener,
3256
- window.fizzyUIUtils
3257
- );
3258
- }
3259
-
3260
- }( window, function factory( window, Flickity, TapListener, utils ) {
3261
-
3262
- function PageDots( parent ) {
3263
- this.parent = parent;
3264
- this._create();
3265
- }
3266
-
3267
- PageDots.prototype = new TapListener();
3268
-
3269
- PageDots.prototype._create = function() {
3270
- // create holder element
3271
- this.holder = document.createElement('ol');
3272
- this.holder.className = 'flickity-page-dots';
3273
- // create dots, array of elements
3274
- this.dots = [];
3275
- // events
3276
- this.on( 'tap', this.onTap );
3277
- this.on( 'pointerDown', this.parent.childUIPointerDown.bind( this.parent ) );
3278
- };
3279
-
3280
- PageDots.prototype.activate = function() {
3281
- this.setDots();
3282
- this.bindTap( this.holder );
3283
- // add to DOM
3284
- this.parent.element.appendChild( this.holder );
3285
- };
3286
-
3287
- PageDots.prototype.deactivate = function() {
3288
- // remove from DOM
3289
- this.parent.element.removeChild( this.holder );
3290
- TapListener.prototype.destroy.call( this );
3291
- };
3292
-
3293
- PageDots.prototype.setDots = function() {
3294
- // get difference between number of slides and number of dots
3295
- var delta = this.parent.slides.length - this.dots.length;
3296
- if ( delta > 0 ) {
3297
- this.addDots( delta );
3298
- } else if ( delta < 0 ) {
3299
- this.removeDots( -delta );
3300
- }
3301
- };
3302
-
3303
- PageDots.prototype.addDots = function( count ) {
3304
- var fragment = document.createDocumentFragment();
3305
- var newDots = [];
3306
- while ( count ) {
3307
- var dot = document.createElement('li');
3308
- dot.className = 'dot';
3309
- fragment.appendChild( dot );
3310
- newDots.push( dot );
3311
- count--;
3312
- }
3313
- this.holder.appendChild( fragment );
3314
- this.dots = this.dots.concat( newDots );
3315
- };
3316
-
3317
- PageDots.prototype.removeDots = function( count ) {
3318
- // remove from this.dots collection
3319
- var removeDots = this.dots.splice( this.dots.length - count, count );
3320
- // remove from DOM
3321
- removeDots.forEach( function( dot ) {
3322
- this.holder.removeChild( dot );
3323
- }, this );
3324
- };
3325
-
3326
- PageDots.prototype.updateSelected = function() {
3327
- // remove selected class on previous
3328
- if ( this.selectedDot ) {
3329
- this.selectedDot.className = 'dot';
3330
- }
3331
- // don't proceed if no dots
3332
- if ( !this.dots.length ) {
3333
- return;
3334
- }
3335
- this.selectedDot = this.dots[ this.parent.selectedIndex ];
3336
- this.selectedDot.className = 'dot is-selected';
3337
- };
3338
-
3339
- PageDots.prototype.onTap = function( event ) {
3340
- var target = event.target;
3341
- // only care about dot clicks
3342
- if ( target.nodeName != 'LI' ) {
3343
- return;
3344
- }
3345
-
3346
- this.parent.uiChange();
3347
- var index = this.dots.indexOf( target );
3348
- this.parent.select( index );
3349
- };
3350
-
3351
- PageDots.prototype.destroy = function() {
3352
- this.deactivate();
3353
- };
3354
-
3355
- Flickity.PageDots = PageDots;
3356
-
3357
- // -------------------------- Flickity -------------------------- //
3358
-
3359
- utils.extend( Flickity.defaults, {
3360
- pageDots: true
3361
- });
3362
-
3363
- Flickity.createMethods.push('_createPageDots');
3364
-
3365
- var proto = Flickity.prototype;
3366
-
3367
- proto._createPageDots = function() {
3368
- if ( !this.options.pageDots ) {
3369
- return;
3370
- }
3371
- this.pageDots = new PageDots( this );
3372
- // events
3373
- this.on( 'activate', this.activatePageDots );
3374
- this.on( 'select', this.updateSelectedPageDots );
3375
- this.on( 'cellChange', this.updatePageDots );
3376
- this.on( 'resize', this.updatePageDots );
3377
- this.on( 'deactivate', this.deactivatePageDots );
3378
- };
3379
-
3380
- proto.activatePageDots = function() {
3381
- this.pageDots.activate();
3382
- };
3383
-
3384
- proto.updateSelectedPageDots = function() {
3385
- this.pageDots.updateSelected();
3386
- };
3387
-
3388
- proto.updatePageDots = function() {
3389
- this.pageDots.setDots();
3390
- };
3391
-
3392
- proto.deactivatePageDots = function() {
3393
- this.pageDots.deactivate();
3394
- };
3395
-
3396
- // ----- ----- //
3397
-
3398
- Flickity.PageDots = PageDots;
3399
-
3400
- return Flickity;
3401
-
3402
- }));
3403
- } (pageDots));
3404
- return pageDots.exports;
3405
- }
3406
-
3407
- var player = {exports: {}};
3408
-
3409
- var hasRequiredPlayer;
3410
-
3411
- function requirePlayer () {
3412
- if (hasRequiredPlayer) return player.exports;
3413
- hasRequiredPlayer = 1;
3414
- (function (module) {
3415
- // player & autoPlay
3416
- ( function( window, factory ) {
3417
- // universal module definition
3418
- /* jshint strict: false */
3419
- if ( module.exports ) {
3420
- // CommonJS
3421
- module.exports = factory(
3422
- requireEvEmitter(),
3423
- requireUtils(),
3424
- requireFlickity()
3425
- );
3426
- } else {
3427
- // browser global
3428
- factory(
3429
- window.EvEmitter,
3430
- window.fizzyUIUtils,
3431
- window.Flickity
3432
- );
3433
- }
3434
-
3435
- }( window, function factory( EvEmitter, utils, Flickity ) {
3436
-
3437
- // -------------------------- Page Visibility -------------------------- //
3438
- // https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API
3439
-
3440
- var hiddenProperty, visibilityEvent;
3441
- if ( 'hidden' in document ) {
3442
- hiddenProperty = 'hidden';
3443
- visibilityEvent = 'visibilitychange';
3444
- } else if ( 'webkitHidden' in document ) {
3445
- hiddenProperty = 'webkitHidden';
3446
- visibilityEvent = 'webkitvisibilitychange';
3447
- }
3448
-
3449
- // -------------------------- Player -------------------------- //
3450
-
3451
- function Player( parent ) {
3452
- this.parent = parent;
3453
- this.state = 'stopped';
3454
- // visibility change event handler
3455
- if ( visibilityEvent ) {
3456
- this.onVisibilityChange = function() {
3457
- this.visibilityChange();
3458
- }.bind( this );
3459
- this.onVisibilityPlay = function() {
3460
- this.visibilityPlay();
3461
- }.bind( this );
3462
- }
3463
- }
3464
-
3465
- Player.prototype = Object.create( EvEmitter.prototype );
3466
-
3467
- // start play
3468
- Player.prototype.play = function() {
3469
- if ( this.state == 'playing' ) {
3470
- return;
3471
- }
3472
- // do not play if page is hidden, start playing when page is visible
3473
- var isPageHidden = document[ hiddenProperty ];
3474
- if ( visibilityEvent && isPageHidden ) {
3475
- document.addEventListener( visibilityEvent, this.onVisibilityPlay );
3476
- return;
3477
- }
3478
-
3479
- this.state = 'playing';
3480
- // listen to visibility change
3481
- if ( visibilityEvent ) {
3482
- document.addEventListener( visibilityEvent, this.onVisibilityChange );
3483
- }
3484
- // start ticking
3485
- this.tick();
3486
- };
3487
-
3488
- Player.prototype.tick = function() {
3489
- // do not tick if not playing
3490
- if ( this.state != 'playing' ) {
3491
- return;
3492
- }
3493
-
3494
- var time = this.parent.options.autoPlay;
3495
- // default to 3 seconds
3496
- time = typeof time == 'number' ? time : 3000;
3497
- var _this = this;
3498
- // HACK: reset ticks if stopped and started within interval
3499
- this.clear();
3500
- this.timeout = setTimeout( function() {
3501
- _this.parent.next( true );
3502
- _this.tick();
3503
- }, time );
3504
- };
3505
-
3506
- Player.prototype.stop = function() {
3507
- this.state = 'stopped';
3508
- this.clear();
3509
- // remove visibility change event
3510
- if ( visibilityEvent ) {
3511
- document.removeEventListener( visibilityEvent, this.onVisibilityChange );
3512
- }
3513
- };
3514
-
3515
- Player.prototype.clear = function() {
3516
- clearTimeout( this.timeout );
3517
- };
3518
-
3519
- Player.prototype.pause = function() {
3520
- if ( this.state == 'playing' ) {
3521
- this.state = 'paused';
3522
- this.clear();
3523
- }
3524
- };
3525
-
3526
- Player.prototype.unpause = function() {
3527
- // re-start play if paused
3528
- if ( this.state == 'paused' ) {
3529
- this.play();
3530
- }
3531
- };
3532
-
3533
- // pause if page visibility is hidden, unpause if visible
3534
- Player.prototype.visibilityChange = function() {
3535
- var isPageHidden = document[ hiddenProperty ];
3536
- this[ isPageHidden ? 'pause' : 'unpause' ]();
3537
- };
3538
-
3539
- Player.prototype.visibilityPlay = function() {
3540
- this.play();
3541
- document.removeEventListener( visibilityEvent, this.onVisibilityPlay );
3542
- };
3543
-
3544
- // -------------------------- Flickity -------------------------- //
3545
-
3546
- utils.extend( Flickity.defaults, {
3547
- pauseAutoPlayOnHover: true
3548
- });
3549
-
3550
- Flickity.createMethods.push('_createPlayer');
3551
- var proto = Flickity.prototype;
3552
-
3553
- proto._createPlayer = function() {
3554
- this.player = new Player( this );
3555
-
3556
- this.on( 'activate', this.activatePlayer );
3557
- this.on( 'uiChange', this.stopPlayer );
3558
- this.on( 'pointerDown', this.stopPlayer );
3559
- this.on( 'deactivate', this.deactivatePlayer );
3560
- };
3561
-
3562
- proto.activatePlayer = function() {
3563
- if ( !this.options.autoPlay ) {
3564
- return;
3565
- }
3566
- this.player.play();
3567
- this.element.addEventListener( 'mouseenter', this );
3568
- };
3569
-
3570
- // Player API, don't hate the ... thanks I know where the door is
3571
-
3572
- proto.playPlayer = function() {
3573
- this.player.play();
3574
- };
3575
-
3576
- proto.stopPlayer = function() {
3577
- this.player.stop();
3578
- };
3579
-
3580
- proto.pausePlayer = function() {
3581
- this.player.pause();
3582
- };
3583
-
3584
- proto.unpausePlayer = function() {
3585
- this.player.unpause();
3586
- };
3587
-
3588
- proto.deactivatePlayer = function() {
3589
- this.player.stop();
3590
- this.element.removeEventListener( 'mouseenter', this );
3591
- };
3592
-
3593
- // ----- mouseenter/leave ----- //
3594
-
3595
- // pause auto-play on hover
3596
- proto.onmouseenter = function() {
3597
- if ( !this.options.pauseAutoPlayOnHover ) {
3598
- return;
3599
- }
3600
- this.player.pause();
3601
- this.element.addEventListener( 'mouseleave', this );
3602
- };
3603
-
3604
- // resume auto-play on hover off
3605
- proto.onmouseleave = function() {
3606
- this.player.unpause();
3607
- this.element.removeEventListener( 'mouseleave', this );
3608
- };
3609
-
3610
- // ----- ----- //
3611
-
3612
- Flickity.Player = Player;
3613
-
3614
- return Flickity;
3615
-
3616
- }));
3617
- } (player));
3618
- return player.exports;
3619
- }
3620
-
3621
- var addRemoveCell = {exports: {}};
3622
-
3623
- var hasRequiredAddRemoveCell;
3624
-
3625
- function requireAddRemoveCell () {
3626
- if (hasRequiredAddRemoveCell) return addRemoveCell.exports;
3627
- hasRequiredAddRemoveCell = 1;
3628
- (function (module) {
3629
- // add, remove cell
3630
- ( function( window, factory ) {
3631
- // universal module definition
3632
- /* jshint strict: false */
3633
- if ( module.exports ) {
3634
- // CommonJS
3635
- module.exports = factory(
3636
- window,
3637
- requireFlickity(),
3638
- requireUtils()
3639
- );
3640
- } else {
3641
- // browser global
3642
- factory(
3643
- window,
3644
- window.Flickity,
3645
- window.fizzyUIUtils
3646
- );
3647
- }
3648
-
3649
- }( window, function factory( window, Flickity, utils ) {
3650
-
3651
- // append cells to a document fragment
3652
- function getCellsFragment( cells ) {
3653
- var fragment = document.createDocumentFragment();
3654
- cells.forEach( function( cell ) {
3655
- fragment.appendChild( cell.element );
3656
- });
3657
- return fragment;
3658
- }
3659
-
3660
- // -------------------------- add/remove cell prototype -------------------------- //
3661
-
3662
- var proto = Flickity.prototype;
3663
-
3664
- /**
3665
- * Insert, prepend, or append cells
3666
- * @param {Element, Array, NodeList} elems
3667
- * @param {Integer} index
3668
- */
3669
- proto.insert = function( elems, index ) {
3670
- var cells = this._makeCells( elems );
3671
- if ( !cells || !cells.length ) {
3672
- return;
3673
- }
3674
- var len = this.cells.length;
3675
- // default to append
3676
- index = index === undefined ? len : index;
3677
- // add cells with document fragment
3678
- var fragment = getCellsFragment( cells );
3679
- // append to slider
3680
- var isAppend = index == len;
3681
- if ( isAppend ) {
3682
- this.slider.appendChild( fragment );
3683
- } else {
3684
- var insertCellElement = this.cells[ index ].element;
3685
- this.slider.insertBefore( fragment, insertCellElement );
3686
- }
3687
- // add to this.cells
3688
- if ( index === 0 ) {
3689
- // prepend, add to start
3690
- this.cells = cells.concat( this.cells );
3691
- } else if ( isAppend ) {
3692
- // append, add to end
3693
- this.cells = this.cells.concat( cells );
3694
- } else {
3695
- // insert in this.cells
3696
- var endCells = this.cells.splice( index, len - index );
3697
- this.cells = this.cells.concat( cells ).concat( endCells );
3698
- }
3699
-
3700
- this._sizeCells( cells );
3701
-
3702
- var selectedIndexDelta = index > this.selectedIndex ? 0 : cells.length;
3703
- this._cellAddedRemoved( index, selectedIndexDelta );
3704
- };
3705
-
3706
- proto.append = function( elems ) {
3707
- this.insert( elems, this.cells.length );
3708
- };
3709
-
3710
- proto.prepend = function( elems ) {
3711
- this.insert( elems, 0 );
3712
- };
3713
-
3714
- /**
3715
- * Remove cells
3716
- * @param {Element, Array, NodeList} elems
3717
- */
3718
- proto.remove = function( elems ) {
3719
- var cells = this.getCells( elems );
3720
- var selectedIndexDelta = 0;
3721
- var len = cells.length;
3722
- var i, cell;
3723
- // calculate selectedIndexDelta, easier if done in seperate loop
3724
- for ( i=0; i < len; i++ ) {
3725
- cell = cells[i];
3726
- var wasBefore = this.cells.indexOf( cell ) < this.selectedIndex;
3727
- selectedIndexDelta -= wasBefore ? 1 : 0;
3728
- }
3729
-
3730
- for ( i=0; i < len; i++ ) {
3731
- cell = cells[i];
3732
- cell.remove();
3733
- // remove item from collection
3734
- utils.removeFrom( this.cells, cell );
3735
- }
3736
-
3737
- if ( cells.length ) {
3738
- // update stuff
3739
- this._cellAddedRemoved( 0, selectedIndexDelta );
3740
- }
3741
- };
3742
-
3743
- // updates when cells are added or removed
3744
- proto._cellAddedRemoved = function( changedCellIndex, selectedIndexDelta ) {
3745
- // TODO this math isn't perfect with grouped slides
3746
- selectedIndexDelta = selectedIndexDelta || 0;
3747
- this.selectedIndex += selectedIndexDelta;
3748
- this.selectedIndex = Math.max( 0, Math.min( this.slides.length - 1, this.selectedIndex ) );
3749
-
3750
- this.cellChange( changedCellIndex, true );
3751
- // backwards compatibility
3752
- this.emitEvent( 'cellAddedRemoved', [ changedCellIndex, selectedIndexDelta ] );
3753
- };
3754
-
3755
- /**
3756
- * logic to be run after a cell's size changes
3757
- * @param {Element} elem - cell's element
3758
- */
3759
- proto.cellSizeChange = function( elem ) {
3760
- var cell = this.getCell( elem );
3761
- if ( !cell ) {
3762
- return;
3763
- }
3764
- cell.getSize();
3765
-
3766
- var index = this.cells.indexOf( cell );
3767
- this.cellChange( index );
3768
- };
3769
-
3770
- /**
3771
- * logic any time a cell is changed: added, removed, or size changed
3772
- * @param {Integer} changedCellIndex - index of the changed cell, optional
3773
- */
3774
- proto.cellChange = function( changedCellIndex, isPositioningSlider ) {
3775
- var prevSlideableWidth = this.slideableWidth;
3776
- this._positionCells( changedCellIndex );
3777
- this._getWrapShiftCells();
3778
- this.setGallerySize();
3779
- this.emitEvent( 'cellChange', [ changedCellIndex ] );
3780
- // position slider
3781
- if ( this.options.freeScroll ) {
3782
- // shift x by change in slideableWidth
3783
- // TODO fix position shifts when prepending w/ freeScroll
3784
- var deltaX = prevSlideableWidth - this.slideableWidth;
3785
- this.x += deltaX * this.cellAlign;
3786
- this.positionSlider();
3787
- } else {
3788
- // do not position slider after lazy load
3789
- if ( isPositioningSlider ) {
3790
- this.positionSliderAtSelected();
3791
- }
3792
- this.select( this.selectedIndex );
3793
- }
3794
- };
3795
-
3796
- // ----- ----- //
3797
-
3798
- return Flickity;
3799
-
3800
- }));
3801
- } (addRemoveCell));
3802
- return addRemoveCell.exports;
3803
- }
3804
-
3805
- var lazyload = {exports: {}};
3806
-
3807
- var hasRequiredLazyload;
3808
-
3809
- function requireLazyload () {
3810
- if (hasRequiredLazyload) return lazyload.exports;
3811
- hasRequiredLazyload = 1;
3812
- (function (module) {
3813
- // lazyload
3814
- ( function( window, factory ) {
3815
- // universal module definition
3816
- /* jshint strict: false */
3817
- if ( module.exports ) {
3818
- // CommonJS
3819
- module.exports = factory(
3820
- window,
3821
- requireFlickity(),
3822
- requireUtils()
3823
- );
3824
- } else {
3825
- // browser global
3826
- factory(
3827
- window,
3828
- window.Flickity,
3829
- window.fizzyUIUtils
3830
- );
3831
- }
3832
-
3833
- }( window, function factory( window, Flickity, utils ) {
3834
-
3835
- Flickity.createMethods.push('_createLazyload');
3836
- var proto = Flickity.prototype;
3837
-
3838
- proto._createLazyload = function() {
3839
- this.on( 'select', this.lazyLoad );
3840
- };
3841
-
3842
- proto.lazyLoad = function() {
3843
- var lazyLoad = this.options.lazyLoad;
3844
- if ( !lazyLoad ) {
3845
- return;
3846
- }
3847
- // get adjacent cells, use lazyLoad option for adjacent count
3848
- var adjCount = typeof lazyLoad == 'number' ? lazyLoad : 0;
3849
- var cellElems = this.getAdjacentCellElements( adjCount );
3850
- // get lazy images in those cells
3851
- var lazyImages = [];
3852
- cellElems.forEach( function( cellElem ) {
3853
- var lazyCellImages = getCellLazyImages( cellElem );
3854
- lazyImages = lazyImages.concat( lazyCellImages );
3855
- });
3856
- // load lazy images
3857
- lazyImages.forEach( function( img ) {
3858
- new LazyLoader( img, this );
3859
- }, this );
3860
- };
3861
-
3862
- function getCellLazyImages( cellElem ) {
3863
- // check if cell element is lazy image
3864
- if ( cellElem.nodeName == 'IMG' &&
3865
- cellElem.getAttribute('data-flickity-lazyload') ) {
3866
- return [ cellElem ];
3867
- }
3868
- // select lazy images in cell
3869
- var imgs = cellElem.querySelectorAll('img[data-flickity-lazyload]');
3870
- return utils.makeArray( imgs );
3871
- }
3872
-
3873
- // -------------------------- LazyLoader -------------------------- //
3874
-
3875
- /**
3876
- * class to handle loading images
3877
- */
3878
- function LazyLoader( img, flickity ) {
3879
- this.img = img;
3880
- this.flickity = flickity;
3881
- this.load();
3882
- }
3883
-
3884
- LazyLoader.prototype.handleEvent = utils.handleEvent;
3885
-
3886
- LazyLoader.prototype.load = function() {
3887
- this.img.addEventListener( 'load', this );
3888
- this.img.addEventListener( 'error', this );
3889
- // load image
3890
- this.img.src = this.img.getAttribute('data-flickity-lazyload');
3891
- // remove attr
3892
- this.img.removeAttribute('data-flickity-lazyload');
3893
- };
3894
-
3895
- LazyLoader.prototype.onload = function( event ) {
3896
- this.complete( event, 'flickity-lazyloaded' );
3897
- };
3898
-
3899
- LazyLoader.prototype.onerror = function( event ) {
3900
- this.complete( event, 'flickity-lazyerror' );
3901
- };
3902
-
3903
- LazyLoader.prototype.complete = function( event, className ) {
3904
- // unbind events
3905
- this.img.removeEventListener( 'load', this );
3906
- this.img.removeEventListener( 'error', this );
3907
-
3908
- var cell = this.flickity.getParentCell( this.img );
3909
- var cellElem = cell && cell.element;
3910
- this.flickity.cellSizeChange( cellElem );
3911
-
3912
- this.img.classList.add( className );
3913
- this.flickity.dispatchEvent( 'lazyLoad', event, cellElem );
3914
- };
3915
-
3916
- // ----- ----- //
3917
-
3918
- Flickity.LazyLoader = LazyLoader;
3919
-
3920
- return Flickity;
3921
-
3922
- }));
3923
- } (lazyload));
3924
- return lazyload.exports;
3925
- }
3926
-
3927
- /*!
3928
- * Flickity v2.0.10
3929
- * Touch, responsive, flickable carousels
3930
- *
3931
- * Licensed GPLv3 for open source use
3932
- * or Flickity Commercial License for commercial use
3933
- *
3934
- * http://flickity.metafizzy.co
3935
- * Copyright 2017 Metafizzy
3936
- */
3937
-
3938
- (function (module) {
3939
- ( function( window, factory ) {
3940
- // universal module definition
3941
- /* jshint strict: false */
3942
- if ( module.exports ) {
3943
- // CommonJS
3944
- module.exports = factory(
3945
- requireFlickity(),
3946
- requireDrag(),
3947
- requirePrevNextButton(),
3948
- requirePageDots(),
3949
- requirePlayer(),
3950
- requireAddRemoveCell(),
3951
- requireLazyload()
3952
- );
3953
- }
3954
-
3955
- })( window, function factory( Flickity ) {
3956
- /*jshint strict: false*/
3957
- return Flickity;
3958
- });
3959
- } (js));
3960
-
3961
- var jsExports = js.exports;
3962
- const index = /*@__PURE__*/index$2.getDefaultExportFromCjs(jsExports);
3963
-
3964
- const index$1 = /*#__PURE__*/_mergeNamespaces({
3965
- __proto__: null,
3966
- default: index
3967
- }, [jsExports]);
3968
-
3969
- exports.index = index$1;