PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/files/caroufredsel/6.1.0/jquery.carouFredSel-6.1.0.js

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