Debian Codegraph @

debian/missing-sources/owl.carousel.js

raw
1 /**
2 * Owl carousel
3 * @version 2.0.0-beta.3
4 * @author Bartosz Wojciechowski
5 * @license The MIT License (MIT)
6 * @todo Lazy Load Icon
7 * @todo prevent animationend bubling
8 * @todo itemsScaleUp
9 * @todo Test Zepto
10 * @todo stagePadding calculate wrong active classes
11 */
12 ;(function($, window, document, undefined) {
13
14 /**
15 * Creates a carousel.
16 * @class The Owl Carousel.
17 * @public
18 * @param {HTMLElement|jQuery} element - The element to create the carousel for.
19 * @param {Object} [options] - The options
20 */
21 function Owl(element, options) {
22
23 /**
24 * Current settings for the carousel.
25 * @public
26 */
27 this.settings = null;
28
29 /**
30 * Current options set by the caller including defaults.
31 * @public
32 */
33 this.options = $.extend({}, Owl.Defaults, options);
34
35 /**
36 * Plugin element.
37 * @public
38 */
39 this.$element = $(element);
40
41 /**
42 * Proxied event handlers.
43 * @protected
44 */
45 this._handlers = {};
46
47 /**
48 * References to the running plugins of this carousel.
49 * @protected
50 */
51 this._plugins = {};
52
53 /**
54 * Currently suppressed events to prevent them from beeing retriggered.
55 * @protected
56 */
57 this._supress = {};
58
59 /**
60 * Absolute current position.
61 * @protected
62 */
63 this._current = null;
64
65 /**
66 * Animation speed in milliseconds.
67 * @protected
68 */
69 this._speed = null;
70
71 /**
72 * Coordinates of all items in pixel.
73 * @todo The name of this member is missleading.
74 * @protected
75 */
76 this._coordinates = [];
77
78 /**
79 * Current breakpoint.
80 * @todo Real media queries would be nice.
81 * @protected
82 */
83 this._breakpoint = null;
84
85 /**
86 * Current width of the plugin element.
87 */
88 this._width = null;
89
90 /**
91 * All real items.
92 * @protected
93 */
94 this._items = [];
95
96 /**
97 * All cloned items.
98 * @protected
99 */
100 this._clones = [];
101
102 /**
103 * Merge values of all items.
104 * @todo Maybe this could be part of a plugin.
105 * @protected
106 */
107 this._mergers = [];
108
109 /**
110 * Widths of all items.
111 */
112 this._widths = [];
113
114 /**
115 * Invalidated parts within the update process.
116 * @protected
117 */
118 this._invalidated = {};
119
120 /**
121 * Ordered list of workers for the update process.
122 * @protected
123 */
124 this._pipe = [];
125
126 /**
127 * Current state information for the drag operation.
128 * @todo #261
129 * @protected
130 */
131 this._drag = {
132 time: null,
133 target: null,
134 pointer: null,
135 stage: {
136 start: null,
137 current: null
138 },
139 direction: null
140 };
141
142 /**
143 * Current state information and their tags.
144 * @type {Object}
145 * @protected
146 */
147 this._states = {
148 current: {},
149 tags: {
150 'initializing': [ 'busy' ],
151 'animating': [ 'busy' ],
152 'dragging': [ 'interacting' ]
153 }
154 };
155
156 $.each([ 'onResize', 'onThrottledResize' ], $.proxy(function(i, handler) {
157 this._handlers[handler] = $.proxy(this[handler], this);
158 }, this));
159
160 $.each(Owl.Plugins, $.proxy(function(key, plugin) {
161 this._plugins[key.charAt(0).toLowerCase() + key.slice(1)]
162 = new plugin(this);
163 }, this));
164
165 $.each(Owl.Workers, $.proxy(function(priority, worker) {
166 this._pipe.push({
167 'filter': worker.filter,
168 'run': $.proxy(worker.run, this)
169 });
170 }, this));
171
172 this.setup();
173 this.initialize();
174 }
175
176 /**
177 * Default options for the carousel.
178 * @public
179 */
180 Owl.Defaults = {
181 items: 3,
182 loop: false,
183 center: false,
184 rewind: false,
185
186 mouseDrag: true,
187 touchDrag: true,
188 pullDrag: true,
189 freeDrag: false,
190
191 margin: 0,
192 stagePadding: 0,
193
194 merge: false,
195 mergeFit: true,
196 autoWidth: false,
197
198 startPosition: 0,
199 rtl: false,
200
201 smartSpeed: 250,
202 fluidSpeed: false,
203 dragEndSpeed: false,
204
205 responsive: {},
206 responsiveRefreshRate: 200,
207 responsiveBaseElement: window,
208
209 fallbackEasing: 'swing',
210
211 info: false,
212
213 nestedItemSelector: false,
214 itemElement: 'div',
215 stageElement: 'div',
216
217 refreshClass: 'owl-refresh',
218 loadedClass: 'owl-loaded',
219 loadingClass: 'owl-loading',
220 rtlClass: 'owl-rtl',
221 responsiveClass: 'owl-responsive',
222 dragClass: 'owl-drag',
223 itemClass: 'owl-item',
224 stageClass: 'owl-stage',
225 stageOuterClass: 'owl-stage-outer',
226 grabClass: 'owl-grab'
227 };
228
229 /**
230 * Enumeration for width.
231 * @public
232 * @readonly
233 * @enum {String}
234 */
235 Owl.Width = {
236 Default: 'default',
237 Inner: 'inner',
238 Outer: 'outer'
239 };
240
241 /**
242 * Enumeration for types.
243 * @public
244 * @readonly
245 * @enum {String}
246 */
247 Owl.Type = {
248 Event: 'event',
249 State: 'state'
250 };
251
252 /**
253 * Contains all registered plugins.
254 * @public
255 */
256 Owl.Plugins = {};
257
258 /**
259 * List of workers involved in the update process.
260 */
261 Owl.Workers = [ {
262 filter: [ 'width', 'settings' ],
263 run: function() {
264 this._width = this.$element.width();
265 }
266 }, {
267 filter: [ 'width', 'items', 'settings' ],
268 run: function(cache) {
269 cache.current = this._items && this._items[this.relative(this._current)];
270 }
271 }, {
272 filter: [ 'items', 'settings' ],
273 run: function() {
274 this.$stage.children('.cloned').remove();
275 }
276 }, {
277 filter: [ 'width', 'items', 'settings' ],
278 run: function(cache) {
279 var margin = this.settings.margin || '',
280 grid = !this.settings.autoWidth,
281 rtl = this.settings.rtl,
282 css = {
283 'width': 'auto',
284 'margin-left': rtl ? margin : '',
285 'margin-right': rtl ? '' : margin
286 };
287
288 !grid && this.$stage.children().css(css);
289
290 cache.css = css;
291 }
292 }, {
293 filter: [ 'width', 'items', 'settings' ],
294 run: function(cache) {
295 var width = (this.width() / this.settings.items).toFixed(3) - this.settings.margin,
296 merge = null,
297 iterator = this._items.length,
298 grid = !this.settings.autoWidth,
299 widths = [];
300
301 cache.items = {
302 merge: false,
303 width: width
304 };
305
306 while (iterator--) {
307 merge = this._mergers[iterator];
308 merge = this.settings.mergeFit && Math.min(merge, this.settings.items) || merge;
309
310 cache.items.merge = merge > 1 || cache.items.merge;
311
312 widths[iterator] = !grid ? this._items[iterator].width() : width * merge;
313 }
314
315 this._widths = widths;
316 }
317 }, {
318 filter: [ 'items', 'settings' ],
319 run: function() {
320 var clones = [],
321 items = this._items,
322 settings = this.settings,
323 view = Math.max(settings.items * 2, 4),
324 size = Math.ceil(items.length / 2) * 2,
325 repeat = settings.loop && items.length ? settings.rewind ? view : Math.max(view, size) : 0,
326 append = '',
327 prepend = '';
328
329 repeat /= 2;
330
331 while (repeat--) {
332 clones.push(this.normalize(clones.length / 2, true));
333 append = append + items[clones[clones.length - 1]][0].outerHTML;
334 clones.push(this.normalize(items.length - 1 - (clones.length - 1) / 2, true));
335 prepend = items[clones[clones.length - 1]][0].outerHTML + prepend;
336 }
337
338 this._clones = clones;
339
340 $(append).addClass('cloned').appendTo(this.$stage);
341 $(prepend).addClass('cloned').prependTo(this.$stage);
342 }
343 }, {
344 filter: [ 'width', 'items', 'settings' ],
345 run: function() {
346 var rtl = this.settings.rtl ? 1 : -1,
347 size = this._clones.length + this._items.length,
348 iterator = -1,
349 previous = 0,
350 current = 0,
351 coordinates = [];
352
353 while (++iterator < size) {
354 previous = coordinates[iterator - 1] || 0;
355 current = this._widths[this.relative(iterator)] + this.settings.margin;
356 coordinates.push(previous + current * rtl);
357 }
358
359 this._coordinates = coordinates;
360 }
361 }, {
362 filter: [ 'width', 'items', 'settings' ],
363 run: function() {
364 var padding = this.settings.stagePadding,
365 coordinates = this._coordinates,
366 css = {
367 'width': Math.ceil(Math.abs(coordinates[coordinates.length - 1])) + padding * 2,
368 'padding-left': padding || '',
369 'padding-right': padding || ''
370 };
371
372 this.$stage.css(css);
373 }
374 }, {
375 filter: [ 'width', 'items', 'settings' ],
376 run: function(cache) {
377 var iterator = this._coordinates.length,
378 grid = !this.settings.autoWidth,
379 items = this.$stage.children();
380
381 if (grid && cache.items.merge) {
382 while (iterator--) {
383 cache.css.width = this._widths[this.relative(iterator)];
384 items.eq(iterator).css(cache.css);
385 }
386 } else if (grid) {
387 cache.css.width = cache.items.width;
388 items.css(cache.css);
389 }
390 }
391 }, {
392 filter: [ 'items' ],
393 run: function() {
394 this._coordinates.length < 1 && this.$stage.removeAttr('style');
395 }
396 }, {
397 filter: [ 'width', 'items', 'settings' ],
398 run: function(cache) {
399 cache.current = cache.current ? this.$stage.children().index(cache.current) : 0;
400 cache.current = Math.max(this.minimum(), Math.min(this.maximum(), cache.current));
401 this.reset(cache.current);
402 }
403 }, {
404 filter: [ 'position' ],
405 run: function() {
406 this.animate(this.coordinates(this._current));
407 }
408 }, {
409 filter: [ 'width', 'position', 'items', 'settings' ],
410 run: function() {
411 var rtl = this.settings.rtl ? 1 : -1,
412 padding = this.settings.stagePadding * 2,
413 begin = this.coordinates(this.current()) + padding,
414 end = begin + this.width() * rtl,
415 inner, outer, matches = [], i, n;
416
417 for (i = 0, n = this._coordinates.length; i < n; i++) {
418 inner = this._coordinates[i - 1] || 0;
419 outer = Math.abs(this._coordinates[i]) + padding * rtl;
420
421 if ((this.op(inner, '<=', begin) && (this.op(inner, '>', end)))
422 || (this.op(outer, '<', begin) && this.op(outer, '>', end))) {
423 matches.push(i);
424 }
425 }
426
427 this.$stage.children('.active').removeClass('active');
428 this.$stage.children(':eq(' + matches.join('), :eq(') + ')').addClass('active');
429
430 if (this.settings.center) {
431 this.$stage.children('.center').removeClass('center');
432 this.$stage.children().eq(this.current()).addClass('center');
433 }
434 }
435 } ];
436
437 /**
438 * Initializes the carousel.
439 * @protected
440 */
441 Owl.prototype.initialize = function() {
442 this.enter('initializing');
443 this.trigger('initialize');
444
445 this.$element.toggleClass(this.settings.rtlClass, this.settings.rtl);
446
447 if (this.settings.autoWidth && !this.is('pre-loading')) {
448 var imgs, nestedSelector, width;
449 imgs = this.$element.find('img');
450 nestedSelector = this.settings.nestedItemSelector ? '.' + this.settings.nestedItemSelector : undefined;
451 width = this.$element.children(nestedSelector).width();
452
453 if (imgs.length && width <= 0) {
454 this.preloadAutoWidthImages(imgs);
455 }
456 }
457
458 this.$element.addClass(this.options.loadingClass);
459
460 // create stage
461 this.$stage = $('<' + this.settings.stageElement + ' class="' + this.settings.stageClass + '"/>')
462 .wrap('<div class="' + this.settings.stageOuterClass + '"/>');
463
464 // append stage
465 this.$element.append(this.$stage.parent());
466
467 // append content
468 this.replace(this.$element.children().not(this.$stage.parent()));
469
470 // check visibility
471 if (this.$element.is(':visible')) {
472 // update view
473 this.refresh();
474 } else {
475 // invalidate width
476 this.invalidate('width');
477 }
478
479 this.$element
480 .removeClass(this.options.loadingClass)
481 .addClass(this.options.loadedClass);
482
483 // register event handlers
484 this.registerEventHandlers();
485
486 this.leave('initializing');
487 this.trigger('initialized');
488 };
489
490 /**
491 * Setups the current settings.
492 * @todo Remove responsive classes. Why should adaptive designs be brought into IE8?
493 * @todo Support for media queries by using `matchMedia` would be nice.
494 * @public
495 */
496 Owl.prototype.setup = function() {
497 var viewport = this.viewport(),
498 overwrites = this.options.responsive,
499 match = -1,
500 settings = null;
501
502 if (!overwrites) {
503 settings = $.extend({}, this.options);
504 } else {
505 $.each(overwrites, function(breakpoint) {
506 if (breakpoint <= viewport && breakpoint > match) {
507 match = Number(breakpoint);
508 }
509 });
510
511 settings = $.extend({}, this.options, overwrites[match]);
512 delete settings.responsive;
513
514 // responsive class
515 if (settings.responsiveClass) {
516 this.$element.attr('class',
517 this.$element.attr('class').replace(new RegExp('(' + this.options.responsiveClass + '-)\\S+\\s', 'g'), '$1' + match)
518 );
519 }
520 }
521
522 if (this.settings === null || this._breakpoint !== match) {
523 this.trigger('change', { property: { name: 'settings', value: settings } });
524 this._breakpoint = match;
525 this.settings = settings;
526 this.invalidate('settings');
527 this.trigger('changed', { property: { name: 'settings', value: this.settings } });
528 }
529 };
530
531 /**
532 * Updates option logic if necessery.
533 * @protected
534 */
535 Owl.prototype.optionsLogic = function() {
536 if (this.settings.autoWidth) {
537 this.settings.stagePadding = false;
538 this.settings.merge = false;
539 }
540 };
541
542 /**
543 * Prepares an item before add.
544 * @todo Rename event parameter `content` to `item`.
545 * @protected
546 * @returns {jQuery|HTMLElement} - The item container.
547 */
548 Owl.prototype.prepare = function(item) {
549 var event = this.trigger('prepare', { content: item });
550
551 if (!event.data) {
552 event.data = $('<' + this.settings.itemElement + '/>')
553 .addClass(this.options.itemClass).append(item)
554 }
555
556 this.trigger('prepared', { content: event.data });
557
558 return event.data;
559 };
560
561 /**
562 * Updates the view.
563 * @public
564 */
565 Owl.prototype.update = function() {
566 var i = 0,
567 n = this._pipe.length,
568 filter = $.proxy(function(p) { return this[p] }, this._invalidated),
569 cache = {};
570
571 while (i < n) {
572 if (this._invalidated.all || $.grep(this._pipe[i].filter, filter).length > 0) {
573 this._pipe[i].run(cache);
574 }
575 i++;
576 }
577
578 this._invalidated = {};
579
580 !this.is('valid') && this.enter('valid');
581 };
582
583 /**
584 * Gets the width of the view.
585 * @public
586 * @param {Owl.Width} [dimension=Owl.Width.Default] - The dimension to return.
587 * @returns {Number} - The width of the view in pixel.
588 */
589 Owl.prototype.width = function(dimension) {
590 dimension = dimension || Owl.Width.Default;
591 switch (dimension) {
592 case Owl.Width.Inner:
593 case Owl.Width.Outer:
594 return this._width;
595 default:
596 return this._width - this.settings.stagePadding * 2 + this.settings.margin;
597 }
598 };
599
600 /**
601 * Refreshes the carousel primarily for adaptive purposes.
602 * @public
603 */
604 Owl.prototype.refresh = function() {
605 this.enter('refreshing');
606 this.trigger('refresh');
607
608 this.setup();
609
610 this.optionsLogic();
611
612 this.$element.addClass(this.options.refreshClass);
613
614 this.update();
615
616 this.$element.removeClass(this.options.refreshClass);
617
618 this.leave('refreshing');
619 this.trigger('refreshed');
620 };
621
622 /**
623 * Checks window `resize` event.
624 * @protected
625 */
626 Owl.prototype.onThrottledResize = function() {
627 window.clearTimeout(this.resizeTimer);
628 this.resizeTimer = window.setTimeout(this._handlers.onResize, this.settings.responsiveRefreshRate);
629 };
630
631 /**
632 * Checks window `resize` event.
633 * @protected
634 */
635 Owl.prototype.onResize = function() {
636 if (!this._items.length) {
637 return false;
638 }
639
640 if (this._width === this.$element.width()) {
641 return false;
642 }
643
644 if (!this.$element.is(':visible')) {
645 return false;
646 }
647
648 this.enter('resizing');
649
650 if (this.trigger('resize').isDefaultPrevented()) {
651 this.leave('resizing');
652 return false;
653 }
654
655 this.invalidate('width');
656
657 this.refresh();
658
659 this.leave('resizing');
660 this.trigger('resized');
661 };
662
663 /**
664 * Registers event handlers.
665 * @todo Check `msPointerEnabled`
666 * @todo #261
667 * @protected
668 */
669 Owl.prototype.registerEventHandlers = function() {
670 if ($.support.transition) {
671 this.$stage.on($.support.transition.end + '.owl.core', $.proxy(this.onTransitionEnd, this));
672 }
673
674 if (this.settings.responsive !== false) {
675 this.on(window, 'resize', this._handlers.onThrottledResize);
676 }
677
678 if (this.settings.mouseDrag) {
679 this.$element.addClass(this.options.dragClass);
680 this.$stage.on('mousedown.owl.core', $.proxy(this.onDragStart, this));
681 this.$stage.on('dragstart.owl.core selectstart.owl.core', function() { return false });
682 }
683
684 if (this.settings.touchDrag){
685 this.$stage.on('touchstart.owl.core', $.proxy(this.onDragStart, this));
686 this.$stage.on('touchcancel.owl.core', $.proxy(this.onDragEnd, this));
687 }
688 };
689
690 /**
691 * Handles `touchstart` and `mousedown` events.
692 * @todo Horizontal swipe threshold as option
693 * @todo #261
694 * @protected
695 * @param {Event} event - The event arguments.
696 */
697 Owl.prototype.onDragStart = function(event) {
698 var stage = null;
699
700 if (event.which === 3) {
701 return;
702 }
703
704 if ($.support.transform) {
705 stage = this.$stage.css('transform').replace(/.*\(|\)| /g, '').split(',');
706 stage = {
707 x: stage[stage.length === 16 ? 12 : 4],
708 y: stage[stage.length === 16 ? 13 : 5]
709 };
710 } else {
711 stage = this.$stage.position();
712 stage = {
713 x: this.settings.rtl ?
714 stage.left + this.$stage.width() - this.width() + this.settings.margin :
715 stage.left,
716 y: stage.top
717 };
718 }
719
720 if (this.is('animating')) {
721 $.support.transform ? this.animate(stage.x) : this.$stage.stop()
722 this.invalidate('position');
723 }
724
725 this.$element.toggleClass(this.options.grabClass, event.type === 'mousedown');
726
727 this.speed(0);
728
729 this._drag.time = new Date().getTime();
730 this._drag.target = $(event.target);
731 this._drag.stage.start = stage;
732 this._drag.stage.current = stage;
733 this._drag.pointer = this.pointer(event);
734
735 $(document).on('mouseup.owl.core touchend.owl.core', $.proxy(this.onDragEnd, this));
736
737 $(document).one('mousemove.owl.core touchmove.owl.core', $.proxy(function(event) {
738 var delta = this.difference(this._drag.pointer, this.pointer(event));
739
740 $(document).on('mousemove.owl.core touchmove.owl.core', $.proxy(this.onDragMove, this));
741
742 if (Math.abs(delta.x) < Math.abs(delta.y) && this.is('valid')) {
743 return;
744 }
745
746 event.preventDefault();
747
748 this.enter('dragging');
749 this.trigger('drag');
750 }, this));
751 };
752
753 /**
754 * Handles the `touchmove` and `mousemove` events.
755 * @todo #261
756 * @protected
757 * @param {Event} event - The event arguments.
758 */
759 Owl.prototype.onDragMove = function(event) {
760 var minimum = null,
761 maximum = null,
762 pull = null,
763 delta = this.difference(this._drag.pointer, this.pointer(event)),
764 stage = this.difference(this._drag.stage.start, delta);
765
766 if (!this.is('dragging')) {
767 return;
768 }
769
770 event.preventDefault();
771
772 if (this.settings.loop) {
773 minimum = this.coordinates(this.minimum());
774 maximum = this.coordinates(this.maximum() + 1) - minimum;
775 stage.x = (((stage.x - minimum) % maximum + maximum) % maximum) + minimum;
776 } else {
777 minimum = this.settings.rtl ? this.coordinates(this.maximum()) : this.coordinates(this.minimum());
778 maximum = this.settings.rtl ? this.coordinates(this.minimum()) : this.coordinates(this.maximum());
779 pull = this.settings.pullDrag ? -1 * delta.x / 5 : 0;
780 stage.x = Math.max(Math.min(stage.x, minimum + pull), maximum + pull);
781 }
782
783 this._drag.stage.current = stage;
784
785 this.animate(stage.x);
786 };
787
788 /**
789 * Handles the `touchend` and `mouseup` events.
790 * @todo #261
791 * @todo Threshold for click event
792 * @protected
793 * @param {Event} event - The event arguments.
794 */
795 Owl.prototype.onDragEnd = function(event) {
796 var delta = this.difference(this._drag.pointer, this.pointer(event)),
797 stage = this._drag.stage.current,
798 direction = delta.x > 0 ^ this.settings.rtl ? 'left' : 'right';
799
800 $(document).off('.owl.core');
801
802 this.$element.removeClass(this.options.grabClass);
803
804 if (delta.x !== 0 && this.is('dragging') || !this.is('valid')) {
805 this.speed(this.settings.dragEndSpeed || this.settings.smartSpeed);
806 this.current(this.closest(stage.x, delta.x !== 0 ? direction : this._drag.direction));
807 this.invalidate('position');
808 this.update();
809
810 this._drag.direction = direction;
811
812 if (Math.abs(delta.x) > 3 || new Date().getTime() - this._drag.time > 300) {
813 this._drag.target.one('click.owl.core', function() { return false; });
814 }
815 }
816
817 if (!this.is('dragging')) {
818 return;
819 }
820
821 this.leave('dragging');
822 this.trigger('dragged');
823 };
824
825 /**
826 * Gets absolute position of the closest item for a coordinate.
827 * @todo Setting `freeDrag` makes `closest` not reusable. See #165.
828 * @protected
829 * @param {Number} coordinate - The coordinate in pixel.
830 * @param {String} direction - The direction to check for the closest item. Ether `left` or `right`.
831 * @return {Number} - The absolute position of the closest item.
832 */
833 Owl.prototype.closest = function(coordinate, direction) {
834 var position = -1,
835 pull = 30,
836 width = this.width(),
837 coordinates = this.coordinates();
838
839 if (!this.settings.freeDrag) {
840 // check closest item
841 $.each(coordinates, $.proxy(function(index, value) {
842 if (coordinate > value - pull && coordinate < value + pull) {
843 position = index;
844 } else if (this.op(coordinate, '<', value)
845 && this.op(coordinate, '>', coordinates[index + 1] || value - width)) {
846 position = direction === 'left' ? index + 1 : index;
847 }
848 return position === -1;
849 }, this));
850 }
851
852 if (!this.settings.loop) {
853 // non loop boundries
854 if (this.op(coordinate, '>', coordinates[this.minimum()])) {
855 position = coordinate = this.minimum();
856 } else if (this.op(coordinate, '<', coordinates[this.maximum()])) {
857 position = coordinate = this.maximum();
858 }
859 }
860
861 return position;
862 };
863
864 /**
865 * Animates the stage.
866 * @todo #270
867 * @public
868 * @param {Number} coordinate - The coordinate in pixels.
869 */
870 Owl.prototype.animate = function(coordinate) {
871 var animate = this.speed() > 0;
872
873 this.is('animating') && this.onTransitionEnd();
874
875 if (animate) {
876 this.enter('animating');
877 this.trigger('translate');
878 }
879
880 if ($.support.transform3d && $.support.transition) {
881 this.$stage.css({
882 transform: 'translate3d(' + coordinate + 'px,0px,0px)',
883 transition: (this.speed() / 1000) + 's'
884 });
885 } else if (animate) {
886 this.$stage.animate({
887 left: coordinate + 'px'
888 }, this.speed(), this.settings.fallbackEasing, $.proxy(this.onTransitionEnd, this));
889 } else {
890 this.$stage.css({
891 left: coordinate + 'px'
892 });
893 }
894 };
895
896 /**
897 * Checks whether the carousel is in a specific state or not.
898 * @param {String} state - The state to check.
899 * @returns {Boolean} - The flag which indicates if the carousel is busy.
900 */
901 Owl.prototype.is = function(state) {
902 return this._states.current[state] && this._states.current[state] > 0;
903 };
904
905 /**
906 * Sets the absolute position of the current item.
907 * @public
908 * @param {Number} [position] - The new absolute position or nothing to leave it unchanged.
909 * @returns {Number} - The absolute position of the current item.
910 */
911 Owl.prototype.current = function(position) {
912 if (position === undefined) {
913 return this._current;
914 }
915
916 if (this._items.length === 0) {
917 return undefined;
918 }
919
920 position = this.normalize(position);
921
922 if (this._current !== position) {
923 var event = this.trigger('change', { property: { name: 'position', value: position } });
924
925 if (event.data !== undefined) {
926 position = this.normalize(event.data);
927 }
928
929 this._current = position;
930
931 this.invalidate('position');
932
933 this.trigger('changed', { property: { name: 'position', value: this._current } });
934 }
935
936 return this._current;
937 };
938
939 /**
940 * Invalidates the given part of the update routine.
941 * @param {String} [part] - The part to invalidate.
942 * @returns {Array.<String>} - The invalidated parts.
943 */
944 Owl.prototype.invalidate = function(part) {
945 if ($.type(part) === 'string') {
946 this._invalidated[part] = true;
947 this.is('valid') && this.leave('valid');
948 }
949 return $.map(this._invalidated, function(v, i) { return i });
950 };
951
952 /**
953 * Resets the absolute position of the current item.
954 * @public
955 * @param {Number} position - The absolute position of the new item.
956 */
957 Owl.prototype.reset = function(position) {
958 position = this.normalize(position);
959
960 if (position === undefined) {
961 return;
962 }
963
964 this._speed = 0;
965 this._current = position;
966
967 this.suppress([ 'translate', 'translated' ]);
968
969 this.animate(this.coordinates(position));
970
971 this.release([ 'translate', 'translated' ]);
972 };
973
974 /**
975 * Normalizes an absolute or a relative position of an item.
976 * @public
977 * @param {Number} position - The absolute or relative position to normalize.
978 * @param {Boolean} [relative=false] - Whether the given position is relative or not.
979 * @returns {Number} - The normalized position.
980 */
981 Owl.prototype.normalize = function(position, relative) {
982 var n = this._items.length,
983 m = relative ? 0 : this._clones.length;
984
985 if (!$.isNumeric(position) || n < 1) {
986 position = undefined;
987 } else if (position < 0 || position >= n + m) {
988 position = ((position - m / 2) % n + n) % n + m / 2;
989 }
990
991 return position;
992 };
993
994 /**
995 * Converts an absolute position of an item into a relative one.
996 * @public
997 * @param {Number} position - The absolute position to convert.
998 * @returns {Number} - The converted position.
999 */
1000 Owl.prototype.relative = function(position) {
1001 position -= this._clones.length / 2;
1002 return this.normalize(position, true);
1003 };
1004
1005 /**
1006 * Gets the maximum position for the current item.
1007 * @public
1008 * @param {Boolean} [relative=false] - Whether to return an absolute position or a relative position.
1009 * @returns {Number}
1010 */
1011 Owl.prototype.maximum = function(relative) {
1012 var settings = this.settings,
1013 maximum = this._coordinates.length,
1014 boundary = Math.abs(this._coordinates[maximum - 1]) - this._width,
1015 i = -1, j;
1016
1017 if (settings.loop) {
1018 maximum = this._clones.length / 2 + this._items.length - 1;
1019 } else if (settings.autoWidth || settings.merge) {
1020 // binary search
1021 while (maximum - i > 1) {
1022 Math.abs(this._coordinates[j = maximum + i >> 1]) < boundary
1023 ? i = j : maximum = j;
1024 }
1025 } else if (settings.center) {
1026 maximum = this._items.length - 1;
1027 } else {
1028 maximum = this._items.length - settings.items;
1029 }
1030
1031 if (relative) {
1032 maximum -= this._clones.length / 2;
1033 }
1034
1035 return Math.max(maximum, 0);
1036 };
1037
1038 /**
1039 * Gets the minimum position for the current item.
1040 * @public
1041 * @param {Boolean} [relative=false] - Whether to return an absolute position or a relative position.
1042 * @returns {Number}
1043 */
1044 Owl.prototype.minimum = function(relative) {
1045 return relative ? 0 : this._clones.length / 2;
1046 };
1047
1048 /**
1049 * Gets an item at the specified relative position.
1050 * @public
1051 * @param {Number} [position] - The relative position of the item.
1052 * @return {jQuery|Array.<jQuery>} - The item at the given position or all items if no position was given.
1053 */
1054 Owl.prototype.items = function(position) {
1055 if (position === undefined) {
1056 return this._items.slice();
1057 }
1058
1059 position = this.normalize(position, true);
1060 return this._items[position];
1061 };
1062
1063 /**
1064 * Gets an item at the specified relative position.
1065 * @public
1066 * @param {Number} [position] - The relative position of the item.
1067 * @return {jQuery|Array.<jQuery>} - The item at the given position or all items if no position was given.
1068 */
1069 Owl.prototype.mergers = function(position) {
1070 if (position === undefined) {
1071 return this._mergers.slice();
1072 }
1073
1074 position = this.normalize(position, true);
1075 return this._mergers[position];
1076 };
1077
1078 /**
1079 * Gets the absolute positions of clones for an item.
1080 * @public
1081 * @param {Number} [position] - The relative position of the item.
1082 * @returns {Array.<Number>} - The absolute positions of clones for the item or all if no position was given.
1083 */
1084 Owl.prototype.clones = function(position) {
1085 var odd = this._clones.length / 2,
1086 even = odd + this._items.length,
1087 map = function(index) { return index % 2 === 0 ? even + index / 2 : odd - (index + 1) / 2 };
1088
1089 if (position === undefined) {
1090 return $.map(this._clones, function(v, i) { return map(i) });
1091 }
1092
1093 return $.map(this._clones, function(v, i) { return v === position ? map(i) : null });
1094 };
1095
1096 /**
1097 * Sets the current animation speed.
1098 * @public
1099 * @param {Number} [speed] - The animation speed in milliseconds or nothing to leave it unchanged.
1100 * @returns {Number} - The current animation speed in milliseconds.
1101 */
1102 Owl.prototype.speed = function(speed) {
1103 if (speed !== undefined) {
1104 this._speed = speed;
1105 }
1106
1107 return this._speed;
1108 };
1109
1110 /**
1111 * Gets the coordinate of an item.
1112 * @todo The name of this method is missleanding.
1113 * @public
1114 * @param {Number} position - The absolute position of the item within `minimum()` and `maximum()`.
1115 * @returns {Number|Array.<Number>} - The coordinate of the item in pixel or all coordinates.
1116 */
1117 Owl.prototype.coordinates = function(position) {
1118 var coordinate = null;
1119
1120 if (position === undefined) {
1121 return $.map(this._coordinates, $.proxy(function(coordinate, index) {
1122 return this.coordinates(index);
1123 }, this));
1124 }
1125
1126 if (this.settings.center) {
1127 coordinate = this._coordinates[position];
1128 coordinate += (this.width() - coordinate + (this._coordinates[position - 1] || 0)) / 2 * (this.settings.rtl ? -1 : 1);
1129 } else {
1130 coordinate = this._coordinates[position - 1] || 0;
1131 }
1132
1133 return coordinate;
1134 };
1135
1136 /**
1137 * Calculates the speed for a translation.
1138 * @protected
1139 * @param {Number} from - The absolute position of the start item.
1140 * @param {Number} to - The absolute position of the target item.
1141 * @param {Number} [factor=undefined] - The time factor in milliseconds.
1142 * @returns {Number} - The time in milliseconds for the translation.
1143 */
1144 Owl.prototype.duration = function(from, to, factor) {
1145 return Math.min(Math.max(Math.abs(to - from), 1), 6) * Math.abs((factor || this.settings.smartSpeed));
1146 };
1147
1148 /**
1149 * Slides to the specified item.
1150 * @public
1151 * @param {Number} position - The position of the item.
1152 * @param {Number} [speed] - The time in milliseconds for the transition.
1153 */
1154 Owl.prototype.to = function(position, speed) {
1155 var current = this.current(),
1156 revert = null,
1157 distance = position - this.relative(current),
1158 direction = (distance > 0) - (distance < 0),
1159 items = this._items.length,
1160 minimum = this.minimum(),
1161 maximum = this.maximum();
1162
1163 if (this.settings.loop) {
1164 if (!this.settings.rewind && Math.abs(distance) > items / 2) {
1165 distance += direction * -1 * items;
1166 }
1167
1168 position = current + distance;
1169 revert = ((position - minimum) % items + items) % items + minimum;
1170
1171 if (revert !== position && revert - distance <= maximum && revert - distance > 0) {
1172 current = revert - distance;
1173 position = revert;
1174 this.reset(current);
1175 }
1176 } else if (this.settings.rewind) {
1177 maximum += 1;
1178 position = (position % maximum + maximum) % maximum;
1179 } else {
1180 position = Math.max(minimum, Math.min(maximum, position));
1181 }
1182
1183 this.speed(this.duration(current, position, speed));
1184 this.current(position);
1185
1186 if (this.$element.is(':visible')) {
1187 this.update();
1188 }
1189 };
1190
1191 /**
1192 * Slides to the next item.
1193 * @public
1194 * @param {Number} [speed] - The time in milliseconds for the transition.
1195 */
1196 Owl.prototype.next = function(speed) {
1197 speed = speed || false;
1198 this.to(this.relative(this.current()) + 1, speed);
1199 };
1200
1201 /**
1202 * Slides to the previous item.
1203 * @public
1204 * @param {Number} [speed] - The time in milliseconds for the transition.
1205 */
1206 Owl.prototype.prev = function(speed) {
1207 speed = speed || false;
1208 this.to(this.relative(this.current()) - 1, speed);
1209 };
1210
1211 /**
1212 * Handles the end of an animation.
1213 * @protected
1214 * @param {Event} event - The event arguments.
1215 */
1216 Owl.prototype.onTransitionEnd = function(event) {
1217
1218 // if css2 animation then event object is undefined
1219 if (event !== undefined) {
1220 event.stopPropagation();
1221
1222 // Catch only owl-stage transitionEnd event
1223 if ((event.target || event.srcElement || event.originalTarget) !== this.$stage.get(0)) {
1224 return false;
1225 }
1226 }
1227
1228 this.leave('animating');
1229 this.trigger('translated');
1230 };
1231
1232 /**
1233 * Gets viewport width.
1234 * @protected
1235 * @return {Number} - The width in pixel.
1236 */
1237 Owl.prototype.viewport = function() {
1238 var width;
1239 if (this.options.responsiveBaseElement !== window) {
1240 width = $(this.options.responsiveBaseElement).width();
1241 } else if (window.innerWidth) {
1242 width = window.innerWidth;
1243 } else if (document.documentElement && document.documentElement.clientWidth) {
1244 width = document.documentElement.clientWidth;
1245 } else {
1246 throw 'Can not detect viewport width.';
1247 }
1248 return width;
1249 };
1250
1251 /**
1252 * Replaces the current content.
1253 * @public
1254 * @param {HTMLElement|jQuery|String} content - The new content.
1255 */
1256 Owl.prototype.replace = function(content) {
1257 this.$stage.empty();
1258 this._items = [];
1259
1260 if (content) {
1261 content = (content instanceof jQuery) ? content : $(content);
1262 }
1263
1264 if (this.settings.nestedItemSelector) {
1265 content = content.find('.' + this.settings.nestedItemSelector);
1266 }
1267
1268 content.filter(function() {
1269 return this.nodeType === 1;
1270 }).each($.proxy(function(index, item) {
1271 item = this.prepare(item);
1272 this.$stage.append(item);
1273 this._items.push(item);
1274 this._mergers.push(item.find('[data-merge]').andSelf('[data-merge]').attr('data-merge') * 1 || 1);
1275 }, this));
1276
1277 this.reset($.isNumeric(this.settings.startPosition) ? this.settings.startPosition : 0);
1278
1279 this.invalidate('items');
1280 };
1281
1282 /**
1283 * Adds an item.
1284 * @todo Use `item` instead of `content` for the event arguments.
1285 * @public
1286 * @param {HTMLElement|jQuery|String} content - The item content to add.
1287 * @param {Number} [position] - The relative position at which to insert the item otherwise the item will be added to the end.
1288 */
1289 Owl.prototype.add = function(content, position) {
1290 var current = this.relative(this._current);
1291
1292 position = position === undefined ? this._items.length : this.normalize(position, true);
1293 content = content instanceof jQuery ? content : $(content);
1294
1295 this.trigger('add', { content: content, position: position });
1296
1297 content = this.prepare(content);
1298
1299 if (this._items.length === 0 || position === this._items.length) {
1300 this._items.length === 0 && this.$stage.append(content);
1301 this._items.length !== 0 && this._items[position - 1].after(content);
1302 this._items.push(content);
1303 this._mergers.push(content.find('[data-merge]').andSelf('[data-merge]').attr('data-merge') * 1 || 1);
1304 } else {
1305 this._items[position].before(content);
1306 this._items.splice(position, 0, content);
1307 this._mergers.splice(position, 0, content.find('[data-merge]').andSelf('[data-merge]').attr('data-merge') * 1 || 1);
1308 }
1309
1310 this._items[current] && this.reset(this._items[current].index());
1311
1312 this.invalidate('items');
1313
1314 this.trigger('added', { content: content, position: position });
1315 };
1316
1317 /**
1318 * Removes an item by its position.
1319 * @todo Use `item` instead of `content` for the event arguments.
1320 * @public
1321 * @param {Number} position - The relative position of the item to remove.
1322 */
1323 Owl.prototype.remove = function(position) {
1324 position = this.normalize(position, true);
1325
1326 if (position === undefined) {
1327 return;
1328 }
1329
1330 this.trigger('remove', { content: this._items[position], position: position });
1331
1332 this._items[position].remove();
1333 this._items.splice(position, 1);
1334 this._mergers.splice(position, 1);
1335
1336 this.invalidate('items');
1337
1338 this.trigger('removed', { content: null, position: position });
1339 };
1340
1341 /**
1342 * Preloads images with auto width.
1343 * @todo Replace by a more generic approach
1344 * @protected
1345 */
1346 Owl.prototype.preloadAutoWidthImages = function(images) {
1347 images.each($.proxy(function(i, element) {
1348 this.enter('pre-loading');
1349 element = $(element);
1350 $(new Image()).one('load', $.proxy(function(e) {
1351 element.attr('src', e.target.src);
1352 element.css('opacity', 1);
1353 this.leave('pre-loading');
1354 !this.is('pre-loading') && !this.is('initializing') && this.refresh();
1355 }, this)).attr('src', element.attr('src') || element.attr('data-src') || element.attr('data-src-retina'));
1356 }, this));
1357 };
1358
1359 /**
1360 * Destroys the carousel.
1361 * @public
1362 */
1363 Owl.prototype.destroy = function() {
1364
1365 this.$element.off('.owl.core');
1366 this.$stage.off('.owl.core');
1367 $(document).off('.owl.core');
1368
1369 if (this.settings.responsive !== false) {
1370 window.clearTimeout(this.resizeTimer);
1371 this.off(window, 'resize', this._handlers.onThrottledResize);
1372 }
1373
1374 for (var i in this._plugins) {
1375 this._plugins[i].destroy();
1376 }
1377
1378 this.$stage.children('.cloned').remove();
1379
1380 this.$stage.unwrap();
1381 this.$stage.children().contents().unwrap();
1382 this.$stage.children().unwrap();
1383
1384 this.$element
1385 .removeClass(this.options.refreshClass)
1386 .removeClass(this.options.loadingClass)
1387 .removeClass(this.options.loadedClass)
1388 .removeClass(this.options.rtlClass)
1389 .removeClass(this.options.dragClass)
1390 .removeClass(this.options.grabClass)
1391 .attr('class', this.$element.attr('class').replace(new RegExp(this.options.responsiveClass + '-\\S+\\s', 'g'), ''))
1392 .removeData('owl.carousel');
1393 };
1394
1395 /**
1396 * Operators to calculate right-to-left and left-to-right.
1397 * @protected
1398 * @param {Number} [a] - The left side operand.
1399 * @param {String} [o] - The operator.
1400 * @param {Number} [b] - The right side operand.
1401 */
1402 Owl.prototype.op = function(a, o, b) {
1403 var rtl = this.settings.rtl;
1404 switch (o) {
1405 case '<':
1406 return rtl ? a > b : a < b;
1407 case '>':
1408 return rtl ? a < b : a > b;
1409 case '>=':
1410 return rtl ? a <= b : a >= b;
1411 case '<=':
1412 return rtl ? a >= b : a <= b;
1413 default:
1414 break;
1415 }
1416 };
1417
1418 /**
1419 * Attaches to an internal event.
1420 * @protected
1421 * @param {HTMLElement} element - The event source.
1422 * @param {String} event - The event name.
1423 * @param {Function} listener - The event handler to attach.
1424 * @param {Boolean} capture - Wether the event should be handled at the capturing phase or not.
1425 */
1426 Owl.prototype.on = function(element, event, listener, capture) {
1427 if (element.addEventListener) {
1428 element.addEventListener(event, listener, capture);
1429 } else if (element.attachEvent) {
1430 element.attachEvent('on' + event, listener);
1431 }
1432 };
1433
1434 /**
1435 * Detaches from an internal event.
1436 * @protected
1437 * @param {HTMLElement} element - The event source.
1438 * @param {String} event - The event name.
1439 * @param {Function} listener - The attached event handler to detach.
1440 * @param {Boolean} capture - Wether the attached event handler was registered as a capturing listener or not.
1441 */
1442 Owl.prototype.off = function(element, event, listener, capture) {
1443 if (element.removeEventListener) {
1444 element.removeEventListener(event, listener, capture);
1445 } else if (element.detachEvent) {
1446 element.detachEvent('on' + event, listener);
1447 }
1448 };
1449
1450 /**
1451 * Triggers a public event.
1452 * @todo Remove `status`, `relatedTarget` should be used instead.
1453 * @protected
1454 * @param {String} name - The event name.
1455 * @param {*} [data=null] - The event data.
1456 * @param {String} [namespace=carousel] - The event namespace.
1457 * @param {String} [state] - The state which is associated with the event.
1458 * @param {Boolean} [enter=false] - Indicates if the call enters the specified state or not.
1459 * @returns {Event} - The event arguments.
1460 */
1461 Owl.prototype.trigger = function(name, data, namespace, state, enter) {
1462 var status = {
1463 item: { count: this._items.length, index: this.current() }
1464 }, handler = $.camelCase(
1465 $.grep([ 'on', name, namespace ], function(v) { return v })
1466 .join('-').toLowerCase()
1467 ), event = $.Event(
1468 [ name, 'owl', namespace || 'carousel' ].join('.').toLowerCase(),
1469 $.extend({ relatedTarget: this }, status, data)
1470 );
1471
1472 if (!this._supress[name]) {
1473 $.each(this._plugins, function(name, plugin) {
1474 if (plugin.onTrigger) {
1475 plugin.onTrigger(event);
1476 }
1477 });
1478
1479 this.register({ type: Owl.Type.Event, name: name });
1480 this.$element.trigger(event);
1481
1482 if (this.settings && typeof this.settings[handler] === 'function') {
1483 this.settings[handler].call(this, event);
1484 }
1485 }
1486
1487 return event;
1488 };
1489
1490 /**
1491 * Enters a state.
1492 * @param name - The state name.
1493 */
1494 Owl.prototype.enter = function(name) {
1495 $.each([ name ].concat(this._states.tags[name] || []), $.proxy(function(i, name) {
1496 if (this._states.current[name] === undefined) {
1497 this._states.current[name] = 0;
1498 }
1499
1500 this._states.current[name]++;
1501 }, this));
1502 };
1503
1504 /**
1505 * Leaves a state.
1506 * @param name - The state name.
1507 */
1508 Owl.prototype.leave = function(name) {
1509 $.each([ name ].concat(this._states.tags[name] || []), $.proxy(function(i, name) {
1510 this._states.current[name]--;
1511 }, this));
1512 };
1513
1514 /**
1515 * Registers an event or state.
1516 * @public
1517 * @param {Object} object - The event or state to register.
1518 */
1519 Owl.prototype.register = function(object) {
1520 if (object.type === Owl.Type.Event) {
1521 if (!$.event.special[object.name]) {
1522 $.event.special[object.name] = {};
1523 }
1524
1525 if (!$.event.special[object.name].owl) {
1526 var _default = $.event.special[object.name]._default;
1527 $.event.special[object.name]._default = function(e) {
1528 if (_default && _default.apply && (!e.namespace || e.namespace.indexOf('owl') === -1)) {
1529 return _default.apply(this, arguments);
1530 }
1531 return e.namespace && e.namespace.indexOf('owl') > -1;
1532 };
1533 $.event.special[object.name].owl = true;
1534 }
1535 } else if (object.type === Owl.Type.State) {
1536 if (!this._states.tags[object.name]) {
1537 this._states.tags[object.name] = object.tags;
1538 } else {
1539 this._states.tags[object.name] = this._states.tags[object.name].concat(object.tags);
1540 }
1541
1542 this._states.tags[object.name] = $.grep(this._states.tags[object.name], $.proxy(function(tag, i) {
1543 return $.inArray(tag, this._states.tags[object.name]) === i;
1544 }, this));
1545 }
1546 };
1547
1548 /**
1549 * Suppresses events.
1550 * @protected
1551 * @param {Array.<String>} events - The events to suppress.
1552 */
1553 Owl.prototype.suppress = function(events) {
1554 $.each(events, $.proxy(function(index, event) {
1555 this._supress[event] = true;
1556 }, this));
1557 };
1558
1559 /**
1560 * Releases suppressed events.
1561 * @protected
1562 * @param {Array.<String>} events - The events to release.
1563 */
1564 Owl.prototype.release = function(events) {
1565 $.each(events, $.proxy(function(index, event) {
1566 delete this._supress[event];
1567 }, this));
1568 };
1569
1570 /**
1571 * Gets unified pointer coordinates from event.
1572 * @todo #261
1573 * @protected
1574 * @param {Event} - The `mousedown` or `touchstart` event.
1575 * @returns {Object} - Contains `x` and `y` coordinates of current pointer position.
1576 */
1577 Owl.prototype.pointer = function(event) {
1578 var result = { x: null, y: null };
1579
1580 event = event.originalEvent || event || window.event;
1581
1582 event = event.touches && event.touches.length ?
1583 event.touches[0] : event.changedTouches && event.changedTouches.length ?
1584 event.changedTouches[0] : event;
1585
1586 if (event.pageX) {
1587 result.x = event.pageX;
1588 result.y = event.pageY;
1589 } else {
1590 result.x = event.clientX;
1591 result.y = event.clientY;
1592 }
1593
1594 return result;
1595 };
1596
1597 /**
1598 * Gets the difference of two vectors.
1599 * @todo #261
1600 * @protected
1601 * @param {Object} - The first vector.
1602 * @param {Object} - The second vector.
1603 * @returns {Object} - The difference.
1604 */
1605 Owl.prototype.difference = function(first, second) {
1606 return {
1607 x: first.x - second.x,
1608 y: first.y - second.y
1609 };
1610 };
1611
1612 /**
1613 * The jQuery Plugin for the Owl Carousel
1614 * @todo Navigation plugin `next` and `prev`
1615 * @public
1616 */
1617 $.fn.owlCarousel = function(option) {
1618 var args = Array.prototype.slice.call(arguments, 1);
1619
1620 return this.each(function() {
1621 var $this = $(this),
1622 data = $this.data('owl.carousel');
1623
1624 if (!data) {
1625 data = new Owl(this, typeof option == 'object' && option);
1626 $this.data('owl.carousel', data);
1627
1628 $.each([
1629 'next', 'prev', 'to', 'destroy', 'refresh', 'replace', 'add', 'remove'
1630 ], function(i, event) {
1631 data.register({ type: Owl.Type.Event, name: event });
1632 data.$element.on(event + '.owl.carousel.core', $.proxy(function(e) {
1633 if (e.namespace && e.relatedTarget !== this) {
1634 this.suppress([ event ]);
1635 data[event].apply(this, [].slice.call(arguments, 1));
1636 this.release([ event ]);
1637 }
1638 }, data));
1639 });
1640 }
1641
1642 if (typeof option == 'string' && option.charAt(0) !== '_') {
1643 data[option].apply(data, args);
1644 }
1645 });
1646 };
1647
1648 /**
1649 * The constructor for the jQuery Plugin
1650 * @public
1651 */
1652 $.fn.owlCarousel.Constructor = Owl;
1653
1654 })(window.Zepto || window.jQuery, window, document);
1655
1656 /**
1657 * AutoRefresh Plugin
1658 * @version 2.0.0-beta.3
1659 * @author Artus Kolanowski
1660 * @license The MIT License (MIT)
1661 */
1662 ;(function($, window, document, undefined) {
1663
1664 /**
1665 * Creates the auto refresh plugin.
1666 * @class The Auto Refresh Plugin
1667 * @param {Owl} carousel - The Owl Carousel
1668 */
1669 var AutoRefresh = function(carousel) {
1670 /**
1671 * Reference to the core.
1672 * @protected
1673 * @type {Owl}
1674 */
1675 this._core = carousel;
1676
1677 /**
1678 * Refresh interval.
1679 * @protected
1680 * @type {number}
1681 */
1682 this._interval = null;
1683
1684 /**
1685 * Whether the element is currently visible or not.
1686 * @protected
1687 * @type {Boolean}
1688 */
1689 this._visible = null;
1690
1691 /**
1692 * All event handlers.
1693 * @protected
1694 * @type {Object}
1695 */
1696 this._handlers = {
1697 'initialized.owl.carousel': $.proxy(function(e) {
1698 if (e.namespace && this._core.settings.autoRefresh) {
1699 this.watch();
1700 }
1701 }, this)
1702 };
1703
1704 // set default options
1705 this._core.options = $.extend({}, AutoRefresh.Defaults, this._core.options);
1706
1707 // register event handlers
1708 this._core.$element.on(this._handlers);
1709 };
1710
1711 /**
1712 * Default options.
1713 * @public
1714 */
1715 AutoRefresh.Defaults = {
1716 autoRefresh: true,
1717 autoRefreshInterval: 500
1718 };
1719
1720 /**
1721 * Watches the element.
1722 */
1723 AutoRefresh.prototype.watch = function() {
1724 if (this._interval) {
1725 return;
1726 }
1727
1728 this._visible = this._core.$element.is(':visible');
1729 this._interval = window.setInterval($.proxy(this.refresh, this), this._core.settings.autoRefreshInterval);
1730 };
1731
1732 /**
1733 * Refreshes the element.
1734 */
1735 AutoRefresh.prototype.refresh = function() {
1736 if (this._core.$element.is(':visible') === this._visible) {
1737 return;
1738 }
1739
1740 this._visible = !this._visible;
1741
1742 this._core.$element.toggleClass('owl-hidden', !this._visible);
1743
1744 this._visible && (this._core.invalidate('width') && this._core.refresh());
1745 };
1746
1747 /**
1748 * Destroys the plugin.
1749 */
1750 AutoRefresh.prototype.destroy = function() {
1751 var handler, property;
1752
1753 window.clearInterval(this._interval);
1754
1755 for (handler in this._handlers) {
1756 this._core.$element.off(handler, this._handlers[handler]);
1757 }
1758 for (property in Object.getOwnPropertyNames(this)) {
1759 typeof this[property] != 'function' && (this[property] = null);
1760 }
1761 };
1762
1763 $.fn.owlCarousel.Constructor.Plugins.AutoRefresh = AutoRefresh;
1764
1765 })(window.Zepto || window.jQuery, window, document);
1766
1767 /**
1768 * Lazy Plugin
1769 * @version 2.0.0-beta.3
1770 * @author Bartosz Wojciechowski
1771 * @license The MIT License (MIT)
1772 */
1773 ;(function($, window, document, undefined) {
1774
1775 /**
1776 * Creates the lazy plugin.
1777 * @class The Lazy Plugin
1778 * @param {Owl} carousel - The Owl Carousel
1779 */
1780 var Lazy = function(carousel) {
1781
1782 /**
1783 * Reference to the core.
1784 * @protected
1785 * @type {Owl}
1786 */
1787 this._core = carousel;
1788
1789 /**
1790 * Already loaded items.
1791 * @protected
1792 * @type {Array.<jQuery>}
1793 */
1794 this._loaded = [];
1795
1796 /**
1797 * Event handlers.
1798 * @protected
1799 * @type {Object}
1800 */
1801 this._handlers = {
1802 'initialized.owl.carousel change.owl.carousel': $.proxy(function(e) {
1803 if (!e.namespace) {
1804 return;
1805 }
1806
1807 if (!this._core.settings || !this._core.settings.lazyLoad) {
1808 return;
1809 }
1810
1811 if ((e.property && e.property.name == 'position') || e.type == 'initialized') {
1812 var settings = this._core.settings,
1813 n = (settings.center && Math.ceil(settings.items / 2) || settings.items),
1814 i = ((settings.center && n * -1) || 0),
1815 position = ((e.property && e.property.value) || this._core.current()) + i,
1816 clones = this._core.clones().length,
1817 load = $.proxy(function(i, v) { this.load(v) }, this);
1818
1819 while (i++ < n) {
1820 this.load(clones / 2 + this._core.relative(position));
1821 clones && $.each(this._core.clones(this._core.relative(position)), load);
1822 position++;
1823 }
1824 }
1825 }, this)
1826 };
1827
1828 // set the default options
1829 this._core.options = $.extend({}, Lazy.Defaults, this._core.options);
1830
1831 // register event handler
1832 this._core.$element.on(this._handlers);
1833 }
1834
1835 /**
1836 * Default options.
1837 * @public
1838 */
1839 Lazy.Defaults = {
1840 lazyLoad: false
1841 }
1842
1843 /**
1844 * Loads all resources of an item at the specified position.
1845 * @param {Number} position - The absolute position of the item.
1846 * @protected
1847 */
1848 Lazy.prototype.load = function(position) {
1849 var $item = this._core.$stage.children().eq(position),
1850 $elements = $item && $item.find('.owl-lazy');
1851
1852 if (!$elements || $.inArray($item.get(0), this._loaded) > -1) {
1853 return;
1854 }
1855
1856 $elements.each($.proxy(function(index, element) {
1857 var $element = $(element), image,
1858 url = (window.devicePixelRatio > 1 && $element.attr('data-src-retina')) || $element.attr('data-src');
1859
1860 this._core.trigger('load', { element: $element, url: url }, 'lazy');
1861
1862 if ($element.is('img')) {
1863 $element.one('load.owl.lazy', $.proxy(function() {
1864 $element.css('opacity', 1);
1865 this._core.trigger('loaded', { element: $element, url: url }, 'lazy');
1866 }, this)).attr('src', url);
1867 } else {
1868 image = new Image();
1869 image.onload = $.proxy(function() {
1870 $element.css({
1871 'background-image': 'url(' + url + ')',
1872 'opacity': '1'
1873 });
1874 this._core.trigger('loaded', { element: $element, url: url }, 'lazy');
1875 }, this);
1876 image.src = url;
1877 }
1878 }, this));
1879
1880 this._loaded.push($item.get(0));
1881 }
1882
1883 /**
1884 * Destroys the plugin.
1885 * @public
1886 */
1887 Lazy.prototype.destroy = function() {
1888 var handler, property;
1889
1890 for (handler in this.handlers) {
1891 this._core.$element.off(handler, this.handlers[handler]);
1892 }
1893 for (property in Object.getOwnPropertyNames(this)) {
1894 typeof this[property] != 'function' && (this[property] = null);
1895 }
1896 };
1897
1898 $.fn.owlCarousel.Constructor.Plugins.Lazy = Lazy;
1899
1900 })(window.Zepto || window.jQuery, window, document);
1901
1902 /**
1903 * AutoHeight Plugin
1904 * @version 2.0.0-beta.3
1905 * @author Bartosz Wojciechowski
1906 * @license The MIT License (MIT)
1907 */
1908 ;(function($, window, document, undefined) {
1909
1910 /**
1911 * Creates the auto height plugin.
1912 * @class The Auto Height Plugin
1913 * @param {Owl} carousel - The Owl Carousel
1914 */
1915 var AutoHeight = function(carousel) {
1916 /**
1917 * Reference to the core.
1918 * @protected
1919 * @type {Owl}
1920 */
1921 this._core = carousel;
1922
1923 /**
1924 * All event handlers.
1925 * @protected
1926 * @type {Object}
1927 */
1928 this._handlers = {
1929 'initialized.owl.carousel refreshed.owl.carousel': $.proxy(function(e) {
1930 if (e.namespace && this._core.settings.autoHeight) {
1931 this.update();
1932 }
1933 }, this),
1934 'changed.owl.carousel': $.proxy(function(e) {
1935 if (e.namespace && this._core.settings.autoHeight && e.property.name == 'position'){
1936 this.update();
1937 }
1938 }, this),
1939 'loaded.owl.lazy': $.proxy(function(e) {
1940 if (e.namespace && this._core.settings.autoHeight
1941 && e.element.closest('.' + this._core.settings.itemClass).index() === this._core.current()) {
1942 this.update();
1943 }
1944 }, this)
1945 };
1946
1947 // set default options
1948 this._core.options = $.extend({}, AutoHeight.Defaults, this._core.options);
1949
1950 // register event handlers
1951 this._core.$element.on(this._handlers);
1952 };
1953
1954 /**
1955 * Default options.
1956 * @public
1957 */
1958 AutoHeight.Defaults = {
1959 autoHeight: false,
1960 autoHeightClass: 'owl-height'
1961 };
1962
1963 /**
1964 * Updates the view.
1965 */
1966 AutoHeight.prototype.update = function() {
1967 var start = this._core._current,
1968 end = start + this._core.settings.items,
1969 visible = this._core.$stage.children().toArray().slice(start, end);
1970 heights = [],
1971 maxheight = 0;
1972
1973 $.each(visible, function(index, item) {
1974 heights.push($(item).height());
1975 });
1976
1977 maxheight = Math.max.apply(null, heights);
1978
1979 this._core.$stage.parent()
1980 .height(maxheight)
1981 .addClass(this._core.settings.autoHeightClass);
1982 };
1983
1984 AutoHeight.prototype.destroy = function() {
1985 var handler, property;
1986
1987 for (handler in this._handlers) {
1988 this._core.$element.off(handler, this._handlers[handler]);
1989 }
1990 for (property in Object.getOwnPropertyNames(this)) {
1991 typeof this[property] != 'function' && (this[property] = null);
1992 }
1993 };
1994
1995 $.fn.owlCarousel.Constructor.Plugins.AutoHeight = AutoHeight;
1996
1997 })(window.Zepto || window.jQuery, window, document);
1998
1999 /**
2000 * Video Plugin
2001 * @version 2.0.0-beta.3
2002 * @author Bartosz Wojciechowski
2003 * @license The MIT License (MIT)
2004 */
2005 ;(function($, window, document, undefined) {
2006
2007 /**
2008 * Creates the video plugin.
2009 * @class The Video Plugin
2010 * @param {Owl} carousel - The Owl Carousel
2011 */
2012 var Video = function(carousel) {
2013 /**
2014 * Reference to the core.
2015 * @protected
2016 * @type {Owl}
2017 */
2018 this._core = carousel;
2019
2020 /**
2021 * Cache all video URLs.
2022 * @protected
2023 * @type {Object}
2024 */
2025 this._videos = {};
2026
2027 /**
2028 * Current playing item.
2029 * @protected
2030 * @type {jQuery}
2031 */
2032 this._playing = null;
2033
2034 /**
2035 * All event handlers.
2036 * @todo The cloned content removale is too late
2037 * @protected
2038 * @type {Object}
2039 */
2040 this._handlers = {
2041 'initialized.owl.carousel': $.proxy(function(e) {
2042 if (e.namespace) {
2043 this._core.register({ type: 'state', name: 'playing', tags: [ 'interacting' ] });
2044 }
2045 }, this),
2046 'resize.owl.carousel': $.proxy(function(e) {
2047 if (e.namespace && this._core.settings.video && this.isInFullScreen()) {
2048 e.preventDefault();
2049 }
2050 }, this),
2051 'refreshed.owl.carousel': $.proxy(function(e) {
2052 if (e.namespace && this._core.is('resizing')) {
2053 this._core.$stage.find('.cloned .owl-video-frame').remove();
2054 }
2055 }, this),
2056 'changed.owl.carousel': $.proxy(function(e) {
2057 if (e.namespace && e.property.name === 'position' && this._playing) {
2058 this.stop();
2059 }
2060 }, this),
2061 'prepared.owl.carousel': $.proxy(function(e) {
2062 if (!e.namespace) {
2063 return;
2064 }
2065
2066 var $element = $(e.content).find('.owl-video');
2067
2068 if ($element.length) {
2069 $element.css('display', 'none');
2070 this.fetch($element, $(e.content));
2071 }
2072 }, this)
2073 };
2074
2075 // set default options
2076 this._core.options = $.extend({}, Video.Defaults, this._core.options);
2077
2078 // register event handlers
2079 this._core.$element.on(this._handlers);
2080
2081 this._core.$element.on('click.owl.video', '.owl-video-play-icon', $.proxy(function(e) {
2082 this.play(e);
2083 }, this));
2084 };
2085
2086 /**
2087 * Default options.
2088 * @public
2089 */
2090 Video.Defaults = {
2091 video: false,
2092 videoHeight: false,
2093 videoWidth: false
2094 };
2095
2096 /**
2097 * Gets the video ID and the type (YouTube/Vimeo only).
2098 * @protected
2099 * @param {jQuery} target - The target containing the video data.
2100 * @param {jQuery} item - The item containing the video.
2101 */
2102 Video.prototype.fetch = function(target, item) {
2103 var type = target.attr('data-vimeo-id') ? 'vimeo' : 'youtube',
2104 id = target.attr('data-vimeo-id') || target.attr('data-youtube-id'),
2105 width = target.attr('data-width') || this._core.settings.videoWidth,
2106 height = target.attr('data-height') || this._core.settings.videoHeight,
2107 url = target.attr('href');
2108
2109 if (url) {
2110 id = url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?/);
2111
2112 if (id[3].indexOf('youtu') > -1) {
2113 type = 'youtube';
2114 } else if (id[3].indexOf('vimeo') > -1) {
2115 type = 'vimeo';
2116 } else {
2117 throw new Error('Video URL not supported.');
2118 }
2119 id = id[6];
2120 } else {
2121 throw new Error('Missing video URL.');
2122 }
2123
2124 this._videos[url] = {
2125 type: type,
2126 id: id,
2127 width: width,
2128 height: height
2129 };
2130
2131 item.attr('data-video', url);
2132
2133 this.thumbnail(target, this._videos[url]);
2134 };
2135
2136 /**
2137 * Creates video thumbnail.
2138 * @protected
2139 * @param {jQuery} target - The target containing the video data.
2140 * @param {Object} info - The video info object.
2141 * @see `fetch`
2142 */
2143 Video.prototype.thumbnail = function(target, video) {
2144 var tnLink,
2145 icon,
2146 path,
2147 dimensions = video.width && video.height ? 'style="width:' + video.width + 'px;height:' + video.height + 'px;"' : '',
2148 customTn = target.find('img'),
2149 srcType = 'src',
2150 lazyClass = '',
2151 settings = this._core.settings,
2152 create = function(path) {
2153 icon = '<div class="owl-video-play-icon"></div>';
2154
2155 if (settings.lazyLoad) {
2156 tnLink = '<div class="owl-video-tn ' + lazyClass + '" ' + srcType + '="' + path + '"></div>';
2157 } else {
2158 tnLink = '<div class="owl-video-tn" style="opacity:1;background-image:url(' + path + ')"></div>';
2159 }
2160 target.after(tnLink);
2161 target.after(icon);
2162 };
2163
2164 // wrap video content into owl-video-wrapper div
2165 target.wrap('<div class="owl-video-wrapper"' + dimensions + '></div>');
2166
2167 if (this._core.settings.lazyLoad) {
2168 srcType = 'data-src';
2169 lazyClass = 'owl-lazy';
2170 }
2171
2172 // custom thumbnail
2173 if (customTn.length) {
2174 create(customTn.attr(srcType));
2175 customTn.remove();
2176 return false;
2177 }
2178
2179 if (video.type === 'youtube') {
2180 path = "http://img.youtube.com/vi/" + video.id + "/hqdefault.jpg";
2181 create(path);
2182 } else if (video.type === 'vimeo') {
2183 $.ajax({
2184 type: 'GET',
2185 url: 'http://vimeo.com/api/v2/video/' + video.id + '.json',
2186 jsonp: 'callback',
2187 dataType: 'jsonp',
2188 success: function(data) {
2189 path = data[0].thumbnail_large;
2190 create(path);
2191 }
2192 });
2193 }
2194 };
2195
2196 /**
2197 * Stops the current video.
2198 * @public
2199 */
2200 Video.prototype.stop = function() {
2201 this._core.trigger('stop', null, 'video');
2202 this._playing.find('.owl-video-frame').remove();
2203 this._playing.removeClass('owl-video-playing');
2204 this._playing = null;
2205 this._core.leave('playing');
2206 this._core.trigger('stopped', null, 'video');
2207 };
2208
2209 /**
2210 * Starts the current video.
2211 * @public
2212 * @param {Event} event - The event arguments.
2213 */
2214 Video.prototype.play = function(event) {
2215 var target = $(event.target),
2216 item = target.closest('.' + this._core.settings.itemClass),
2217 video = this._videos[item.attr('data-video')],
2218 width = video.width || '100%',
2219 height = video.height || this._core.$stage.height(),
2220 html;
2221
2222 if (this._playing) {
2223 return;
2224 }
2225
2226 this._core.enter('playing');
2227 this._core.trigger('play', null, 'video');
2228
2229 item = this._core.items(this._core.relative(item.index()));
2230
2231 this._core.reset(item.index());
2232
2233 if (video.type === 'youtube') {
2234 html = '<iframe width="' + width + '" height="' + height + '" src="http://www.youtube.com/embed/' +
2235 video.id + '?autoplay=1&v=' + video.id + '" frameborder="0" allowfullscreen></iframe>';
2236 } else if (video.type === 'vimeo') {
2237 html = '<iframe src="http://player.vimeo.com/video/' + video.id +
2238 '?autoplay=1" width="' + width + '" height="' + height +
2239 '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
2240 }
2241
2242 $('<div class="owl-video-frame">' + html + '</div>').insertAfter(item.find('.owl-video'));
2243
2244 this._playing = item.addClass('owl-video-playing');
2245 };
2246
2247 /**
2248 * Checks whether an video is currently in full screen mode or not.
2249 * @todo Bad style because looks like a readonly method but changes members.
2250 * @protected
2251 * @returns {Boolean}
2252 */
2253 Video.prototype.isInFullScreen = function() {
2254 var element = document.fullscreenElement || document.mozFullScreenElement ||
2255 document.webkitFullscreenElement;
2256
2257 return element && $(element).parent().hasClass('owl-video-frame');
2258 };
2259
2260 /**
2261 * Destroys the plugin.
2262 */
2263 Video.prototype.destroy = function() {
2264 var handler, property;
2265
2266 this._core.$element.off('click.owl.video');
2267
2268 for (handler in this._handlers) {
2269 this._core.$element.off(handler, this._handlers[handler]);
2270 }
2271 for (property in Object.getOwnPropertyNames(this)) {
2272 typeof this[property] != 'function' && (this[property] = null);
2273 }
2274 };
2275
2276 $.fn.owlCarousel.Constructor.Plugins.Video = Video;
2277
2278 })(window.Zepto || window.jQuery, window, document);
2279
2280 /**
2281 * Animate Plugin
2282 * @version 2.0.0-beta.3
2283 * @author Bartosz Wojciechowski
2284 * @license The MIT License (MIT)
2285 */
2286 ;(function($, window, document, undefined) {
2287
2288 /**
2289 * Creates the animate plugin.
2290 * @class The Navigation Plugin
2291 * @param {Owl} scope - The Owl Carousel
2292 */
2293 var Animate = function(scope) {
2294 this.core = scope;
2295 this.core.options = $.extend({}, Animate.Defaults, this.core.options);
2296 this.swapping = true;
2297 this.previous = undefined;
2298 this.next = undefined;
2299
2300 this.handlers = {
2301 'change.owl.carousel': $.proxy(function(e) {
2302 if (e.namespace && e.property.name == 'position') {
2303 this.previous = this.core.current();
2304 this.next = e.property.value;
2305 }
2306 }, this),
2307 'drag.owl.carousel dragged.owl.carousel translated.owl.carousel': $.proxy(function(e) {
2308 if (e.namespace) {
2309 this.swapping = e.type == 'translated';
2310 }
2311 }, this),
2312 'translate.owl.carousel': $.proxy(function(e) {
2313 if (e.namespace && this.swapping && (this.core.options.animateOut || this.core.options.animateIn)) {
2314 this.swap();
2315 }
2316 }, this)
2317 };
2318
2319 this.core.$element.on(this.handlers);
2320 };
2321
2322 /**
2323 * Default options.
2324 * @public
2325 */
2326 Animate.Defaults = {
2327 animateOut: false,
2328 animateIn: false
2329 };
2330
2331 /**
2332 * Toggles the animation classes whenever an translations starts.
2333 * @protected
2334 * @returns {Boolean|undefined}
2335 */
2336 Animate.prototype.swap = function() {
2337
2338 if (this.core.settings.items !== 1) {
2339 return;
2340 }
2341
2342 if (!$.support.animation || !$.support.transition) {
2343 return;
2344 }
2345
2346 this.core.speed(0);
2347
2348 var left,
2349 clear = $.proxy(this.clear, this),
2350 previous = this.core.$stage.children().eq(this.previous),
2351 next = this.core.$stage.children().eq(this.next),
2352 incoming = this.core.settings.animateIn,
2353 outgoing = this.core.settings.animateOut;
2354
2355 if (this.core.current() === this.previous) {
2356 return;
2357 }
2358
2359 if (outgoing) {
2360 left = this.core.coordinates(this.previous) - this.core.coordinates(this.next);
2361 previous.one($.support.animation.end, clear)
2362 .css( { 'left': left + 'px' } )
2363 .addClass('animated owl-animated-out')
2364 .addClass(outgoing);
2365 }
2366
2367 if (incoming) {
2368 next.one($.support.animation.end, clear)
2369 .addClass('animated owl-animated-in')
2370 .addClass(incoming);
2371 }
2372 };
2373
2374 Animate.prototype.clear = function(e) {
2375 $(e.target).css( { 'left': '' } )
2376 .removeClass('animated owl-animated-out owl-animated-in')
2377 .removeClass(this.core.settings.animateIn)
2378 .removeClass(this.core.settings.animateOut);
2379 this.core.onTransitionEnd();
2380 };
2381
2382 /**
2383 * Destroys the plugin.
2384 * @public
2385 */
2386 Animate.prototype.destroy = function() {
2387 var handler, property;
2388
2389 for (handler in this.handlers) {
2390 this.core.$element.off(handler, this.handlers[handler]);
2391 }
2392 for (property in Object.getOwnPropertyNames(this)) {
2393 typeof this[property] != 'function' && (this[property] = null);
2394 }
2395 };
2396
2397 $.fn.owlCarousel.Constructor.Plugins.Animate = Animate;
2398
2399 })(window.Zepto || window.jQuery, window, document);
2400
2401 /**
2402 * Autoplay Plugin
2403 * @version 2.0.0-beta.3
2404 * @author Bartosz Wojciechowski
2405 * @author Artus Kolanowski
2406 * @license The MIT License (MIT)
2407 */
2408 ;(function($, window, document, undefined) {
2409
2410 /**
2411 * Creates the autoplay plugin.
2412 * @class The Autoplay Plugin
2413 * @param {Owl} scope - The Owl Carousel
2414 */
2415 var Autoplay = function(carousel) {
2416 /**
2417 * Reference to the core.
2418 * @protected
2419 * @type {Owl}
2420 */
2421 this._core = carousel;
2422
2423 /**
2424 * The autoplay interval.
2425 * @type {Number}
2426 */
2427 this._interval = null;
2428
2429 /**
2430 * Indicates whenever the autoplay is paused.
2431 * @type {Boolean}
2432 */
2433 this._paused = false;
2434
2435 /**
2436 * All event handlers.
2437 * @protected
2438 * @type {Object}
2439 */
2440 this._handlers = {
2441 'changed.owl.carousel': $.proxy(function(e) {
2442 if (e.namespace && e.property.name === 'settings') {
2443 if (this._core.settings.autoplay) {
2444 this.play();
2445 } else {
2446 this.stop();
2447 }
2448 }
2449 }, this),
2450 'initialized.owl.carousel': $.proxy(function(e) {
2451 if (e.namespace && this._core.settings.autoplay) {
2452 this.play();
2453 }
2454 }, this),
2455 'play.owl.autoplay': $.proxy(function(e, t, s) {
2456 if (e.namespace) {
2457 this.play(t, s);
2458 }
2459 }, this),
2460 'stop.owl.autoplay': $.proxy(function(e) {
2461 if (e.namespace) {
2462 this.stop();
2463 }
2464 }, this),
2465 'mouseover.owl.autoplay': $.proxy(function() {
2466 if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) {
2467 this.pause();
2468 }
2469 }, this),
2470 'mouseleave.owl.autoplay': $.proxy(function() {
2471 if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) {
2472 this.play();
2473 }
2474 }, this)
2475 };
2476
2477 // register event handlers
2478 this._core.$element.on(this._handlers);
2479
2480 // set default options
2481 this._core.options = $.extend({}, Autoplay.Defaults, this._core.options);
2482 };
2483
2484 /**
2485 * Default options.
2486 * @public
2487 */
2488 Autoplay.Defaults = {
2489 autoplay: false,
2490 autoplayTimeout: 5000,
2491 autoplayHoverPause: false,
2492 autoplaySpeed: false
2493 };
2494
2495 /**
2496 * Starts the autoplay.
2497 * @public
2498 * @param {Number} [timeout] - The interval before the next animation starts.
2499 * @param {Number} [speed] - The animation speed for the animations.
2500 */
2501 Autoplay.prototype.play = function(timeout, speed) {
2502 this._paused = false;
2503
2504 if (this._core.is('rotating')) {
2505 return;
2506 }
2507
2508 this._core.enter('rotating');
2509
2510 this._interval = window.setInterval($.proxy(function() {
2511 if (this._paused || this._core.is('busy') || this._core.is('interacting') || document.hidden) {
2512 return;
2513 }
2514 this._core.next(speed || this._core.settings.autoplaySpeed);
2515 }, this), timeout || this._core.settings.autoplayTimeout);
2516 };
2517
2518 /**
2519 * Stops the autoplay.
2520 * @public
2521 */
2522 Autoplay.prototype.stop = function() {
2523 if (!this._core.is('rotating')) {
2524 return;
2525 }
2526
2527 window.clearInterval(this._interval);
2528 this._core.leave('rotating');
2529 };
2530
2531 /**
2532 * Stops the autoplay.
2533 * @public
2534 */
2535 Autoplay.prototype.pause = function() {
2536 if (!this._core.is('rotating')) {
2537 return;
2538 }
2539
2540 this._paused = true;
2541 };
2542
2543 /**
2544 * Destroys the plugin.
2545 */
2546 Autoplay.prototype.destroy = function() {
2547 var handler, property;
2548
2549 this.stop();
2550
2551 for (handler in this._handlers) {
2552 this._core.$element.off(handler, this._handlers[handler]);
2553 }
2554 for (property in Object.getOwnPropertyNames(this)) {
2555 typeof this[property] != 'function' && (this[property] = null);
2556 }
2557 };
2558
2559 $.fn.owlCarousel.Constructor.Plugins.autoplay = Autoplay;
2560
2561 })(window.Zepto || window.jQuery, window, document);
2562
2563 /**
2564 * Navigation Plugin
2565 * @version 2.0.0-beta.3
2566 * @author Artus Kolanowski
2567 * @license The MIT License (MIT)
2568 */
2569 ;(function($, window, document, undefined) {
2570 'use strict';
2571
2572 /**
2573 * Creates the navigation plugin.
2574 * @class The Navigation Plugin
2575 * @param {Owl} carousel - The Owl Carousel.
2576 */
2577 var Navigation = function(carousel) {
2578 /**
2579 * Reference to the core.
2580 * @protected
2581 * @type {Owl}
2582 */
2583 this._core = carousel;
2584
2585 /**
2586 * Indicates whether the plugin is initialized or not.
2587 * @protected
2588 * @type {Boolean}
2589 */
2590 this._initialized = false;
2591
2592 /**
2593 * The current paging indexes.
2594 * @protected
2595 * @type {Array}
2596 */
2597 this._pages = [];
2598
2599 /**
2600 * All DOM elements of the user interface.
2601 * @protected
2602 * @type {Object}
2603 */
2604 this._controls = {};
2605
2606 /**
2607 * Markup for an indicator.
2608 * @protected
2609 * @type {Array.<String>}
2610 */
2611 this._templates = [];
2612
2613 /**
2614 * The carousel element.
2615 * @type {jQuery}
2616 */
2617 this.$element = this._core.$element;
2618
2619 /**
2620 * Overridden methods of the carousel.
2621 * @protected
2622 * @type {Object}
2623 */
2624 this._overrides = {
2625 next: this._core.next,
2626 prev: this._core.prev,
2627 to: this._core.to
2628 };
2629
2630 /**
2631 * All event handlers.
2632 * @protected
2633 * @type {Object}
2634 */
2635 this._handlers = {
2636 'prepared.owl.carousel': $.proxy(function(e) {
2637 if (e.namespace && this._core.settings.dotsData) {
2638 this._templates.push('<div class="' + this._core.settings.dotClass + '">' +
2639 $(e.content).find('[data-dot]').andSelf('[data-dot]').attr('data-dot') + '</div>');
2640 }
2641 }, this),
2642 'added.owl.carousel': $.proxy(function(e) {
2643 if (e.namespace && this._core.settings.dotsData) {
2644 this._templates.splice(e.position, 0, this._templates.pop());
2645 }
2646 }, this),
2647 'remove.owl.carousel': $.proxy(function(e) {
2648 if (e.namespace && this._core.settings.dotsData) {
2649 this._templates.splice(e.position, 1);
2650 }
2651 }, this),
2652 'changed.owl.carousel': $.proxy(function(e) {
2653 if (e.namespace && e.property.name == 'position') {
2654 this.draw();
2655 }
2656 }, this),
2657 'initialized.owl.carousel': $.proxy(function(e) {
2658 if (e.namespace && !this._initialized) {
2659 this._core.trigger('initialize', null, 'navigation');
2660 this.initialize();
2661 this.update();
2662 this.draw();
2663 this._initialized = true;
2664 this._core.trigger('initialized', null, 'navigation');
2665 }
2666 }, this),
2667 'refreshed.owl.carousel': $.proxy(function(e) {
2668 if (e.namespace && this._initialized) {
2669 this._core.trigger('refresh', null, 'navigation');
2670 this.update();
2671 this.draw();
2672 this._core.trigger('refreshed', null, 'navigation');
2673 }
2674 }, this)
2675 };
2676
2677 // set default options
2678 this._core.options = $.extend({}, Navigation.Defaults, this._core.options);
2679
2680 // register event handlers
2681 this.$element.on(this._handlers);
2682 };
2683
2684 /**
2685 * Default options.
2686 * @public
2687 * @todo Rename `slideBy` to `navBy`
2688 */
2689 Navigation.Defaults = {
2690 nav: false,
2691 navText: [ 'prev', 'next' ],
2692 navSpeed: false,
2693 navElement: 'div',
2694 navContainer: false,
2695 navContainerClass: 'owl-nav',
2696 navClass: [ 'owl-prev', 'owl-next' ],
2697 slideBy: 1,
2698 dotClass: 'owl-dot',
2699 dotsClass: 'owl-dots',
2700 dots: true,
2701 dotsEach: false,
2702 dotsData: false,
2703 dotsSpeed: false,
2704 dotsContainer: false
2705 };
2706
2707 /**
2708 * Initializes the layout of the plugin and extends the carousel.
2709 * @protected
2710 */
2711 Navigation.prototype.initialize = function() {
2712 var override,
2713 settings = this._core.settings;
2714
2715 // create DOM structure for relative navigation
2716 this._controls.$relative = (settings.navContainer ? $(settings.navContainer)
2717 : $('<div>').addClass(settings.navContainerClass).appendTo(this.$element)).addClass('disabled');
2718
2719 this._controls.$previous = $('<' + settings.navElement + '>')
2720 .addClass(settings.navClass[0])
2721 .html(settings.navText[0])
2722 .prependTo(this._controls.$relative)
2723 .on('click', $.proxy(function(e) {
2724 this.prev(settings.navSpeed);
2725 }, this));
2726 this._controls.$next = $('<' + settings.navElement + '>')
2727 .addClass(settings.navClass[1])
2728 .html(settings.navText[1])
2729 .appendTo(this._controls.$relative)
2730 .on('click', $.proxy(function(e) {
2731 this.next(settings.navSpeed);
2732 }, this));
2733
2734 // create DOM structure for absolute navigation
2735 if (!settings.dotsData) {
2736 this._templates = [ $('<div>')
2737 .addClass(settings.dotClass)
2738 .append($('<span>'))
2739 .prop('outerHTML') ];
2740 }
2741
2742 this._controls.$absolute = (settings.dotsContainer ? $(settings.dotsContainer)
2743 : $('<div>').addClass(settings.dotsClass).appendTo(this.$element)).addClass('disabled');
2744
2745 this._controls.$absolute.on('click', 'div', $.proxy(function(e) {
2746 var index = $(e.target).parent().is(this._controls.$absolute)
2747 ? $(e.target).index() : $(e.target).parent().index();
2748
2749 e.preventDefault();
2750
2751 this.to(index, settings.dotsSpeed);
2752 }, this));
2753
2754 // override public methods of the carousel
2755 for (override in this._overrides) {
2756 this._core[override] = $.proxy(this[override], this);
2757 }
2758 };
2759
2760 /**
2761 * Destroys the plugin.
2762 * @protected
2763 */
2764 Navigation.prototype.destroy = function() {
2765 var handler, control, property, override;
2766
2767 for (handler in this._handlers) {
2768 this.$element.off(handler, this._handlers[handler]);
2769 }
2770 for (control in this._controls) {
2771 this._controls[control].remove();
2772 }
2773 for (override in this.overides) {
2774 this._core[override] = this._overrides[override];
2775 }
2776 for (property in Object.getOwnPropertyNames(this)) {
2777 typeof this[property] != 'function' && (this[property] = null);
2778 }
2779 };
2780
2781 /**
2782 * Updates the internal state.
2783 * @protected
2784 */
2785 Navigation.prototype.update = function() {
2786 var i, j, k,
2787 lower = this._core.clones().length / 2,
2788 upper = lower + this._core.items().length,
2789 maximum = this._core.maximum(true),
2790 settings = this._core.settings,
2791 size = settings.center || settings.autoWidth || settings.dotsData
2792 ? 1 : settings.dotsEach || settings.items;
2793
2794 if (settings.slideBy !== 'page') {
2795 settings.slideBy = Math.min(settings.slideBy, settings.items);
2796 }
2797
2798 if (settings.dots || settings.slideBy == 'page') {
2799 this._pages = [];
2800
2801 for (i = lower, j = 0, k = 0; i < upper; i++) {
2802 if (j >= size || j === 0) {
2803 this._pages.push({
2804 start: Math.min(maximum, i - lower),
2805 end: i - lower + size - 1
2806 });
2807 if (Math.min(maximum, i - lower) === maximum) {
2808 break;
2809 }
2810 j = 0, ++k;
2811 }
2812 j += this._core.mergers(this._core.relative(i));
2813 }
2814 }
2815 };
2816
2817 /**
2818 * Draws the user interface.
2819 * @todo The option `dotsData` wont work.
2820 * @protected
2821 */
2822 Navigation.prototype.draw = function() {
2823 var difference,
2824 settings = this._core.settings,
2825 disabled = this._core.items().length <= settings.items,
2826 index = this._core.relative(this._core.current()),
2827 loop = settings.loop || settings.rewind;
2828
2829 this._controls.$relative.toggleClass('disabled', !settings.nav || disabled);
2830
2831 if (settings.nav) {
2832 this._controls.$previous.toggleClass('disabled', !loop && index <= this._core.minimum(true));
2833 this._controls.$next.toggleClass('disabled', !loop && index >= this._core.maximum(true));
2834 }
2835
2836 this._controls.$absolute.toggleClass('disabled', !settings.dots || disabled);
2837
2838 if (settings.dots) {
2839 difference = this._pages.length - this._controls.$absolute.children().length;
2840
2841 if (settings.dotsData && difference !== 0) {
2842 this._controls.$absolute.html(this._templates.join(''));
2843 } else if (difference > 0) {
2844 this._controls.$absolute.append(new Array(difference + 1).join(this._templates[0]));
2845 } else if (difference < 0) {
2846 this._controls.$absolute.children().slice(difference).remove();
2847 }
2848
2849 this._controls.$absolute.find('.active').removeClass('active');
2850 this._controls.$absolute.children().eq($.inArray(this.current(), this._pages)).addClass('active');
2851 }
2852 };
2853
2854 /**
2855 * Extends event data.
2856 * @protected
2857 * @param {Event} event - The event object which gets thrown.
2858 */
2859 Navigation.prototype.onTrigger = function(event) {
2860 var settings = this._core.settings;
2861
2862 event.page = {
2863 index: $.inArray(this.current(), this._pages),
2864 count: this._pages.length,
2865 size: settings && (settings.center || settings.autoWidth || settings.dotsData
2866 ? 1 : settings.dotsEach || settings.items)
2867 };
2868 };
2869
2870 /**
2871 * Gets the current page position of the carousel.
2872 * @protected
2873 * @returns {Number}
2874 */
2875 Navigation.prototype.current = function() {
2876 var current = this._core.relative(this._core.current());
2877 return $.grep(this._pages, $.proxy(function(page, index) {
2878 return page.start <= current && page.end >= current;
2879 }, this)).pop();
2880 };
2881
2882 /**
2883 * Gets the current succesor/predecessor position.
2884 * @protected
2885 * @returns {Number}
2886 */
2887 Navigation.prototype.getPosition = function(successor) {
2888 var position, length,
2889 settings = this._core.settings;
2890
2891 if (settings.slideBy == 'page') {
2892 position = $.inArray(this.current(), this._pages);
2893 length = this._pages.length;
2894 successor ? ++position : --position;
2895 position = this._pages[((position % length) + length) % length].start;
2896 } else {
2897 position = this._core.relative(this._core.current());
2898 length = this._core.items().length;
2899 successor ? position += settings.slideBy : position -= settings.slideBy;
2900 }
2901
2902 return position;
2903 };
2904
2905 /**
2906 * Slides to the next item or page.
2907 * @public
2908 * @param {Number} [speed=false] - The time in milliseconds for the transition.
2909 */
2910 Navigation.prototype.next = function(speed) {
2911 $.proxy(this._overrides.to, this._core)(this.getPosition(true), speed);
2912 };
2913
2914 /**
2915 * Slides to the previous item or page.
2916 * @public
2917 * @param {Number} [speed=false] - The time in milliseconds for the transition.
2918 */
2919 Navigation.prototype.prev = function(speed) {
2920 $.proxy(this._overrides.to, this._core)(this.getPosition(false), speed);
2921 };
2922
2923 /**
2924 * Slides to the specified item or page.
2925 * @public
2926 * @param {Number} position - The position of the item or page.
2927 * @param {Number} [speed] - The time in milliseconds for the transition.
2928 * @param {Boolean} [standard=false] - Whether to use the standard behaviour or not.
2929 */
2930 Navigation.prototype.to = function(position, speed, standard) {
2931 var length;
2932
2933 if (!standard) {
2934 length = this._pages.length;
2935 $.proxy(this._overrides.to, this._core)(this._pages[((position % length) + length) % length].start, speed);
2936 } else {
2937 $.proxy(this._overrides.to, this._core)(position, speed);
2938 }
2939 };
2940
2941 $.fn.owlCarousel.Constructor.Plugins.Navigation = Navigation;
2942
2943 })(window.Zepto || window.jQuery, window, document);
2944
2945 /**
2946 * Hash Plugin
2947 * @version 2.0.0-beta.3
2948 * @author Artus Kolanowski
2949 * @license The MIT License (MIT)
2950 */
2951 ;(function($, window, document, undefined) {
2952 'use strict';
2953
2954 /**
2955 * Creates the hash plugin.
2956 * @class The Hash Plugin
2957 * @param {Owl} carousel - The Owl Carousel
2958 */
2959 var Hash = function(carousel) {
2960 /**
2961 * Reference to the core.
2962 * @protected
2963 * @type {Owl}
2964 */
2965 this._core = carousel;
2966
2967 /**
2968 * Hash index for the items.
2969 * @protected
2970 * @type {Object}
2971 */
2972 this._hashes = {};
2973
2974 /**
2975 * The carousel element.
2976 * @type {jQuery}
2977 */
2978 this.$element = this._core.$element;
2979
2980 /**
2981 * All event handlers.
2982 * @protected
2983 * @type {Object}
2984 */
2985 this._handlers = {
2986 'initialized.owl.carousel': $.proxy(function(e) {
2987 if (e.namespace && this._core.settings.startPosition === 'URLHash') {
2988 $(window).trigger('hashchange.owl.navigation');
2989 }
2990 }, this),
2991 'prepared.owl.carousel': $.proxy(function(e) {
2992 if (e.namespace) {
2993 var hash = $(e.content).find('[data-hash]').andSelf('[data-hash]').attr('data-hash');
2994
2995 if (!hash) {
2996 return;
2997 }
2998
2999 this._hashes[hash] = e.content;
3000 }
3001 }, this),
3002 'changed.owl.carousel': $.proxy(function(e) {
3003 if (e.namespace && e.property.name === 'position') {
3004 var current = this._core.items(this._core.relative(this._core.current())),
3005 hash = $.map(this._hashes, function(item, hash) {
3006 return item === current ? hash : null;
3007 }).join();
3008
3009 if (!hash || window.location.hash.slice(1) === hash) {
3010 return;
3011 }
3012
3013 window.location.hash = hash;
3014 }
3015 }, this)
3016 };
3017
3018 // set default options
3019 this._core.options = $.extend({}, Hash.Defaults, this._core.options);
3020
3021 // register the event handlers
3022 this.$element.on(this._handlers);
3023
3024 // register event listener for hash navigation
3025 $(window).on('hashchange.owl.navigation', $.proxy(function(e) {
3026 var hash = window.location.hash.substring(1),
3027 items = this._core.$stage.children(),
3028 position = this._hashes[hash] && items.index(this._hashes[hash]);
3029
3030 if (position === undefined || position === this._core.current()) {
3031 return;
3032 }
3033
3034 this._core.to(this._core.relative(position), false, true);
3035 }, this));
3036 };
3037
3038 /**
3039 * Default options.
3040 * @public
3041 */
3042 Hash.Defaults = {
3043 URLhashListener: false
3044 };
3045
3046 /**
3047 * Destroys the plugin.
3048 * @public
3049 */
3050 Hash.prototype.destroy = function() {
3051 var handler, property;
3052
3053 $(window).off('hashchange.owl.navigation');
3054
3055 for (handler in this._handlers) {
3056 this._core.$element.off(handler, this._handlers[handler]);
3057 }
3058 for (property in Object.getOwnPropertyNames(this)) {
3059 typeof this[property] != 'function' && (this[property] = null);
3060 }
3061 };
3062
3063 $.fn.owlCarousel.Constructor.Plugins.Hash = Hash;
3064
3065 })(window.Zepto || window.jQuery, window, document);
3066
3067 /**
3068 * Support Plugin
3069 *
3070 * @version 2.0.0-beta.3
3071 * @author Vivid Planet Software GmbH
3072 * @author Artus Kolanowski
3073 * @license The MIT License (MIT)
3074 */
3075 ;(function($, window, document, undefined) {
3076
3077 var style = $('<support>').get(0).style,
3078 prefixes = 'Webkit Moz O ms'.split(' '),
3079 events = {
3080 transition: {
3081 end: {
3082 WebkitTransition: 'webkitTransitionEnd',
3083 MozTransition: 'transitionend',
3084 OTransition: 'oTransitionEnd',
3085 transition: 'transitionend'
3086 }
3087 },
3088 animation: {
3089 end: {
3090 WebkitAnimation: 'webkitAnimationEnd',
3091 MozAnimation: 'animationend',
3092 OAnimation: 'oAnimationEnd',
3093 animation: 'animationend'
3094 }
3095 }
3096 },
3097 tests = {
3098 csstransforms: function() {
3099 return !!test('transform');
3100 },
3101 csstransforms3d: function() {
3102 return !!test('perspective');
3103 },
3104 csstransitions: function() {
3105 return !!test('transition');
3106 },
3107 cssanimations: function() {
3108 return !!test('animation');
3109 }
3110 };
3111
3112 function test(property, prefixed) {
3113 var result = false,
3114 upper = property.charAt(0).toUpperCase() + property.slice(1);
3115
3116 $.each((property + ' ' + prefixes.join(upper + ' ') + upper).split(' '), function(i, property) {
3117 if (style[property] !== undefined) {
3118 result = prefixed ? property : true;
3119 return false;
3120 }
3121 });
3122
3123 return result;
3124 }
3125
3126 function prefixed(property) {
3127 return test(property, true);
3128 }
3129
3130 if (tests.csstransitions()) {
3131 /* jshint -W053 */
3132 $.support.transition = new String(prefixed('transition'))
3133 $.support.transition.end = events.transition.end[ $.support.transition ];
3134 }
3135
3136 if (tests.cssanimations()) {
3137 /* jshint -W053 */
3138 $.support.animation = new String(prefixed('animation'))
3139 $.support.animation.end = events.animation.end[ $.support.animation ];
3140 }
3141
3142 if (tests.csstransforms()) {
3143 /* jshint -W053 */
3144 $.support.transform = new String(prefixed('transform'));
3145 $.support.transform3d = tests.csstransforms3d();
3146 }
3147
3148 })(window.Zepto || window.jQuery, window, document);