/* * jquery caroufredsel 6.2.0 * demo's and documentation: * caroufredsel.dev7studios.com * * copyright (c) 2013 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]); } var fn = {}; fn._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 fn._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; } if (conf.wrapper == 'parent') { sz_storeorigcss($wrp); } else { $wrp.css(orgcss); } $wrp.css({ 'overflow' : 'hidden', 'position' : newposition }); sz_storeorigcss($cfs); $cfs.data('_cfs_origcsszindex', orgcss.zindex); $cfs.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_storeorigcss(a_itm); if (opts.responsive) { sz_setresponsivesizes(opts, a_itm); } }; // /build fn._cfs_bind_events = function() { fn._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, conf); } 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, conf); // 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, conf); scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]); sc_startscroll(scrl, conf); }]); 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, conf); 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, conf); // 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[1]]); } 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_origcsszindex')); 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, conf); scrl.anims.push([$cfs, { 'opacity': 1 }, _onafter]); sc_startscroll(scrl, conf); }]); 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, conf); 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 (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_storeorigcss(itm); 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); fn._cfs_init(opts_orig); fn._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) { return debug(conf, 'not a valid object.'); } if (!is_string(sel)) { sel = 'a.caroufredsel'; } $con.find(sel).each(function() { var h = this.hash || ''; if (h.length > 0 && $cfs.children().index($(h)) != -1) { $(this).unbind('click').click(function(e) { e.preventdefault(); $cfs.trigger(cf_e('slideto', conf), h); }); } }); return true; }); // updatepagestatus event $cfs.bind(cf_e('updatepagestatus', conf), function(e, build, sizes) { e.stoppropagation(); if (!opts.pagination.container) { return; } var ipp = opts.pagination.items || opts.items.visible, pgs = math.ceil(itms.total/ipp); if (build) { if (opts.pagination.anchorbuilder) { opts.pagination.container.children().remove(); opts.pagination.container.each(function() { for (var a = 0; a < pgs; a++) { var i = $cfs.children().eq( gn_getitemindex(a*ipp, 0, true, itms, $cfs) ); $(this).append(opts.pagination.anchorbuilder.call(i[0], a+1)); } }); } opts.pagination.container.each(function() { $(this).children().unbind(opts.pagination.event).each(function(a) { $(this).bind(opts.pagination.event, function(e) { e.preventdefault(); $cfs.trigger(cf_e('slideto', conf), [a*ipp, -opts.pagination.deviation, true, opts.pagination]); }); }); }); } var selected = $cfs.triggerhandler(cf_e('currentpage', conf)) + opts.pagination.deviation; if (selected >= pgs) { selected = 0; } if (selected < 0) { selected = pgs-1; } opts.pagination.container.each(function() { $(this).children().removeclass(cf_c('selected', conf)).eq(selected).addclass(cf_c('selected', conf)); }); return true; }); // updatesizes event $cfs.bind(cf_e('updatesizes', conf), function(e) { var vi = opts.items.visible, a_itm = $cfs.children(), avail_primary = ms_getparentsize($wrp, opts, 'width'); itms.total = a_itm.length; if (crsl.primarysizepercentage) { opts.maxdimension = avail_primary; opts[opts.d['width']] = ms_getpercentage(avail_primary, crsl.primarysizepercentage); } else { opts.maxdimension = ms_getmaxdimension(opts, avail_primary); } if (opts.responsive) { opts.items.width = opts.items.sizesconf.width; opts.items.height = opts.items.sizesconf.height; opts = in_getresponsivevalues(opts, a_itm, avail_primary); vi = opts.items.visible; sz_setresponsivesizes(opts, a_itm); } else if (opts.items.visibleconf.variable) { vi = gn_getvisibleitemsnext(a_itm, opts, 0); } else if (opts.items.filter != '*') { vi = gn_getvisibleitemsnextfilter(a_itm, opts, 0); } if (!opts.circular && itms.first != 0 && vi > itms.first) { if (opts.items.visibleconf.variable) { var ni = gn_getvisibleitemsprev(a_itm, opts, itms.first) - itms.first; } else if (opts.items.filter != '*') { var ni = gn_getvisibleitemsprevfilter(a_itm, opts, itms.first) - itms.first; } else { var ni = opts.items.visible - itms.first; } debug(conf, 'preventing non-circular: sliding '+ni+' items backward.'); $cfs.trigger(cf_e('prev', conf), ni); } opts.items.visible = cf_getitemsadjust(vi, opts, opts.items.visibleconf.adjust, $tt0); opts.items.visibleconf.old = opts.items.visible; opts = in_getalignpadding(opts, a_itm); var sz = sz_setsizes($cfs, opts); $cfs.trigger(cf_e('updatepagestatus', conf), [true, sz]); nv_shownavi(opts, itms.total, conf); nv_enablenavi(opts, itms.first, conf); return sz; }); // destroy event $cfs.bind(cf_e('destroy', conf), function(e, orgorder) { e.stoppropagation(); tmrs = sc_cleartimers(tmrs); $cfs.data('_cfs_iscarousel', false); $cfs.trigger(cf_e('finish', conf)); if (orgorder) { $cfs.trigger(cf_e('jumptostart', conf)); } sz_restoreorigcss($cfs.children()); sz_restoreorigcss($cfs); fn._cfs_unbind_events(); fn._cfs_unbind_buttons(); if (conf.wrapper == 'parent') { sz_restoreorigcss($wrp); } else { $wrp.replacewith($cfs); } return true; }); // debug event $cfs.bind(cf_e('debug', conf), function(e) { debug(conf, 'carousel width: ' + opts.width); debug(conf, 'carousel height: ' + opts.height); debug(conf, 'item widths: ' + opts.items.width); debug(conf, 'item heights: ' + opts.items.height); debug(conf, 'number of items visible: ' + opts.items.visible); if (opts.auto.play) { debug(conf, 'number of items scrolled automatically: ' + opts.auto.items); } if (opts.prev.button) { debug(conf, 'number of items scrolled backward: ' + opts.prev.items); } if (opts.next.button) { debug(conf, 'number of items scrolled forward: ' + opts.next.items); } return conf.debug; }); // triggerevent, making prefixed and namespaced events accessible from outside $cfs.bind('_cfs_triggerevent', function(e, n, o) { e.stoppropagation(); return $cfs.triggerhandler(cf_e(n, conf), o); }); }; // /bind_events fn._cfs_unbind_events = function() { $cfs.unbind(cf_e('', conf)); $cfs.unbind(cf_e('', conf, false)); $cfs.unbind('_cfs_triggerevent'); }; // /unbind_events fn._cfs_bind_buttons = function() { fn._cfs_unbind_buttons(); nv_shownavi(opts, itms.total, conf); nv_enablenavi(opts, itms.first, conf); if (opts.auto.pauseonhover) { var pc = bt_pauseonhoverconfig(opts.auto.pauseonhover); $wrp.bind(cf_e('mouseenter', conf, false), function() { $cfs.trigger(cf_e('pause', conf), pc); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } // play button if (opts.auto.button) { opts.auto.button.bind(cf_e(opts.auto.event, conf, false), function(e) { e.preventdefault(); var ev = false, pc = null; if (crsl.ispaused) { ev = 'play'; } else if (opts.auto.pauseonevent) { ev = 'pause'; pc = bt_pauseonhoverconfig(opts.auto.pauseonevent); } if (ev) { $cfs.trigger(cf_e(ev, conf), pc); } }); } // prev button if (opts.prev.button) { opts.prev.button.bind(cf_e(opts.prev.event, conf, false), function(e) { e.preventdefault(); $cfs.trigger(cf_e('prev', conf)); }); if (opts.prev.pauseonhover) { var pc = bt_pauseonhoverconfig(opts.prev.pauseonhover); opts.prev.button.bind(cf_e('mouseenter', conf, false), function() { $cfs.trigger(cf_e('pause', conf), pc); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } } // next butotn if (opts.next.button) { opts.next.button.bind(cf_e(opts.next.event, conf, false), function(e) { e.preventdefault(); $cfs.trigger(cf_e('next', conf)); }); if (opts.next.pauseonhover) { var pc = bt_pauseonhoverconfig(opts.next.pauseonhover); opts.next.button.bind(cf_e('mouseenter', conf, false), function() { $cfs.trigger(cf_e('pause', conf), pc); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } } // pagination if (opts.pagination.container) { if (opts.pagination.pauseonhover) { var pc = bt_pauseonhoverconfig(opts.pagination.pauseonhover); opts.pagination.container.bind(cf_e('mouseenter', conf, false), function() { $cfs.trigger(cf_e('pause', conf), pc); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } } // prev/next keys if (opts.prev.key || opts.next.key) { $(document).bind(cf_e('keyup', conf, false, true, true), function(e) { var k = e.keycode; if (k == opts.next.key) { e.preventdefault(); $cfs.trigger(cf_e('next', conf)); } if (k == opts.prev.key) { e.preventdefault(); $cfs.trigger(cf_e('prev', conf)); } }); } // pagination keys if (opts.pagination.keys) { $(document).bind(cf_e('keyup', conf, false, true, true), function(e) { var k = e.keycode; if (k >= 49 && k < 58) { k = (k-49) * opts.items.visible; if (k <= itms.total) { e.preventdefault(); $cfs.trigger(cf_e('slideto', conf), [k, 0, true, opts.pagination]); } } }); } // swipe if ($.fn.swipe) { var istouch = 'ontouchstart' in window; if ((istouch && opts.swipe.ontouch) || (!istouch && opts.swipe.onmouse)) { var scp = $.extend(true, {}, opts.prev, opts.swipe), scn = $.extend(true, {}, opts.next, opts.swipe), swp = function() { $cfs.trigger(cf_e('prev', conf), [scp]) }, swn = function() { $cfs.trigger(cf_e('next', conf), [scn]) }; switch (opts.direction) { case 'up': case 'down': opts.swipe.options.swipeup = swn; opts.swipe.options.swipedown = swp; break; default: opts.swipe.options.swipeleft = swn; opts.swipe.options.swiperight = swp; } if (crsl.swipe) { $cfs.swipe('destroy'); } $wrp.swipe(opts.swipe.options); $wrp.css('cursor', 'move'); crsl.swipe = true; } } // mousewheel if ($.fn.mousewheel) { if (opts.mousewheel) { var mcp = $.extend(true, {}, opts.prev, opts.mousewheel), mcn = $.extend(true, {}, opts.next, opts.mousewheel); if (crsl.mousewheel) { $wrp.unbind(cf_e('mousewheel', conf, false)); } $wrp.bind(cf_e('mousewheel', conf, false), function(e, delta) { e.preventdefault(); if (delta > 0) { $cfs.trigger(cf_e('prev', conf), [mcp]); } else { $cfs.trigger(cf_e('next', conf), [mcn]); } }); crsl.mousewheel = true; } } if (opts.auto.play) { $cfs.trigger(cf_e('play', conf), opts.auto.delay); } if (crsl.updateonwindowresize) { var resizefn = function(e) { $cfs.trigger(cf_e('finish', conf)); if (opts.auto.pauseonresize && !crsl.ispaused) { $cfs.trigger(cf_e('play', conf)); } sz_resetmargin($cfs.children(), opts); $cfs.trigger(cf_e('updatesizes', conf)); }; var $w = $(window), onresize = null; if ($.debounce && conf.onwindowresize == 'debounce') { onresize = $.debounce(200, resizefn); } else if ($.throttle && conf.onwindowresize == 'throttle') { onresize = $.throttle(300, resizefn); } else { var _windowwidth = 0, _windowheight = 0; onresize = function() { var nw = $w.width(), nh = $w.height(); if (nw != _windowwidth || nh != _windowheight) { resizefn(); _windowwidth = nw; _windowheight = nh; } }; } $w.bind(cf_e('resize', conf, false, true, true), onresize); } }; // /bind_buttons fn._cfs_unbind_buttons = function() { var ns1 = cf_e('', conf), ns2 = cf_e('', conf, false); ns3 = cf_e('', conf, false, true, true); $(document).unbind(ns3); $(window).unbind(ns3); $wrp.unbind(ns2); if (opts.auto.button) { opts.auto.button.unbind(ns2); } if (opts.prev.button) { opts.prev.button.unbind(ns2); } if (opts.next.button) { opts.next.button.unbind(ns2); } if (opts.pagination.container) { opts.pagination.container.unbind(ns2); if (opts.pagination.anchorbuilder) { opts.pagination.container.children().remove(); } } if (crsl.swipe) { $cfs.swipe('destroy'); $wrp.css('cursor', 'default'); crsl.swipe = false; } if (crsl.mousewheel) { crsl.mousewheel = false; } nv_shownavi(opts, 'hide', conf); nv_enablenavi(opts, 'removeclass', conf); }; // /unbind_buttons // start if (is_boolean(configs)) { configs = { 'debug': configs }; } // set vars var crsl = { 'direction' : 'next', 'ispaused' : true, 'isscrolling' : false, 'isstopped' : false, 'mousewheel' : false, 'swipe' : false }, itms = { 'total' : $cfs.children().length, 'first' : 0 }, tmrs = { 'auto' : null, 'progress' : null, 'starttime' : gettime(), 'timepassed' : 0 }, scrl = { 'isstopped' : false, 'duration' : 0, 'starttime' : 0, 'easing' : '', 'anims' : [] }, clbk = { 'onbefore' : [], 'onafter' : [] }, queu = [], conf = $.extend(true, {}, $.fn.caroufredsel.configs, configs), opts = {}, opts_orig = $.extend(true, {}, options), $wrp = (conf.wrapper == 'parent') ? $cfs.parent() : $cfs.wrap('<'+conf.wrapper.element+' class="'+conf.wrapper.classname+'" />').parent(); conf.selector = $cfs.selector; conf.serialnumber = $.fn.caroufredsel.serialnumber++; conf.transition = (conf.transition && $.fn.transition) ? 'transition' : 'animate'; // create carousel fn._cfs_init(opts_orig, true, starting_position); fn._cfs_build(); fn._cfs_bind_events(); fn._cfs_bind_buttons(); // find item to start if (is_array(opts.items.start)) { var start_arr = opts.items.start; } else { var start_arr = []; if (opts.items.start != 0) { start_arr.push(opts.items.start); } } if (opts.cookie) { start_arr.unshift(parseint(cf_getcookie(opts.cookie), 10)); } if (start_arr.length > 0) { for (var a = 0, l = start_arr.length; a < l; a++) { var s = start_arr[a]; if (s == 0) { continue; } if (s === true) { s = window.location.hash; if (s.length < 1) { continue; } } else if (s === 'random') { s = math.floor(math.random()*itms.total); } if ($cfs.triggerhandler(cf_e('slideto', conf), [s, 0, true, { fx: 'none' }])) { break; } } } var siz = sz_setsizes($cfs, opts), itm = gi_getcurrentitems($cfs.children(), opts); if (opts.oncreate) { opts.oncreate.call($tt0, { 'width': siz.width, 'height': siz.height, 'items': itm }); } $cfs.trigger(cf_e('updatepagestatus', conf), [true, siz]); $cfs.trigger(cf_e('linkanchors', conf)); if (conf.debug) { $cfs.trigger(cf_e('debug', conf)); } return $cfs; }; // global public $.fn.caroufredsel.serialnumber = 1; $.fn.caroufredsel.defaults = { 'synchronise' : false, 'infinite' : true, 'circular' : true, 'responsive' : false, 'direction' : 'left', 'items' : { 'start' : 0 }, 'scroll' : { 'easing' : 'swing', 'duration' : 500, 'pauseonhover' : false, 'event' : 'click', 'queue' : false } }; $.fn.caroufredsel.configs = { 'debug' : false, 'transition' : false, 'onwindowresize': 'throttle', 'events' : { 'prefix' : '', 'namespace' : 'cfs' }, 'wrapper' : { 'element' : 'div', 'classname' : 'caroufredsel_wrapper' }, 'classnames' : {} }; $.fn.caroufredsel.pageanchorbuilder = function(nr) { return ''+nr+''; }; $.fn.caroufredsel.progressbarupdater = function(perc) { $(this).css('width', perc+'%'); }; $.fn.caroufredsel.cookie = { get: function(n) { n += '='; var ca = document.cookie.split(';'); for (var a = 0, l = ca.length; a < l; a++) { var c = ca[a]; while (c.charat(0) == ' ') { c = c.slice(1); } if (c.indexof(n) == 0) { return c.slice(n.length); } } return 0; }, set: function(n, v, d) { var e = ""; if (d) { var date = new date(); date.settime(date.gettime() + (d * 24 * 60 * 60 * 1000)); e = "; expires=" + date.togmtstring(); } document.cookie = n + '=' + v + e + '; path=/'; }, remove: function(n) { $.fn.caroufredsel.cookie.set(n, "", -1); } }; // global private // scrolling functions function sc_setscroll(d, e, c) { if (c.transition == 'transition') { if (e == 'swing') { e = 'ease'; } } return { anims: [], duration: d, orgduration: d, easing: e, starttime: gettime() }; } function sc_startscroll(s, c) { for (var a = 0, l = s.anims.length; a < l; a++) { var b = s.anims[a]; if (!b) { continue; } b[0][c.transition](b[1], s.duration, s.easing, b[2]); } } function sc_stopscroll(s, finish) { if (!is_boolean(finish)) { finish = true; } if (is_object(s.pre)) { sc_stopscroll(s.pre, finish); } for (var a = 0, l = s.anims.length; a < l; a++) { var b = s.anims[a]; b[0].stop(true); if (finish) { b[0].css(b[1]); if (is_function(b[2])) { b[2](); } } } if (is_object(s.post)) { sc_stopscroll(s.post, finish); } } function sc_afterscroll( $c, $c2, o ) { if ($c2) { $c2.remove(); } switch(o.fx) { case 'fade': case 'crossfade': case 'cover-fade': case 'uncover-fade': $c.css('filter', ''); $c.css('opacity', 1); break; } } function sc_firecallbacks($t, o, b, a, c) { if (o[b]) { o[b].call($t, a); } if (c[b].length) { for (var i = 0, l = c[b].length; i < l; i++) { c[b][i].call($t, a); } } return []; } function sc_firequeue($c, q, c) { if (q.length) { $c.trigger(cf_e(q[0][0], c), q[0][1]); q.shift(); } return q; } function sc_hidehiddenitems(hiddenitems) { hiddenitems.each(function() { var hi = $(this); hi.data('_cfs_ishidden', hi.is(':hidden')).hide(); }); } function sc_showhiddenitems(hiddenitems) { if (hiddenitems) { hiddenitems.each(function() { var hi = $(this); if (!hi.data('_cfs_ishidden')) { hi.show(); } }); } } function sc_cleartimers(t) { if (t.auto) { cleartimeout(t.auto); } if (t.progress) { clearinterval(t.progress); } return t; } function sc_mapcallbackarguments(i_old, i_skp, i_new, s_itm, s_dir, s_dur, w_siz) { return { 'width': w_siz.width, 'height': w_siz.height, 'items': { 'old': i_old, 'skipped': i_skp, 'visible': i_new }, 'scroll': { 'items': s_itm, 'direction': s_dir, 'duration': s_dur } }; } function sc_getduration( so, o, ni, siz ) { var dur = so.duration; if (so.fx == 'none') { return 0; } if (dur == 'auto') { dur = o.scroll.duration / o.scroll.items * ni; } else if (dur < 10) { dur = siz / dur; } if (dur < 1) { return 0; } if (so.fx == 'fade') { dur = dur / 2; } return math.round(dur); } // navigation functions function nv_shownavi(o, t, c) { var minimum = (is_number(o.items.minimum)) ? o.items.minimum : o.items.visible + 1; if (t == 'show' || t == 'hide') { var f = t; } else if (minimum > t) { debug(c, 'not enough items ('+t+' total, '+minimum+' needed): hiding navigation.'); var f = 'hide'; } else { var f = 'show'; } var s = (f == 'show') ? 'removeclass' : 'addclass', h = cf_c('hidden', c); if (o.auto.button) { o.auto.button[f]()[s](h); } if (o.prev.button) { o.prev.button[f]()[s](h); } if (o.next.button) { o.next.button[f]()[s](h); } if (o.pagination.container) { o.pagination.container[f]()[s](h); } } function nv_enablenavi(o, f, c) { if (o.circular || o.infinite) return; var fx = (f == 'removeclass' || f == 'addclass') ? f : false, di = cf_c('disabled', c); if (o.auto.button && fx) { o.auto.button[fx](di); } if (o.prev.button) { var fn = fx || (f == 0) ? 'addclass' : 'removeclass'; o.prev.button[fn](di); } if (o.next.button) { var fn = fx || (f == o.items.visible) ? 'addclass' : 'removeclass'; o.next.button[fn](di); } } // get object functions function go_getobject($tt, obj) { if (is_function(obj)) { obj = obj.call($tt); } else if (is_undefined(obj)) { obj = {}; } return obj; } function go_getitemsobject($tt, obj) { obj = go_getobject($tt, obj); if (is_number(obj)) { obj = { 'visible': obj }; } else if (obj == 'variable') { obj = { 'visible': obj, 'width': obj, 'height': obj }; } else if (!is_object(obj)) { obj = {}; } return obj; } function go_getscrollobject($tt, obj) { obj = go_getobject($tt, obj); if (is_number(obj)) { if (obj <= 50) { obj = { 'items': obj }; } else { obj = { 'duration': obj }; } } else if (is_string(obj)) { obj = { 'easing': obj }; } else if (!is_object(obj)) { obj = {}; } return obj; } function go_getnaviobject($tt, obj) { obj = go_getobject($tt, obj); if (is_string(obj)) { var temp = cf_getkeycode(obj); if (temp == -1) { obj = $(obj); } else { obj = temp; } } return obj; } function go_getautoobject($tt, obj) { obj = go_getnaviobject($tt, obj); if (is_jquery(obj)) { obj = { 'button': obj }; } else if (is_boolean(obj)) { obj = { 'play': obj }; } else if (is_number(obj)) { obj = { 'timeoutduration': obj }; } if (obj.progress) { if (is_string(obj.progress) || is_jquery(obj.progress)) { obj.progress = { 'bar': obj.progress }; } } return obj; } function go_complementautoobject($tt, obj) { if (is_function(obj.button)) { obj.button = obj.button.call($tt); } if (is_string(obj.button)) { obj.button = $(obj.button); } if (!is_boolean(obj.play)) { obj.play = true; } if (!is_number(obj.delay)) { obj.delay = 0; } if (is_undefined(obj.pauseonevent)) { obj.pauseonevent = true; } if (!is_boolean(obj.pauseonresize)) { obj.pauseonresize = true; } if (!is_number(obj.timeoutduration)) { obj.timeoutduration = (obj.duration < 10) ? 2500 : obj.duration * 5; } if (obj.progress) { if (is_function(obj.progress.bar)) { obj.progress.bar = obj.progress.bar.call($tt); } if (is_string(obj.progress.bar)) { obj.progress.bar = $(obj.progress.bar); } if (obj.progress.bar) { if (!is_function(obj.progress.updater)) { obj.progress.updater = $.fn.caroufredsel.progressbarupdater; } if (!is_number(obj.progress.interval)) { obj.progress.interval = 50; } } else { obj.progress = false; } } return obj; } function go_getprevnextobject($tt, obj) { obj = go_getnaviobject($tt, obj); if (is_jquery(obj)) { obj = { 'button': obj }; } else if (is_number(obj)) { obj = { 'key': obj }; } return obj; } function go_complementprevnextobject($tt, obj) { if (is_function(obj.button)) { obj.button = obj.button.call($tt); } if (is_string(obj.button)) { obj.button = $(obj.button); } if (is_string(obj.key)) { obj.key = cf_getkeycode(obj.key); } return obj; } function go_getpaginationobject($tt, obj) { obj = go_getnaviobject($tt, obj); if (is_jquery(obj)) { obj = { 'container': obj }; } else if (is_boolean(obj)) { obj = { 'keys': obj }; } return obj; } function go_complementpaginationobject($tt, obj) { if (is_function(obj.container)) { obj.container = obj.container.call($tt); } if (is_string(obj.container)) { obj.container = $(obj.container); } if (!is_number(obj.items)) { obj.items = false; } if (!is_boolean(obj.keys)) { obj.keys = false; } if (!is_function(obj.anchorbuilder) && !is_false(obj.anchorbuilder)) { obj.anchorbuilder = $.fn.caroufredsel.pageanchorbuilder; } if (!is_number(obj.deviation)) { obj.deviation = 0; } return obj; } function go_getswipeobject($tt, obj) { if (is_function(obj)) { obj = obj.call($tt); } if (is_undefined(obj)) { obj = { 'ontouch': false }; } if (is_true(obj)) { obj = { 'ontouch': obj }; } else if (is_number(obj)) { obj = { 'items': obj }; } return obj; } function go_complementswipeobject($tt, obj) { if (!is_boolean(obj.ontouch)) { obj.ontouch = true; } if (!is_boolean(obj.onmouse)) { obj.onmouse = false; } if (!is_object(obj.options)) { obj.options = {}; } if (!is_boolean(obj.options.triggerontouchend)) { obj.options.triggerontouchend = false; } return obj; } function go_getmousewheelobject($tt, obj) { if (is_function(obj)) { obj = obj.call($tt); } if (is_true(obj)) { obj = {}; } else if (is_number(obj)) { obj = { 'items': obj }; } else if (is_undefined(obj)) { obj = false; } return obj; } function go_complementmousewheelobject($tt, obj) { return obj; } // get number functions function gn_getitemindex(num, dev, org, items, $cfs) { if (is_string(num)) { num = $(num, $cfs); } if (is_object(num)) { num = $(num, $cfs); } if (is_jquery(num)) { num = $cfs.children().index(num); if (!is_boolean(org)) { org = false; } } else { if (!is_boolean(org)) { org = true; } } if (!is_number(num)) { num = 0; } if (!is_number(dev)) { dev = 0; } if (org) { num += items.first; } num += dev; if (items.total > 0) { while (num >= items.total) { num -= items.total; } while (num < 0) { num += items.total; } } return num; } // items prev function gn_getvisibleitemsprev(i, o, s) { var t = 0, x = 0; for (var a = s; a >= 0; a--) { var j = i.eq(a); t += (j.is(':visible')) ? j[o.d['outerwidth']](true) : 0; if (t > o.maxdimension) { return x; } if (a == 0) { a = i.length; } x++; } } function gn_getvisibleitemsprevfilter(i, o, s) { return gn_getitemsprevfilter(i, o.items.filter, o.items.visibleconf.org, s); } function gn_getscrollitemsprevfilter(i, o, s, m) { return gn_getitemsprevfilter(i, o.items.filter, m, s); } function gn_getitemsprevfilter(i, f, m, s) { var t = 0, x = 0; for (var a = s, l = i.length; a >= 0; a--) { x++; if (x == l) { return x; } var j = i.eq(a); if (j.is(f)) { t++; if (t == m) { return x; } } if (a == 0) { a = l; } } } function gn_getvisibleorg($c, o) { return o.items.visibleconf.org || $c.children().slice(0, o.items.visible).filter(o.items.filter).length; } // items next function gn_getvisibleitemsnext(i, o, s) { var t = 0, x = 0; for (var a = s, l = i.length-1; a <= l; a++) { var j = i.eq(a); t += (j.is(':visible')) ? j[o.d['outerwidth']](true) : 0; if (t > o.maxdimension) { return x; } x++; if (x == l+1) { return x; } if (a == l) { a = -1; } } } function gn_getvisibleitemsnexttestcircular(i, o, s, l) { var v = gn_getvisibleitemsnext(i, o, s); if (!o.circular) { if (s + v > l) { v = l - s; } } return v; } function gn_getvisibleitemsnextfilter(i, o, s) { return gn_getitemsnextfilter(i, o.items.filter, o.items.visibleconf.org, s, o.circular); } function gn_getscrollitemsnextfilter(i, o, s, m) { return gn_getitemsnextfilter(i, o.items.filter, m+1, s, o.circular) - 1; } function gn_getitemsnextfilter(i, f, m, s, c) { var t = 0, x = 0; for (var a = s, l = i.length-1; a <= l; a++) { x++; if (x >= l) { return x; } var j = i.eq(a); if (j.is(f)) { t++; if (t == m) { return x; } } if (a == l) { a = -1; } } } // get items functions function gi_getcurrentitems(i, o) { return i.slice(0, o.items.visible); } function gi_getolditemsprev(i, o, n) { return i.slice(n, o.items.visibleconf.old+n); } function gi_getnewitemsprev(i, o) { return i.slice(0, o.items.visible); } function gi_getolditemsnext(i, o) { return i.slice(0, o.items.visibleconf.old); } function gi_getnewitemsnext(i, o, n) { return i.slice(n, o.items.visible+n); } // sizes functions function sz_storemargin(i, o, d) { if (o.usepadding) { if (!is_string(d)) { d = '_cfs_origcssmargin'; } i.each(function() { var j = $(this), m = parseint(j.css(o.d['marginright']), 10); if (!is_number(m)) { m = 0; } j.data(d, m); }); } } function sz_resetmargin(i, o, m) { if (o.usepadding) { var x = (is_boolean(m)) ? m : false; if (!is_number(m)) { m = 0; } sz_storemargin(i, o, '_cfs_tempcssmargin'); i.each(function() { var j = $(this); j.css(o.d['marginright'], ((x) ? j.data('_cfs_tempcssmargin') : m + j.data('_cfs_origcssmargin'))); }); } } function sz_storeorigcss(i) { i.each(function() { var j = $(this); j.data('_cfs_origcss', j.attr('style') || ''); }); } function sz_restoreorigcss(i) { i.each(function() { var j = $(this); j.attr('style', j.data('_cfs_origcss') || ''); }); } function sz_setresponsivesizes(o, all) { var visb = o.items.visible, news = o.items[o.d['width']], seco = o[o.d['height']], secp = is_percentage(seco); all.each(function() { var $t = $(this), nw = news - ms_getpaddingbordermargin($t, o, 'width'); $t[o.d['width']](nw); if (secp) { $t[o.d['height']](ms_getpercentage(nw, seco)); } }); } function sz_setsizes($c, o) { var $w = $c.parent(), $i = $c.children(), $v = gi_getcurrentitems($i, o), sz = cf_mapwrappersizes(ms_getsizes($v, o, true), o, false); $w.css(sz); if (o.usepadding) { var p = o.padding, r = p[o.d[1]]; if (o.align && r < 0) { r = 0; } var $l = $v.last(); $l.css(o.d['marginright'], $l.data('_cfs_origcssmargin') + r); $c.css(o.d['top'], p[o.d[0]]); $c.css(o.d['left'], p[o.d[3]]); } $c.css(o.d['width'], sz[o.d['width']]+(ms_gettotalsize($i, o, 'width')*2)); $c.css(o.d['height'], ms_getlargestsize($i, o, 'height')); return sz; } // measuring functions function ms_getsizes(i, o, wrapper) { return [ms_gettotalsize(i, o, 'width', wrapper), ms_getlargestsize(i, o, 'height', wrapper)]; } function ms_getlargestsize(i, o, dim, wrapper) { if (!is_boolean(wrapper)) { wrapper = false; } if (is_number(o[o.d[dim]]) && wrapper) { return o[o.d[dim]]; } if (is_number(o.items[o.d[dim]])) { return o.items[o.d[dim]]; } dim = (dim.tolowercase().indexof('width') > -1) ? 'outerwidth' : 'outerheight'; return ms_gettruelargestsize(i, o, dim); } function ms_gettruelargestsize(i, o, dim) { var s = 0; for (var a = 0, l = i.length; a < l; a++) { var j = i.eq(a); var m = (j.is(':visible')) ? j[o.d[dim]](true) : 0; if (s < m) { s = m; } } return s; } function ms_gettotalsize(i, o, dim, wrapper) { if (!is_boolean(wrapper)) { wrapper = false; } if (is_number(o[o.d[dim]]) && wrapper) { return o[o.d[dim]]; } if (is_number(o.items[o.d[dim]])) { return o.items[o.d[dim]] * i.length; } var d = (dim.tolowercase().indexof('width') > -1) ? 'outerwidth' : 'outerheight', s = 0; for (var a = 0, l = i.length; a < l; a++) { var j = i.eq(a); s += (j.is(':visible')) ? j[o.d[d]](true) : 0; } return s; } function ms_getparentsize($w, o, d) { var isvisible = $w.is(':visible'); if (isvisible) { $w.hide(); } var s = $w.parent()[o.d[d]](); if (isvisible) { $w.show(); } return s; } function ms_getmaxdimension(o, a) { return (is_number(o[o.d['width']])) ? o[o.d['width']] : a; } function ms_hasvariablesizes(i, o, dim) { var s = false, v = false; for (var a = 0, l = i.length; a < l; a++) { var j = i.eq(a); var c = (j.is(':visible')) ? j[o.d[dim]](true) : 0; if (s === false) { s = c; } else if (s != c) { v = true; } if (s == 0) { v = true; } } return v; } function ms_getpaddingbordermargin(i, o, d) { return i[o.d['outer'+d]](true) - i[o.d[d.tolowercase()]](); } function ms_getpercentage(s, o) { if (is_percentage(o)) { o = parseint( o.slice(0, -1), 10 ); if (!is_number(o)) { return s; } s *= o/100; } return s; } // config functions function cf_e(n, c, pf, ns, rd) { if (!is_boolean(pf)) { pf = true; } if (!is_boolean(ns)) { ns = true; } if (!is_boolean(rd)) { rd = false; } if (pf) { n = c.events.prefix + n; } if (ns) { n = n +'.'+ c.events.namespace; } if (ns && rd) { n += c.serialnumber; } return n; } function cf_c(n, c) { return (is_string(c.classnames[n])) ? c.classnames[n] : n; } function cf_mapwrappersizes(ws, o, p) { if (!is_boolean(p)) { p = true; } var pad = (o.usepadding && p) ? o.padding : [0, 0, 0, 0]; var wra = {}; wra[o.d['width']] = ws[0] + pad[1] + pad[3]; wra[o.d['height']] = ws[1] + pad[0] + pad[2]; return wra; } function cf_sortparams(vals, typs) { var arr = []; for (var a = 0, l1 = vals.length; a < l1; a++) { for (var b = 0, l2 = typs.length; b < l2; b++) { if (typs[b].indexof(typeof vals[a]) > -1 && is_undefined(arr[b])) { arr[b] = vals[a]; break; } } } return arr; } function cf_getpadding(p) { if (is_undefined(p)) { return [0, 0, 0, 0]; } if (is_number(p)) { return [p, p, p, p]; } if (is_string(p)) { p = p.split('px').join('').split('em').join('').split(' '); } if (!is_array(p)) { return [0, 0, 0, 0]; } for (var i = 0; i < 4; i++) { p[i] = parseint(p[i], 10); } switch (p.length) { case 0: return [0, 0, 0, 0]; case 1: return [p[0], p[0], p[0], p[0]]; case 2: return [p[0], p[1], p[0], p[1]]; case 3: return [p[0], p[1], p[2], p[1]]; default: return [p[0], p[1], p[2], p[3]]; } } function cf_getalignpadding(itm, o) { var x = (is_number(o[o.d['width']])) ? math.ceil(o[o.d['width']] - ms_gettotalsize(itm, o, 'width')) : 0; switch (o.align) { case 'left': return [0, x]; case 'right': return [x, 0]; case 'center': default: return [math.ceil(x/2), math.floor(x/2)]; } } function cf_getdimensions(o) { var dm = [ ['width' , 'innerwidth' , 'outerwidth' , 'height' , 'innerheight' , 'outerheight' , 'left', 'top' , 'marginright' , 0, 1, 2, 3], ['height' , 'innerheight' , 'outerheight' , 'width' , 'innerwidth' , 'outerwidth' , 'top' , 'left', 'marginbottom', 3, 2, 1, 0] ]; var dl = dm[0].length, dx = (o.direction == 'right' || o.direction == 'left') ? 0 : 1; var dimensions = {}; for (var d = 0; d < dl; d++) { dimensions[dm[0][d]] = dm[dx][d]; } return dimensions; } function cf_getadjust(x, o, a, $t) { var v = x; if (is_function(a)) { v = a.call($t, v); } else if (is_string(a)) { var p = a.split('+'), m = a.split('-'); if (m.length > p.length) { var neg = true, sta = m[0], adj = m[1]; } else { var neg = false, sta = p[0], adj = p[1]; } switch(sta) { case 'even': v = (x % 2 == 1) ? x-1 : x; break; case 'odd': v = (x % 2 == 0) ? x-1 : x; break; default: v = x; break; } adj = parseint(adj, 10); if (is_number(adj)) { if (neg) { adj = -adj; } v += adj; } } if (!is_number(v) || v < 1) { v = 1; } return v; } function cf_getitemsadjust(x, o, a, $t) { return cf_getitemadjustminmax(cf_getadjust(x, o, a, $t), o.items.visibleconf); } function cf_getitemadjustminmax(v, i) { if (is_number(i.min) && v < i.min) { v = i.min; } if (is_number(i.max) && v > i.max) { v = i.max; } if (v < 1) { v = 1; } return v; } function cf_getsyncharr(s) { if (!is_array(s)) { s = [[s]]; } if (!is_array(s[0])) { s = [s]; } for (var j = 0, l = s.length; j < l; j++) { if (is_string(s[j][0])) { s[j][0] = $(s[j][0]); } if (!is_boolean(s[j][1])) { s[j][1] = true; } if (!is_boolean(s[j][2])) { s[j][2] = true; } if (!is_number(s[j][3])) { s[j][3] = 0; } } return s; } function cf_getkeycode(k) { if (k == 'right') { return 39; } if (k == 'left') { return 37; } if (k == 'up') { return 38; } if (k == 'down') { return 40; } return -1; } function cf_setcookie(n, $c, c) { if (n) { var v = $c.triggerhandler(cf_e('currentposition', c)); $.fn.caroufredsel.cookie.set(n, v); } } function cf_getcookie(n) { var c = $.fn.caroufredsel.cookie.get(n); return (c == '') ? 0 : c; } // init function function in_mapcss($elem, props) { var css = {}; for (var p = 0, l = props.length; p < l; p++) { css[props[p]] = $elem.css(props[p]); } return css; } function in_complementitems(obj, opt, itm, sta) { if (!is_object(obj.visibleconf)) { obj.visibleconf = {}; } if (!is_object(obj.sizesconf)) { obj.sizesconf = {}; } if (obj.start == 0 && is_number(sta)) { obj.start = sta; } // visible items if (is_object(obj.visible)) { obj.visibleconf.min = obj.visible.min; obj.visibleconf.max = obj.visible.max; obj.visible = false; } else if (is_string(obj.visible)) { // variable visible items if (obj.visible == 'variable') { obj.visibleconf.variable = true; } // adjust string visible items else { obj.visibleconf.adjust = obj.visible; } obj.visible = false; } else if (is_function(obj.visible)) { obj.visibleconf.adjust = obj.visible; obj.visible = false; } // set items filter if (!is_string(obj.filter)) { obj.filter = (itm.filter(':hidden').length > 0) ? ':visible' : '*'; } // primary item-size not set if (!obj[opt.d['width']]) { // responsive carousel -> set to largest if (opt.responsive) { debug(true, 'set a '+opt.d['width']+' for the items!'); obj[opt.d['width']] = ms_gettruelargestsize(itm, opt, 'outerwidth'); } // non-responsive -> measure it or set to "variable" else { obj[opt.d['width']] = (ms_hasvariablesizes(itm, opt, 'outerwidth')) ? 'variable' : itm[opt.d['outerwidth']](true); } } // secondary item-size not set -> measure it or set to "variable" if (!obj[opt.d['height']]) { obj[opt.d['height']] = (ms_hasvariablesizes(itm, opt, 'outerheight')) ? 'variable' : itm[opt.d['outerheight']](true); } obj.sizesconf.width = obj.width; obj.sizesconf.height = obj.height; return obj; } function in_complementvisibleitems(opt, avl) { // primary item-size variable -> set visible items variable if (opt.items[opt.d['width']] == 'variable') { opt.items.visibleconf.variable = true; } if (!opt.items.visibleconf.variable) { // primary size is number -> calculate visible-items if (is_number(opt[opt.d['width']])) { opt.items.visible = math.floor(opt[opt.d['width']] / opt.items[opt.d['width']]); } // measure and calculate primary size and visible-items else { opt.items.visible = math.floor(avl / opt.items[opt.d['width']]); opt[opt.d['width']] = opt.items.visible * opt.items[opt.d['width']]; if (!opt.items.visibleconf.adjust) { opt.align = false; } } if (opt.items.visible == 'infinity' || opt.items.visible < 1) { debug(true, 'not a valid number of visible items: set to "variable".'); opt.items.visibleconf.variable = true; } } return opt; } function in_complementprimarysize(obj, opt, all) { // primary size set to auto -> measure largest item-size and set it if (obj == 'auto') { obj = ms_gettruelargestsize(all, opt, 'outerwidth'); } return obj; } function in_complementsecondarysize(obj, opt, all) { // secondary size set to auto -> measure largest item-size and set it if (obj == 'auto') { obj = ms_gettruelargestsize(all, opt, 'outerheight'); } // secondary size not set -> set to secondary item-size if (!obj) { obj = opt.items[opt.d['height']]; } return obj; } function in_getalignpadding(o, all) { var p = cf_getalignpadding(gi_getcurrentitems(all, o), o); o.padding[o.d[1]] = p[1]; o.padding[o.d[3]] = p[0]; return o; } function in_getresponsivevalues(o, all, avl) { var visb = cf_getitemadjustminmax(math.ceil(o[o.d['width']] / o.items[o.d['width']]), o.items.visibleconf); if (visb > all.length) { visb = all.length; } var news = math.floor(o[o.d['width']]/visb); o.items.visible = visb; o.items[o.d['width']] = news; o[o.d['width']] = visb * news; return o; } // buttons functions function bt_pauseonhoverconfig(p) { if (is_string(p)) { var i = (p.indexof('immediate') > -1) ? true : false, r = (p.indexof('resume') > -1) ? true : false; } else { var i = r = false; } return [i, r]; } function bt_mousesheelnumber(mw) { return (is_number(mw)) ? mw : null } // helper functions function is_null(a) { return (a === null); } function is_undefined(a) { return (is_null(a) || typeof a == 'undefined' || a === '' || a === 'undefined'); } function is_array(a) { return (a instanceof array); } function is_jquery(a) { return (a instanceof jquery); } function is_object(a) { return ((a instanceof object || typeof a == 'object') && !is_null(a) && !is_jquery(a) && !is_array(a)); } function is_number(a) { return ((a instanceof number || typeof a == 'number') && !isnan(a)); } function is_string(a) { return ((a instanceof string || typeof a == 'string') && !is_undefined(a) && !is_true(a) && !is_false(a)); } function is_function(a) { return (a instanceof function || typeof a == 'function'); } function is_boolean(a) { return (a instanceof boolean || typeof a == 'boolean' || is_true(a) || is_false(a)); } function is_true(a) { return (a === true || a === 'true'); } function is_false(a) { return (a === false || a === 'false'); } function is_percentage(x) { return (is_string(x) && x.slice(-1) == '%'); } function gettime() { return new date().gettime(); } function deprecated( o, n ) { debug(true, o+' is deprecated, support for it will be removed. use '+n+' instead.'); } function debug(d, m) { if (!is_undefined(window.console) && !is_undefined(window.console.log)) { if (is_object(d)) { var s = ' ('+d.selector+')'; d = d.debug; } else { var s = ''; } if (!d) { return false; } if (is_string(m)) { m = 'caroufredsel'+s+': ' + m; } else { m = ['caroufredsel'+s+':', m]; } window.console.log(m); } return false; } // easing functions $.extend($.easing, { 'quadratic': function(t) { var t2 = t * t; return t * (-t2 * t + 4 * t2 - 6 * t + 4); }, 'cubic': function(t) { return t * (4 * t * t - 9 * t + 6); }, 'elastic': function(t) { var t2 = t * t; return t * (33 * t2 * t2 - 106 * t2 * t + 126 * t2 - 67 * t + 15); } }); })(jquery);