PageRenderTime 41ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/files/caroufredsel/6.2.1/jquery.carouFredSel.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 2179 lines | 1767 code | 290 blank | 122 comment | 341 complexity | 2604fdcd70396949d10775d2d7120df2 MD5 | raw file
  1. /*
  2. * jQuery carouFredSel 6.2.1
  3. * Demo's and documentation:
  4. * caroufredsel.dev7studios.com
  5. *
  6. * Copyright (c) 2013 Fred Heusschen
  7. * www.frebsite.nl
  8. *
  9. * Dual licensed under the MIT and GPL licenses.
  10. * http://en.wikipedia.org/wiki/MIT_License
  11. * http://en.wikipedia.org/wiki/GNU_General_Public_License
  12. */
  13. (function($) {
  14. // LOCAL
  15. if ( $.fn.carouFredSel )
  16. {
  17. return;
  18. }
  19. $.fn.caroufredsel = $.fn.carouFredSel = function(options, configs)
  20. {
  21. // no element
  22. if (this.length == 0)
  23. {
  24. debug( true, 'No element found for "' + this.selector + '".' );
  25. return this;
  26. }
  27. // multiple elements
  28. if (this.length > 1)
  29. {
  30. return this.each(function() {
  31. $(this).carouFredSel(options, configs);
  32. });
  33. }
  34. var $cfs = this,
  35. $tt0 = this[0],
  36. starting_position = false;
  37. if ($cfs.data('_cfs_isCarousel'))
  38. {
  39. starting_position = $cfs.triggerHandler('_cfs_triggerEvent', 'currentPosition');
  40. $cfs.trigger('_cfs_triggerEvent', ['destroy', true]);
  41. }
  42. var FN = {};
  43. FN._init = function(o, setOrig, start)
  44. {
  45. o = go_getObject($tt0, o);
  46. o.items = go_getItemsObject($tt0, o.items);
  47. o.scroll = go_getScrollObject($tt0, o.scroll);
  48. o.auto = go_getAutoObject($tt0, o.auto);
  49. o.prev = go_getPrevNextObject($tt0, o.prev);
  50. o.next = go_getPrevNextObject($tt0, o.next);
  51. o.pagination = go_getPaginationObject($tt0, o.pagination);
  52. o.swipe = go_getSwipeObject($tt0, o.swipe);
  53. o.mousewheel = go_getMousewheelObject($tt0, o.mousewheel);
  54. if (setOrig)
  55. {
  56. opts_orig = $.extend(true, {}, $.fn.carouFredSel.defaults, o);
  57. }
  58. opts = $.extend(true, {}, $.fn.carouFredSel.defaults, o);
  59. opts.d = cf_getDimensions(opts);
  60. crsl.direction = (opts.direction == 'up' || opts.direction == 'left') ? 'next' : 'prev';
  61. var a_itm = $cfs.children(),
  62. avail_primary = ms_getParentSize($wrp, opts, 'width');
  63. if (is_true(opts.cookie))
  64. {
  65. opts.cookie = 'caroufredsel_cookie_' + conf.serialNumber;
  66. }
  67. opts.maxDimension = ms_getMaxDimension(opts, avail_primary);
  68. // complement items and sizes
  69. opts.items = in_complementItems(opts.items, opts, a_itm, start);
  70. opts[opts.d['width']] = in_complementPrimarySize(opts[opts.d['width']], opts, a_itm);
  71. opts[opts.d['height']] = in_complementSecondarySize(opts[opts.d['height']], opts, a_itm);
  72. // primary size not set for a responsive carousel
  73. if (opts.responsive)
  74. {
  75. if (!is_percentage(opts[opts.d['width']]))
  76. {
  77. opts[opts.d['width']] = '100%';
  78. }
  79. }
  80. // primary size is percentage
  81. if (is_percentage(opts[opts.d['width']]))
  82. {
  83. crsl.upDateOnWindowResize = true;
  84. crsl.primarySizePercentage = opts[opts.d['width']];
  85. opts[opts.d['width']] = ms_getPercentage(avail_primary, crsl.primarySizePercentage);
  86. if (!opts.items.visible)
  87. {
  88. opts.items.visibleConf.variable = true;
  89. }
  90. }
  91. if (opts.responsive)
  92. {
  93. opts.usePadding = false;
  94. opts.padding = [0, 0, 0, 0];
  95. opts.align = false;
  96. opts.items.visibleConf.variable = false;
  97. }
  98. else
  99. {
  100. // visible-items not set
  101. if (!opts.items.visible)
  102. {
  103. opts = in_complementVisibleItems(opts, avail_primary);
  104. }
  105. // primary size not set -> calculate it or set to "variable"
  106. if (!opts[opts.d['width']])
  107. {
  108. if (!opts.items.visibleConf.variable && is_number(opts.items[opts.d['width']]) && opts.items.filter == '*')
  109. {
  110. opts[opts.d['width']] = opts.items.visible * opts.items[opts.d['width']];
  111. opts.align = false;
  112. }
  113. else
  114. {
  115. opts[opts.d['width']] = 'variable';
  116. }
  117. }
  118. // align not set -> set to center if primary size is number
  119. if (is_undefined(opts.align))
  120. {
  121. opts.align = (is_number(opts[opts.d['width']]))
  122. ? 'center'
  123. : false;
  124. }
  125. // set variabe visible-items
  126. if (opts.items.visibleConf.variable)
  127. {
  128. opts.items.visible = gn_getVisibleItemsNext(a_itm, opts, 0);
  129. }
  130. }
  131. // set visible items by filter
  132. if (opts.items.filter != '*' && !opts.items.visibleConf.variable)
  133. {
  134. opts.items.visibleConf.org = opts.items.visible;
  135. opts.items.visible = gn_getVisibleItemsNextFilter(a_itm, opts, 0);
  136. }
  137. opts.items.visible = cf_getItemsAdjust(opts.items.visible, opts, opts.items.visibleConf.adjust, $tt0);
  138. opts.items.visibleConf.old = opts.items.visible;
  139. if (opts.responsive)
  140. {
  141. if (!opts.items.visibleConf.min)
  142. {
  143. opts.items.visibleConf.min = opts.items.visible;
  144. }
  145. if (!opts.items.visibleConf.max)
  146. {
  147. opts.items.visibleConf.max = opts.items.visible;
  148. }
  149. opts = in_getResponsiveValues(opts, a_itm, avail_primary);
  150. }
  151. else
  152. {
  153. opts.padding = cf_getPadding(opts.padding);
  154. if (opts.align == 'top')
  155. {
  156. opts.align = 'left';
  157. }
  158. else if (opts.align == 'bottom')
  159. {
  160. opts.align = 'right';
  161. }
  162. switch (opts.align)
  163. {
  164. // align: center, left or right
  165. case 'center':
  166. case 'left':
  167. case 'right':
  168. if (opts[opts.d['width']] != 'variable')
  169. {
  170. opts = in_getAlignPadding(opts, a_itm);
  171. opts.usePadding = true;
  172. }
  173. break;
  174. // padding
  175. default:
  176. opts.align = false;
  177. opts.usePadding = (
  178. opts.padding[0] == 0 &&
  179. opts.padding[1] == 0 &&
  180. opts.padding[2] == 0 &&
  181. opts.padding[3] == 0
  182. ) ? false : true;
  183. break;
  184. }
  185. }
  186. if (!is_number(opts.scroll.duration))
  187. {
  188. opts.scroll.duration = 500;
  189. }
  190. if (is_undefined(opts.scroll.items))
  191. {
  192. opts.scroll.items = (opts.responsive || opts.items.visibleConf.variable || opts.items.filter != '*')
  193. ? 'visible'
  194. : opts.items.visible;
  195. }
  196. opts.auto = $.extend(true, {}, opts.scroll, opts.auto);
  197. opts.prev = $.extend(true, {}, opts.scroll, opts.prev);
  198. opts.next = $.extend(true, {}, opts.scroll, opts.next);
  199. opts.pagination = $.extend(true, {}, opts.scroll, opts.pagination);
  200. // swipe and mousewheel extend later on, per direction
  201. opts.auto = go_complementAutoObject($tt0, opts.auto);
  202. opts.prev = go_complementPrevNextObject($tt0, opts.prev);
  203. opts.next = go_complementPrevNextObject($tt0, opts.next);
  204. opts.pagination = go_complementPaginationObject($tt0, opts.pagination);
  205. opts.swipe = go_complementSwipeObject($tt0, opts.swipe);
  206. opts.mousewheel = go_complementMousewheelObject($tt0, opts.mousewheel);
  207. if (opts.synchronise)
  208. {
  209. opts.synchronise = cf_getSynchArr(opts.synchronise);
  210. }
  211. // DEPRECATED
  212. if (opts.auto.onPauseStart)
  213. {
  214. opts.auto.onTimeoutStart = opts.auto.onPauseStart;
  215. deprecated('auto.onPauseStart', 'auto.onTimeoutStart');
  216. }
  217. if (opts.auto.onPausePause)
  218. {
  219. opts.auto.onTimeoutPause = opts.auto.onPausePause;
  220. deprecated('auto.onPausePause', 'auto.onTimeoutPause');
  221. }
  222. if (opts.auto.onPauseEnd)
  223. {
  224. opts.auto.onTimeoutEnd = opts.auto.onPauseEnd;
  225. deprecated('auto.onPauseEnd', 'auto.onTimeoutEnd');
  226. }
  227. if (opts.auto.pauseDuration)
  228. {
  229. opts.auto.timeoutDuration = opts.auto.pauseDuration;
  230. deprecated('auto.pauseDuration', 'auto.timeoutDuration');
  231. }
  232. // /DEPRECATED
  233. }; // /init
  234. FN._build = function() {
  235. $cfs.data('_cfs_isCarousel', true);
  236. var a_itm = $cfs.children(),
  237. orgCSS = in_mapCss($cfs, ['textAlign', 'float', 'position', 'top', 'right', 'bottom', 'left', 'zIndex', 'width', 'height', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft']),
  238. newPosition = 'relative';
  239. switch (orgCSS.position)
  240. {
  241. case 'absolute':
  242. case 'fixed':
  243. newPosition = orgCSS.position;
  244. break;
  245. }
  246. if (conf.wrapper == 'parent')
  247. {
  248. sz_storeOrigCss($wrp);
  249. }
  250. else
  251. {
  252. $wrp.css(orgCSS);
  253. }
  254. $wrp.css({
  255. 'overflow' : 'hidden',
  256. 'position' : newPosition
  257. });
  258. sz_storeOrigCss($cfs);
  259. $cfs.data('_cfs_origCssZindex', orgCSS.zIndex);
  260. $cfs.css({
  261. 'textAlign' : 'left',
  262. 'float' : 'none',
  263. 'position' : 'absolute',
  264. 'top' : 0,
  265. 'right' : 'auto',
  266. 'bottom' : 'auto',
  267. 'left' : 0,
  268. 'marginTop' : 0,
  269. 'marginRight' : 0,
  270. 'marginBottom' : 0,
  271. 'marginLeft' : 0
  272. });
  273. sz_storeMargin(a_itm, opts);
  274. sz_storeOrigCss(a_itm);
  275. if (opts.responsive)
  276. {
  277. sz_setResponsiveSizes(opts, a_itm);
  278. }
  279. }; // /build
  280. FN._bind_events = function() {
  281. FN._unbind_events();
  282. // stop event
  283. $cfs.bind(cf_e('stop', conf), function(e, imm) {
  284. e.stopPropagation();
  285. // button
  286. if (!crsl.isStopped)
  287. {
  288. if (opts.auto.button)
  289. {
  290. opts.auto.button.addClass(cf_c('stopped', conf));
  291. }
  292. }
  293. // set stopped
  294. crsl.isStopped = true;
  295. if (opts.auto.play)
  296. {
  297. opts.auto.play = false;
  298. $cfs.trigger(cf_e('pause', conf), imm);
  299. }
  300. return true;
  301. });
  302. // finish event
  303. $cfs.bind(cf_e('finish', conf), function(e) {
  304. e.stopPropagation();
  305. if (crsl.isScrolling)
  306. {
  307. sc_stopScroll(scrl);
  308. }
  309. return true;
  310. });
  311. // pause event
  312. $cfs.bind(cf_e('pause', conf), function(e, imm, res) {
  313. e.stopPropagation();
  314. tmrs = sc_clearTimers(tmrs);
  315. // immediately pause
  316. if (imm && crsl.isScrolling)
  317. {
  318. scrl.isStopped = true;
  319. var nst = getTime() - scrl.startTime;
  320. scrl.duration -= nst;
  321. if (scrl.pre)
  322. {
  323. scrl.pre.duration -= nst;
  324. }
  325. if (scrl.post)
  326. {
  327. scrl.post.duration -= nst;
  328. }
  329. sc_stopScroll(scrl, false);
  330. }
  331. // update remaining pause-time
  332. if (!crsl.isPaused && !crsl.isScrolling)
  333. {
  334. if (res)
  335. {
  336. tmrs.timePassed += getTime() - tmrs.startTime;
  337. }
  338. }
  339. // button
  340. if (!crsl.isPaused)
  341. {
  342. if (opts.auto.button)
  343. {
  344. opts.auto.button.addClass(cf_c('paused', conf));
  345. }
  346. }
  347. // set paused
  348. crsl.isPaused = true;
  349. // pause pause callback
  350. if (opts.auto.onTimeoutPause)
  351. {
  352. var dur1 = opts.auto.timeoutDuration - tmrs.timePassed,
  353. perc = 100 - Math.ceil( dur1 * 100 / opts.auto.timeoutDuration );
  354. opts.auto.onTimeoutPause.call($tt0, perc, dur1);
  355. }
  356. return true;
  357. });
  358. // play event
  359. $cfs.bind(cf_e('play', conf), function(e, dir, del, res) {
  360. e.stopPropagation();
  361. tmrs = sc_clearTimers(tmrs);
  362. // sort params
  363. var v = [dir, del, res],
  364. t = ['string', 'number', 'boolean'],
  365. a = cf_sortParams(v, t);
  366. dir = a[0];
  367. del = a[1];
  368. res = a[2];
  369. if (dir != 'prev' && dir != 'next')
  370. {
  371. dir = crsl.direction;
  372. }
  373. if (!is_number(del))
  374. {
  375. del = 0;
  376. }
  377. if (!is_boolean(res))
  378. {
  379. res = false;
  380. }
  381. // stopped?
  382. if (res)
  383. {
  384. crsl.isStopped = false;
  385. opts.auto.play = true;
  386. }
  387. if (!opts.auto.play)
  388. {
  389. e.stopImmediatePropagation();
  390. return debug(conf, 'Carousel stopped: Not scrolling.');
  391. }
  392. // button
  393. if (crsl.isPaused)
  394. {
  395. if (opts.auto.button)
  396. {
  397. opts.auto.button.removeClass(cf_c('stopped', conf));
  398. opts.auto.button.removeClass(cf_c('paused', conf));
  399. }
  400. }
  401. // set playing
  402. crsl.isPaused = false;
  403. tmrs.startTime = getTime();
  404. // timeout the scrolling
  405. var dur1 = opts.auto.timeoutDuration + del;
  406. dur2 = dur1 - tmrs.timePassed;
  407. perc = 100 - Math.ceil(dur2 * 100 / dur1);
  408. if (opts.auto.progress)
  409. {
  410. tmrs.progress = setInterval(function() {
  411. var pasd = getTime() - tmrs.startTime + tmrs.timePassed,
  412. perc = Math.ceil(pasd * 100 / dur1);
  413. opts.auto.progress.updater.call(opts.auto.progress.bar[0], perc);
  414. }, opts.auto.progress.interval);
  415. }
  416. tmrs.auto = setTimeout(function() {
  417. if (opts.auto.progress)
  418. {
  419. opts.auto.progress.updater.call(opts.auto.progress.bar[0], 100);
  420. }
  421. if (opts.auto.onTimeoutEnd)
  422. {
  423. opts.auto.onTimeoutEnd.call($tt0, perc, dur2);
  424. }
  425. if (crsl.isScrolling)
  426. {
  427. $cfs.trigger(cf_e('play', conf), dir);
  428. }
  429. else
  430. {
  431. $cfs.trigger(cf_e(dir, conf), opts.auto);
  432. }
  433. }, dur2);
  434. // pause start callback
  435. if (opts.auto.onTimeoutStart)
  436. {
  437. opts.auto.onTimeoutStart.call($tt0, perc, dur2);
  438. }
  439. return true;
  440. });
  441. // resume event
  442. $cfs.bind(cf_e('resume', conf), function(e) {
  443. e.stopPropagation();
  444. if (scrl.isStopped)
  445. {
  446. scrl.isStopped = false;
  447. crsl.isPaused = false;
  448. crsl.isScrolling = true;
  449. scrl.startTime = getTime();
  450. sc_startScroll(scrl, conf);
  451. }
  452. else
  453. {
  454. $cfs.trigger(cf_e('play', conf));
  455. }
  456. return true;
  457. });
  458. // prev + next events
  459. $cfs.bind(cf_e('prev', conf)+' '+cf_e('next', conf), function(e, obj, num, clb, que) {
  460. e.stopPropagation();
  461. // stopped or hidden carousel, don't scroll, don't queue
  462. if (crsl.isStopped || $cfs.is(':hidden'))
  463. {
  464. e.stopImmediatePropagation();
  465. return debug(conf, 'Carousel stopped or hidden: Not scrolling.');
  466. }
  467. // not enough items
  468. var minimum = (is_number(opts.items.minimum)) ? opts.items.minimum : opts.items.visible + 1;
  469. if (minimum > itms.total)
  470. {
  471. e.stopImmediatePropagation();
  472. return debug(conf, 'Not enough items ('+itms.total+' total, '+minimum+' needed): Not scrolling.');
  473. }
  474. // get config
  475. var v = [obj, num, clb, que],
  476. t = ['object', 'number/string', 'function', 'boolean'],
  477. a = cf_sortParams(v, t);
  478. obj = a[0];
  479. num = a[1];
  480. clb = a[2];
  481. que = a[3];
  482. var eType = e.type.slice(conf.events.prefix.length);
  483. if (!is_object(obj))
  484. {
  485. obj = {};
  486. }
  487. if (is_function(clb))
  488. {
  489. obj.onAfter = clb;
  490. }
  491. if (is_boolean(que))
  492. {
  493. obj.queue = que;
  494. }
  495. obj = $.extend(true, {}, opts[eType], obj);
  496. // test conditions callback
  497. if (obj.conditions && !obj.conditions.call($tt0, eType))
  498. {
  499. e.stopImmediatePropagation();
  500. return debug(conf, 'Callback "conditions" returned false.');
  501. }
  502. if (!is_number(num))
  503. {
  504. if (opts.items.filter != '*')
  505. {
  506. num = 'visible';
  507. }
  508. else
  509. {
  510. var arr = [num, obj.items, opts[eType].items];
  511. for (var a = 0, l = arr.length; a < l; a++)
  512. {
  513. if (is_number(arr[a]) || arr[a] == 'page' || arr[a] == 'visible') {
  514. num = arr[a];
  515. break;
  516. }
  517. }
  518. }
  519. switch(num) {
  520. case 'page':
  521. e.stopImmediatePropagation();
  522. return $cfs.triggerHandler(cf_e(eType+'Page', conf), [obj, clb]);
  523. break;
  524. case 'visible':
  525. if (!opts.items.visibleConf.variable && opts.items.filter == '*')
  526. {
  527. num = opts.items.visible;
  528. }
  529. break;
  530. }
  531. }
  532. // resume animation, add current to queue
  533. if (scrl.isStopped)
  534. {
  535. $cfs.trigger(cf_e('resume', conf));
  536. $cfs.trigger(cf_e('queue', conf), [eType, [obj, num, clb]]);
  537. e.stopImmediatePropagation();
  538. return debug(conf, 'Carousel resumed scrolling.');
  539. }
  540. // queue if scrolling
  541. if (obj.duration > 0)
  542. {
  543. if (crsl.isScrolling)
  544. {
  545. if (obj.queue)
  546. {
  547. if (obj.queue == 'last')
  548. {
  549. queu = [];
  550. }
  551. if (obj.queue != 'first' || queu.length == 0)
  552. {
  553. $cfs.trigger(cf_e('queue', conf), [eType, [obj, num, clb]]);
  554. }
  555. }
  556. e.stopImmediatePropagation();
  557. return debug(conf, 'Carousel currently scrolling.');
  558. }
  559. }
  560. tmrs.timePassed = 0;
  561. $cfs.trigger(cf_e('slide_'+eType, conf), [obj, num]);
  562. // synchronise
  563. if (opts.synchronise)
  564. {
  565. var s = opts.synchronise,
  566. c = [obj, num];
  567. for (var j = 0, l = s.length; j < l; j++) {
  568. var d = eType;
  569. if (!s[j][2])
  570. {
  571. d = (d == 'prev') ? 'next' : 'prev';
  572. }
  573. if (!s[j][1])
  574. {
  575. c[0] = s[j][0].triggerHandler('_cfs_triggerEvent', ['configuration', d]);
  576. }
  577. c[1] = num + s[j][3];
  578. s[j][0].trigger('_cfs_triggerEvent', ['slide_'+d, c]);
  579. }
  580. }
  581. return true;
  582. });
  583. // prev event
  584. $cfs.bind(cf_e('slide_prev', conf), function(e, sO, nI) {
  585. e.stopPropagation();
  586. var a_itm = $cfs.children();
  587. // non-circular at start, scroll to end
  588. if (!opts.circular)
  589. {
  590. if (itms.first == 0)
  591. {
  592. if (opts.infinite)
  593. {
  594. $cfs.trigger(cf_e('next', conf), itms.total-1);
  595. }
  596. return e.stopImmediatePropagation();
  597. }
  598. }
  599. sz_resetMargin(a_itm, opts);
  600. // find number of items to scroll
  601. if (!is_number(nI))
  602. {
  603. if (opts.items.visibleConf.variable)
  604. {
  605. nI = gn_getVisibleItemsPrev(a_itm, opts, itms.total-1);
  606. }
  607. else if (opts.items.filter != '*')
  608. {
  609. var xI = (is_number(sO.items)) ? sO.items : gn_getVisibleOrg($cfs, opts);
  610. nI = gn_getScrollItemsPrevFilter(a_itm, opts, itms.total-1, xI);
  611. }
  612. else
  613. {
  614. nI = opts.items.visible;
  615. }
  616. nI = cf_getAdjust(nI, opts, sO.items, $tt0);
  617. }
  618. // prevent non-circular from scrolling to far
  619. if (!opts.circular)
  620. {
  621. if (itms.total - nI < itms.first)
  622. {
  623. nI = itms.total - itms.first;
  624. }
  625. }
  626. // set new number of visible items
  627. opts.items.visibleConf.old = opts.items.visible;
  628. if (opts.items.visibleConf.variable)
  629. {
  630. var vI = cf_getItemsAdjust(gn_getVisibleItemsNext(a_itm, opts, itms.total-nI), opts, opts.items.visibleConf.adjust, $tt0);
  631. if (opts.items.visible+nI <= vI && nI < itms.total)
  632. {
  633. nI++;
  634. vI = cf_getItemsAdjust(gn_getVisibleItemsNext(a_itm, opts, itms.total-nI), opts, opts.items.visibleConf.adjust, $tt0);
  635. }
  636. opts.items.visible = vI;
  637. }
  638. else if (opts.items.filter != '*')
  639. {
  640. var vI = gn_getVisibleItemsNextFilter(a_itm, opts, itms.total-nI);
  641. opts.items.visible = cf_getItemsAdjust(vI, opts, opts.items.visibleConf.adjust, $tt0);
  642. }
  643. sz_resetMargin(a_itm, opts, true);
  644. // scroll 0, don't scroll
  645. if (nI == 0)
  646. {
  647. e.stopImmediatePropagation();
  648. return debug(conf, '0 items to scroll: Not scrolling.');
  649. }
  650. debug(conf, 'Scrolling '+nI+' items backward.');
  651. // save new config
  652. itms.first += nI;
  653. while (itms.first >= itms.total)
  654. {
  655. itms.first -= itms.total;
  656. }
  657. // non-circular callback
  658. if (!opts.circular)
  659. {
  660. if (itms.first == 0 && sO.onEnd)
  661. {
  662. sO.onEnd.call($tt0, 'prev');
  663. }
  664. if (!opts.infinite)
  665. {
  666. nv_enableNavi(opts, itms.first, conf);
  667. }
  668. }
  669. // rearrange items
  670. $cfs.children().slice(itms.total-nI, itms.total).prependTo($cfs);
  671. if (itms.total < opts.items.visible + nI)
  672. {
  673. $cfs.children().slice(0, (opts.items.visible+nI)-itms.total).clone(true).appendTo($cfs);
  674. }
  675. // the needed items
  676. var a_itm = $cfs.children(),
  677. i_old = gi_getOldItemsPrev(a_itm, opts, nI),
  678. i_new = gi_getNewItemsPrev(a_itm, opts),
  679. i_cur_l = a_itm.eq(nI-1),
  680. i_old_l = i_old.last(),
  681. i_new_l = i_new.last();
  682. sz_resetMargin(a_itm, opts);
  683. var pL = 0,
  684. pR = 0;
  685. if (opts.align)
  686. {
  687. var p = cf_getAlignPadding(i_new, opts);
  688. pL = p[0];
  689. pR = p[1];
  690. }
  691. var oL = (pL < 0) ? opts.padding[opts.d[3]] : 0;
  692. // hide items for fx directscroll
  693. var hiddenitems = false,
  694. i_skp = $();
  695. if (opts.items.visible < nI)
  696. {
  697. i_skp = a_itm.slice(opts.items.visibleConf.old, nI);
  698. if (sO.fx == 'directscroll')
  699. {
  700. var orgW = opts.items[opts.d['width']];
  701. hiddenitems = i_skp;
  702. i_cur_l = i_new_l;
  703. sc_hideHiddenItems(hiddenitems);
  704. opts.items[opts.d['width']] = 'variable';
  705. }
  706. }
  707. // save new sizes
  708. var $cf2 = false,
  709. i_siz = ms_getTotalSize(a_itm.slice(0, nI), opts, 'width'),
  710. w_siz = cf_mapWrapperSizes(ms_getSizes(i_new, opts, true), opts, !opts.usePadding),
  711. i_siz_vis = 0,
  712. a_cfs = {},
  713. a_wsz = {},
  714. a_cur = {},
  715. a_old = {},
  716. a_new = {},
  717. a_lef = {},
  718. a_lef_vis = {},
  719. a_dur = sc_getDuration(sO, opts, nI, i_siz);
  720. switch(sO.fx)
  721. {
  722. case 'cover':
  723. case 'cover-fade':
  724. i_siz_vis = ms_getTotalSize(a_itm.slice(0, opts.items.visible), opts, 'width');
  725. break;
  726. }
  727. if (hiddenitems)
  728. {
  729. opts.items[opts.d['width']] = orgW;
  730. }
  731. sz_resetMargin(a_itm, opts, true);
  732. if (pR >= 0)
  733. {
  734. sz_resetMargin(i_old_l, opts, opts.padding[opts.d[1]]);
  735. }
  736. if (pL >= 0)
  737. {
  738. sz_resetMargin(i_cur_l, opts, opts.padding[opts.d[3]]);
  739. }
  740. if (opts.align)
  741. {
  742. opts.padding[opts.d[1]] = pR;
  743. opts.padding[opts.d[3]] = pL;
  744. }
  745. a_lef[opts.d['left']] = -(i_siz - oL);
  746. a_lef_vis[opts.d['left']] = -(i_siz_vis - oL);
  747. a_wsz[opts.d['left']] = w_siz[opts.d['width']];
  748. // scrolling functions
  749. var _s_wrapper = function() {},
  750. _a_wrapper = function() {},
  751. _s_paddingold = function() {},
  752. _a_paddingold = function() {},
  753. _s_paddingnew = function() {},
  754. _a_paddingnew = function() {},
  755. _s_paddingcur = function() {},
  756. _a_paddingcur = function() {},
  757. _onafter = function() {},
  758. _moveitems = function() {},
  759. _position = function() {};
  760. // clone carousel
  761. switch(sO.fx)
  762. {
  763. case 'crossfade':
  764. case 'cover':
  765. case 'cover-fade':
  766. case 'uncover':
  767. case 'uncover-fade':
  768. $cf2 = $cfs.clone(true).appendTo($wrp);
  769. break;
  770. }
  771. switch(sO.fx)
  772. {
  773. case 'crossfade':
  774. case 'uncover':
  775. case 'uncover-fade':
  776. $cf2.children().slice(0, nI).remove();
  777. $cf2.children().slice(opts.items.visibleConf.old).remove();
  778. break;
  779. case 'cover':
  780. case 'cover-fade':
  781. $cf2.children().slice(opts.items.visible).remove();
  782. $cf2.css(a_lef_vis);
  783. break;
  784. }
  785. $cfs.css(a_lef);
  786. // reset all scrolls
  787. scrl = sc_setScroll(a_dur, sO.easing, conf);
  788. // animate / set carousel
  789. a_cfs[opts.d['left']] = (opts.usePadding) ? opts.padding[opts.d[3]] : 0;
  790. // animate / set wrapper
  791. if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable')
  792. {
  793. _s_wrapper = function() {
  794. $wrp.css(w_siz);
  795. };
  796. _a_wrapper = function() {
  797. scrl.anims.push([$wrp, w_siz]);
  798. };
  799. }
  800. // animate / set items
  801. if (opts.usePadding)
  802. {
  803. if (i_new_l.not(i_cur_l).length)
  804. {
  805. a_cur[opts.d['marginRight']] = i_cur_l.data('_cfs_origCssMargin');
  806. if (pL < 0)
  807. {
  808. i_cur_l.css(a_cur);
  809. }
  810. else
  811. {
  812. _s_paddingcur = function() {
  813. i_cur_l.css(a_cur);
  814. };
  815. _a_paddingcur = function() {
  816. scrl.anims.push([i_cur_l, a_cur]);
  817. };
  818. }
  819. }
  820. switch(sO.fx)
  821. {
  822. case 'cover':
  823. case 'cover-fade':
  824. $cf2.children().eq(nI-1).css(a_cur);
  825. break;
  826. }
  827. if (i_new_l.not(i_old_l).length)
  828. {
  829. a_old[opts.d['marginRight']] = i_old_l.data('_cfs_origCssMargin');
  830. _s_paddingold = function() {
  831. i_old_l.css(a_old);
  832. };
  833. _a_paddingold = function() {
  834. scrl.anims.push([i_old_l, a_old]);
  835. };
  836. }
  837. if (pR >= 0)
  838. {
  839. a_new[opts.d['marginRight']] = i_new_l.data('_cfs_origCssMargin') + opts.padding[opts.d[1]];
  840. _s_paddingnew = function() {
  841. i_new_l.css(a_new);
  842. };
  843. _a_paddingnew = function() {
  844. scrl.anims.push([i_new_l, a_new]);
  845. };
  846. }
  847. }
  848. // set position
  849. _position = function() {
  850. $cfs.css(a_cfs);
  851. };
  852. var overFill = opts.items.visible+nI-itms.total;
  853. // rearrange items
  854. _moveitems = function() {
  855. if (overFill > 0)
  856. {
  857. $cfs.children().slice(itms.total).remove();
  858. i_old = $( $cfs.children().slice(itms.total-(opts.items.visible-overFill)).get().concat( $cfs.children().slice(0, overFill).get() ) );
  859. }
  860. sc_showHiddenItems(hiddenitems);
  861. if (opts.usePadding)
  862. {
  863. var l_itm = $cfs.children().eq(opts.items.visible+nI-1);
  864. l_itm.css(opts.d['marginRight'], l_itm.data('_cfs_origCssMargin'));
  865. }
  866. };
  867. var cb_arguments = sc_mapCallbackArguments(i_old, i_skp, i_new, nI, 'prev', a_dur, w_siz);
  868. // fire onAfter callbacks
  869. _onafter = function() {
  870. sc_afterScroll($cfs, $cf2, sO);
  871. crsl.isScrolling = false;
  872. clbk.onAfter = sc_fireCallbacks($tt0, sO, 'onAfter', cb_arguments, clbk);
  873. queu = sc_fireQueue($cfs, queu, conf);
  874. if (!crsl.isPaused)
  875. {
  876. $cfs.trigger(cf_e('play', conf));
  877. }
  878. };
  879. // fire onBefore callback
  880. crsl.isScrolling = true;
  881. tmrs = sc_clearTimers(tmrs);
  882. clbk.onBefore = sc_fireCallbacks($tt0, sO, 'onBefore', cb_arguments, clbk);
  883. switch(sO.fx)
  884. {
  885. case 'none':
  886. $cfs.css(a_cfs);
  887. _s_wrapper();
  888. _s_paddingold();
  889. _s_paddingnew();
  890. _s_paddingcur();
  891. _position();
  892. _moveitems();
  893. _onafter();
  894. break;
  895. case 'fade':
  896. scrl.anims.push([$cfs, { 'opacity': 0 }, function() {
  897. _s_wrapper();
  898. _s_paddingold();
  899. _s_paddingnew();
  900. _s_paddingcur();
  901. _position();
  902. _moveitems();
  903. scrl = sc_setScroll(a_dur, sO.easing, conf);
  904. scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
  905. sc_startScroll(scrl, conf);
  906. }]);
  907. break;
  908. case 'crossfade':
  909. $cfs.css({ 'opacity': 0 });
  910. scrl.anims.push([$cf2, { 'opacity': 0 }]);
  911. scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
  912. _a_wrapper();
  913. _s_paddingold();
  914. _s_paddingnew();
  915. _s_paddingcur();
  916. _position();
  917. _moveitems();
  918. break;
  919. case 'cover':
  920. scrl.anims.push([$cf2, a_cfs, function() {
  921. _s_paddingold();
  922. _s_paddingnew();
  923. _s_paddingcur();
  924. _position();
  925. _moveitems();
  926. _onafter();
  927. }]);
  928. _a_wrapper();
  929. break;
  930. case 'cover-fade':
  931. scrl.anims.push([$cfs, { 'opacity': 0 }]);
  932. scrl.anims.push([$cf2, a_cfs, function() {
  933. _s_paddingold();
  934. _s_paddingnew();
  935. _s_paddingcur();
  936. _position();
  937. _moveitems();
  938. _onafter();
  939. }]);
  940. _a_wrapper();
  941. break;
  942. case 'uncover':
  943. scrl.anims.push([$cf2, a_wsz, _onafter]);
  944. _a_wrapper();
  945. _s_paddingold();
  946. _s_paddingnew();
  947. _s_paddingcur();
  948. _position();
  949. _moveitems();
  950. break;
  951. case 'uncover-fade':
  952. $cfs.css({ 'opacity': 0 });
  953. scrl.anims.push([$cfs, { 'opacity': 1 }]);
  954. scrl.anims.push([$cf2, a_wsz, _onafter]);
  955. _a_wrapper();
  956. _s_paddingold();
  957. _s_paddingnew();
  958. _s_paddingcur();
  959. _position();
  960. _moveitems();
  961. break;
  962. default:
  963. scrl.anims.push([$cfs, a_cfs, function() {
  964. _moveitems();
  965. _onafter();
  966. }]);
  967. _a_wrapper();
  968. _a_paddingold();
  969. _a_paddingnew();
  970. _a_paddingcur();
  971. break;
  972. }
  973. sc_startScroll(scrl, conf);
  974. cf_setCookie(opts.cookie, $cfs, conf);
  975. $cfs.trigger(cf_e('updatePageStatus', conf), [false, w_siz]);
  976. return true;
  977. });
  978. // next event
  979. $cfs.bind(cf_e('slide_next', conf), function(e, sO, nI) {
  980. e.stopPropagation();
  981. var a_itm = $cfs.children();
  982. // non-circular at end, scroll to start
  983. if (!opts.circular)
  984. {
  985. if (itms.first == opts.items.visible)
  986. {
  987. if (opts.infinite)
  988. {
  989. $cfs.trigger(cf_e('prev', conf), itms.total-1);
  990. }
  991. return e.stopImmediatePropagation();
  992. }
  993. }
  994. sz_resetMargin(a_itm, opts);
  995. // find number of items to scroll
  996. if (!is_number(nI))
  997. {
  998. if (opts.items.filter != '*')
  999. {
  1000. var xI = (is_number(sO.items)) ? sO.items : gn_getVisibleOrg($cfs, opts);
  1001. nI = gn_getScrollItemsNextFilter(a_itm, opts, 0, xI);
  1002. }
  1003. else
  1004. {
  1005. nI = opts.items.visible;
  1006. }
  1007. nI = cf_getAdjust(nI, opts, sO.items, $tt0);
  1008. }
  1009. var lastItemNr = (itms.first == 0) ? itms.total : itms.first;
  1010. // prevent non-circular from scrolling to far
  1011. if (!opts.circular)
  1012. {
  1013. if (opts.items.visibleConf.variable)
  1014. {
  1015. var vI = gn_getVisibleItemsNext(a_itm, opts, nI),
  1016. xI = gn_getVisibleItemsPrev(a_itm, opts, lastItemNr-1);
  1017. }
  1018. else
  1019. {
  1020. var vI = opts.items.visible,
  1021. xI = opts.items.visible;
  1022. }
  1023. if (nI + vI > lastItemNr)
  1024. {
  1025. nI = lastItemNr - xI;
  1026. }
  1027. }
  1028. // set new number of visible items
  1029. opts.items.visibleConf.old = opts.items.visible;
  1030. if (opts.items.visibleConf.variable)
  1031. {
  1032. var vI = cf_getItemsAdjust(gn_getVisibleItemsNextTestCircular(a_itm, opts, nI, lastItemNr), opts, opts.items.visibleConf.adjust, $tt0);
  1033. while (opts.items.visible-nI >= vI && nI < itms.total)
  1034. {
  1035. nI++;
  1036. vI = cf_getItemsAdjust(gn_getVisibleItemsNextTestCircular(a_itm, opts, nI, lastItemNr), opts, opts.items.visibleConf.adjust, $tt0);
  1037. }
  1038. opts.items.visible = vI;
  1039. }
  1040. else if (opts.items.filter != '*')
  1041. {
  1042. var vI = gn_getVisibleItemsNextFilter(a_itm, opts, nI);
  1043. opts.items.visible = cf_getItemsAdjust(vI, opts, opts.items.visibleConf.adjust, $tt0);
  1044. }
  1045. sz_resetMargin(a_itm, opts, true);
  1046. // scroll 0, don't scroll
  1047. if (nI == 0)
  1048. {
  1049. e.stopImmediatePropagation();
  1050. return debug(conf, '0 items to scroll: Not scrolling.');
  1051. }
  1052. debug(conf, 'Scrolling '+nI+' items forward.');
  1053. // save new config
  1054. itms.first -= nI;
  1055. while (itms.first < 0)
  1056. {
  1057. itms.first += itms.total;
  1058. }
  1059. // non-circular callback
  1060. if (!opts.circular)
  1061. {
  1062. if (itms.first == opts.items.visible && sO.onEnd)
  1063. {
  1064. sO.onEnd.call($tt0, 'next');
  1065. }
  1066. if (!opts.infinite)
  1067. {
  1068. nv_enableNavi(opts, itms.first, conf);
  1069. }
  1070. }
  1071. // rearrange items
  1072. if (itms.total < opts.items.visible+nI)
  1073. {
  1074. $cfs.children().slice(0, (opts.items.visible+nI)-itms.total).clone(true).appendTo($cfs);
  1075. }
  1076. // the needed items
  1077. var a_itm = $cfs.children(),
  1078. i_old = gi_getOldItemsNext(a_itm, opts),
  1079. i_new = gi_getNewItemsNext(a_itm, opts, nI),
  1080. i_cur_l = a_itm.eq(nI-1),
  1081. i_old_l = i_old.last(),
  1082. i_new_l = i_new.last();
  1083. sz_resetMargin(a_itm, opts);
  1084. var pL = 0,
  1085. pR = 0;
  1086. if (opts.align)
  1087. {
  1088. var p = cf_getAlignPadding(i_new, opts);
  1089. pL = p[0];
  1090. pR = p[1];
  1091. }
  1092. // hide items for fx directscroll
  1093. var hiddenitems = false,
  1094. i_skp = $();
  1095. if (opts.items.visibleConf.old < nI)
  1096. {
  1097. i_skp = a_itm.slice(opts.items.visibleConf.old, nI);
  1098. if (sO.fx == 'directscroll')
  1099. {
  1100. var orgW = opts.items[opts.d['width']];
  1101. hiddenitems = i_skp;
  1102. i_cur_l = i_old_l;
  1103. sc_hideHiddenItems(hiddenitems);
  1104. opts.items[opts.d['width']] = 'variable';
  1105. }
  1106. }
  1107. // save new sizes
  1108. var $cf2 = false,
  1109. i_siz = ms_getTotalSize(a_itm.slice(0, nI), opts, 'width'),
  1110. w_siz = cf_mapWrapperSizes(ms_getSizes(i_new, opts, true), opts, !opts.usePadding),
  1111. i_siz_vis = 0,
  1112. a_cfs = {},
  1113. a_cfs_vis = {},
  1114. a_cur = {},
  1115. a_old = {},
  1116. a_lef = {},
  1117. a_dur = sc_getDuration(sO, opts, nI, i_siz);
  1118. switch(sO.fx)
  1119. {
  1120. case 'uncover':
  1121. case 'uncover-fade':
  1122. i_siz_vis = ms_getTotalSize(a_itm.slice(0, opts.items.visibleConf.old), opts, 'width');
  1123. break;
  1124. }
  1125. if (hiddenitems)
  1126. {
  1127. opts.items[opts.d['width']] = orgW;
  1128. }
  1129. if (opts.align)
  1130. {
  1131. if (opts.padding[opts.d[1]] < 0)
  1132. {
  1133. opts.padding[opts.d[1]] = 0;
  1134. }
  1135. }
  1136. sz_resetMargin(a_itm, opts, true);
  1137. sz_resetMargin(i_old_l, opts, opts.padding[opts.d[1]]);
  1138. if (opts.align)
  1139. {
  1140. opts.padding[opts.d[1]] = pR;
  1141. opts.padding[opts.d[3]] = pL;
  1142. }
  1143. a_lef[opts.d['left']] = (opts.usePadding) ? opts.padding[opts.d[3]] : 0;
  1144. // scrolling functions
  1145. var _s_wrapper = function() {},
  1146. _a_wrapper = function() {},
  1147. _s_paddingold = function() {},
  1148. _a_paddingold = function() {},
  1149. _s_paddingcur = function() {},
  1150. _a_paddingcur = function() {},
  1151. _onafter = function() {},
  1152. _moveitems = function() {},
  1153. _position = function() {};
  1154. // clone carousel
  1155. switch(sO.fx)
  1156. {
  1157. case 'crossfade':
  1158. case 'cover':
  1159. case 'cover-fade':
  1160. case 'uncover':
  1161. case 'uncover-fade':
  1162. $cf2 = $cfs.clone(true).appendTo($wrp);
  1163. $cf2.children().slice(opts.items.visibleConf.old).remove();
  1164. break;
  1165. }
  1166. switch(sO.fx)
  1167. {
  1168. case 'crossfade':
  1169. case 'cover':
  1170. case 'cover-fade':
  1171. $cfs.css('zIndex', 1);
  1172. $cf2.css('zIndex', 0);
  1173. break;
  1174. }
  1175. // reset all scrolls
  1176. scrl = sc_setScroll(a_dur, sO.easing, conf);
  1177. // animate / set carousel
  1178. a_cfs[opts.d['left']] = -i_siz;
  1179. a_cfs_vis[opts.d['left']] = -i_siz_vis;
  1180. if (pL < 0)
  1181. {
  1182. a_cfs[opts.d['left']] += pL;
  1183. }
  1184. // animate / set wrapper
  1185. if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable')
  1186. {
  1187. _s_wrapper = function() {
  1188. $wrp.css(w_siz);
  1189. };
  1190. _a_wrapper = function() {
  1191. scrl.anims.push([$wrp, w_siz]);
  1192. };
  1193. }
  1194. // animate / set items
  1195. if (opts.usePadding)
  1196. {
  1197. var i_new_l_m = i_new_l.data('_cfs_origCssMargin');
  1198. if (pR >= 0)
  1199. {
  1200. i_new_l_m += opts.padding[opts.d[1]];
  1201. }
  1202. i_new_l.css(opts.d['marginRight'], i_new_l_m);
  1203. if (i_cur_l.not(i_old_l).length)
  1204. {
  1205. a_old[opts.d['marginRight']] = i_old_l.data('_cfs_origCssMargin');
  1206. }
  1207. _s_paddingold = function() {
  1208. i_old_l.css(a_old);
  1209. };
  1210. _a_paddingold = function() {
  1211. scrl.anims.push([i_old_l, a_old]);
  1212. };
  1213. var i_cur_l_m = i_cur_l.data('_cfs_origCssMargin');
  1214. if (pL > 0)
  1215. {
  1216. i_cur_l_m += opts.padding[opts.d[3]];
  1217. }
  1218. a_cur[opts.d['marginRight']] = i_cur_l_m;
  1219. _s_paddingcur = function() {
  1220. i_cur_l.css(a_cur);
  1221. };
  1222. _a_paddingcur = function() {
  1223. scrl.anims.push([i_cur_l, a_cur]);
  1224. };
  1225. }
  1226. // set position
  1227. _position = function() {
  1228. $cfs.css(a_lef);
  1229. };
  1230. var overFill = opts.items.visible+nI-itms.total;
  1231. // rearrange items
  1232. _moveitems = function() {
  1233. if (overFill > 0)
  1234. {
  1235. $cfs.children().slice(itms.total).remove();
  1236. }
  1237. var l_itm = $cfs.children().slice(0, nI).appendTo($cfs).last();
  1238. if (overFill > 0)
  1239. {
  1240. i_new = gi_getCurrentItems(a_itm, opts);
  1241. }
  1242. sc_showHiddenItems(hiddenitems);
  1243. if (opts.usePadding)
  1244. {
  1245. if (itms.total < opts.items.visible+nI) {
  1246. var i_cur_l = $cfs.children().eq(opts.items.visible-1);
  1247. i_cur_l.css(opts.d['marginRight'], i_cur_l.data('_cfs_origCssMargin') + opts.padding[opts.d[1]]);
  1248. }
  1249. l_itm.css(opts.d['marginRight'], l_itm.data('_cfs_origCssMargin'));
  1250. }
  1251. };
  1252. var cb_arguments = sc_mapCallbackArguments(i_old, i_skp, i_new, nI, 'next', a_dur, w_siz);
  1253. // fire onAfter callbacks
  1254. _onafter = function() {
  1255. $cfs.css('zIndex', $cfs.data('_cfs_origCssZindex'));
  1256. sc_afterScroll($cfs, $cf2, sO);
  1257. crsl.isScrolling = false;
  1258. clbk.onAfter = sc_fireCallbacks($tt0, sO, 'onAfter', cb_arguments, clbk);
  1259. queu = sc_fireQueue($cfs, queu, conf);
  1260. if (!crsl.isPaused)
  1261. {
  1262. $cfs.trigger(cf_e('play', conf));
  1263. }
  1264. };
  1265. // fire onBefore callbacks
  1266. crsl.isScrolling = true;
  1267. tmrs = sc_clearTimers(tmrs);
  1268. clbk.onBefore = sc_fireCallbacks($tt0, sO, 'onBefore', cb_arguments, clbk);
  1269. switch(sO.fx)
  1270. {
  1271. case 'none':
  1272. $cfs.css(a_cfs);
  1273. _s_wrapper();
  1274. _s_paddingold();
  1275. _s_paddingcur();
  1276. _position();
  1277. _moveitems();
  1278. _onafter();
  1279. break;
  1280. case 'fade':
  1281. scrl.anims.push([$cfs, { 'opacity': 0 }, function() {
  1282. _s_wrapper();
  1283. _s_paddingold();
  1284. _s_paddingcur();
  1285. _position();
  1286. _moveitems();
  1287. scrl = sc_setScroll(a_dur, sO.easing, conf);
  1288. scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
  1289. sc_startScroll(scrl, conf);
  1290. }]);
  1291. break;
  1292. case 'crossfade':
  1293. $cfs.css({ 'opacity': 0 });
  1294. scrl.anims.push([$cf2, { 'opacity': 0 }]);
  1295. scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
  1296. _a_wrapper();
  1297. _s_paddingold();
  1298. _s_paddingcur();
  1299. _position();
  1300. _moveitems();
  1301. break;
  1302. case 'cover':
  1303. $cfs.css(opts.d['left'], $wrp[opts.d['width']]());
  1304. scrl.anims.push([$cfs, a_lef, _onafter]);
  1305. _a_wrapper();
  1306. _s_paddingold();
  1307. _s_paddingcur();
  1308. _moveitems();
  1309. break;
  1310. case 'cover-fade':
  1311. $cfs.css(opts.d['left'], $wrp[opts.d['width']]());
  1312. scrl.anims.push([$cf2, { 'opacity': 0 }]);
  1313. scrl.anims.push([$cfs, a_lef, _onafter]);
  1314. _a_wrapper();
  1315. _s_paddingold();
  1316. _s_paddingcur();
  1317. _moveitems();
  1318. break;
  1319. case 'uncover':
  1320. scrl.anims.push([$cf2, a_cfs_vis, _onafter]);
  1321. _a_wrapper();
  1322. _s_paddingold();
  1323. _s_paddingcur();
  1324. _position();
  1325. _moveitems();
  1326. break;
  1327. case 'uncover-fade':
  1328. $cfs.css({ 'opacity': 0 });
  1329. scrl.anims.push([$cfs, { 'opacity': 1 }]);
  1330. scrl.anims.push([$cf2, a_cfs_vis, _onafter]);
  1331. _a_wrapper();
  1332. _s_paddingold();
  1333. _s_paddingcur();
  1334. _position();
  1335. _moveitems();
  1336. break;
  1337. default:
  1338. scrl.anims.push([$cfs, a_cfs, function() {
  1339. _position();
  1340. _moveitems();
  1341. _onafter();
  1342. }]);
  1343. _a_wrapper();
  1344. _a_paddingold();
  1345. _a_paddingcur();
  1346. break;
  1347. }
  1348. sc_startScroll(scrl, conf);
  1349. cf_setCookie(opts.cookie, $cfs, conf);
  1350. $cfs.trigger(cf_e('updatePageStatus', conf), [false, w_siz]);
  1351. return true;
  1352. });
  1353. // slideTo event
  1354. $cfs.bind(cf_e('slideTo', conf), function(e, num, dev, org, obj, dir, clb) {
  1355. e.stopPropagation();
  1356. var v = [num, dev, org, obj, dir, clb],
  1357. t = ['string/number/object', 'number', 'boolean', 'object', 'string', 'function'],
  1358. a = cf_sortParams(v, t);
  1359. obj = a[3];
  1360. dir = a[4];
  1361. clb = a[5];
  1362. num = gn_getItemIndex(a[0], a[1], a[2], itms, $cfs);
  1363. if (num == 0)
  1364. {
  1365. return false;
  1366. }
  1367. if (!is_object(obj))
  1368. {
  1369. obj = false;
  1370. }
  1371. if (dir != 'prev' && dir != 'next')
  1372. {
  1373. if (opts.circular)
  1374. {
  1375. dir = (num <= itms.total / 2) ? 'next' : 'prev';
  1376. }
  1377. else
  1378. {
  1379. dir = (itms.first == 0 || itms.first > num) ? 'next' : 'prev';
  1380. }
  1381. }
  1382. if (dir == 'prev')
  1383. {
  1384. num = itms.total-num;
  1385. }
  1386. $cfs.trigger(cf_e(dir, conf), [obj, num, clb]);
  1387. return true;
  1388. });
  1389. // prevPage event
  1390. $cfs.bind(cf_e('prevPage', conf), function(e, obj, clb) {
  1391. e.stopPropagation();
  1392. var cur = $cfs.triggerHandler(cf_e('currentPage', conf));
  1393. return $cfs.triggerHandler(cf_e('slideToPage', conf), [cur-1, obj, 'prev', clb]);
  1394. });
  1395. // nextPage event
  1396. $cfs.bind(cf_e('nextPage', conf), function(e, obj, clb) {
  1397. e.stopPropagation();
  1398. var cur = $cfs.triggerHandler(cf_e('currentPage', conf));
  1399. return $cfs.triggerHandler(cf_e('slideToPage', conf), [cur+1, obj, 'next', clb]);
  1400. });
  1401. // slideToPage event
  1402. $cfs.bind(cf_e('slideToPage', conf), function(e, pag, obj, dir, clb) {
  1403. e.stopPropagation();
  1404. if (!is_number(pag))
  1405. {
  1406. pag = $cfs.triggerHandler(cf_e('currentPage', conf));
  1407. }
  1408. var ipp = opts.pagination.items || opts.items.visible,
  1409. max = Math.ceil(itms.total / ipp)-1;
  1410. if (pag < 0)
  1411. {
  1412. pag = max;
  1413. }
  1414. if (pag > max)
  1415. {
  1416. pag = 0;
  1417. }
  1418. return $cfs.triggerHandler(cf_e('slideTo', conf), [pag*ipp, 0, true, obj, dir, clb]);
  1419. });
  1420. // jumpToStart event
  1421. $cfs.bind(cf_e('jumpToStart', conf), function(e, s) {
  1422. e.stopPropagation();
  1423. if (s)
  1424. {
  1425. s = gn_getItemIndex(s, 0, true, itms, $cfs);
  1426. }
  1427. else
  1428. {
  1429. s = 0;
  1430. }
  1431. s += itms.first;
  1432. if (s != 0)
  1433. {
  1434. if (itms.total > 0)
  1435. {
  1436. while (s > itms.total)
  1437. {
  1438. s -= itms.total;
  1439. }
  1440. }
  1441. $cfs.prepend($cfs.children().slice(s, itms.total));
  1442. }
  1443. return true;
  1444. });
  1445. // synchronise event
  1446. $cfs.bind(cf_e('synchronise', conf), function(e, s) {
  1447. e.stopPropagation();
  1448. if (s)
  1449. {
  1450. s = cf_getSynchArr(s);
  1451. }
  1452. else if (opts.synchronise)
  1453. {
  1454. s = opts.synchronise;
  1455. }
  1456. else
  1457. {
  1458. return debug(conf, 'No carousel to synchronise.');
  1459. }
  1460. var n = $cfs.triggerHandler(cf_e('currentPosition', conf)),
  1461. x = true;
  1462. for (var j = 0, l = s.length; j < l; j++)
  1463. {
  1464. if (!s[j][0].triggerHandler(cf_e('slideTo', conf), [n, s[j][3], true]))
  1465. {
  1466. x = false;
  1467. }
  1468. }
  1469. return x;
  1470. });
  1471. // queue event
  1472. $cfs.bind(cf_e('queue', conf), function(e, dir, opt) {
  1473. e.stopPropagation();
  1474. if (is_function(dir))
  1475. {
  1476. dir.call($tt0, queu);
  1477. }
  1478. else if (is_array(dir))
  1479. {
  1480. queu = dir;
  1481. }
  1482. else if (!is_undefined(dir))
  1483. {
  1484. queu.push([dir, opt]);
  1485. }
  1486. return queu;
  1487. });
  1488. // insertItem event
  1489. $cfs.bind(cf_e('insertItem', conf), function(e, itm, num, org, dev) {
  1490. e.stopPropagation();
  1491. var v = [itm, num, org, dev],
  1492. t = ['string/object', 'string/number/object', 'boolean', 'number'],
  1493. a = cf_sortParams(v, t);
  1494. itm = a[0];
  1495. num = a[1];
  1496. org = a[2];
  1497. dev = a[3];
  1498. if (is_object(itm) && !is_jquery(itm))
  1499. {
  1500. itm = $(itm);
  1501. }
  1502. else if (is_string(itm))
  1503. {
  1504. itm = $(itm);
  1505. }
  1506. if (!is_jquery(itm) || itm.length == 0)
  1507. {
  1508. return debug(conf, 'Not a valid object.');
  1509. }
  1510. if (is_undefined(num))
  1511. {
  1512. num = 'end';
  1513. }
  1514. sz_storeMargin(itm, opts);
  1515. sz_storeOrigCss(itm);
  1516. var orgNum = num,
  1517. before = 'before';
  1518. if (num == 'end')
  1519. {
  1520. if (org)
  1521. {
  1522. if (itms.first == 0)
  1523. {
  1524. num = itms.total-1;
  1525. before = 'after';
  1526. }
  1527. else
  1528. {
  1529. num = itms.first;
  1530. itms.first += itm.length;
  1531. }
  1532. if (num < 0)
  1533. {
  1534. num = 0;
  1535. }
  1536. }
  1537. else
  1538. {
  1539. num = itms.total-1;
  1540. before = 'after';
  1541. }
  1542. }
  1543. else
  1544. {
  1545. num = gn_getItemIndex(num, dev, org, itms, $cfs);
  1546. }
  1547. var $cit = $cfs.children().eq(num);
  1548. if ($cit.length)
  1549. {
  1550. $cit[before](itm);
  1551. }
  1552. else
  1553. {
  1554. debug(conf, 'Correct insert-position not found! Appending item to the end.');
  1555. $cfs.append(itm);
  1556. }
  1557. if (orgNum != 'end' && !org)
  1558. {
  1559. if (num < itms.first)
  1560. {
  1561. itms.first += itm.length;
  1562. }
  1563. }
  1564. itms.total = $cfs.children().length;
  1565. if (itms.first >= itms.total)
  1566. {
  1567. itms.first -= itms.total;
  1568. }
  1569. $cfs.trigger(cf_e('updateSizes', conf));
  1570. $cfs.trigger(cf_e('linkAnchors', conf));
  1571. return true;
  1572. });
  1573. // removeItem event
  1574. $cfs.bind(cf_e('removeItem', conf), function(e, num, org, dev) {
  1575. e.stopPropagation();
  1576. var v = [num, org, dev],
  1577. t = ['string/number/object', 'boolean', 'number'],
  1578. a = cf_sortParams(v, t);
  1579. num = a[0];
  1580. org = a[1];
  1581. dev = a[2];
  1582. var removed = false;
  1583. if (num instanceof $ && num.length > 1)
  1584. {
  1585. $removed = $();
  1586. num.each(function(i, el) {
  1587. var $rem = $cfs.trigger(cf_e('removeItem', conf), [$(this), org, dev]);
  1588. if ( $rem )
  1589. {
  1590. $removed = $removed.add($rem);
  1591. }
  1592. });
  1593. return $removed;
  1594. }
  1595. if (is_undefined(num) || num == 'end')
  1596. {
  1597. $removed = $cfs.children().last();
  1598. }
  1599. else
  1600. {
  1601. num = gn_getItemIndex(num, dev, org, itms, $cfs);
  1602. var $removed = $cfs.children().eq(num);
  1603. if ( $removed.length )
  1604. {
  1605. if (num < itms.first)
  1606. {
  1607. itms.first -= $removed.length;
  1608. }
  1609. }
  1610. }
  1611. if ( $removed && $removed.length )
  1612. {
  1613. $removed.detach();
  1614. itms.total = $cfs.children().length;
  1615. $cfs.trigger(cf_e('updateSizes', conf));
  1616. }
  1617. return $removed;
  1618. });
  1619. // onBefore and onAfter event
  1620. $cfs.bind(cf_e('onBefore', conf)+' '+cf_e('onAfter', conf), function(e, fn) {
  1621. e.stopPropagation();
  1622. var eType = e.type.slice(conf.events.prefix.length);
  1623. if (is_array(fn))
  1624. {
  1625. clbk[eType] = fn;
  1626. }
  1627. if (is_function(fn))
  1628. {
  1629. clbk[eType].push(fn);
  1630. }
  1631. return clbk[eType];
  1632. });
  1633. // currentPosition event
  1634. $cfs.bind(cf_e('currentPosition', conf), function(e, fn) {
  1635. e.stopPropagation();
  1636. if (itms.first == 0)
  1637. {
  1638. var val = 0;
  1639. }
  1640. else
  1641. {
  1642. var val = itms.total - itms.first;
  1643. }
  1644. if (is_function(fn))
  1645. {
  1646. fn.call($tt0, val);
  1647. }
  1648. return val;
  1649. });
  1650. // currentPage event
  1651. $cfs.bind(cf_e('currentPage', conf), function(e, fn) {
  1652. e.stopPropagation();
  1653. var ipp = opts.pagination.items || opts.items.visible,
  1654. max = Math.ceil(itms.total/ipp-1),
  1655. nr;
  1656. if (itms.first == 0)
  1657. {
  1658. nr = 0;
  1659. }
  1660. else if (itms.first < itms.total % ipp)
  1661. {
  1662. nr = 0;
  1663. }
  1664. else if (itms.first == ipp && !opts.circular)
  1665. {
  1666. nr = max;
  1667. }
  1668. else
  1669. {
  1670. nr = Math.round((itms.total-itms.first)/ipp);
  1671. }
  1672. if (nr < 0)
  1673. {
  1674. nr = 0;
  1675. }
  1676. if (nr > max)
  1677. {
  1678. nr = max;
  1679. }
  1680. if (is_function(fn))
  1681. {
  1682. fn.call($tt0, nr);
  1683. }
  1684. return nr;
  1685. });
  1686. // currentVisible event
  1687. $cfs.bind(cf_e('currentVisible', conf), function(e, fn) {
  1688. e.stopPropagation();
  1689. var $i = gi_getCurrentItems($cfs.children(), opts);
  1690. if (is_function(fn))
  1691. {
  1692. fn.call($tt0, $i);
  1693. }
  1694. return $i;
  1695. });
  1696. // slice event
  1697. $cfs.bind(cf_e('slice', conf), function(e, f, l, fn) {
  1698. e.stopPropagation();
  1699. if (itms.total == 0)
  1700. {
  1701. return false;
  1702. }
  1703. var v = [f, l, fn],
  1704. t = ['number', 'number', 'function'],
  1705. a = cf_sortParams(v, t);
  1706. f = (is_number(a[0])) ? a[0] : 0;
  1707. l = (is_number(a[1])) ? a[1] : itms.total;
  1708. fn = a[2];
  1709. f += itms.first;
  1710. l += itms.first;
  1711. if (items.total > 0)
  1712. {
  1713. while (f > itms.total)
  1714. {
  1715. f -= itms.total;
  1716. }
  1717. while (l > itms.total)
  1718. {
  1719. l -= itms.total;
  1720. }
  1721. while (f < 0)
  1722. {
  1723. f += itms.total;
  1724. }
  1725. while (l < 0)
  1726. {
  1727. l += itms.total;
  1728. }
  1729. }
  1730. var $iA = $cfs.children(),
  1731. $i;
  1732. if (l > f)
  1733. {
  1734. $i = $iA.slice(f, l);
  1735. }
  1736. else
  1737. {
  1738. $i = $( $iA.slice(f, itms.total).get().concat( $iA.slice(0, l).get() ) );
  1739. }
  1740. if (is_function(fn))
  1741. {
  1742. fn.call($tt0, $i);
  1743. }
  1744. return $i;
  1745. });
  1746. // isPaused, isStopped and isScrolling events
  1747. $cfs.bind(cf_e('isPaused', conf)+' '+cf_e('isStopped', conf)+' '+cf_e('isScrolling', conf), function(e, fn) {
  1748. e.stopPropagation();
  1749. var eType = e.type.slice(conf.events.prefix.length),
  1750. value = crsl[eType];
  1751. if (is_function(fn))
  1752. {
  1753. fn.call($tt0, value);
  1754. }
  1755. return value;
  1756. });
  1757. // configuration event
  1758. $cfs.bind(cf_e('configuration', conf), function(e, a, b, c) {
  1759. e.stopPropagation();
  1760. var reInit = false;
  1761. // return entire configuration-object
  1762. if (is_function(a))
  1763. {
  1764. a.call($tt0, opts);
  1765. }
  1766. // set multiple options via object
  1767. else if (is_object(a))
  1768. {
  1769. opts_orig = $.extend(true, {}, opts_orig, a);
  1770. if (b !== false) reInit = true;
  1771. else opts = $.extend(true, {}, opts, a);
  1772. }
  1773. else if (!is_undefined(a))
  1774. {
  1775. // callback function for specific option
  1776. if (is_function(b))
  1777. {
  1778. var val = eval('opts.'+a);
  1779. if (is_undefined(val))
  1780. {
  1781. val = '';
  1782. }
  1783. b.call($tt0, val);
  1784. }
  1785. // set individual option
  1786. else if (!is_undefined(b))
  1787. {
  1788. if (typeof c !== 'boolean') c = true;
  1789. eval('opts_orig.'+a+' = b');
  1790. if (c !== false) reInit = true;
  1791. else eval('opts.'+a+' = b');
  1792. }
  1793. // return value for specific option
  1794. else
  1795. {
  1796. return eval('opts.'+a);
  1797. }
  1798. }
  1799. if (reInit)
  1800. {
  1801. sz_resetMargin($cfs.children(), opts);
  1802. FN._init(opts_orig);
  1803. FN._bind_buttons();
  1804. var sz = sz_setSizes($cfs, opts);
  1805. $cfs.trigger(cf_e('updatePageStatus', conf), [true, sz]);
  1806. }
  1807. return opts;
  1808. });
  1809. // linkAnchors event
  1810. $cfs.bind(cf_e('linkAnchors', conf), function(e, $con, sel) {
  1811. e.stopPropagation();
  1812. if (is_undefined($con))
  1813. {
  1814. $con = $('body');
  1815. }
  1816. else if (is_string($con))
  1817. {
  1818. $con = $($con);
  1819. }
  1820. if (!is_jquery($con) || $con.length == 0)
  1821. {
  1822. return debug(conf, 'Not a valid object.');
  1823. }
  1824. if (!is_string(sel))
  1825. {
  1826. sel = 'a.caroufredsel';
  1827. }
  1828. $con.find(sel).each(function() {
  1829. var h = this.hash || '';
  1830. if (h.length > 0 && $cfs.children().index($(h)) != -1)
  1831. {
  1832. $(this).unbind('click').click(function(e) {
  1833. e.preventDefault();
  1834. $cfs.trigger(cf_e('slideTo', conf), h);
  1835. });
  1836. }
  1837. });
  1838. return true;
  1839. });
  1840. // updatePageStatus event
  1841. $cfs.bind(cf_e('updatePageStatus', conf), function(e, build, sizes) {
  1842. e.stopPropagation();
  1843. if (!opts.pagination.container)
  1844. {
  1845. return;
  1846. }
  1847. var ipp = opts.pagination.items || opts.items.visible,
  1848. pgs = Math.ceil(itms.total/ipp);
  1849. if (build)
  1850. {
  1851. if (opts.pagination.anchorBuilder)
  1852. {
  1853. opts.pagination.container.children().remove();
  1854. opts.pagination.container.each(function() {
  1855. for (var a = 0; a < pgs; a++)
  1856. {
  1857. var i = $cfs.children().eq( gn_getItemIndex(a*ipp, 0, true, itms, $cfs) );
  1858. $(this).append(opts.pagination.anchorBuilder.call(i[0], a+1));
  1859. }
  1860. });
  1861. }
  1862. opts.pagination.container.each(function() {
  1863. $(this).children().unbind(opts.pagination.event).each(function(a) {
  1864. $(this).bind(opts.pagination.event, function(e) {
  1865. e.preventDefault();
  1866. $cfs.trigger(cf_e('slideTo', conf), [a*ipp, -opts.pagination.deviation, true, opts.pagination]);
  1867. });
  1868. });
  1869. });
  1870. }
  1871. var selected = $cfs.triggerHandler(cf_e('currentPage', conf)) + opts.pagination.deviation;
  1872. if (selected >= pgs)
  1873. {
  1874. selected = 0;
  1875. }
  1876. if (selected < 0)
  1877. {
  1878. selected = pgs-1;
  1879. }
  1880. opts.pagination.container.each(function() {
  1881. $(this).children().removeClass(cf_c('selected', conf)).eq(selected).addClass(cf_c('selected', conf));
  1882. });
  1883. return true;
  1884. });
  1885. // updateSizes event
  1886. $cfs.bind(cf_e('updateSizes', conf), function(e) {
  1887. var vI = opts.items.visible,
  1888. a_itm = $cfs.children(),
  1889. avail_