Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3275 строки
83 KiB

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