Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

1512 linhas
52 KiB

  1. /*
  2. * jQuery OwlCarousel v1.3.3
  3. *
  4. * Copyright (c) 2013 Bartosz Wojciechowski
  5. * http://www.owlgraphic.com/owlcarousel/
  6. *
  7. * Licensed under MIT
  8. *
  9. */
  10. /*JS Lint helpers: */
  11. /*global dragMove: false, dragEnd: false, $, jQuery, alert, window, document */
  12. /*jslint nomen: true, continue:true */
  13. if (typeof Object.create !== "function") {
  14. Object.create = function (obj) {
  15. function F() {}
  16. F.prototype = obj;
  17. return new F();
  18. };
  19. }
  20. (function ($, window, document) {
  21. var Carousel = {
  22. init : function (options, el) {
  23. var base = this;
  24. base.$elem = $(el);
  25. base.options = $.extend({}, $.fn.owlCarousel.options, base.$elem.data(), options);
  26. base.userOptions = options;
  27. base.loadContent();
  28. },
  29. loadContent : function () {
  30. var base = this, url;
  31. function getData(data) {
  32. var i, content = "";
  33. if (typeof base.options.jsonSuccess === "function") {
  34. base.options.jsonSuccess.apply(this, [data]);
  35. } else {
  36. for (i in data.owl) {
  37. if (data.owl.hasOwnProperty(i)) {
  38. content += data.owl[i].item;
  39. }
  40. }
  41. base.$elem.html(content);
  42. }
  43. base.logIn();
  44. }
  45. if (typeof base.options.beforeInit === "function") {
  46. base.options.beforeInit.apply(this, [base.$elem]);
  47. }
  48. if (typeof base.options.jsonPath === "string") {
  49. url = base.options.jsonPath;
  50. $.getJSON(url, getData);
  51. } else {
  52. base.logIn();
  53. }
  54. },
  55. logIn : function () {
  56. var base = this;
  57. base.$elem.data("owl-originalStyles", base.$elem.attr("style"));
  58. base.$elem.data("owl-originalClasses", base.$elem.attr("class"));
  59. base.$elem.css({opacity: 0});
  60. base.orignalItems = base.options.items;
  61. base.checkBrowser();
  62. base.wrapperWidth = 0;
  63. base.checkVisible = null;
  64. base.setVars();
  65. },
  66. setVars : function () {
  67. var base = this;
  68. if (base.$elem.children().length === 0) {return false; }
  69. base.baseClass();
  70. base.eventTypes();
  71. base.$userItems = base.$elem.children();
  72. base.itemsAmount = base.$userItems.length;
  73. base.wrapItems();
  74. base.$owlItems = base.$elem.find(".owl-item");
  75. base.$owlWrapper = base.$elem.find(".owl-wrapper");
  76. base.playDirection = "next";
  77. base.prevItem = 0;
  78. base.prevArr = [0];
  79. base.currentItem = 0;
  80. base.customEvents();
  81. base.onStartup();
  82. },
  83. onStartup : function () {
  84. var base = this;
  85. base.updateItems();
  86. base.calculateAll();
  87. base.buildControls();
  88. base.updateControls();
  89. base.response();
  90. base.moveEvents();
  91. base.stopOnHover();
  92. base.owlStatus();
  93. if (base.options.transitionStyle !== false) {
  94. base.transitionTypes(base.options.transitionStyle);
  95. }
  96. if (base.options.autoPlay === true) {
  97. base.options.autoPlay = 5000;
  98. }
  99. base.play();
  100. base.$elem.find(".owl-wrapper").css("display", "block");
  101. if (!base.$elem.is(":visible")) {
  102. base.watchVisibility();
  103. } else {
  104. base.$elem.css("opacity", 1);
  105. }
  106. base.onstartup = false;
  107. base.eachMoveUpdate();
  108. if (typeof base.options.afterInit === "function") {
  109. base.options.afterInit.apply(this, [base.$elem]);
  110. }
  111. },
  112. eachMoveUpdate : function () {
  113. var base = this;
  114. if (base.options.lazyLoad === true) {
  115. base.lazyLoad();
  116. }
  117. if (base.options.autoHeight === true) {
  118. base.autoHeight();
  119. }
  120. base.onVisibleItems();
  121. if (typeof base.options.afterAction === "function") {
  122. base.options.afterAction.apply(this, [base.$elem]);
  123. }
  124. },
  125. updateVars : function () {
  126. var base = this;
  127. if (typeof base.options.beforeUpdate === "function") {
  128. base.options.beforeUpdate.apply(this, [base.$elem]);
  129. }
  130. base.watchVisibility();
  131. base.updateItems();
  132. base.calculateAll();
  133. base.updatePosition();
  134. base.updateControls();
  135. base.eachMoveUpdate();
  136. if (typeof base.options.afterUpdate === "function") {
  137. base.options.afterUpdate.apply(this, [base.$elem]);
  138. }
  139. },
  140. reload : function () {
  141. var base = this;
  142. window.setTimeout(function () {
  143. base.updateVars();
  144. }, 0);
  145. },
  146. watchVisibility : function () {
  147. var base = this;
  148. if (base.$elem.is(":visible") === false) {
  149. base.$elem.css({opacity: 0});
  150. window.clearInterval(base.autoPlayInterval);
  151. window.clearInterval(base.checkVisible);
  152. } else {
  153. return false;
  154. }
  155. base.checkVisible = window.setInterval(function () {
  156. if (base.$elem.is(":visible")) {
  157. base.reload();
  158. base.$elem.animate({opacity: 1}, 200);
  159. window.clearInterval(base.checkVisible);
  160. }
  161. }, 500);
  162. },
  163. wrapItems : function () {
  164. var base = this;
  165. base.$userItems.wrapAll("<div class=\"owl-wrapper\">").wrap("<div class=\"owl-item\"></div>");
  166. base.$elem.find(".owl-wrapper").wrap("<div class=\"owl-wrapper-outer\">");
  167. base.wrapperOuter = base.$elem.find(".owl-wrapper-outer");
  168. base.$elem.css("display", "block");
  169. },
  170. baseClass : function () {
  171. var base = this,
  172. hasBaseClass = base.$elem.hasClass(base.options.baseClass),
  173. hasThemeClass = base.$elem.hasClass(base.options.theme);
  174. if (!hasBaseClass) {
  175. base.$elem.addClass(base.options.baseClass);
  176. }
  177. if (!hasThemeClass) {
  178. base.$elem.addClass(base.options.theme);
  179. }
  180. },
  181. updateItems : function () {
  182. var base = this, width, i;
  183. if (base.options.responsive === false) {
  184. return false;
  185. }
  186. if (base.options.singleItem === true) {
  187. base.options.items = base.orignalItems = 1;
  188. base.options.itemsCustom = false;
  189. base.options.itemsDesktop = false;
  190. base.options.itemsDesktopSmall = false;
  191. base.options.itemsTablet = false;
  192. base.options.itemsTabletSmall = false;
  193. base.options.itemsMobile = false;
  194. return false;
  195. }
  196. width = $(base.options.responsiveBaseWidth).width();
  197. if (width > (base.options.itemsDesktop[0] || base.orignalItems)) {
  198. base.options.items = base.orignalItems;
  199. }
  200. if (base.options.itemsCustom !== false) {
  201. //Reorder array by screen size
  202. base.options.itemsCustom.sort(function (a, b) {return a[0] - b[0]; });
  203. for (i = 0; i < base.options.itemsCustom.length; i += 1) {
  204. if (base.options.itemsCustom[i][0] <= width) {
  205. base.options.items = base.options.itemsCustom[i][1];
  206. }
  207. }
  208. } else {
  209. if (width <= base.options.itemsDesktop[0] && base.options.itemsDesktop !== false) {
  210. base.options.items = base.options.itemsDesktop[1];
  211. }
  212. if (width <= base.options.itemsDesktopSmall[0] && base.options.itemsDesktopSmall !== false) {
  213. base.options.items = base.options.itemsDesktopSmall[1];
  214. }
  215. if (width <= base.options.itemsTablet[0] && base.options.itemsTablet !== false) {
  216. base.options.items = base.options.itemsTablet[1];
  217. }
  218. if (width <= base.options.itemsTabletSmall[0] && base.options.itemsTabletSmall !== false) {
  219. base.options.items = base.options.itemsTabletSmall[1];
  220. }
  221. if (width <= base.options.itemsMobile[0] && base.options.itemsMobile !== false) {
  222. base.options.items = base.options.itemsMobile[1];
  223. }
  224. }
  225. //if number of items is less than declared
  226. if (base.options.items > base.itemsAmount && base.options.itemsScaleUp === true) {
  227. base.options.items = base.itemsAmount;
  228. }
  229. },
  230. response : function () {
  231. var base = this,
  232. smallDelay,
  233. lastWindowWidth;
  234. if (base.options.responsive !== true) {
  235. return false;
  236. }
  237. lastWindowWidth = $(window).width();
  238. base.resizer = function () {
  239. if ($(window).width() !== lastWindowWidth) {
  240. if (base.options.autoPlay !== false) {
  241. window.clearInterval(base.autoPlayInterval);
  242. }
  243. window.clearTimeout(smallDelay);
  244. smallDelay = window.setTimeout(function () {
  245. lastWindowWidth = $(window).width();
  246. base.updateVars();
  247. }, base.options.responsiveRefreshRate);
  248. }
  249. };
  250. $(window).resize(base.resizer);
  251. },
  252. updatePosition : function () {
  253. var base = this;
  254. base.jumpTo(base.currentItem);
  255. if (base.options.autoPlay !== false) {
  256. base.checkAp();
  257. }
  258. },
  259. appendItemsSizes : function () {
  260. var base = this,
  261. roundPages = 0,
  262. lastItem = base.itemsAmount - base.options.items;
  263. base.$owlItems.each(function (index) {
  264. var $this = $(this);
  265. $this
  266. .css({"width": base.itemWidth})
  267. .data("owl-item", Number(index));
  268. if (index % base.options.items === 0 || index === lastItem) {
  269. if (!(index > lastItem)) {
  270. roundPages += 1;
  271. }
  272. }
  273. $this.data("owl-roundPages", roundPages);
  274. });
  275. },
  276. appendWrapperSizes : function () {
  277. var base = this,
  278. width = base.$owlItems.length * base.itemWidth;
  279. base.$owlWrapper.css({
  280. "width": width * 2,
  281. "left": 0
  282. });
  283. base.appendItemsSizes();
  284. },
  285. calculateAll : function () {
  286. var base = this;
  287. base.calculateWidth();
  288. base.appendWrapperSizes();
  289. base.loops();
  290. base.max();
  291. },
  292. calculateWidth : function () {
  293. var base = this;
  294. base.itemWidth = Math.round(base.$elem.width() / base.options.items);
  295. },
  296. max : function () {
  297. var base = this,
  298. maximum = ((base.itemsAmount * base.itemWidth) - base.options.items * base.itemWidth) * -1;
  299. if (base.options.items > base.itemsAmount) {
  300. base.maximumItem = 0;
  301. maximum = 0;
  302. base.maximumPixels = 0;
  303. } else {
  304. base.maximumItem = base.itemsAmount - base.options.items;
  305. base.maximumPixels = maximum;
  306. }
  307. return maximum;
  308. },
  309. min : function () {
  310. return 0;
  311. },
  312. loops : function () {
  313. var base = this,
  314. prev = 0,
  315. elWidth = 0,
  316. i,
  317. item,
  318. roundPageNum;
  319. base.positionsInArray = [0];
  320. base.pagesInArray = [];
  321. for (i = 0; i < base.itemsAmount; i += 1) {
  322. elWidth += base.itemWidth;
  323. base.positionsInArray.push(-elWidth);
  324. if (base.options.scrollPerPage === true) {
  325. item = $(base.$owlItems[i]);
  326. roundPageNum = item.data("owl-roundPages");
  327. if (roundPageNum !== prev) {
  328. base.pagesInArray[prev] = base.positionsInArray[i];
  329. prev = roundPageNum;
  330. }
  331. }
  332. }
  333. },
  334. buildControls : function () {
  335. var base = this;
  336. if (base.options.navigation === true || base.options.pagination === true) {
  337. base.owlControls = $("<div class=\"owl-controls\"/>").toggleClass("clickable", !base.browser.isTouch).appendTo(base.$elem);
  338. }
  339. if (base.options.pagination === true) {
  340. base.buildPagination();
  341. }
  342. if (base.options.navigation === true) {
  343. base.buildButtons();
  344. }
  345. },
  346. buildButtons : function () {
  347. var base = this,
  348. buttonsWrapper = $("<div class=\"owl-buttons\"/>");
  349. base.owlControls.append(buttonsWrapper);
  350. base.buttonPrev = $("<div/>", {
  351. "class" : "owl-prev",
  352. "html" : base.options.navigationText[0] || ""
  353. });
  354. base.buttonNext = $("<div/>", {
  355. "class" : "owl-next",
  356. "html" : base.options.navigationText[1] || ""
  357. });
  358. buttonsWrapper
  359. .append(base.buttonPrev)
  360. .append(base.buttonNext);
  361. buttonsWrapper.on("touchstart.owlControls mousedown.owlControls", "div[class^=\"owl\"]", function (event) {
  362. event.preventDefault();
  363. });
  364. buttonsWrapper.on("touchend.owlControls mouseup.owlControls", "div[class^=\"owl\"]", function (event) {
  365. event.preventDefault();
  366. if ($(this).hasClass("owl-next")) {
  367. base.next();
  368. } else {
  369. base.prev();
  370. }
  371. });
  372. },
  373. buildPagination : function () {
  374. var base = this;
  375. base.paginationWrapper = $("<div class=\"owl-pagination\"/>");
  376. base.owlControls.append(base.paginationWrapper);
  377. base.paginationWrapper.on("touchend.owlControls mouseup.owlControls", ".owl-page", function (event) {
  378. event.preventDefault();
  379. if (Number($(this).data("owl-page")) !== base.currentItem) {
  380. base.goTo(Number($(this).data("owl-page")), true);
  381. }
  382. });
  383. },
  384. updatePagination : function () {
  385. var base = this,
  386. counter,
  387. lastPage,
  388. lastItem,
  389. i,
  390. paginationButton,
  391. paginationButtonInner;
  392. if (base.options.pagination === false) {
  393. return false;
  394. }
  395. base.paginationWrapper.html("");
  396. counter = 0;
  397. lastPage = base.itemsAmount - base.itemsAmount % base.options.items;
  398. for (i = 0; i < base.itemsAmount; i += 1) {
  399. if (i % base.options.items === 0) {
  400. counter += 1;
  401. if (lastPage === i) {
  402. lastItem = base.itemsAmount - base.options.items;
  403. }
  404. paginationButton = $("<div/>", {
  405. "class" : "owl-page"
  406. });
  407. paginationButtonInner = $("<span></span>", {
  408. "text": base.options.paginationNumbers === true ? counter : "",
  409. "class": base.options.paginationNumbers === true ? "owl-numbers" : ""
  410. });
  411. paginationButton.append(paginationButtonInner);
  412. paginationButton.data("owl-page", lastPage === i ? lastItem : i);
  413. paginationButton.data("owl-roundPages", counter);
  414. base.paginationWrapper.append(paginationButton);
  415. }
  416. }
  417. base.checkPagination();
  418. },
  419. checkPagination : function () {
  420. var base = this;
  421. if (base.options.pagination === false) {
  422. return false;
  423. }
  424. base.paginationWrapper.find(".owl-page").each(function () {
  425. if ($(this).data("owl-roundPages") === $(base.$owlItems[base.currentItem]).data("owl-roundPages")) {
  426. base.paginationWrapper
  427. .find(".owl-page")
  428. .removeClass("active");
  429. $(this).addClass("active");
  430. }
  431. });
  432. },
  433. checkNavigation : function () {
  434. var base = this;
  435. if (base.options.navigation === false) {
  436. return false;
  437. }
  438. if (base.options.rewindNav === false) {
  439. if (base.currentItem === 0 && base.maximumItem === 0) {
  440. base.buttonPrev.addClass("disabled");
  441. base.buttonNext.addClass("disabled");
  442. } else if (base.currentItem === 0 && base.maximumItem !== 0) {
  443. base.buttonPrev.addClass("disabled");
  444. base.buttonNext.removeClass("disabled");
  445. } else if (base.currentItem === base.maximumItem) {
  446. base.buttonPrev.removeClass("disabled");
  447. base.buttonNext.addClass("disabled");
  448. } else if (base.currentItem !== 0 && base.currentItem !== base.maximumItem) {
  449. base.buttonPrev.removeClass("disabled");
  450. base.buttonNext.removeClass("disabled");
  451. }
  452. }
  453. },
  454. updateControls : function () {
  455. var base = this;
  456. base.updatePagination();
  457. base.checkNavigation();
  458. if (base.owlControls) {
  459. if (base.options.items >= base.itemsAmount) {
  460. base.owlControls.hide();
  461. } else {
  462. base.owlControls.show();
  463. }
  464. }
  465. },
  466. destroyControls : function () {
  467. var base = this;
  468. if (base.owlControls) {
  469. base.owlControls.remove();
  470. }
  471. },
  472. next : function (speed) {
  473. var base = this;
  474. if (base.isTransition) {
  475. return false;
  476. }
  477. base.currentItem += base.options.scrollPerPage === true ? base.options.items : 1;
  478. if (base.currentItem > base.maximumItem + (base.options.scrollPerPage === true ? (base.options.items - 1) : 0)) {
  479. if (base.options.rewindNav === true) {
  480. base.currentItem = 0;
  481. speed = "rewind";
  482. } else {
  483. base.currentItem = base.maximumItem;
  484. return false;
  485. }
  486. }
  487. base.goTo(base.currentItem, speed);
  488. },
  489. prev : function (speed) {
  490. var base = this;
  491. if (base.isTransition) {
  492. return false;
  493. }
  494. if (base.options.scrollPerPage === true && base.currentItem > 0 && base.currentItem < base.options.items) {
  495. base.currentItem = 0;
  496. } else {
  497. base.currentItem -= base.options.scrollPerPage === true ? base.options.items : 1;
  498. }
  499. if (base.currentItem < 0) {
  500. if (base.options.rewindNav === true) {
  501. base.currentItem = base.maximumItem;
  502. speed = "rewind";
  503. } else {
  504. base.currentItem = 0;
  505. return false;
  506. }
  507. }
  508. base.goTo(base.currentItem, speed);
  509. },
  510. goTo : function (position, speed, drag) {
  511. var base = this,
  512. goToPixel;
  513. if (base.isTransition) {
  514. return false;
  515. }
  516. if (typeof base.options.beforeMove === "function") {
  517. base.options.beforeMove.apply(this, [base.$elem]);
  518. }
  519. if (position >= base.maximumItem) {
  520. position = base.maximumItem;
  521. } else if (position <= 0) {
  522. position = 0;
  523. }
  524. base.currentItem = base.owl.currentItem = position;
  525. if (base.options.transitionStyle !== false && drag !== "drag" && base.options.items === 1 && base.browser.support3d === true) {
  526. base.swapSpeed(0);
  527. if (base.browser.support3d === true) {
  528. base.transition3d(base.positionsInArray[position]);
  529. } else {
  530. base.css2slide(base.positionsInArray[position], 1);
  531. }
  532. base.afterGo();
  533. base.singleItemTransition();
  534. return false;
  535. }
  536. goToPixel = base.positionsInArray[position];
  537. if (base.browser.support3d === true) {
  538. base.isCss3Finish = false;
  539. if (speed === true) {
  540. base.swapSpeed("paginationSpeed");
  541. window.setTimeout(function () {
  542. base.isCss3Finish = true;
  543. }, base.options.paginationSpeed);
  544. } else if (speed === "rewind") {
  545. base.swapSpeed(base.options.rewindSpeed);
  546. window.setTimeout(function () {
  547. base.isCss3Finish = true;
  548. }, base.options.rewindSpeed);
  549. } else {
  550. base.swapSpeed("slideSpeed");
  551. window.setTimeout(function () {
  552. base.isCss3Finish = true;
  553. }, base.options.slideSpeed);
  554. }
  555. base.transition3d(goToPixel);
  556. } else {
  557. if (speed === true) {
  558. base.css2slide(goToPixel, base.options.paginationSpeed);
  559. } else if (speed === "rewind") {
  560. base.css2slide(goToPixel, base.options.rewindSpeed);
  561. } else {
  562. base.css2slide(goToPixel, base.options.slideSpeed);
  563. }
  564. }
  565. base.afterGo();
  566. },
  567. jumpTo : function (position) {
  568. var base = this;
  569. if (typeof base.options.beforeMove === "function") {
  570. base.options.beforeMove.apply(this, [base.$elem]);
  571. }
  572. if (position >= base.maximumItem || position === -1) {
  573. position = base.maximumItem;
  574. } else if (position <= 0) {
  575. position = 0;
  576. }
  577. base.swapSpeed(0);
  578. if (base.browser.support3d === true) {
  579. base.transition3d(base.positionsInArray[position]);
  580. } else {
  581. base.css2slide(base.positionsInArray[position], 1);
  582. }
  583. base.currentItem = base.owl.currentItem = position;
  584. base.afterGo();
  585. },
  586. afterGo : function () {
  587. var base = this;
  588. base.prevArr.push(base.currentItem);
  589. base.prevItem = base.owl.prevItem = base.prevArr[base.prevArr.length - 2];
  590. base.prevArr.shift(0);
  591. if (base.prevItem !== base.currentItem) {
  592. base.checkPagination();
  593. base.checkNavigation();
  594. base.eachMoveUpdate();
  595. if (base.options.autoPlay !== false) {
  596. base.checkAp();
  597. }
  598. }
  599. if (typeof base.options.afterMove === "function" && base.prevItem !== base.currentItem) {
  600. base.options.afterMove.apply(this, [base.$elem]);
  601. }
  602. },
  603. stop : function () {
  604. var base = this;
  605. base.apStatus = "stop";
  606. window.clearInterval(base.autoPlayInterval);
  607. },
  608. checkAp : function () {
  609. var base = this;
  610. if (base.apStatus !== "stop") {
  611. base.play();
  612. }
  613. },
  614. play : function () {
  615. var base = this;
  616. base.apStatus = "play";
  617. if (base.options.autoPlay === false) {
  618. return false;
  619. }
  620. window.clearInterval(base.autoPlayInterval);
  621. base.autoPlayInterval = window.setInterval(function () {
  622. base.next(true);
  623. }, base.options.autoPlay);
  624. },
  625. swapSpeed : function (action) {
  626. var base = this;
  627. if (action === "slideSpeed") {
  628. base.$owlWrapper.css(base.addCssSpeed(base.options.slideSpeed));
  629. } else if (action === "paginationSpeed") {
  630. base.$owlWrapper.css(base.addCssSpeed(base.options.paginationSpeed));
  631. } else if (typeof action !== "string") {
  632. base.$owlWrapper.css(base.addCssSpeed(action));
  633. }
  634. },
  635. addCssSpeed : function (speed) {
  636. return {
  637. "-webkit-transition": "all " + speed + "ms ease",
  638. "-moz-transition": "all " + speed + "ms ease",
  639. "-o-transition": "all " + speed + "ms ease",
  640. "transition": "all " + speed + "ms ease"
  641. };
  642. },
  643. removeTransition : function () {
  644. return {
  645. "-webkit-transition": "",
  646. "-moz-transition": "",
  647. "-o-transition": "",
  648. "transition": ""
  649. };
  650. },
  651. doTranslate : function (pixels) {
  652. return {
  653. "-webkit-transform": "translate3d(" + pixels + "px, 0px, 0px)",
  654. "-moz-transform": "translate3d(" + pixels + "px, 0px, 0px)",
  655. "-o-transform": "translate3d(" + pixels + "px, 0px, 0px)",
  656. "-ms-transform": "translate3d(" + pixels + "px, 0px, 0px)",
  657. "transform": "translate3d(" + pixels + "px, 0px,0px)"
  658. };
  659. },
  660. transition3d : function (value) {
  661. var base = this;
  662. base.$owlWrapper.css(base.doTranslate(value));
  663. },
  664. css2move : function (value) {
  665. var base = this;
  666. base.$owlWrapper.css({"left" : value});
  667. },
  668. css2slide : function (value, speed) {
  669. var base = this;
  670. base.isCssFinish = false;
  671. base.$owlWrapper.stop(true, true).animate({
  672. "left" : value
  673. }, {
  674. duration : speed || base.options.slideSpeed,
  675. complete : function () {
  676. base.isCssFinish = true;
  677. }
  678. });
  679. },
  680. checkBrowser : function () {
  681. var base = this,
  682. translate3D = "translate3d(0px, 0px, 0px)",
  683. tempElem = document.createElement("div"),
  684. regex,
  685. asSupport,
  686. support3d,
  687. isTouch;
  688. tempElem.style.cssText = " -moz-transform:" + translate3D +
  689. "; -ms-transform:" + translate3D +
  690. "; -o-transform:" + translate3D +
  691. "; -webkit-transform:" + translate3D +
  692. "; transform:" + translate3D;
  693. regex = /translate3d\(0px, 0px, 0px\)/g;
  694. asSupport = tempElem.style.cssText.match(regex);
  695. support3d = (asSupport !== null && asSupport.length === 1);
  696. isTouch = "ontouchstart" in window || window.navigator.msMaxTouchPoints;
  697. base.browser = {
  698. "support3d" : support3d,
  699. "isTouch" : isTouch
  700. };
  701. },
  702. moveEvents : function () {
  703. var base = this;
  704. if (base.options.mouseDrag !== false || base.options.touchDrag !== false) {
  705. base.gestures();
  706. base.disabledEvents();
  707. }
  708. },
  709. eventTypes : function () {
  710. var base = this,
  711. types = ["s", "e", "x"];
  712. base.ev_types = {};
  713. if (base.options.mouseDrag === true && base.options.touchDrag === true) {
  714. types = [
  715. "touchstart.owl mousedown.owl",
  716. "touchmove.owl mousemove.owl",
  717. "touchend.owl touchcancel.owl mouseup.owl"
  718. ];
  719. } else if (base.options.mouseDrag === false && base.options.touchDrag === true) {
  720. types = [
  721. "touchstart.owl",
  722. "touchmove.owl",
  723. "touchend.owl touchcancel.owl"
  724. ];
  725. } else if (base.options.mouseDrag === true && base.options.touchDrag === false) {
  726. types = [
  727. "mousedown.owl",
  728. "mousemove.owl",
  729. "mouseup.owl"
  730. ];
  731. }
  732. base.ev_types.start = types[0];
  733. base.ev_types.move = types[1];
  734. base.ev_types.end = types[2];
  735. },
  736. disabledEvents : function () {
  737. var base = this;
  738. base.$elem.on("dragstart.owl", function (event) { event.preventDefault(); });
  739. base.$elem.on("mousedown.disableTextSelect", function (e) {
  740. return $(e.target).is('input, textarea, select, option');
  741. });
  742. },
  743. gestures : function () {
  744. /*jslint unparam: true*/
  745. var base = this,
  746. locals = {
  747. offsetX : 0,
  748. offsetY : 0,
  749. baseElWidth : 0,
  750. relativePos : 0,
  751. position: null,
  752. minSwipe : null,
  753. maxSwipe: null,
  754. sliding : null,
  755. dargging: null,
  756. targetElement : null
  757. };
  758. base.isCssFinish = true;
  759. function getTouches(event) {
  760. if (event.touches !== undefined) {
  761. return {
  762. x : event.touches[0].pageX,
  763. y : event.touches[0].pageY
  764. };
  765. }
  766. if (event.touches === undefined) {
  767. if (event.pageX !== undefined) {
  768. return {
  769. x : event.pageX,
  770. y : event.pageY
  771. };
  772. }
  773. if (event.pageX === undefined) {
  774. return {
  775. x : event.clientX,
  776. y : event.clientY
  777. };
  778. }
  779. }
  780. }
  781. function swapEvents(type) {
  782. if (type === "on") {
  783. $(document).on(base.ev_types.move, dragMove);
  784. $(document).on(base.ev_types.end, dragEnd);
  785. } else if (type === "off") {
  786. $(document).off(base.ev_types.move);
  787. $(document).off(base.ev_types.end);
  788. }
  789. }
  790. function dragStart(event) {
  791. var ev = event.originalEvent || event || window.event,
  792. position;
  793. if (ev.which === 3) {
  794. return false;
  795. }
  796. if (base.itemsAmount <= base.options.items) {
  797. return;
  798. }
  799. if (base.isCssFinish === false && !base.options.dragBeforeAnimFinish) {
  800. return false;
  801. }
  802. if (base.isCss3Finish === false && !base.options.dragBeforeAnimFinish) {
  803. return false;
  804. }
  805. if (base.options.autoPlay !== false) {
  806. window.clearInterval(base.autoPlayInterval);
  807. }
  808. if (base.browser.isTouch !== true && !base.$owlWrapper.hasClass("grabbing")) {
  809. base.$owlWrapper.addClass("grabbing");
  810. }
  811. base.newPosX = 0;
  812. base.newRelativeX = 0;
  813. $(this).css(base.removeTransition());
  814. position = $(this).position();
  815. locals.relativePos = position.left;
  816. locals.offsetX = getTouches(ev).x - position.left;
  817. locals.offsetY = getTouches(ev).y - position.top;
  818. swapEvents("on");
  819. locals.sliding = false;
  820. locals.targetElement = ev.target || ev.srcElement;
  821. }
  822. function dragMove(event) {
  823. var ev = event.originalEvent || event || window.event,
  824. minSwipe,
  825. maxSwipe;
  826. base.newPosX = getTouches(ev).x - locals.offsetX;
  827. base.newPosY = getTouches(ev).y - locals.offsetY;
  828. base.newRelativeX = base.newPosX - locals.relativePos;
  829. if (typeof base.options.startDragging === "function" && locals.dragging !== true && base.newRelativeX !== 0) {
  830. locals.dragging = true;
  831. base.options.startDragging.apply(base, [base.$elem]);
  832. }
  833. if ((base.newRelativeX > 8 || base.newRelativeX < -8) && (base.browser.isTouch === true)) {
  834. if (ev.preventDefault !== undefined) {
  835. ev.preventDefault();
  836. } else {
  837. ev.returnValue = false;
  838. }
  839. locals.sliding = true;
  840. }
  841. if ((base.newPosY > 10 || base.newPosY < -10) && locals.sliding === false) {
  842. $(document).off("touchmove.owl");
  843. }
  844. minSwipe = function () {
  845. return base.newRelativeX / 5;
  846. };
  847. maxSwipe = function () {
  848. return base.maximumPixels + base.newRelativeX / 5;
  849. };
  850. base.newPosX = Math.max(Math.min(base.newPosX, minSwipe()), maxSwipe());
  851. if (base.browser.support3d === true) {
  852. base.transition3d(base.newPosX);
  853. } else {
  854. base.css2move(base.newPosX);
  855. }
  856. }
  857. function dragEnd(event) {
  858. var ev = event.originalEvent || event || window.event,
  859. newPosition,
  860. handlers,
  861. owlStopEvent;
  862. ev.target = ev.target || ev.srcElement;
  863. locals.dragging = false;
  864. if (base.browser.isTouch !== true) {
  865. base.$owlWrapper.removeClass("grabbing");
  866. }
  867. if (base.newRelativeX < 0) {
  868. base.dragDirection = base.owl.dragDirection = "left";
  869. } else {
  870. base.dragDirection = base.owl.dragDirection = "right";
  871. }
  872. if (base.newRelativeX !== 0) {
  873. newPosition = base.getNewPosition();
  874. base.goTo(newPosition, false, "drag");
  875. if (locals.targetElement === ev.target && base.browser.isTouch !== true) {
  876. $(ev.target).on("click.disable", function (ev) {
  877. ev.stopImmediatePropagation();
  878. ev.stopPropagation();
  879. ev.preventDefault();
  880. $(ev.target).off("click.disable");
  881. });
  882. handlers = $._data(ev.target, "events").click;
  883. owlStopEvent = handlers.pop();
  884. handlers.splice(0, 0, owlStopEvent);
  885. }
  886. }
  887. swapEvents("off");
  888. }
  889. base.$elem.on(base.ev_types.start, ".owl-wrapper", dragStart);
  890. },
  891. getNewPosition : function () {
  892. var base = this,
  893. newPosition = base.closestItem();
  894. if (newPosition > base.maximumItem) {
  895. base.currentItem = base.maximumItem;
  896. newPosition = base.maximumItem;
  897. } else if (base.newPosX >= 0) {
  898. newPosition = 0;
  899. base.currentItem = 0;
  900. }
  901. return newPosition;
  902. },
  903. closestItem : function () {
  904. var base = this,
  905. array = base.options.scrollPerPage === true ? base.pagesInArray : base.positionsInArray,
  906. goal = base.newPosX,
  907. closest = null;
  908. $.each(array, function (i, v) {
  909. if (goal - (base.itemWidth / 20) > array[i + 1] && goal - (base.itemWidth / 20) < v && base.moveDirection() === "left") {
  910. closest = v;
  911. if (base.options.scrollPerPage === true) {
  912. base.currentItem = $.inArray(closest, base.positionsInArray);
  913. } else {
  914. base.currentItem = i;
  915. }
  916. } else if (goal + (base.itemWidth / 20) < v && goal + (base.itemWidth / 20) > (array[i + 1] || array[i] - base.itemWidth) && base.moveDirection() === "right") {
  917. if (base.options.scrollPerPage === true) {
  918. closest = array[i + 1] || array[array.length - 1];
  919. base.currentItem = $.inArray(closest, base.positionsInArray);
  920. } else {
  921. closest = array[i + 1];
  922. base.currentItem = i + 1;
  923. }
  924. }
  925. });
  926. return base.currentItem;
  927. },
  928. moveDirection : function () {
  929. var base = this,
  930. direction;
  931. if (base.newRelativeX < 0) {
  932. direction = "right";
  933. base.playDirection = "next";
  934. } else {
  935. direction = "left";
  936. base.playDirection = "prev";
  937. }
  938. return direction;
  939. },
  940. customEvents : function () {
  941. /*jslint unparam: true*/
  942. var base = this;
  943. base.$elem.on("owl.next", function () {
  944. base.next();
  945. });
  946. base.$elem.on("owl.prev", function () {
  947. base.prev();
  948. });
  949. base.$elem.on("owl.play", function (event, speed) {
  950. base.options.autoPlay = speed;
  951. base.play();
  952. base.hoverStatus = "play";
  953. });
  954. base.$elem.on("owl.stop", function () {
  955. base.stop();
  956. base.hoverStatus = "stop";
  957. });
  958. base.$elem.on("owl.goTo", function (event, item) {
  959. base.goTo(item);
  960. });
  961. base.$elem.on("owl.jumpTo", function (event, item) {
  962. base.jumpTo(item);
  963. });
  964. },
  965. stopOnHover : function () {
  966. var base = this;
  967. if (base.options.stopOnHover === true && base.browser.isTouch !== true && base.options.autoPlay !== false) {
  968. base.$elem.on("mouseover", function () {
  969. base.stop();
  970. });
  971. base.$elem.on("mouseout", function () {
  972. if (base.hoverStatus !== "stop") {
  973. base.play();
  974. }
  975. });
  976. }
  977. },
  978. lazyLoad : function () {
  979. var base = this,
  980. i,
  981. $item,
  982. itemNumber,
  983. $lazyImg,
  984. follow;
  985. if (base.options.lazyLoad === false) {
  986. return false;
  987. }
  988. for (i = 0; i < base.itemsAmount; i += 1) {
  989. $item = $(base.$owlItems[i]);
  990. if ($item.data("owl-loaded") === "loaded") {
  991. continue;
  992. }
  993. itemNumber = $item.data("owl-item");
  994. $lazyImg = $item.find(".lazyOwl");
  995. if (typeof $lazyImg.data("src") !== "string") {
  996. $item.data("owl-loaded", "loaded");
  997. continue;
  998. }
  999. if ($item.data("owl-loaded") === undefined) {
  1000. $lazyImg.hide();
  1001. $item.addClass("loading").data("owl-loaded", "checked");
  1002. }
  1003. if (base.options.lazyFollow === true) {
  1004. follow = itemNumber >= base.currentItem;
  1005. } else {
  1006. follow = true;
  1007. }
  1008. if (follow && itemNumber < base.currentItem + base.options.items && $lazyImg.length) {
  1009. base.lazyPreload($item, $lazyImg);
  1010. }
  1011. }
  1012. },
  1013. lazyPreload : function ($item, $lazyImg) {
  1014. var base = this,
  1015. iterations = 0,
  1016. isBackgroundImg;
  1017. if ($lazyImg.prop("tagName") === "DIV") {
  1018. $lazyImg.css("background-image", "url(" + $lazyImg.data("src") + ")");
  1019. isBackgroundImg = true;
  1020. } else {
  1021. $lazyImg[0].src = $lazyImg.data("src");
  1022. }
  1023. function showImage() {
  1024. $item.data("owl-loaded", "loaded").removeClass("loading");
  1025. $lazyImg.removeAttr("data-src");
  1026. if (base.options.lazyEffect === "fade") {
  1027. $lazyImg.fadeIn(400);
  1028. } else {
  1029. $lazyImg.show();
  1030. }
  1031. if (typeof base.options.afterLazyLoad === "function") {
  1032. base.options.afterLazyLoad.apply(this, [base.$elem]);
  1033. }
  1034. }
  1035. function checkLazyImage() {
  1036. iterations += 1;
  1037. if (base.completeImg($lazyImg.get(0)) || isBackgroundImg === true) {
  1038. showImage();
  1039. } else if (iterations <= 100) {//if image loads in less than 10 seconds
  1040. window.setTimeout(checkLazyImage, 100);
  1041. } else {
  1042. showImage();
  1043. }
  1044. }
  1045. checkLazyImage();
  1046. },
  1047. autoHeight : function () {
  1048. var base = this,
  1049. $currentimg = $(base.$owlItems[base.currentItem]).find("img"),
  1050. iterations;
  1051. function addHeight() {
  1052. var $currentItem = $(base.$owlItems[base.currentItem]).height();
  1053. base.wrapperOuter.css("height", $currentItem + "px");
  1054. if (!base.wrapperOuter.hasClass("autoHeight")) {
  1055. window.setTimeout(function () {
  1056. base.wrapperOuter.addClass("autoHeight");
  1057. }, 0);
  1058. }
  1059. }
  1060. function checkImage() {
  1061. iterations += 1;
  1062. if (base.completeImg($currentimg.get(0))) {
  1063. addHeight();
  1064. } else if (iterations <= 100) { //if image loads in less than 10 seconds
  1065. window.setTimeout(checkImage, 100);
  1066. } else {
  1067. base.wrapperOuter.css("height", ""); //Else remove height attribute
  1068. }
  1069. }
  1070. if ($currentimg.get(0) !== undefined) {
  1071. iterations = 0;
  1072. checkImage();
  1073. } else {
  1074. addHeight();
  1075. }
  1076. },
  1077. completeImg : function (img) {
  1078. var naturalWidthType;
  1079. if (!img.complete) {
  1080. return false;
  1081. }
  1082. naturalWidthType = typeof img.naturalWidth;
  1083. if (naturalWidthType !== "undefined" && img.naturalWidth === 0) {
  1084. return false;
  1085. }
  1086. return true;
  1087. },
  1088. onVisibleItems : function () {
  1089. var base = this,
  1090. i;
  1091. if (base.options.addClassActive === true) {
  1092. base.$owlItems.removeClass("active");
  1093. }
  1094. base.visibleItems = [];
  1095. for (i = base.currentItem; i < base.currentItem + base.options.items; i += 1) {
  1096. base.visibleItems.push(i);
  1097. if (base.options.addClassActive === true) {
  1098. $(base.$owlItems[i]).addClass("active");
  1099. }
  1100. }
  1101. base.owl.visibleItems = base.visibleItems;
  1102. },
  1103. transitionTypes : function (className) {
  1104. var base = this;
  1105. //Currently available: "fade", "backSlide", "goDown", "fadeUp"
  1106. base.outClass = "owl-" + className + "-out";
  1107. base.inClass = "owl-" + className + "-in";
  1108. },
  1109. singleItemTransition : function () {
  1110. var base = this,
  1111. outClass = base.outClass,
  1112. inClass = base.inClass,
  1113. $currentItem = base.$owlItems.eq(base.currentItem),
  1114. $prevItem = base.$owlItems.eq(base.prevItem),
  1115. prevPos = Math.abs(base.positionsInArray[base.currentItem]) + base.positionsInArray[base.prevItem],
  1116. origin = Math.abs(base.positionsInArray[base.currentItem]) + base.itemWidth / 2,
  1117. animEnd = 'webkitAnimationEnd oAnimationEnd MSAnimationEnd animationend';
  1118. base.isTransition = true;
  1119. base.$owlWrapper
  1120. .addClass('owl-origin')
  1121. .css({
  1122. "-webkit-transform-origin" : origin + "px",
  1123. "-moz-perspective-origin" : origin + "px",
  1124. "perspective-origin" : origin + "px"
  1125. });
  1126. function transStyles(prevPos) {
  1127. return {
  1128. "position" : "relative",
  1129. "left" : prevPos + "px"
  1130. };
  1131. }
  1132. $prevItem
  1133. .css(transStyles(prevPos, 10))
  1134. .addClass(outClass)
  1135. .on(animEnd, function () {
  1136. base.endPrev = true;
  1137. $prevItem.off(animEnd);
  1138. base.clearTransStyle($prevItem, outClass);
  1139. });
  1140. $currentItem
  1141. .addClass(inClass)
  1142. .on(animEnd, function () {
  1143. base.endCurrent = true;
  1144. $currentItem.off(animEnd);
  1145. base.clearTransStyle($currentItem, inClass);
  1146. });
  1147. },
  1148. clearTransStyle : function (item, classToRemove) {
  1149. var base = this;
  1150. item.css({
  1151. "position" : "",
  1152. "left" : ""
  1153. }).removeClass(classToRemove);
  1154. if (base.endPrev && base.endCurrent) {
  1155. base.$owlWrapper.removeClass('owl-origin');
  1156. base.endPrev = false;
  1157. base.endCurrent = false;
  1158. base.isTransition = false;
  1159. }
  1160. },
  1161. owlStatus : function () {
  1162. var base = this;
  1163. base.owl = {
  1164. "userOptions" : base.userOptions,
  1165. "baseElement" : base.$elem,
  1166. "userItems" : base.$userItems,
  1167. "owlItems" : base.$owlItems,
  1168. "currentItem" : base.currentItem,
  1169. "prevItem" : base.prevItem,
  1170. "visibleItems" : base.visibleItems,
  1171. "isTouch" : base.browser.isTouch,
  1172. "browser" : base.browser,
  1173. "dragDirection" : base.dragDirection
  1174. };
  1175. },
  1176. clearEvents : function () {
  1177. var base = this;
  1178. base.$elem.off(".owl owl mousedown.disableTextSelect");
  1179. $(document).off(".owl owl");
  1180. $(window).off("resize", base.resizer);
  1181. },
  1182. unWrap : function () {
  1183. var base = this;
  1184. if (base.$elem.children().length !== 0) {
  1185. base.$owlWrapper.unwrap();
  1186. base.$userItems.unwrap().unwrap();
  1187. if (base.owlControls) {
  1188. base.owlControls.remove();
  1189. }
  1190. }
  1191. base.clearEvents();
  1192. base.$elem
  1193. .attr("style", base.$elem.data("owl-originalStyles") || "")
  1194. .attr("class", base.$elem.data("owl-originalClasses"));
  1195. },
  1196. destroy : function () {
  1197. var base = this;
  1198. base.stop();
  1199. window.clearInterval(base.checkVisible);
  1200. base.unWrap();
  1201. base.$elem.removeData();
  1202. },
  1203. reinit : function (newOptions) {
  1204. var base = this,
  1205. options = $.extend({}, base.userOptions, newOptions);
  1206. base.unWrap();
  1207. base.init(options, base.$elem);
  1208. },
  1209. addItem : function (htmlString, targetPosition) {
  1210. var base = this,
  1211. position;
  1212. if (!htmlString) {return false; }
  1213. if (base.$elem.children().length === 0) {
  1214. base.$elem.append(htmlString);
  1215. base.setVars();
  1216. return false;
  1217. }
  1218. base.unWrap();
  1219. if (targetPosition === undefined || targetPosition === -1) {
  1220. position = -1;
  1221. } else {
  1222. position = targetPosition;
  1223. }
  1224. if (position >= base.$userItems.length || position === -1) {
  1225. base.$userItems.eq(-1).after(htmlString);
  1226. } else {
  1227. base.$userItems.eq(position).before(htmlString);
  1228. }
  1229. base.setVars();
  1230. },
  1231. removeItem : function (targetPosition) {
  1232. var base = this,
  1233. position;
  1234. if (base.$elem.children().length === 0) {
  1235. return false;
  1236. }
  1237. if (targetPosition === undefined || targetPosition === -1) {
  1238. position = -1;
  1239. } else {
  1240. position = targetPosition;
  1241. }
  1242. base.unWrap();
  1243. base.$userItems.eq(position).remove();
  1244. base.setVars();
  1245. }
  1246. };
  1247. $.fn.owlCarousel = function (options) {
  1248. return this.each(function () {
  1249. if ($(this).data("owl-init") === true) {
  1250. return false;
  1251. }
  1252. $(this).data("owl-init", true);
  1253. var carousel = Object.create(Carousel);
  1254. carousel.init(options, this);
  1255. $.data(this, "owlCarousel", carousel);
  1256. });
  1257. };
  1258. $.fn.owlCarousel.options = {
  1259. items : 5,
  1260. itemsCustom : false,
  1261. itemsDesktop : [1199, 4],
  1262. itemsDesktopSmall : [979, 3],
  1263. itemsTablet : [768, 2],
  1264. itemsTabletSmall : false,
  1265. itemsMobile : [479, 1],
  1266. singleItem : false,
  1267. itemsScaleUp : false,
  1268. slideSpeed : 200,
  1269. paginationSpeed : 800,
  1270. rewindSpeed : 1000,
  1271. autoPlay : false,
  1272. stopOnHover : false,
  1273. navigation : false,
  1274. navigationText : ["prev", "next"],
  1275. rewindNav : true,
  1276. scrollPerPage : false,
  1277. pagination : true,
  1278. paginationNumbers : false,
  1279. responsive : true,
  1280. responsiveRefreshRate : 200,
  1281. responsiveBaseWidth : window,
  1282. baseClass : "owl-carousel",
  1283. theme : "owl-theme",
  1284. lazyLoad : false,
  1285. lazyFollow : true,
  1286. lazyEffect : "fade",
  1287. autoHeight : false,
  1288. jsonPath : false,
  1289. jsonSuccess : false,
  1290. dragBeforeAnimFinish : true,
  1291. mouseDrag : true,
  1292. touchDrag : true,
  1293. addClassActive : false,
  1294. transitionStyle : false,
  1295. beforeUpdate : false,
  1296. afterUpdate : false,
  1297. beforeInit : false,
  1298. afterInit : false,
  1299. beforeMove : false,
  1300. afterMove : false,
  1301. afterAction : false,
  1302. startDragging : false,
  1303. afterLazyLoad: false
  1304. };
  1305. }(jQuery, window, document));