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