owl.carousel.js 88 KB

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