owl.carousel.js 87 KB

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