owl.js 83 KB

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