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