PageRenderTime 106ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/Mirros/jsdelivr
JavaScript | 2178 lines | 1766 code | 290 blank | 122 comment | 341 complexity | 096375940b494c4c55146be92f6a5c1f MD5 | raw file
  1. /*
  2. * jQuery carouFredSel 6.2.0
  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._cfs_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._cfs_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._cfs_bind_events = function() {
  281. FN._cfs_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. $cfs.css({ 'opacity': 1 });
  934. _s_paddingold();
  935. _s_paddingnew();
  936. _s_paddingcur();
  937. _position();
  938. _moveitems();
  939. _onafter();
  940. }]);
  941. _a_wrapper();
  942. break;
  943. case 'uncover':
  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. case 'uncover-fade':
  953. $cfs.css({ 'opacity': 0 });
  954. scrl.anims.push([$cfs, { 'opacity': 1 }]);
  955. scrl.anims.push([$cf2, a_wsz, _onafter]);
  956. _a_wrapper();
  957. _s_paddingold();
  958. _s_paddingnew();
  959. _s_paddingcur();
  960. _position();
  961. _moveitems();
  962. break;
  963. default:
  964. scrl.anims.push([$cfs, a_cfs, function() {
  965. _moveitems();
  966. _onafter();
  967. }]);
  968. _a_wrapper();
  969. _a_paddingold();
  970. _a_paddingnew();
  971. _a_paddingcur();
  972. break;
  973. }
  974. sc_startScroll(scrl, conf);
  975. cf_setCookie(opts.cookie, $cfs, conf);
  976. $cfs.trigger(cf_e('updatePageStatus', conf), [false, w_siz]);
  977. return true;
  978. });
  979. // next event
  980. $cfs.bind(cf_e('slide_next', conf), function(e, sO, nI) {
  981. e.stopPropagation();
  982. var a_itm = $cfs.children();
  983. // non-circular at end, scroll to start
  984. if (!opts.circular)
  985. {
  986. if (itms.first == opts.items.visible)
  987. {
  988. if (opts.infinite)
  989. {
  990. $cfs.trigger(cf_e('prev', conf), itms.total-1);
  991. }
  992. return e.stopImmediatePropagation();
  993. }
  994. }
  995. sz_resetMargin(a_itm, opts);
  996. // find number of items to scroll
  997. if (!is_number(nI))
  998. {
  999. if (opts.items.filter != '*')
  1000. {
  1001. var xI = (is_number(sO.items)) ? sO.items : gn_getVisibleOrg($cfs, opts);
  1002. nI = gn_getScrollItemsNextFilter(a_itm, opts, 0, xI);
  1003. }
  1004. else
  1005. {
  1006. nI = opts.items.visible;
  1007. }
  1008. nI = cf_getAdjust(nI, opts, sO.items, $tt0);
  1009. }
  1010. var lastItemNr = (itms.first == 0) ? itms.total : itms.first;
  1011. // prevent non-circular from scrolling to far
  1012. if (!opts.circular)
  1013. {
  1014. if (opts.items.visibleConf.variable)
  1015. {
  1016. var vI = gn_getVisibleItemsNext(a_itm, opts, nI),
  1017. xI = gn_getVisibleItemsPrev(a_itm, opts, lastItemNr-1);
  1018. }
  1019. else
  1020. {
  1021. var vI = opts.items.visible,
  1022. xI = opts.items.visible;
  1023. }
  1024. if (nI + vI > lastItemNr)
  1025. {
  1026. nI = lastItemNr - xI;
  1027. }
  1028. }
  1029. // set new number of visible items
  1030. opts.items.visibleConf.old = opts.items.visible;
  1031. if (opts.items.visibleConf.variable)
  1032. {
  1033. var vI = cf_getItemsAdjust(gn_getVisibleItemsNextTestCircular(a_itm, opts, nI, lastItemNr), opts, opts.items.visibleConf.adjust, $tt0);
  1034. while (opts.items.visible-nI >= vI && nI < itms.total)
  1035. {
  1036. nI++;
  1037. vI = cf_getItemsAdjust(gn_getVisibleItemsNextTestCircular(a_itm, opts, nI, lastItemNr), opts, opts.items.visibleConf.adjust, $tt0);
  1038. }
  1039. opts.items.visible = vI;
  1040. }
  1041. else if (opts.items.filter != '*')
  1042. {
  1043. var vI = gn_getVisibleItemsNextFilter(a_itm, opts, nI);
  1044. opts.items.visible = cf_getItemsAdjust(vI, opts, opts.items.visibleConf.adjust, $tt0);
  1045. }
  1046. sz_resetMargin(a_itm, opts, true);
  1047. // scroll 0, don't scroll
  1048. if (nI == 0)
  1049. {
  1050. e.stopImmediatePropagation();
  1051. return debug(conf, '0 items to scroll: Not scrolling.');
  1052. }
  1053. debug(conf, 'Scrolling '+nI+' items forward.');
  1054. // save new config
  1055. itms.first -= nI;
  1056. while (itms.first < 0)
  1057. {
  1058. itms.first += itms.total;
  1059. }
  1060. // non-circular callback
  1061. if (!opts.circular)
  1062. {
  1063. if (itms.first == opts.items.visible && sO.onEnd)
  1064. {
  1065. sO.onEnd.call($tt0, 'next');
  1066. }
  1067. if (!opts.infinite)
  1068. {
  1069. nv_enableNavi(opts, itms.first, conf);
  1070. }
  1071. }
  1072. // rearrange items
  1073. if (itms.total < opts.items.visible+nI)
  1074. {
  1075. $cfs.children().slice(0, (opts.items.visible+nI)-itms.total).clone(true).appendTo($cfs);
  1076. }
  1077. // the needed items
  1078. var a_itm = $cfs.children(),
  1079. i_old = gi_getOldItemsNext(a_itm, opts),
  1080. i_new = gi_getNewItemsNext(a_itm, opts, nI),
  1081. i_cur_l = a_itm.eq(nI-1),
  1082. i_old_l = i_old.last(),
  1083. i_new_l = i_new.last();
  1084. sz_resetMargin(a_itm, opts);
  1085. var pL = 0,
  1086. pR = 0;
  1087. if (opts.align)
  1088. {
  1089. var p = cf_getAlignPadding(i_new, opts);
  1090. pL = p[0];
  1091. pR = p[1];
  1092. }
  1093. // hide items for fx directscroll
  1094. var hiddenitems = false,
  1095. i_skp = $();
  1096. if (opts.items.visibleConf.old < nI)
  1097. {
  1098. i_skp = a_itm.slice(opts.items.visibleConf.old, nI);
  1099. if (sO.fx == 'directscroll')
  1100. {
  1101. var orgW = opts.items[opts.d['width']];
  1102. hiddenitems = i_skp;
  1103. i_cur_l = i_old_l;
  1104. sc_hideHiddenItems(hiddenitems);
  1105. opts.items[opts.d['width']] = 'variable';
  1106. }
  1107. }
  1108. // save new sizes
  1109. var $cf2 = false,
  1110. i_siz = ms_getTotalSize(a_itm.slice(0, nI), opts, 'width'),
  1111. w_siz = cf_mapWrapperSizes(ms_getSizes(i_new, opts, true), opts, !opts.usePadding),
  1112. i_siz_vis = 0,
  1113. a_cfs = {},
  1114. a_cfs_vis = {},
  1115. a_cur = {},
  1116. a_old = {},
  1117. a_lef = {},
  1118. a_dur = sc_getDuration(sO, opts, nI, i_siz);
  1119. switch(sO.fx)
  1120. {
  1121. case 'uncover':
  1122. case 'uncover-fade':
  1123. i_siz_vis = ms_getTotalSize(a_itm.slice(0, opts.items.visibleConf.old), opts, 'width');
  1124. break;
  1125. }
  1126. if (hiddenitems)
  1127. {
  1128. opts.items[opts.d['width']] = orgW;
  1129. }
  1130. if (opts.align)
  1131. {
  1132. if (opts.padding[opts.d[1]] < 0)
  1133. {
  1134. opts.padding[opts.d[1]] = 0;
  1135. }
  1136. }
  1137. sz_resetMargin(a_itm, opts, true);
  1138. sz_resetMargin(i_old_l, opts, opts.padding[opts.d[1]]);
  1139. if (opts.align)
  1140. {
  1141. opts.padding[opts.d[1]] = pR;
  1142. opts.padding[opts.d[3]] = pL;
  1143. }
  1144. a_lef[opts.d['left']] = (opts.usePadding) ? opts.padding[opts.d[3]] : 0;
  1145. // scrolling functions
  1146. var _s_wrapper = function() {},
  1147. _a_wrapper = function() {},
  1148. _s_paddingold = function() {},
  1149. _a_paddingold = function() {},
  1150. _s_paddingcur = function() {},
  1151. _a_paddingcur = function() {},
  1152. _onafter = function() {},
  1153. _moveitems = function() {},
  1154. _position = function() {};
  1155. // clone carousel
  1156. switch(sO.fx)
  1157. {
  1158. case 'crossfade':
  1159. case 'cover':
  1160. case 'cover-fade':
  1161. case 'uncover':
  1162. case 'uncover-fade':
  1163. $cf2 = $cfs.clone(true).appendTo($wrp);
  1164. $cf2.children().slice(opts.items.visibleConf.old).remove();
  1165. break;
  1166. }
  1167. switch(sO.fx)
  1168. {
  1169. case 'crossfade':
  1170. case 'cover':
  1171. case 'cover-fade':
  1172. $cfs.css('zIndex', 1);
  1173. $cf2.css('zIndex', 0);
  1174. break;
  1175. }
  1176. // reset all scrolls
  1177. scrl = sc_setScroll(a_dur, sO.easing, conf);
  1178. // animate / set carousel
  1179. a_cfs[opts.d['left']] = -i_siz;
  1180. a_cfs_vis[opts.d['left']] = -i_siz_vis;
  1181. if (pL < 0)
  1182. {
  1183. a_cfs[opts.d['left']] += pL;
  1184. }
  1185. // animate / set wrapper
  1186. if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable')
  1187. {
  1188. _s_wrapper = function() {
  1189. $wrp.css(w_siz);
  1190. };
  1191. _a_wrapper = function() {
  1192. scrl.anims.push([$wrp, w_siz]);
  1193. };
  1194. }
  1195. // animate / set items
  1196. if (opts.usePadding)
  1197. {
  1198. var i_new_l_m = i_new_l.data('_cfs_origCssMargin');
  1199. if (pR >= 0)
  1200. {
  1201. i_new_l_m += opts.padding[opts.d[1]];
  1202. }
  1203. i_new_l.css(opts.d['marginRight'], i_new_l_m);
  1204. if (i_cur_l.not(i_old_l).length)
  1205. {
  1206. a_old[opts.d['marginRight']] = i_old_l.data('_cfs_origCssMargin');
  1207. }
  1208. _s_paddingold = function() {
  1209. i_old_l.css(a_old);
  1210. };
  1211. _a_paddingold = function() {
  1212. scrl.anims.push([i_old_l, a_old]);
  1213. };
  1214. var i_cur_l_m = i_cur_l.data('_cfs_origCssMargin');
  1215. if (pL > 0)
  1216. {
  1217. i_cur_l_m += opts.padding[opts.d[3]];
  1218. }
  1219. a_cur[opts.d['marginRight']] = i_cur_l_m;
  1220. _s_paddingcur = function() {
  1221. i_cur_l.css(a_cur);
  1222. };
  1223. _a_paddingcur = function() {
  1224. scrl.anims.push([i_cur_l, a_cur]);
  1225. };
  1226. }
  1227. // set position
  1228. _position = function() {
  1229. $cfs.css(a_lef);
  1230. };
  1231. var overFill = opts.items.visible+nI-itms.total;
  1232. // rearrange items
  1233. _moveitems = function() {
  1234. if (overFill > 0)
  1235. {
  1236. $cfs.children().slice(itms.total).remove();
  1237. }
  1238. var l_itm = $cfs.children().slice(0, nI).appendTo($cfs).last();
  1239. if (overFill > 0)
  1240. {
  1241. i_new = gi_getCurrentItems(a_itm, opts);
  1242. }
  1243. sc_showHiddenItems(hiddenitems);
  1244. if (opts.usePadding)
  1245. {
  1246. if (itms.total < opts.items.visible+nI) {
  1247. var i_cur_l = $cfs.children().eq(opts.items.visible-1);
  1248. i_cur_l.css(opts.d['marginRight'], i_cur_l.data('_cfs_origCssMargin') + opts.padding[opts.d[1]]);
  1249. }
  1250. l_itm.css(opts.d['marginRight'], l_itm.data('_cfs_origCssMargin'));
  1251. }
  1252. };
  1253. var cb_arguments = sc_mapCallbackArguments(i_old, i_skp, i_new, nI, 'next', a_dur, w_siz);
  1254. // fire onAfter callbacks
  1255. _onafter = function() {
  1256. $cfs.css('zIndex', $cfs.data('_cfs_origCssZindex'));
  1257. sc_afterScroll($cfs, $cf2, sO);
  1258. crsl.isScrolling = false;
  1259. clbk.onAfter = sc_fireCallbacks($tt0, sO, 'onAfter', cb_arguments, clbk);
  1260. queu = sc_fireQueue($cfs, queu, conf);
  1261. if (!crsl.isPaused)
  1262. {
  1263. $cfs.trigger(cf_e('play', conf));
  1264. }
  1265. };
  1266. // fire onBefore callbacks
  1267. crsl.isScrolling = true;
  1268. tmrs = sc_clearTimers(tmrs);
  1269. clbk.onBefore = sc_fireCallbacks($tt0, sO, 'onBefore', cb_arguments, clbk);
  1270. switch(sO.fx)
  1271. {
  1272. case 'none':
  1273. $cfs.css(a_cfs);
  1274. _s_wrapper();
  1275. _s_paddingold();
  1276. _s_paddingcur();
  1277. _position();
  1278. _moveitems();
  1279. _onafter();
  1280. break;
  1281. case 'fade':
  1282. scrl.anims.push([$cfs, { 'opacity': 0 }, function() {
  1283. _s_wrapper();
  1284. _s_paddingold();
  1285. _s_paddingcur();
  1286. _position();
  1287. _moveitems();
  1288. scrl = sc_setScroll(a_dur, sO.easing, conf);
  1289. scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
  1290. sc_startScroll(scrl, conf);
  1291. }]);
  1292. break;
  1293. case 'crossfade':
  1294. $cfs.css({ 'opacity': 0 });
  1295. scrl.anims.push([$cf2, { 'opacity': 0 }]);
  1296. scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
  1297. _a_wrapper();
  1298. _s_paddingold();
  1299. _s_paddingcur();
  1300. _position();
  1301. _moveitems();
  1302. break;
  1303. case 'cover':
  1304. $cfs.css(opts.d['left'], $wrp[opts.d['width']]());
  1305. scrl.anims.push([$cfs, a_lef, _onafter]);
  1306. _a_wrapper();
  1307. _s_paddingold();
  1308. _s_paddingcur();
  1309. _moveitems();
  1310. break;
  1311. case 'cover-fade':
  1312. $cfs.css(opts.d['left'], $wrp[opts.d['width']]());
  1313. scrl.anims.push([$cf2, { 'opacity': 0 }]);
  1314. scrl.anims.push([$cfs, a_lef, _onafter]);
  1315. _a_wrapper();
  1316. _s_paddingold();
  1317. _s_paddingcur();
  1318. _moveitems();
  1319. break;
  1320. case 'uncover':
  1321. scrl.anims.push([$cf2, a_cfs_vis, _onafter]);
  1322. _a_wrapper();
  1323. _s_paddingold();
  1324. _s_paddingcur();
  1325. _position();
  1326. _moveitems();
  1327. break;
  1328. case 'uncover-fade':
  1329. $cfs.css({ 'opacity': 0 });
  1330. scrl.anims.push([$cfs, { 'opacity': 1 }]);
  1331. scrl.anims.push([$cf2, a_cfs_vis, _onafter]);
  1332. _a_wrapper();
  1333. _s_paddingold();
  1334. _s_paddingcur();
  1335. _position();
  1336. _moveitems();
  1337. break;
  1338. default:
  1339. scrl.anims.push([$cfs, a_cfs, function() {
  1340. _position();
  1341. _moveitems();
  1342. _onafter();
  1343. }]);
  1344. _a_wrapper();
  1345. _a_paddingold();
  1346. _a_paddingcur();
  1347. break;
  1348. }
  1349. sc_startScroll(scrl, conf);
  1350. cf_setCookie(opts.cookie, $cfs, conf);
  1351. $cfs.trigger(cf_e('updatePageStatus', conf), [false, w_siz]);
  1352. return true;
  1353. });
  1354. // slideTo event
  1355. $cfs.bind(cf_e('slideTo', conf), function(e, num, dev, org, obj, dir, clb) {
  1356. e.stopPropagation();
  1357. var v = [num, dev, org, obj, dir, clb],
  1358. t = ['string/number/object', 'number', 'boolean', 'object', 'string', 'function'],
  1359. a = cf_sortParams(v, t);
  1360. obj = a[3];
  1361. dir = a[4];
  1362. clb = a[5];
  1363. num = gn_getItemIndex(a[0], a[1], a[2], itms, $cfs);
  1364. if (num == 0)
  1365. {
  1366. return false;
  1367. }
  1368. if (!is_object(obj))
  1369. {
  1370. obj = false;
  1371. }
  1372. if (dir != 'prev' && dir != 'next')
  1373. {
  1374. if (opts.circular)
  1375. {
  1376. dir = (num <= itms.total / 2) ? 'next' : 'prev';
  1377. }
  1378. else
  1379. {
  1380. dir = (itms.first == 0 || itms.first > num) ? 'next' : 'prev';
  1381. }
  1382. }
  1383. if (dir == 'prev')
  1384. {
  1385. num = itms.total-num;
  1386. }
  1387. $cfs.trigger(cf_e(dir, conf), [obj, num, clb]);
  1388. return true;
  1389. });
  1390. // prevPage event
  1391. $cfs.bind(cf_e('prevPage', conf), function(e, obj, clb) {
  1392. e.stopPropagation();
  1393. var cur = $cfs.triggerHandler(cf_e('currentPage', conf));
  1394. return $cfs.triggerHandler(cf_e('slideToPage', conf), [cur-1, obj, 'prev', clb]);
  1395. });
  1396. // nextPage event
  1397. $cfs.bind(cf_e('nextPage', conf), function(e, obj, clb) {
  1398. e.stopPropagation();
  1399. var cur = $cfs.triggerHandler(cf_e('currentPage', conf));
  1400. return $cfs.triggerHandler(cf_e('slideToPage', conf), [cur+1, obj, 'next', clb]);
  1401. });
  1402. // slideToPage event
  1403. $cfs.bind(cf_e('slideToPage', conf), function(e, pag, obj, dir, clb) {
  1404. e.stopPropagation();
  1405. if (!is_number(pag))
  1406. {
  1407. pag = $cfs.triggerHandler(cf_e('currentPage', conf));
  1408. }
  1409. var ipp = opts.pagination.items || opts.items.visible,
  1410. max = Math.ceil(itms.total / ipp)-1;
  1411. if (pag < 0)
  1412. {
  1413. pag = max;
  1414. }
  1415. if (pag > max)
  1416. {
  1417. pag = 0;
  1418. }
  1419. return $cfs.triggerHandler(cf_e('slideTo', conf), [pag*ipp, 0, true, obj, dir, clb]);
  1420. });
  1421. // jumpToStart event
  1422. $cfs.bind(cf_e('jumpToStart', conf), function(e, s) {
  1423. e.stopPropagation();
  1424. if (s)
  1425. {
  1426. s = gn_getItemIndex(s, 0, true, itms, $cfs);
  1427. }
  1428. else
  1429. {
  1430. s = 0;
  1431. }
  1432. s += itms.first;
  1433. if (s != 0)
  1434. {
  1435. if (itms.total > 0)
  1436. {
  1437. while (s > itms.total)
  1438. {
  1439. s -= itms.total;
  1440. }
  1441. }
  1442. $cfs.prepend($cfs.children().slice(s, itms.total));
  1443. }
  1444. return true;
  1445. });
  1446. // synchronise event
  1447. $cfs.bind(cf_e('synchronise', conf), function(e, s) {
  1448. e.stopPropagation();
  1449. if (s)
  1450. {
  1451. s = cf_getSynchArr(s);
  1452. }
  1453. else if (opts.synchronise)
  1454. {
  1455. s = opts.synchronise;
  1456. }
  1457. else
  1458. {
  1459. return debug(conf, 'No carousel to synchronise.');
  1460. }
  1461. var n = $cfs.triggerHandler(cf_e('currentPosition', conf)),
  1462. x = true;
  1463. for (var j = 0, l = s.length; j < l; j++)
  1464. {
  1465. if (!s[j][0].triggerHandler(cf_e('slideTo', conf), [n, s[j][3], true]))
  1466. {
  1467. x = false;
  1468. }
  1469. }
  1470. return x;
  1471. });
  1472. // queue event
  1473. $cfs.bind(cf_e('queue', conf), function(e, dir, opt) {
  1474. e.stopPropagation();
  1475. if (is_function(dir))
  1476. {
  1477. dir.call($tt0, queu);
  1478. }
  1479. else if (is_array(dir))
  1480. {
  1481. queu = dir;
  1482. }
  1483. else if (!is_undefined(dir))
  1484. {
  1485. queu.push([dir, opt]);
  1486. }
  1487. return queu;
  1488. });
  1489. // insertItem event
  1490. $cfs.bind(cf_e('insertItem', conf), function(e, itm, num, org, dev) {
  1491. e.stopPropagation();
  1492. var v = [itm, num, org, dev],
  1493. t = ['string/object', 'string/number/object', 'boolean', 'number'],
  1494. a = cf_sortParams(v, t);
  1495. itm = a[0];
  1496. num = a[1];
  1497. org = a[2];
  1498. dev = a[3];
  1499. if (is_object(itm) && !is_jquery(itm))
  1500. {
  1501. itm = $(itm);
  1502. }
  1503. else if (is_string(itm))
  1504. {
  1505. itm = $(itm);
  1506. }
  1507. if (!is_jquery(itm) || itm.length == 0)
  1508. {
  1509. return debug(conf, 'Not a valid object.');
  1510. }
  1511. if (is_undefined(num))
  1512. {
  1513. num = 'end';
  1514. }
  1515. sz_storeMargin(itm, opts);
  1516. sz_storeOrigCss(itm);
  1517. var orgNum = num,
  1518. before = 'before';
  1519. if (num == 'end')
  1520. {
  1521. if (org)
  1522. {
  1523. if (itms.first == 0)
  1524. {
  1525. num = itms.total-1;
  1526. before = 'after';
  1527. }
  1528. else
  1529. {
  1530. num = itms.first;
  1531. itms.first += itm.length;
  1532. }
  1533. if (num < 0)
  1534. {
  1535. num = 0;
  1536. }
  1537. }
  1538. else
  1539. {
  1540. num = itms.total-1;
  1541. before = 'after';
  1542. }
  1543. }
  1544. else
  1545. {
  1546. num = gn_getItemIndex(num, dev, org, itms, $cfs);
  1547. }
  1548. var $cit = $cfs.children().eq(num);
  1549. if ($cit.length)
  1550. {
  1551. $cit[before](itm);
  1552. }
  1553. else
  1554. {
  1555. debug(conf, 'Correct insert-position not found! Appending item to the end.');
  1556. $cfs.append(itm);
  1557. }
  1558. if (orgNum != 'end' && !org)
  1559. {
  1560. if (num < itms.first)
  1561. {
  1562. itms.first += itm.length;
  1563. }
  1564. }
  1565. itms.total = $cfs.children().length;
  1566. if (itms.first >= itms.total)
  1567. {
  1568. itms.first -= itms.total;
  1569. }
  1570. $cfs.trigger(cf_e('updateSizes', conf));
  1571. $cfs.trigger(cf_e('linkAnchors', conf));
  1572. return true;
  1573. });
  1574. // removeItem event
  1575. $cfs.bind(cf_e('removeItem', conf), function(e, num, org, dev) {
  1576. e.stopPropagation();
  1577. var v = [num, org, dev],
  1578. t = ['string/number/object', 'boolean', 'number'],
  1579. a = cf_sortParams(v, t);
  1580. num = a[0];
  1581. org = a[1];
  1582. dev = a[2];
  1583. var removed = false;
  1584. if (num instanceof $ && num.length > 1)
  1585. {
  1586. $removed = $();
  1587. num.each(function(i, el) {
  1588. var $rem = $cfs.trigger(cf_e('removeItem', conf), [$(this), org, dev]);
  1589. if ( $rem )
  1590. {
  1591. $removed = $removed.add($rem);
  1592. }
  1593. });
  1594. return $removed;
  1595. }
  1596. if (is_undefined(num) || num == 'end')
  1597. {
  1598. $removed = $cfs.children().last();
  1599. }
  1600. else
  1601. {
  1602. num = gn_getItemIndex(num, dev, org, itms, $cfs);
  1603. var $removed = $cfs.children().eq(num);
  1604. if ( $removed.length )
  1605. {
  1606. if (num < itms.first)
  1607. {
  1608. itms.first -= $removed.length;
  1609. }
  1610. }
  1611. }
  1612. if ( $removed && $removed.length )
  1613. {
  1614. $removed.detach();
  1615. itms.total = $cfs.children().length;
  1616. $cfs.trigger(cf_e('updateSizes', conf));
  1617. }
  1618. return $removed;
  1619. });
  1620. // onBefore and onAfter event
  1621. $cfs.bind(cf_e('onBefore', conf)+' '+cf_e('onAfter', conf), function(e, fn) {
  1622. e.stopPropagation();
  1623. var eType = e.type.slice(conf.events.prefix.length);
  1624. if (is_array(fn))
  1625. {
  1626. clbk[eType] = fn;
  1627. }
  1628. if (is_function(fn))
  1629. {
  1630. clbk[eType].push(fn);
  1631. }
  1632. return clbk[eType];
  1633. });
  1634. // currentPosition event
  1635. $cfs.bind(cf_e('currentPosition', conf), function(e, fn) {
  1636. e.stopPropagation();
  1637. if (itms.first == 0)
  1638. {
  1639. var val = 0;
  1640. }
  1641. else
  1642. {
  1643. var val = itms.total - itms.first;
  1644. }
  1645. if (is_function(fn))
  1646. {
  1647. fn.call($tt0, val);
  1648. }
  1649. return val;
  1650. });
  1651. // currentPage event
  1652. $cfs.bind(cf_e('currentPage', conf), function(e, fn) {
  1653. e.stopPropagation();
  1654. var ipp = opts.pagination.items || opts.items.visible,
  1655. max = Math.ceil(itms.total/ipp-1),
  1656. nr;
  1657. if (itms.first == 0)
  1658. {
  1659. nr = 0;
  1660. }
  1661. else if (itms.first < itms.total % ipp)
  1662. {
  1663. nr = 0;
  1664. }
  1665. else if (itms.first == ipp && !opts.circular)
  1666. {
  1667. nr = max;
  1668. }
  1669. else
  1670. {
  1671. nr = Math.round((itms.total-itms.first)/ipp);
  1672. }
  1673. if (nr < 0)
  1674. {
  1675. nr = 0;
  1676. }
  1677. if (nr > max)
  1678. {
  1679. nr = max;
  1680. }
  1681. if (is_function(fn))
  1682. {
  1683. fn.call($tt0, nr);
  1684. }
  1685. return nr;
  1686. });
  1687. // currentVisible event
  1688. $cfs.bind(cf_e('currentVisible', conf), function(e, fn) {
  1689. e.stopPropagation();
  1690. var $i = gi_getCurrentItems($cfs.children(), opts);
  1691. if (is_function(fn))
  1692. {
  1693. fn.call($tt0, $i);
  1694. }
  1695. return $i;
  1696. });
  1697. // slice event
  1698. $cfs.bind(cf_e('slice', conf), function(e, f, l, fn) {
  1699. e.stopPropagation();
  1700. if (itms.total == 0)
  1701. {
  1702. return false;
  1703. }
  1704. var v = [f, l, fn],
  1705. t = ['number', 'number', 'function'],
  1706. a = cf_sortParams(v, t);
  1707. f = (is_number(a[0])) ? a[0] : 0;
  1708. l = (is_number(a[1])) ? a[1] : itms.total;
  1709. fn = a[2];
  1710. f += itms.first;
  1711. l += itms.first;
  1712. if (items.total > 0)
  1713. {
  1714. while (f > itms.total)
  1715. {
  1716. f -= itms.total;
  1717. }
  1718. while (l > itms.total)
  1719. {
  1720. l -= itms.total;
  1721. }
  1722. while (f < 0)
  1723. {
  1724. f += itms.total;
  1725. }
  1726. while (l < 0)
  1727. {
  1728. l += itms.total;
  1729. }
  1730. }
  1731. var $iA = $cfs.children(),
  1732. $i;
  1733. if (l > f)
  1734. {
  1735. $i = $iA.slice(f, l);
  1736. }
  1737. else
  1738. {
  1739. $i = $( $iA.slice(f, itms.total).get().concat( $iA.slice(0, l).get() ) );
  1740. }
  1741. if (is_function(fn))
  1742. {
  1743. fn.call($tt0, $i);
  1744. }
  1745. return $i;
  1746. });
  1747. // isPaused, isStopped and isScrolling events
  1748. $cfs.bind(cf_e('isPaused', conf)+' '+cf_e('isStopped', conf)+' '+cf_e('isScrolling', conf), function(e, fn) {
  1749. e.stopPropagation();
  1750. var eType = e.type.slice(conf.events.prefix.length),
  1751. value = crsl[eType];
  1752. if (is_function(fn))
  1753. {
  1754. fn.call($tt0, value);
  1755. }
  1756. return value;
  1757. });
  1758. // configuration event
  1759. $cfs.bind(cf_e('configuration', conf), function(e, a, b, c) {
  1760. e.stopPropagation();
  1761. var reInit = false;
  1762. // return entire configuration-object
  1763. if (is_function(a))
  1764. {
  1765. a.call($tt0, opts);
  1766. }
  1767. // set multiple options via object
  1768. else if (is_object(a))
  1769. {
  1770. opts_orig = $.extend(true, {}, opts_orig, a);
  1771. if (b !== false) reInit = true;
  1772. else opts = $.extend(true, {}, opts, a);
  1773. }
  1774. else if (!is_undefined(a))
  1775. {
  1776. // callback function for specific option
  1777. if (is_function(b))
  1778. {
  1779. var val = eval('opts.'+a);
  1780. if (is_undefined(val))
  1781. {
  1782. val = '';
  1783. }
  1784. b.call($tt0, val);
  1785. }
  1786. // set individual option
  1787. else if (!is_undefined(b))
  1788. {
  1789. if (typeof c !== 'boolean') c = true;
  1790. eval('opts_orig.'+a+' = b');
  1791. if (c !== false) reInit = true;
  1792. else eval('opts.'+a+' = b');
  1793. }
  1794. // return value for specific option
  1795. else
  1796. {
  1797. return eval('opts.'+a);
  1798. }
  1799. }
  1800. if (reInit)
  1801. {
  1802. sz_resetMargin($cfs.children(), opts);
  1803. FN._cfs_init(opts_orig);
  1804. FN._cfs_bind_buttons();
  1805. var sz = sz_setSizes($cfs, opts);
  1806. $cfs.trigger(cf_e('updatePageStatus', conf), [true, sz]);
  1807. }
  1808. return opts;
  1809. });
  1810. // linkAnchors event
  1811. $cfs.bind(cf_e('linkAnchors', conf), function(e, $con, sel) {
  1812. e.stopPropagation();
  1813. if (is_undefined($con))
  1814. {
  1815. $con = $('body');
  1816. }
  1817. else if (is_string($con))
  1818. {
  1819. $con = $($con);
  1820. }
  1821. if (!is_jquery($con) || $con.length == 0)
  1822. {
  1823. return debug(conf, 'Not a valid object.');
  1824. }
  1825. if (!is_string(sel))
  1826. {
  1827. sel = 'a.caroufredsel';
  1828. }
  1829. $con.find(sel).each(function() {
  1830. var h = this.hash || '';
  1831. if (h.length > 0 && $cfs.children().index($(h)) != -1)
  1832. {
  1833. $(this).unbind('click').click(function(e) {
  1834. e.preventDefault();
  1835. $cfs.trigger(cf_e('slideTo', conf), h);
  1836. });
  1837. }
  1838. });
  1839. return true;
  1840. });
  1841. // updatePageStatus event
  1842. $cfs.bind(cf_e('updatePageStatus', conf), function(e, build, sizes) {
  1843. e.stopPropagation();
  1844. if (!opts.pagination.container)
  1845. {
  1846. return;
  1847. }
  1848. var ipp = opts.pagination.items || opts.items.visible,
  1849. pgs = Math.ceil(itms.total/ipp);
  1850. if (build)
  1851. {
  1852. if (opts.pagination.anchorBuilder)
  1853. {
  1854. opts.pagination.container.children().remove();
  1855. opts.pagination.container.each(function() {
  1856. for (var a = 0; a < pgs; a++)
  1857. {
  1858. var i = $cfs.children().eq( gn_getItemIndex(a*ipp, 0, true, itms, $cfs) );
  1859. $(this).append(opts.pagination.anchorBuilder.call(i[0], a+1));
  1860. }
  1861. });
  1862. }
  1863. opts.pagination.container.each(function() {
  1864. $(this).children().unbind(opts.pagination.event).each(function(a) {
  1865. $(this).bind(opts.pagination.event, function(e) {
  1866. e.preventDefault();
  1867. $cfs.trigger(cf_e('slideTo', conf), [a*ipp, -opts.pagination.deviation, true, opts.pagination]);
  1868. });
  1869. });
  1870. });
  1871. }
  1872. var selected = $cfs.triggerHandler(cf_e('currentPage', conf)) + opts.pagination.deviation;
  1873. if (selected >= pgs)
  1874. {
  1875. selected = 0;
  1876. }
  1877. if (selected < 0)
  1878. {
  1879. selected = pgs-1;
  1880. }
  1881. opts.pagination.container.each(function() {
  1882. $(this).children().removeClass(cf_c('selected', conf)).eq(selected).addClass(cf_c('selected', conf));
  1883. });
  1884. return true;
  1885. });
  1886. // updateSizes event
  1887. $cfs.bind(cf_e('updateSizes', conf), function(e) {
  1888. var vI = op