owl.carousel.js 37 KB

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