/files/caroufredsel/6.1.0/jquery.carouFredSel-6.1.0.js
JavaScript | 2092 lines | 1683 code | 280 blank | 129 comment | 327 complexity | c7fee07900babc62d46e97e416e472ed MD5 | raw file
- /*
- * jQuery carouFredSel 6.1.0
- * Demo's and documentation:
- * caroufredsel.frebsite.nl
- *
- * Copyright (c) 2012 Fred Heusschen
- * www.frebsite.nl
- *
- * Dual licensed under the MIT and GPL licenses.
- * http://en.wikipedia.org/wiki/MIT_License
- * http://en.wikipedia.org/wiki/GNU_General_Public_License
- */
-
-
- (function($) {
-
-
- // LOCAL
-
- if ( $.fn.carouFredSel )
- {
- return;
- }
-
- $.fn.caroufredsel = $.fn.carouFredSel = function(options, configs)
- {
-
- // no element
- if (this.length == 0)
- {
- debug( true, 'No element found for "' + this.selector + '".' );
- return this;
- }
-
- // multiple elements
- if (this.length > 1)
- {
- return this.each(function() {
- $(this).carouFredSel(options, configs);
- });
- }
-
-
- var $cfs = this,
- $tt0 = this[0],
- starting_position = false;
-
- if ($cfs.data('_cfs_isCarousel'))
- {
- starting_position = $cfs.triggerHandler('_cfs_triggerEvent', 'currentPosition');
- $cfs.trigger('_cfs_triggerEvent', ['destroy', true]);
- }
-
-
- $cfs._cfs_init = function(o, setOrig, start)
- {
- o = go_getObject($tt0, o);
-
- o.items = go_getItemsObject($tt0, o.items);
- o.scroll = go_getScrollObject($tt0, o.scroll);
- o.auto = go_getAutoObject($tt0, o.auto);
- o.prev = go_getPrevNextObject($tt0, o.prev);
- o.next = go_getPrevNextObject($tt0, o.next);
- o.pagination = go_getPaginationObject($tt0, o.pagination);
- o.swipe = go_getSwipeObject($tt0, o.swipe);
- o.mousewheel = go_getMousewheelObject($tt0, o.mousewheel);
-
- if (setOrig)
- {
- opts_orig = $.extend(true, {}, $.fn.carouFredSel.defaults, o);
- }
-
- opts = $.extend(true, {}, $.fn.carouFredSel.defaults, o);
- opts.d = cf_getDimensions(opts);
-
- crsl.direction = (opts.direction == 'up' || opts.direction == 'left') ? 'next' : 'prev';
-
- var a_itm = $cfs.children(),
- avail_primary = ms_getParentSize($wrp, opts, 'width');
-
- if (is_true(opts.cookie))
- {
- opts.cookie = 'caroufredsel_cookie_' + conf.serialNumber;
- }
-
- opts.maxDimension = ms_getMaxDimension(opts, avail_primary);
-
- // complement items and sizes
- opts.items = in_complementItems(opts.items, opts, a_itm, start);
- opts[opts.d['width']] = in_complementPrimarySize(opts[opts.d['width']], opts, a_itm);
- opts[opts.d['height']] = in_complementSecondarySize(opts[opts.d['height']], opts, a_itm);
-
- // primary size not set for a responsive carousel
- if (opts.responsive)
- {
- if (!is_percentage(opts[opts.d['width']]))
- {
- opts[opts.d['width']] = '100%';
- }
- }
-
- // primary size is percentage
- if (is_percentage(opts[opts.d['width']]))
- {
- crsl.upDateOnWindowResize = true;
- crsl.primarySizePercentage = opts[opts.d['width']];
- opts[opts.d['width']] = ms_getPercentage(avail_primary, crsl.primarySizePercentage);
- if (!opts.items.visible)
- {
- opts.items.visibleConf.variable = true;
- }
- }
-
- if (opts.responsive)
- {
- opts.usePadding = false;
- opts.padding = [0, 0, 0, 0];
- opts.align = false;
- opts.items.visibleConf.variable = false;
- }
- else
- {
- // visible-items not set
- if (!opts.items.visible)
- {
- opts = in_complementVisibleItems(opts, avail_primary);
- }
-
- // primary size not set -> calculate it or set to "variable"
- if (!opts[opts.d['width']])
- {
- if (!opts.items.visibleConf.variable && is_number(opts.items[opts.d['width']]) && opts.items.filter == '*')
- {
- opts[opts.d['width']] = opts.items.visible * opts.items[opts.d['width']];
- opts.align = false;
- }
- else
- {
- opts[opts.d['width']] = 'variable';
- }
- }
- // align not set -> set to center if primary size is number
- if (is_undefined(opts.align))
- {
- opts.align = (is_number(opts[opts.d['width']]))
- ? 'center'
- : false;
- }
- // set variabe visible-items
- if (opts.items.visibleConf.variable)
- {
- opts.items.visible = gn_getVisibleItemsNext(a_itm, opts, 0);
- }
- }
-
- // set visible items by filter
- if (opts.items.filter != '*' && !opts.items.visibleConf.variable)
- {
- opts.items.visibleConf.org = opts.items.visible;
- opts.items.visible = gn_getVisibleItemsNextFilter(a_itm, opts, 0);
- }
-
- opts.items.visible = cf_getItemsAdjust(opts.items.visible, opts, opts.items.visibleConf.adjust, $tt0);
- opts.items.visibleConf.old = opts.items.visible;
-
- if (opts.responsive)
- {
- if (!opts.items.visibleConf.min)
- {
- opts.items.visibleConf.min = opts.items.visible;
- }
- if (!opts.items.visibleConf.max)
- {
- opts.items.visibleConf.max = opts.items.visible;
- }
- opts = in_getResponsiveValues(opts, a_itm, avail_primary);
- }
- else
- {
- opts.padding = cf_getPadding(opts.padding);
-
- if (opts.align == 'top')
- {
- opts.align = 'left';
- }
- else if (opts.align == 'bottom')
- {
- opts.align = 'right';
- }
-
- switch (opts.align)
- {
- // align: center, left or right
- case 'center':
- case 'left':
- case 'right':
- if (opts[opts.d['width']] != 'variable')
- {
- opts = in_getAlignPadding(opts, a_itm);
- opts.usePadding = true;
- }
- break;
-
- // padding
- default:
- opts.align = false;
- opts.usePadding = (
- opts.padding[0] == 0 &&
- opts.padding[1] == 0 &&
- opts.padding[2] == 0 &&
- opts.padding[3] == 0
- ) ? false : true;
- break;
- }
- }
-
- if (!is_number(opts.scroll.duration))
- {
- opts.scroll.duration = 500;
- }
- if (is_undefined(opts.scroll.items))
- {
- opts.scroll.items = (opts.responsive || opts.items.visibleConf.variable || opts.items.filter != '*')
- ? 'visible'
- : opts.items.visible;
- }
-
- opts.auto = $.extend(true, {}, opts.scroll, opts.auto);
- opts.prev = $.extend(true, {}, opts.scroll, opts.prev);
- opts.next = $.extend(true, {}, opts.scroll, opts.next);
- opts.pagination = $.extend(true, {}, opts.scroll, opts.pagination);
- // swipe and mousewheel extend later on, per direction
-
- opts.auto = go_complementAutoObject($tt0, opts.auto);
- opts.prev = go_complementPrevNextObject($tt0, opts.prev);
- opts.next = go_complementPrevNextObject($tt0, opts.next);
- opts.pagination = go_complementPaginationObject($tt0, opts.pagination);
- opts.swipe = go_complementSwipeObject($tt0, opts.swipe);
- opts.mousewheel = go_complementMousewheelObject($tt0, opts.mousewheel);
-
- if (opts.synchronise)
- {
- opts.synchronise = cf_getSynchArr(opts.synchronise);
- }
-
-
- // DEPRECATED
- if (opts.auto.onPauseStart)
- {
- opts.auto.onTimeoutStart = opts.auto.onPauseStart;
- deprecated('auto.onPauseStart', 'auto.onTimeoutStart');
- }
- if (opts.auto.onPausePause)
- {
- opts.auto.onTimeoutPause = opts.auto.onPausePause;
- deprecated('auto.onPausePause', 'auto.onTimeoutPause');
- }
- if (opts.auto.onPauseEnd)
- {
- opts.auto.onTimeoutEnd = opts.auto.onPauseEnd;
- deprecated('auto.onPauseEnd', 'auto.onTimeoutEnd');
- }
- if (opts.auto.pauseDuration)
- {
- opts.auto.timeoutDuration = opts.auto.pauseDuration;
- deprecated('auto.pauseDuration', 'auto.timeoutDuration');
- }
- // /DEPRECATED
-
-
- }; // /init
-
-
- $cfs._cfs_build = function() {
- $cfs.data('_cfs_isCarousel', true);
-
- var a_itm = $cfs.children(),
- orgCSS = in_mapCss($cfs, ['textAlign', 'float', 'position', 'top', 'right', 'bottom', 'left', 'zIndex', 'width', 'height', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft']),
- newPosition = 'relative';
-
- switch (orgCSS.position)
- {
- case 'absolute':
- case 'fixed':
- newPosition = orgCSS.position;
- break;
- }
-
- $wrp.css(orgCSS).css({
- 'overflow' : 'hidden',
- 'position' : newPosition
- });
-
- $cfs.data('_cfs_origCss', orgCSS).css({
- 'textAlign' : 'left',
- 'float' : 'none',
- 'position' : 'absolute',
- 'top' : 0,
- 'right' : 'auto',
- 'bottom' : 'auto',
- 'left' : 0,
- 'marginTop' : 0,
- 'marginRight' : 0,
- 'marginBottom' : 0,
- 'marginLeft' : 0
- });
-
- sz_storeMargin(a_itm, opts);
- sz_storeSizes(a_itm, opts);
- if (opts.responsive)
- {
- sz_setResponsiveSizes(opts, a_itm);
- }
-
- }; // /build
-
-
- $cfs._cfs_bind_events = function() {
- $cfs._cfs_unbind_events();
-
-
- // stop event
- $cfs.bind(cf_e('stop', conf), function(e, imm) {
- e.stopPropagation();
-
- // button
- if (!crsl.isStopped)
- {
- if (opts.auto.button)
- {
- opts.auto.button.addClass(cf_c('stopped', conf));
- }
- }
-
- // set stopped
- crsl.isStopped = true;
-
- if (opts.auto.play)
- {
- opts.auto.play = false;
- $cfs.trigger(cf_e('pause', conf), imm);
- }
- return true;
- });
-
-
- // finish event
- $cfs.bind(cf_e('finish', conf), function(e) {
- e.stopPropagation();
- if (crsl.isScrolling)
- {
- sc_stopScroll(scrl);
- }
- return true;
- });
-
-
- // pause event
- $cfs.bind(cf_e('pause', conf), function(e, imm, res) {
- e.stopPropagation();
- tmrs = sc_clearTimers(tmrs);
-
- // immediately pause
- if (imm && crsl.isScrolling)
- {
- scrl.isStopped = true;
- var nst = getTime() - scrl.startTime;
- scrl.duration -= nst;
- if (scrl.pre)
- {
- scrl.pre.duration -= nst;
- }
- if (scrl.post)
- {
- scrl.post.duration -= nst;
- }
- sc_stopScroll(scrl, false);
- }
-
- // update remaining pause-time
- if (!crsl.isPaused && !crsl.isScrolling)
- {
- if (res)
- {
- tmrs.timePassed += getTime() - tmrs.startTime;
- }
- }
-
- // button
- if (!crsl.isPaused)
- {
- if (opts.auto.button)
- {
- opts.auto.button.addClass(cf_c('paused', conf));
- }
- }
-
- // set paused
- crsl.isPaused = true;
-
- // pause pause callback
- if (opts.auto.onTimeoutPause)
- {
- var dur1 = opts.auto.timeoutDuration - tmrs.timePassed,
- perc = 100 - Math.ceil( dur1 * 100 / opts.auto.timeoutDuration );
-
- opts.auto.onTimeoutPause.call($tt0, perc, dur1);
- }
- return true;
- });
-
-
- // play event
- $cfs.bind(cf_e('play', conf), function(e, dir, del, res) {
- e.stopPropagation();
- tmrs = sc_clearTimers(tmrs);
-
- // sort params
- var v = [dir, del, res],
- t = ['string', 'number', 'boolean'],
- a = cf_sortParams(v, t);
-
- dir = a[0];
- del = a[1];
- res = a[2];
-
- if (dir != 'prev' && dir != 'next')
- {
- dir = crsl.direction;
- }
- if (!is_number(del))
- {
- del = 0;
- }
- if (!is_boolean(res))
- {
- res = false;
- }
-
- // stopped?
- if (res)
- {
- crsl.isStopped = false;
- opts.auto.play = true;
- }
- if (!opts.auto.play)
- {
- e.stopImmediatePropagation();
- return debug(conf, 'Carousel stopped: Not scrolling.');
- }
-
- // button
- if (crsl.isPaused)
- {
- if (opts.auto.button)
- {
- opts.auto.button.removeClass(cf_c('stopped', conf));
- opts.auto.button.removeClass(cf_c('paused', conf));
- }
- }
-
- // set playing
- crsl.isPaused = false;
- tmrs.startTime = getTime();
-
- // timeout the scrolling
- var dur1 = opts.auto.timeoutDuration + del;
- dur2 = dur1 - tmrs.timePassed;
- perc = 100 - Math.ceil(dur2 * 100 / dur1);
-
- if (opts.auto.progress)
- {
- tmrs.progress = setInterval(function() {
- var pasd = getTime() - tmrs.startTime + tmrs.timePassed,
- perc = Math.ceil(pasd * 100 / dur1);
- opts.auto.progress.updater.call(opts.auto.progress.bar[0], perc);
- }, opts.auto.progress.interval);
- }
-
- tmrs.auto = setTimeout(function() {
- if (opts.auto.progress)
- {
- opts.auto.progress.updater.call(opts.auto.progress.bar[0], 100);
- }
- if (opts.auto.onTimeoutEnd)
- {
- opts.auto.onTimeoutEnd.call($tt0, perc, dur2);
- }
- if (crsl.isScrolling)
- {
- $cfs.trigger(cf_e('play', conf), dir);
- }
- else
- {
- $cfs.trigger(cf_e(dir, conf), opts.auto);
- }
- }, dur2);
-
- // pause start callback
- if (opts.auto.onTimeoutStart)
- {
- opts.auto.onTimeoutStart.call($tt0, perc, dur2);
- }
-
- return true;
- });
-
-
- // resume event
- $cfs.bind(cf_e('resume', conf), function(e) {
- e.stopPropagation();
- if (scrl.isStopped)
- {
- scrl.isStopped = false;
- crsl.isPaused = false;
- crsl.isScrolling = true;
- scrl.startTime = getTime();
- sc_startScroll(scrl);
- }
- else
- {
- $cfs.trigger(cf_e('play', conf));
- }
- return true;
- });
-
-
- // prev + next events
- $cfs.bind(cf_e('prev', conf)+' '+cf_e('next', conf), function(e, obj, num, clb, que) {
- e.stopPropagation();
-
- // stopped or hidden carousel, don't scroll, don't queue
- if (crsl.isStopped || $cfs.is(':hidden'))
- {
- e.stopImmediatePropagation();
- return debug(conf, 'Carousel stopped or hidden: Not scrolling.');
- }
-
- // not enough items
- var minimum = (is_number(opts.items.minimum)) ? opts.items.minimum : opts.items.visible + 1;
- if (minimum > itms.total)
- {
- e.stopImmediatePropagation();
- return debug(conf, 'Not enough items ('+itms.total+' total, '+minimum+' needed): Not scrolling.');
- }
-
- // get config
- var v = [obj, num, clb, que],
- t = ['object', 'number/string', 'function', 'boolean'],
- a = cf_sortParams(v, t);
-
- obj = a[0];
- num = a[1];
- clb = a[2];
- que = a[3];
-
- var eType = e.type.slice(conf.events.prefix.length);
-
- if (!is_object(obj))
- {
- obj = {};
- }
- if (is_function(clb))
- {
- obj.onAfter = clb;
- }
- if (is_boolean(que))
- {
- obj.queue = que;
- }
- obj = $.extend(true, {}, opts[eType], obj);
-
- // test conditions callback
- if (obj.conditions && !obj.conditions.call($tt0, eType))
- {
- e.stopImmediatePropagation();
- return debug(conf, 'Callback "conditions" returned false.');
- }
-
- if (!is_number(num))
- {
- if (opts.items.filter != '*')
- {
- num = 'visible';
- }
- else
- {
- var arr = [num, obj.items, opts[eType].items];
- for (var a = 0, l = arr.length; a < l; a++)
- {
- if (is_number(arr[a]) || arr[a] == 'page' || arr[a] == 'visible') {
- num = arr[a];
- break;
- }
- }
- }
- switch(num) {
- case 'page':
- e.stopImmediatePropagation();
- return $cfs.triggerHandler(cf_e(eType+'Page', conf), [obj, clb]);
- break;
-
- case 'visible':
- if (!opts.items.visibleConf.variable && opts.items.filter == '*')
- {
- num = opts.items.visible;
- }
- break;
- }
- }
-
- // resume animation, add current to queue
- if (scrl.isStopped)
- {
- $cfs.trigger(cf_e('resume', conf));
- $cfs.trigger(cf_e('queue', conf), [eType, [obj, num, clb]]);
- e.stopImmediatePropagation();
- return debug(conf, 'Carousel resumed scrolling.');
- }
-
- // queue if scrolling
- if (obj.duration > 0)
- {
- if (crsl.isScrolling)
- {
- if (obj.queue)
- {
- if (obj.queue == 'last')
- {
- queu = [];
- }
- if (obj.queue != 'first' || queu.length == 0)
- {
- $cfs.trigger(cf_e('queue', conf), [eType, [obj, num, clb]]);
- }
- }
- e.stopImmediatePropagation();
- return debug(conf, 'Carousel currently scrolling.');
- }
- }
-
- tmrs.timePassed = 0;
- $cfs.trigger(cf_e('slide_'+eType, conf), [obj, num]);
-
- // synchronise
- if (opts.synchronise)
- {
- var s = opts.synchronise,
- c = [obj, num];
-
- for (var j = 0, l = s.length; j < l; j++) {
- var d = eType;
- if (!s[j][2])
- {
- d = (d == 'prev') ? 'next' : 'prev';
- }
- if (!s[j][1])
- {
- c[0] = s[j][0].triggerHandler('_cfs_triggerEvent', ['configuration', d]);
- }
- c[1] = num + s[j][3];
- s[j][0].trigger('_cfs_triggerEvent', ['slide_'+d, c]);
- }
- }
- return true;
- });
-
-
- // prev event
- $cfs.bind(cf_e('slide_prev', conf), function(e, sO, nI) {
- e.stopPropagation();
- var a_itm = $cfs.children();
-
- // non-circular at start, scroll to end
- if (!opts.circular)
- {
- if (itms.first == 0)
- {
- if (opts.infinite)
- {
- $cfs.trigger(cf_e('next', conf), itms.total-1);
- }
- return e.stopImmediatePropagation();
- }
- }
-
- sz_resetMargin(a_itm, opts);
-
- // find number of items to scroll
- if (!is_number(nI))
- {
- if (opts.items.visibleConf.variable)
- {
- nI = gn_getVisibleItemsPrev(a_itm, opts, itms.total-1);
- }
- else if (opts.items.filter != '*')
- {
- var xI = (is_number(sO.items)) ? sO.items : gn_getVisibleOrg($cfs, opts);
- nI = gn_getScrollItemsPrevFilter(a_itm, opts, itms.total-1, xI);
- }
- else
- {
- nI = opts.items.visible;
- }
- nI = cf_getAdjust(nI, opts, sO.items, $tt0);
- }
-
- // prevent non-circular from scrolling to far
- if (!opts.circular)
- {
- if (itms.total - nI < itms.first)
- {
- nI = itms.total - itms.first;
- }
- }
-
- // set new number of visible items
- opts.items.visibleConf.old = opts.items.visible;
- if (opts.items.visibleConf.variable)
- {
- var vI = cf_getItemsAdjust(gn_getVisibleItemsNext(a_itm, opts, itms.total-nI), opts, opts.items.visibleConf.adjust, $tt0);
- if (opts.items.visible+nI <= vI && nI < itms.total)
- {
- nI++;
- vI = cf_getItemsAdjust(gn_getVisibleItemsNext(a_itm, opts, itms.total-nI), opts, opts.items.visibleConf.adjust, $tt0);
- }
- opts.items.visible = vI;
- }
- else if (opts.items.filter != '*')
- {
- var vI = gn_getVisibleItemsNextFilter(a_itm, opts, itms.total-nI);
- opts.items.visible = cf_getItemsAdjust(vI, opts, opts.items.visibleConf.adjust, $tt0);
- }
-
- sz_resetMargin(a_itm, opts, true);
-
- // scroll 0, don't scroll
- if (nI == 0)
- {
- e.stopImmediatePropagation();
- return debug(conf, '0 items to scroll: Not scrolling.');
- }
- debug(conf, 'Scrolling '+nI+' items backward.');
-
-
- // save new config
- itms.first += nI;
- while (itms.first >= itms.total)
- {
- itms.first -= itms.total;
- }
-
- // non-circular callback
- if (!opts.circular)
- {
- if (itms.first == 0 && sO.onEnd)
- {
- sO.onEnd.call($tt0, 'prev');
- }
- if (!opts.infinite)
- {
- nv_enableNavi(opts, itms.first, conf);
- }
- }
-
- // rearrange items
- $cfs.children().slice(itms.total-nI, itms.total).prependTo($cfs);
- if (itms.total < opts.items.visible + nI)
- {
- $cfs.children().slice(0, (opts.items.visible+nI)-itms.total).clone(true).appendTo($cfs);
- }
-
- // the needed items
- var a_itm = $cfs.children(),
- i_old = gi_getOldItemsPrev(a_itm, opts, nI),
- i_new = gi_getNewItemsPrev(a_itm, opts),
- i_cur_l = a_itm.eq(nI-1),
- i_old_l = i_old.last(),
- i_new_l = i_new.last();
-
- sz_resetMargin(a_itm, opts);
-
- var pL = 0,
- pR = 0;
-
- if (opts.align)
- {
- var p = cf_getAlignPadding(i_new, opts);
- pL = p[0];
- pR = p[1];
- }
- var oL = (pL < 0) ? opts.padding[opts.d[3]] : 0;
-
- // hide items for fx directscroll
- var hiddenitems = false,
- i_skp = $();
- if (opts.items.visible < nI)
- {
- i_skp = a_itm.slice(opts.items.visibleConf.old, nI);
- if (sO.fx == 'directscroll')
- {
- var orgW = opts.items[opts.d['width']];
- hiddenitems = i_skp;
- i_cur_l = i_new_l;
- sc_hideHiddenItems(hiddenitems);
- opts.items[opts.d['width']] = 'variable';
- }
- }
-
- // save new sizes
- var $cf2 = false,
- i_siz = ms_getTotalSize(a_itm.slice(0, nI), opts, 'width'),
- w_siz = cf_mapWrapperSizes(ms_getSizes(i_new, opts, true), opts, !opts.usePadding),
- i_siz_vis = 0,
- a_cfs = {},
- a_wsz = {},
- a_cur = {},
- a_old = {},
- a_new = {},
- a_lef = {},
- a_lef_vis = {},
- a_dur = sc_getDuration(sO, opts, nI, i_siz);
-
- switch(sO.fx)
- {
- case 'cover':
- case 'cover-fade':
- i_siz_vis = ms_getTotalSize(a_itm.slice(0, opts.items.visible), opts, 'width');
- break;
- }
-
- if (hiddenitems)
- {
- opts.items[opts.d['width']] = orgW;
- }
-
- sz_resetMargin(a_itm, opts, true);
- if (pR >= 0)
- {
- sz_resetMargin(i_old_l, opts, opts.padding[opts.d[1]]);
- }
- if (pL >= 0)
- {
- sz_resetMargin(i_cur_l, opts, opts.padding[opts.d[3]]);
- }
-
- if (opts.align)
- {
- opts.padding[opts.d[1]] = pR;
- opts.padding[opts.d[3]] = pL;
- }
-
- a_lef[opts.d['left']] = -(i_siz - oL);
- a_lef_vis[opts.d['left']] = -(i_siz_vis - oL);
- a_wsz[opts.d['left']] = w_siz[opts.d['width']];
-
- // scrolling functions
- var _s_wrapper = function() {},
- _a_wrapper = function() {},
- _s_paddingold = function() {},
- _a_paddingold = function() {},
- _s_paddingnew = function() {},
- _a_paddingnew = function() {},
- _s_paddingcur = function() {},
- _a_paddingcur = function() {},
- _onafter = function() {},
- _moveitems = function() {},
- _position = function() {};
-
- // clone carousel
- switch(sO.fx)
- {
- case 'crossfade':
- case 'cover':
- case 'cover-fade':
- case 'uncover':
- case 'uncover-fade':
- $cf2 = $cfs.clone(true).appendTo($wrp);
- break;
- }
- switch(sO.fx)
- {
- case 'crossfade':
- case 'uncover':
- case 'uncover-fade':
- $cf2.children().slice(0, nI).remove();
- $cf2.children().slice(opts.items.visibleConf.old).remove();
- break;
-
- case 'cover':
- case 'cover-fade':
- $cf2.children().slice(opts.items.visible).remove();
- $cf2.css(a_lef_vis);
- break;
- }
-
- $cfs.css(a_lef);
-
- // reset all scrolls
- scrl = sc_setScroll(a_dur, sO.easing);
-
- // animate / set carousel
- a_cfs[opts.d['left']] = (opts.usePadding) ? opts.padding[opts.d[3]] : 0;
-
- // animate / set wrapper
- if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable')
- {
- _s_wrapper = function() {
- $wrp.css(w_siz);
- };
- _a_wrapper = function() {
- scrl.anims.push([$wrp, w_siz]);
- };
- }
-
- // animate / set items
- if (opts.usePadding)
- {
- if (i_new_l.not(i_cur_l).length)
- {
- a_cur[opts.d['marginRight']] = i_cur_l.data('_cfs_origCssMargin');
-
- if (pL < 0)
- {
- i_cur_l.css(a_cur);
- }
- else
- {
- _s_paddingcur = function() {
- i_cur_l.css(a_cur);
- };
- _a_paddingcur = function() {
- scrl.anims.push([i_cur_l, a_cur]);
- };
- }
- }
- switch(sO.fx)
- {
- case 'cover':
- case 'cover-fade':
- $cf2.children().eq(nI-1).css(a_cur);
- break;
- }
-
- if (i_new_l.not(i_old_l).length)
- {
- a_old[opts.d['marginRight']] = i_old_l.data('_cfs_origCssMargin');
- _s_paddingold = function() {
- i_old_l.css(a_old);
- };
- _a_paddingold = function() {
- scrl.anims.push([i_old_l, a_old]);
- };
- }
-
- if (pR >= 0)
- {
- a_new[opts.d['marginRight']] = i_new_l.data('_cfs_origCssMargin') + opts.padding[opts.d[1]];
- _s_paddingnew = function() {
- i_new_l.css(a_new);
- };
- _a_paddingnew = function() {
- scrl.anims.push([i_new_l, a_new]);
- };
- }
- }
-
- // set position
- _position = function() {
- $cfs.css(a_cfs);
- };
-
-
- var overFill = opts.items.visible+nI-itms.total;
-
- // rearrange items
- _moveitems = function() {
- if (overFill > 0)
- {
- $cfs.children().slice(itms.total).remove();
- i_old = $( $cfs.children().slice(itms.total-(opts.items.visible-overFill)).get().concat( $cfs.children().slice(0, overFill).get() ) );
- }
- sc_showHiddenItems(hiddenitems);
-
- if (opts.usePadding)
- {
- var l_itm = $cfs.children().eq(opts.items.visible+nI-1);
- l_itm.css(opts.d['marginRight'], l_itm.data('_cfs_origCssMargin'));
- }
- };
-
-
- var cb_arguments = sc_mapCallbackArguments(i_old, i_skp, i_new, nI, 'prev', a_dur, w_siz);
-
- // fire onAfter callbacks
- _onafter = function() {
- sc_afterScroll($cfs, $cf2, sO);
- crsl.isScrolling = false;
- clbk.onAfter = sc_fireCallbacks($tt0, sO, 'onAfter', cb_arguments, clbk);
- queu = sc_fireQueue($cfs, queu, conf);
-
- if (!crsl.isPaused)
- {
- $cfs.trigger(cf_e('play', conf));
- }
- };
-
- // fire onBefore callback
- crsl.isScrolling = true;
- tmrs = sc_clearTimers(tmrs);
- clbk.onBefore = sc_fireCallbacks($tt0, sO, 'onBefore', cb_arguments, clbk);
-
- switch(sO.fx)
- {
- case 'none':
- $cfs.css(a_cfs);
- _s_wrapper();
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- _onafter();
- break;
-
- case 'fade':
- scrl.anims.push([$cfs, { 'opacity': 0 }, function() {
- _s_wrapper();
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- scrl = sc_setScroll(a_dur, sO.easing);
- scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
- sc_startScroll(scrl);
- }]);
- break;
-
- case 'crossfade':
- $cfs.css({ 'opacity': 0 });
- scrl.anims.push([$cf2, { 'opacity': 0 }]);
- scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- break;
-
- case 'cover':
- scrl.anims.push([$cf2, a_cfs, function() {
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- _onafter();
- }]);
- _a_wrapper();
- break;
-
- case 'cover-fade':
- scrl.anims.push([$cfs, { 'opacity': 0 }]);
- scrl.anims.push([$cf2, a_cfs, function() {
- $cfs.css({ 'opacity': 1 });
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- _onafter();
- }]);
- _a_wrapper();
- break;
-
- case 'uncover':
- scrl.anims.push([$cf2, a_wsz, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- break;
-
- case 'uncover-fade':
- $cfs.css({ 'opacity': 0 });
- scrl.anims.push([$cfs, { 'opacity': 1 }]);
- scrl.anims.push([$cf2, a_wsz, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingnew();
- _s_paddingcur();
- _position();
- _moveitems();
- break;
-
- default:
- scrl.anims.push([$cfs, a_cfs, function() {
- _moveitems();
- _onafter();
- }]);
- _a_wrapper();
- _a_paddingold();
- _a_paddingnew();
- _a_paddingcur();
- break;
- }
-
- sc_startScroll(scrl);
- cf_setCookie(opts.cookie, $cfs, conf);
-
- $cfs.trigger(cf_e('updatePageStatus', conf), [false, w_siz]);
-
- return true;
- });
-
-
- // next event
- $cfs.bind(cf_e('slide_next', conf), function(e, sO, nI) {
- e.stopPropagation();
- var a_itm = $cfs.children();
-
- // non-circular at end, scroll to start
- if (!opts.circular)
- {
- if (itms.first == opts.items.visible)
- {
- if (opts.infinite)
- {
- $cfs.trigger(cf_e('prev', conf), itms.total-1);
- }
- return e.stopImmediatePropagation();
- }
- }
-
- sz_resetMargin(a_itm, opts);
-
- // find number of items to scroll
- if (!is_number(nI))
- {
- if (opts.items.filter != '*')
- {
- var xI = (is_number(sO.items)) ? sO.items : gn_getVisibleOrg($cfs, opts);
- nI = gn_getScrollItemsNextFilter(a_itm, opts, 0, xI);
- }
- else
- {
- nI = opts.items.visible;
- }
- nI = cf_getAdjust(nI, opts, sO.items, $tt0);
- }
-
- var lastItemNr = (itms.first == 0) ? itms.total : itms.first;
-
- // prevent non-circular from scrolling to far
- if (!opts.circular)
- {
- if (opts.items.visibleConf.variable)
- {
- var vI = gn_getVisibleItemsNext(a_itm, opts, nI),
- xI = gn_getVisibleItemsPrev(a_itm, opts, lastItemNr-1);
- }
- else
- {
- var vI = opts.items.visible,
- xI = opts.items.visible;
- }
-
- if (nI + vI > lastItemNr)
- {
- nI = lastItemNr - xI;
- }
- }
-
- // set new number of visible items
- opts.items.visibleConf.old = opts.items.visible;
- if (opts.items.visibleConf.variable)
- {
- var vI = cf_getItemsAdjust(gn_getVisibleItemsNextTestCircular(a_itm, opts, nI, lastItemNr), opts, opts.items.visibleConf.adjust, $tt0);
- while (opts.items.visible-nI >= vI && nI < itms.total)
- {
- nI++;
- vI = cf_getItemsAdjust(gn_getVisibleItemsNextTestCircular(a_itm, opts, nI, lastItemNr), opts, opts.items.visibleConf.adjust, $tt0);
- }
- opts.items.visible = vI;
- }
- else if (opts.items.filter != '*')
- {
- var vI = gn_getVisibleItemsNextFilter(a_itm, opts, nI);
- opts.items.visible = cf_getItemsAdjust(vI, opts, opts.items.visibleConf.adjust, $tt0);
- }
-
- sz_resetMargin(a_itm, opts, true);
-
- // scroll 0, don't scroll
- if (nI == 0)
- {
- e.stopImmediatePropagation();
- return debug(conf, '0 items to scroll: Not scrolling.');
- }
- debug(conf, 'Scrolling '+nI+' items forward.');
-
-
- // save new config
- itms.first -= nI;
- while (itms.first < 0)
- {
- itms.first += itms.total;
- }
-
- // non-circular callback
- if (!opts.circular)
- {
- if (itms.first == opts.items.visible && sO.onEnd)
- {
- sO.onEnd.call($tt0, 'next');
- }
- if (!opts.infinite)
- {
- nv_enableNavi(opts, itms.first, conf);
- }
- }
-
- // rearrange items
- if (itms.total < opts.items.visible+nI)
- {
- $cfs.children().slice(0, (opts.items.visible+nI)-itms.total).clone(true).appendTo($cfs);
- }
-
- // the needed items
- var a_itm = $cfs.children(),
- i_old = gi_getOldItemsNext(a_itm, opts),
- i_new = gi_getNewItemsNext(a_itm, opts, nI),
- i_cur_l = a_itm.eq(nI-1),
- i_old_l = i_old.last(),
- i_new_l = i_new.last();
-
- sz_resetMargin(a_itm, opts);
-
- var pL = 0,
- pR = 0;
-
- if (opts.align)
- {
- var p = cf_getAlignPadding(i_new, opts);
- pL = p[0];
- pR = p[1];
- }
-
- // hide items for fx directscroll
- var hiddenitems = false,
- i_skp = $();
- if (opts.items.visibleConf.old < nI)
- {
- i_skp = a_itm.slice(opts.items.visibleConf.old, nI);
- if (sO.fx == 'directscroll')
- {
- var orgW = opts.items[opts.d['width']];
- hiddenitems = i_skp;
- i_cur_l = i_old_l;
- sc_hideHiddenItems(hiddenitems);
- opts.items[opts.d['width']] = 'variable';
- }
- }
-
- // save new sizes
- var $cf2 = false,
- i_siz = ms_getTotalSize(a_itm.slice(0, nI), opts, 'width'),
- w_siz = cf_mapWrapperSizes(ms_getSizes(i_new, opts, true), opts, !opts.usePadding),
- i_siz_vis = 0,
- a_cfs = {},
- a_cfs_vis = {},
- a_cur = {},
- a_old = {},
- a_lef = {},
- a_dur = sc_getDuration(sO, opts, nI, i_siz);
-
- switch(sO.fx)
- {
- case 'uncover':
- case 'uncover-fade':
- i_siz_vis = ms_getTotalSize(a_itm.slice(0, opts.items.visibleConf.old), opts, 'width');
- break;
- }
-
- if (hiddenitems)
- {
- opts.items[opts.d['width']] = orgW;
- }
-
- if (opts.align)
- {
- if (opts.padding[opts.d[1]] < 0)
- {
- opts.padding[opts.d[1]] = 0;
- }
- }
- sz_resetMargin(a_itm, opts, true);
- sz_resetMargin(i_old_l, opts, opts.padding[opts.d[1]]);
-
- if (opts.align)
- {
- opts.padding[opts.d[1]] = pR;
- opts.padding[opts.d[3]] = pL;
- }
-
- a_lef[opts.d['left']] = (opts.usePadding) ? opts.padding[opts.d[3]] : 0;
-
- // scrolling functions
- var _s_wrapper = function() {},
- _a_wrapper = function() {},
- _s_paddingold = function() {},
- _a_paddingold = function() {},
- _s_paddingcur = function() {},
- _a_paddingcur = function() {},
- _onafter = function() {},
- _moveitems = function() {},
- _position = function() {};
-
- // clone carousel
- switch(sO.fx)
- {
- case 'crossfade':
- case 'cover':
- case 'cover-fade':
- case 'uncover':
- case 'uncover-fade':
- $cf2 = $cfs.clone(true).appendTo($wrp);
- $cf2.children().slice(opts.items.visibleConf.old).remove();
- break;
- }
- switch(sO.fx)
- {
- case 'crossfade':
- case 'cover':
- case 'cover-fade':
- $cfs.css('zIndex', 1);
- $cf2.css('zIndex', 0);
- break;
- }
-
- // reset all scrolls
- scrl = sc_setScroll(a_dur, sO.easing);
-
- // animate / set carousel
- a_cfs[opts.d['left']] = -i_siz;
- a_cfs_vis[opts.d['left']] = -i_siz_vis;
-
- if (pL < 0)
- {
- a_cfs[opts.d['left']] += pL;
- }
-
- // animate / set wrapper
- if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable')
- {
- _s_wrapper = function() {
- $wrp.css(w_siz);
- };
- _a_wrapper = function() {
- scrl.anims.push([$wrp, w_siz]);
- };
- }
-
- // animate / set items
- if (opts.usePadding)
- {
- var i_new_l_m = i_new_l.data('_cfs_origCssMargin');
- if (pR >= 0)
- {
- i_new_l_m += opts.padding[opts.d[1]];
- }
- i_new_l.css(opts.d['marginRight'], i_new_l_m);
-
- if (i_cur_l.not(i_old_l).length)
- {
- a_old[opts.d['marginRight']] = i_old_l.data('_cfs_origCssMargin');
- }
- _s_paddingold = function() {
- i_old_l.css(a_old);
- };
- _a_paddingold = function() {
- scrl.anims.push([i_old_l, a_old]);
- };
-
- var i_cur_l_m = i_cur_l.data('_cfs_origCssMargin');
- if (pL > 0)
- {
- i_cur_l_m += opts.padding[opts.d[3]];
- }
- a_cur[opts.d['marginRight']] = i_cur_l_m;
- _s_paddingcur = function() {
- i_cur_l.css(a_cur);
- };
- _a_paddingcur = function() {
- scrl.anims.push([i_cur_l, a_cur]);
- };
- }
-
- // set position
- _position = function() {
- $cfs.css(a_lef);
- };
-
-
- var overFill = opts.items.visible+nI-itms.total;
-
- // rearrange items
- _moveitems = function() {
- if (overFill > 0)
- {
- $cfs.children().slice(itms.total).remove();
- }
- var l_itm = $cfs.children().slice(0, nI).appendTo($cfs).last();
- if (overFill > 0)
- {
- i_new = gi_getCurrentItems(a_itm, opts);
- }
- sc_showHiddenItems(hiddenitems);
-
- if (opts.usePadding)
- {
- if (itms.total < opts.items.visible+nI) {
- var i_cur_l = $cfs.children().eq(opts.items.visible-1);
- i_cur_l.css(opts.d['marginRight'], i_cur_l.data('_cfs_origCssMargin') + opts.padding[opts.d[3]]);
- }
- l_itm.css(opts.d['marginRight'], l_itm.data('_cfs_origCssMargin'));
- }
- };
-
-
- var cb_arguments = sc_mapCallbackArguments(i_old, i_skp, i_new, nI, 'next', a_dur, w_siz);
-
- // fire onAfter callbacks
- _onafter = function() {
- $cfs.css('zIndex', $cfs.data('_cfs_origCss').zIndex);
- sc_afterScroll($cfs, $cf2, sO);
- crsl.isScrolling = false;
- clbk.onAfter = sc_fireCallbacks($tt0, sO, 'onAfter', cb_arguments, clbk);
- queu = sc_fireQueue($cfs, queu, conf);
-
- if (!crsl.isPaused)
- {
- $cfs.trigger(cf_e('play', conf));
- }
- };
-
- // fire onBefore callbacks
- crsl.isScrolling = true;
- tmrs = sc_clearTimers(tmrs);
- clbk.onBefore = sc_fireCallbacks($tt0, sO, 'onBefore', cb_arguments, clbk);
-
- switch(sO.fx)
- {
- case 'none':
- $cfs.css(a_cfs);
- _s_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _position();
- _moveitems();
- _onafter();
- break;
-
- case 'fade':
- scrl.anims.push([$cfs, { 'opacity': 0 }, function() {
- _s_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _position();
- _moveitems();
- scrl = sc_setScroll(a_dur, sO.easing);
- scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
- sc_startScroll(scrl);
- }]);
- break;
-
- case 'crossfade':
- $cfs.css({ 'opacity': 0 });
- scrl.anims.push([$cf2, { 'opacity': 0 }]);
- scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _position();
- _moveitems();
- break;
-
- case 'cover':
- $cfs.css(opts.d['left'], $wrp[opts.d['width']]());
- scrl.anims.push([$cfs, a_lef, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _moveitems();
- break;
-
- case 'cover-fade':
- $cfs.css(opts.d['left'], $wrp[opts.d['width']]());
- scrl.anims.push([$cf2, { 'opacity': 0 }]);
- scrl.anims.push([$cfs, a_lef, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _moveitems();
- break;
-
- case 'uncover':
- scrl.anims.push([$cf2, a_cfs_vis, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _position();
- _moveitems();
- break;
-
- case 'uncover-fade':
- $cfs.css({ 'opacity': 0 });
- scrl.anims.push([$cfs, { 'opacity': 1 }]);
- scrl.anims.push([$cf2, a_cfs_vis, _onafter]);
- _a_wrapper();
- _s_paddingold();
- _s_paddingcur();
- _position();
- _moveitems();
- break;
-
- default:
- scrl.anims.push([$cfs, a_cfs, function() {
- _position();
- _moveitems();
- _onafter();
- }]);
- _a_wrapper();
- _a_paddingold();
- _a_paddingcur();
- break;
- }
-
- sc_startScroll(scrl);
- cf_setCookie(opts.cookie, $cfs, conf);
-
- $cfs.trigger(cf_e('updatePageStatus', conf), [false, w_siz]);
-
- return true;
- });
-
-
- // slideTo event
- $cfs.bind(cf_e('slideTo', conf), function(e, num, dev, org, obj, dir, clb) {
- e.stopPropagation();
-
- var v = [num, dev, org, obj, dir, clb],
- t = ['string/number/object', 'number', 'boolean', 'object', 'string', 'function'],
- a = cf_sortParams(v, t);
-
- obj = a[3];
- dir = a[4];
- clb = a[5];
-
- num = gn_getItemIndex(a[0], a[1], a[2], itms, $cfs);
-
- if (num == 0)
- {
- return false;
- }
- if (!is_object(obj))
- {
- obj = false;
- }
-
- /*
- if (crsl.isScrolling)
- {
- if (!is_object(obj) || obj.duration > 0)
- {
- // return false;
- }
- }
- */
-
- if (dir != 'prev' && dir != 'next')
- {
- if (opts.circular)
- {
- dir = (num <= itms.total / 2) ? 'next' : 'prev';
- }
- else
- {
- dir = (itms.first == 0 || itms.first > num) ? 'next' : 'prev';
- }
- }
-
- if (dir == 'prev')
- {
- num = itms.total-num;
- }
- $cfs.trigger(cf_e(dir, conf), [obj, num, clb]);
-
- return true;
- });
-
-
- // prevPage event
- $cfs.bind(cf_e('prevPage', conf), function(e, obj, clb) {
- e.stopPropagation();
- var cur = $cfs.triggerHandler(cf_e('currentPage', conf));
- return $cfs.triggerHandler(cf_e('slideToPage', conf), [cur-1, obj, 'prev', clb]);
- });
-
-
- // nextPage event
- $cfs.bind(cf_e('nextPage', conf), function(e, obj, clb) {
- e.stopPropagation();
- var cur = $cfs.triggerHandler(cf_e('currentPage', conf));
- return $cfs.triggerHandler(cf_e('slideToPage', conf), [cur+1, obj, 'next', clb]);
- });
-
-
- // slideToPage event
- $cfs.bind(cf_e('slideToPage', conf), function(e, pag, obj, dir, clb) {
- e.stopPropagation();
- if (!is_number(pag))
- {
- pag = $cfs.triggerHandler(cf_e('currentPage', conf));
- }
- var ipp = opts.pagination.items || opts.items.visible,
- max = Math.ceil(itms.total / ipp)-1;
-
- if (pag < 0)
- {
- pag = max;
- }
- if (pag > max)
- {
- pag = 0;
- }
- return $cfs.triggerHandler(cf_e('slideTo', conf), [pag*ipp, 0, true, obj, dir, clb]);
- });
-
- // jumpToStart event
- $cfs.bind(cf_e('jumpToStart', conf), function(e, s) {
- e.stopPropagation();
- if (s)
- {
- s = gn_getItemIndex(s, 0, true, itms, $cfs);
- }
- else
- {
- s = 0;
- }
-
- s += itms.first;
- if (s != 0)
- {
- if (itms.total > 0)
- {
- while (s > itms.total)
- {
- s -= itms.total;
- }
- }
- $cfs.prepend($cfs.children().slice(s, itms.total));
- }
- return true;
- });
-
-
- // synchronise event
- $cfs.bind(cf_e('synchronise', conf), function(e, s) {
- e.stopPropagation();
- if (s)
- {
- s = cf_getSynchArr(s);
- }
- else if (opts.synchronise)
- {
- s = opts.synchronise;
- }
- else
- {
- return debug(conf, 'No carousel to synchronise.');
- }
-
- var n = $cfs.triggerHandler(cf_e('currentPosition', conf)),
- x = true;
-
- for (var j = 0, l = s.length; j < l; j++)
- {
- if (!s[j][0].triggerHandler(cf_e('slideTo', conf), [n, s[j][3], true]))
- {
- x = false;
- }
- }
- return x;
- });
-
-
- // queue event
- $cfs.bind(cf_e('queue', conf), function(e, dir, opt) {
- e.stopPropagation();
- if (is_function(dir))
- {
- dir.call($tt0, queu);
- }
- else if (is_array(dir))
- {
- queu = dir;
- }
- else if (!is_undefined(dir))
- {
- queu.push([dir, opt]);
- }
- return queu;
- });
-
-
- // insertItem event
- $cfs.bind(cf_e('insertItem', conf), function(e, itm, num, org, dev) {
- e.stopPropagation();
-
- var v = [itm, num, org, dev],
- t = ['string/object', 'string/number/object', 'boolean', 'number'],
- a = cf_sortParams(v, t);
-
- itm = a[0];
- num = a[1];
- org = a[2];
- dev = a[3];
-
- if (is_object(itm) && !is_jquery(itm))
- {
- itm = $(itm);
- }
- else if (is_string(itm))
- {
- itm = $(itm);
- }
- if (!is_jquery(itm) || itm.length == 0)
- {
- return debug(conf, 'Not a valid object.');
- }
-
- if (is_undefined(num))
- {
- num = 'end';
- }
-
- sz_storeMargin(itm, opts);
- sz_storeSizes(itm, opts);
-
- var orgNum = num,
- before = 'before';
-
- if (num == 'end')
- {
- if (org)
- {
- if (itms.first == 0)
- {
- num = itms.total-1;
- before = 'after';
- }
- else
- {
- num = itms.first;
- itms.first += itm.length;
- }
- if (num < 0)
- {
- num = 0;
- }
- }
- else
- {
- num = itms.total-1;
- before = 'after';
- }
- }
- else
- {
- num = gn_getItemIndex(num, dev, org, itms, $cfs);
- }
-
- var $cit = $cfs.children().eq(num);
- if ($cit.length)
- {
- $cit[before](itm);
- }
- else
- {
- debug(conf, 'Correct insert-position not found! Appending item to the end.');
- $cfs.append(itm);
- }
-
- if (orgNum != 'end' && !org)
- {
- if (num < itms.first)
- {
- itms.first += itm.length;
- }
- }
- itms.total = $cfs.children().length;
- if (itms.first >= itms.total)
- {
- itms.first -= itms.total;
- }
-
- $cfs.trigger(cf_e('updateSizes', conf));
- $cfs.trigger(cf_e('linkAnchors', conf));
-
- return true;
- });
-
-
- // removeItem event
- $cfs.bind(cf_e('removeItem', conf), function(e, num, org, dev) {
- e.stopPropagation();
-
- var v = [num, org, dev],
- t = ['string/number/object', 'boolean', 'number'],
- a = cf_sortParams(v, t);
-
- num = a[0];
- org = a[1];
- dev = a[2];
-
- var removed = false;
- if (num instanceof $ && num.length > 1)
- {
- $removed = $();
- num.each(function(i, el) {
- var $rem = $cfs.trigger(cf_e('removeItem', conf), [$(this), org, dev]);
- if ($rem) $removed = $removed.add($rem);
- });
- return $removed;
- }
-
- if (is_undefined(num) || num == 'end')
- {
- $removed = $cfs.children().last();
- }
- else
- {
- num = gn_getItemIndex(num, dev, org, itms, $cfs);
- var $removed = $cfs.children().eq(num);
- if ($removed.length){
- if (num < itms.first) itms.first -= $removed.length;
- }
- }
- if ($removed && $removed.length)
- {
- $removed.detach();
- itms.total = $cfs.children().length;
- $cfs.trigger(cf_e('updateSizes', conf));
- }
-
- return $removed;
- });
-
-
- // onBefore and onAfter event
- $cfs.bind(cf_e('onBefore', conf)+' '+cf_e('onAfter', conf), function(e, fn) {
- e.stopPropagation();
- var eType = e.type.slice(conf.events.prefix.length);
- if (is_array(fn))
- {
- clbk[eType] = fn;
- }
- if (is_function(fn))
- {
- clbk[eType].push(fn);
- }
- return clbk[eType];
- });
-
-
- // currentPosition event
- $cfs.bind(cf_e('currentPosition', conf), function(e, fn) {
- e.stopPropagation();
- if (itms.first == 0)
- {
- var val = 0;
- }
- else
- {
- var val = itms.total - itms.first;
- }
- if (is_function(fn))
- {
- fn.call($tt0, val);
- }
- return val;
- });
-
-
- // currentPage event
- $cfs.bind(cf_e('currentPage', conf), function(e, fn) {
- e.stopPropagation();
- var ipp = opts.pagination.items || opts.items.visible,
- max = Math.ceil(itms.total/ipp-1),
- nr;
- if (itms.first == 0)
- {
- nr = 0;
- }
- else if (itms.first < itms.total % ipp)
- {
- nr = 0;
- }
- else if (itms.first == ipp && !opts.circular)
- {
- nr = max;
- }
- else
- {
- nr = Math.round((itms.total-itms.first)/ipp);
- }
- if (nr < 0)
- {
- nr = 0;
- }
- if (nr > max)
- {
- nr = max;
- }
- if (is_function(fn))
- {
- fn.call($tt0, nr);
- }
- return nr;
- });
-
-
- // currentVisible event
- $cfs.bind(cf_e('currentVisible', conf), function(e, fn) {
- e.stopPropagation();
- var $i = gi_getCurrentItems($cfs.children(), opts);
- if (is_function(fn))
- {
- fn.call($tt0, $i);
- }
- return $i;
- });
-
-
- // slice event
- $cfs.bind(cf_e('slice', conf), function(e, f, l, fn) {
- e.stopPropagation();
-
- if (itms.total == 0)
- {
- return false;
- }
-
- var v = [f, l, fn],
- t = ['number', 'number', 'function'],
- a = cf_sortParams(v, t);
-
- f = (is_number(a[0])) ? a[0] : 0;
- l = (is_number(a[1])) ? a[1] : itms.total;
- fn = a[2];
-
- f += itms.first;
- l += itms.first;
-
- if (items.total > 0)
- {
- while (f > itms.total)
- {
- f -= itms.total;
- }
- while (l > itms.total)
- {
- l -= itms.total;
- }
- while (f < 0)
- {
- f += itms.total;
- }
- while (l < 0)
- {
- l += itms.total;
- }
- }
- var $iA = $cfs.children(),
- $i;
-
- if (l > f)
- {
- $i = $iA.slice(f, l);
- }
- else
- {
- $i = $( $iA.slice(f, itms.total).get().concat( $iA.slice(0, l).get() ) );
- }
-
- if (is_function(fn))
- {
- fn.call($tt0, $i);
- }
- return $i;
- });
-
-
- // isPaused, isStopped and isScrolling events
- $cfs.bind(cf_e('isPaused', conf)+' '+cf_e('isStopped', conf)+' '+cf_e('isScrolling', conf), function(e, fn) {
- e.stopPropagation();
- var eType = e.type.slice(conf.events.prefix.length),
- value = crsl[eType];
- if (is_function(fn))
- {
- fn.call($tt0, value);
- }
- return value;
- });
-
-
- // configuration event
- $cfs.bind(cf_e('configuration', conf), function(e, a, b, c) {
- e.stopPropagation();
- var reInit = false;
-
- // return entire configuration-object
- if (is_function(a))
- {
- a.call($tt0, opts);
- }
- // set multiple options via object
- else if (is_object(a))
- {
- opts_orig = $.extend(true, {}, opts_orig, a);
- if (b !== false) reInit = true;
- else opts = $.extend(true, {}, opts, a);
-
- }
- else if (!is_undefined(a))
- {
-
- // callback function for specific option
- if (is_function(b))
- {
- var val = eval('opts.'+a);
- if (is_undefined(val))
- {
- val = '';
- }
- b.call($tt0, val);
- }
- // set individual option
- else if (!is_undefined(b))
- {
- if (typeof c !== 'boolean') c = true;
- eval('opts_orig.'+a+' = b');
- if (c !== false) reInit = true;
- else eval('opts.'+a+' = b');
- }
- // return value for specific option
- else
- {
- return eval('opts.'+a);
- }
- }
- if (reInit)
- {
- sz_resetMargin($cfs.children(), opts);
- $cfs._cfs_init(opts_orig);
- $cfs._cfs_bind_buttons();
- var sz = sz_setSizes($cfs, opts);
- $cfs.trigger(cf_e('updatePageStatus', conf), [true, sz]);
- }
- return opts;
- });
-
-
- // linkAnchors event
- $cfs.bind(cf_e('linkAnchors', conf), function(e, $con, sel) {
- e.stopPropagation();
-
- if (is_undefined($con))
- {
- $con = $('body');
- }
- else if (is_string($con))
- {
- $con = $($con);
- }
- if (!is_jquery($con) || $con.length == 0)
-