/* * jquery caroufredsel 5.2.3 * demo's and documentation: * caroufredsel.frebsite.nl * * copyright (c) 2011 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 = function(options, configs) { if (this.length == 0) { debug(true, 'no element found for "'+this.selector+'".'); return this; } if (this.length > 1) { return this.each(function() { $(this).caroufredsel(options, configs); }); } var $cfs = this, $tt0 = this[0]; if ($cfs.data('cfs_iscarousel')) { var starting_position = $cfs.triggerhandler('_cfs_currentposition'); $cfs.trigger('_cfs_destroy', true); } else { var starting_position = false; } $cfs._cfs_init = function(o, setorig, start) { o = go_getobject($tt0, o); // deprecated if (o.debug) { conf.debug = o.debug; debug(conf, 'the "debug" option should be moved to the second configuration-object.'); } // /deprecated var obs = ['items', 'scroll', 'auto', 'prev', 'next', 'pagination']; for (var a = 0, l = obs.length; a < l; a++) { o[obs[a]] = go_getobject($tt0, o[obs[a]]); } if (typeof o.scroll == 'number') { if (o.scroll <= 50) o.scroll = { 'items' : o.scroll }; else o.scroll = { 'duration' : o.scroll }; } else { if (typeof o.scroll == 'string') o.scroll = { 'easing' : o.scroll }; } if (typeof o.items == 'number') o.items = { 'visible' : o.items }; else if ( o.items == 'variable') o.items = { 'visible' : o.items, 'width' : o.items, 'height' : o.items }; if (typeof o.items != 'object') o.items = {}; if (setorig) opts_orig = $.extend(true, {}, $.fn.caroufredsel.defaults, o); opts = $.extend(true, {}, $.fn.caroufredsel.defaults, o); if (typeof opts.items.visibleconf != 'object') opts.items.visibleconf = {}; if (opts.items.start == 0 && typeof start == 'number') { opts.items.start = start; } crsl.direction = (opts.direction == 'up' || opts.direction == 'left') ? 'next' : 'prev'; var dims = [ ['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 dn = dims[0].length, dx = (opts.direction == 'right' || opts.direction == 'left') ? 0 : 1; opts.d = {}; for (var d = 0; d < dn; d++) { opts.d[dims[0][d]] = dims[dx][d]; } var all_itm = $cfs.children(); // primairy size set to auto -> measure largest size and set it if (opts[opts.d['width']] == 'auto') { var lrgst = ms_gettruelargestsize(all_itm, opts, 'outerwidth'); opts[opts.d['width']] = lrgst; } // secondairy size set to auto -> measure largest size and set it if (opts[opts.d['height']] == 'auto') { var lrgst = ms_gettruelargestsize(all_itm, opts, 'outerheight'); opts[opts.d['height']] = lrgst; } // primairy item-size not set -> measure it or set to "variable" if (!opts.items[opts.d['width']]) { opts.items[opts.d['width']] = (ms_hasvariablesizes(all_itm, opts, 'outerwidth')) ? 'variable' : all_itm[opts.d['outerwidth']](true); } // secondairy item-size not set -> measure it or set to "variable" if (!opts.items[opts.d['height']]) { opts.items[opts.d['height']] = (ms_hasvariablesizes(all_itm, opts, 'outerheight')) ? 'variable' : all_itm[opts.d['outerheight']](true); } // secondairy size not set -> set to secondairy item-size if (!opts[opts.d['height']]) { opts[opts.d['height']] = opts.items[opts.d['height']]; } // min and max visible items if (typeof opts.items.visible == 'object') { opts.items.visibleconf.min = opts.items.visible.min; opts.items.visibleconf.max = opts.items.visible.max; opts.items.visible = false; } // adjusting visible items if (typeof opts.items.visible == 'string' || typeof opts.items.visible == 'function') { opts.items.visibleconf.adjust = opts.items.visible; opts.items.visible = false; } // visible-items not set if (!opts.items.visible) { // primairy item-size variable -> set visible items variable if (opts.items[opts.d['width']] == 'variable') { opts.items.visibleconf.variable = true; } if (!opts.items.visibleconf.variable) { // primairy size is number -> calculate visible-items if (typeof opts[opts.d['width']] == 'number') { opts.items.visible = math.floor(opts[opts.d['width']] / opts.items[opts.d['width']]); } else { // measure and calculate primairy size and visible-items var maxs = ms_gettrueinnersize($wrp.parent(), opts, 'innerwidth'); opts.items.visible = math.floor(maxs / opts.items[opts.d['width']]); opts[opts.d['width']] = opts.items.visible * opts.items[opts.d['width']]; if (!opts.items.visibleconf.adjust) opts.align = false; } if (opts.items.visible == 'infinity' || opts.items.visible < 1) { debug(true, 'not a valid number of visible items: set to "variable".'); opts.items.visibleconf.variable = true; } } } // primairy size not set -> calculate it or set to "variable" if (!opts[opts.d['width']]) { if (!opts.items.visibleconf.variable && opts.items[opts.d['width']] != 'variable') { opts[opts.d['width']] = opts.items.visible * opts.items[opts.d['width']]; opts.align = false; } else { opts[opts.d['width']] = 'variable'; } } // variable primairy item-sizes with variabe visible-items if (opts.items.visibleconf.variable) { opts.maxdimention = (opts[opts.d['width']] == 'variable') ? ms_gettrueinnersize($wrp.parent(), opts, 'innerwidth') : opts[opts.d['width']]; if (opts.align === false) { opts[opts.d['width']] = 'variable'; } opts.items.visible = gn_getvisibleitemsnext(all_itm, opts, 0); if (opts.items.visible > itms.total) { opts.items.visible = itms.total; } } if (typeof opts.padding == 'undefined') { opts.padding = 0; } // align not set -> set to center if primairy size is number if (typeof opts.align == 'undefined') { opts.align = (opts[opts.d['width']] == 'variable') ? false : 'center'; } opts.items.visible = cf_getitemsadjust(opts.items.visible, opts, opts.items.visibleconf.adjust, $tt0); opts.items.visibleconf.old = opts.items.visible; opts.usepadding = false; opts.padding = cf_getpadding(opts.padding); if (opts.align == 'top') opts.align = 'left'; 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') { var p = cf_getalignpadding(gi_getcurrentitems(all_itm, opts), opts); opts.usepadding = true; opts.padding[opts.d[1]] = p[1]; opts.padding[opts.d[3]] = p[0]; } 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 (typeof opts.cookie == 'boolean' && opts.cookie) opts.cookie = 'caroufredsel_cookie_'+$cfs.attr('id'); if (typeof opts.items.minimum != 'number') opts.items.minimum = opts.items.visible; if (typeof opts.scroll.duration != 'number') opts.scroll.duration = 500; if (typeof opts.scroll.items == 'undefined') opts.scroll.items = (opts.items.visibleconf.variable) ? 'variable' : opts.items.visible; opts.auto = go_getnaviobject($tt0, opts.auto, 'auto'); opts.prev = go_getnaviobject($tt0, opts.prev); opts.next = go_getnaviobject($tt0, opts.next); opts.pagination = go_getnaviobject($tt0, opts.pagination, 'pagination'); 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); if (typeof opts.pagination.keys != 'boolean') opts.pagination.keys = false; if (typeof opts.pagination.anchorbuilder != 'function') opts.pagination.anchorbuilder = $.fn.caroufredsel.pageanchorbuilder; if (typeof opts.auto.play != 'boolean') opts.auto.play = true; if (typeof opts.auto.delay != 'number') opts.auto.delay = 0; if (typeof opts.auto.pauseduration != 'number') opts.auto.pauseduration = (opts.auto.duration < 10) ? 2500 : opts.auto.duration * 5; if (opts.synchronise) { opts.synchronise = cf_getsyncharr(opts.synchronise); } if (conf.debug) { debug(conf, 'carousel width: '+opts.width); debug(conf, 'carousel height: '+opts.height); if (opts.maxdimention) debug(conf, 'available '+opts.d['width']+': '+opts.maxdimention); 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); } }; // /init $cfs._cfs_build = function() { $cfs.data('cfs_iscarousel', true); if ($cfs.css('position') == 'absolute' || $cfs.css('position') == 'fixed') { debug(conf, 'carousels css-attribute "position" should be "static" or "relative".'); } var orgcss = { 'float' : $cfs.css('float'), 'position' : $cfs.css('position'), 'top' : $cfs.css('top'), 'right' : $cfs.css('right'), 'bottom' : $cfs.css('bottom'), 'left' : $cfs.css('left'), 'width' : $cfs.css('width'), 'height' : $cfs.css('height'), 'margintop' : $cfs.css('margintop'), 'marginright' : $cfs.css('marginright'), 'marginbottom' : $cfs.css('marginbottom'), 'marginleft' : $cfs.css('marginleft') }; $wrp.css(orgcss).css({ 'overflow' : 'hidden', 'position' : (orgcss.position == 'absolute') ? 'absolute' : 'relative' }); $cfs.data('cfs_origcss', orgcss).css({ 'float' : 'none', 'position' : 'absolute', 'top' : 0, 'left' : 0, 'margintop' : 0, 'marginright' : 0, 'marginbottom' : 0, 'marginleft' : 0 }); if (opts.usepadding) { $cfs.children().each(function() { var m = parseint($(this).css(opts.d['marginright'])); if (isnan(m)) m = 0; $(this).data('cfs_origcssmargin', m); }); } }; // /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.onpausepause) { var dur1 = opts.auto.pauseduration - tmrs.timepassed, perc = 100 - math.ceil( dur1 * 100 / opts.auto.pauseduration ); opts.auto.onpausepause.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); var dir = a[0], del = a[1], res = a[2]; if (dir != 'prev' && dir != 'next') dir = crsl.direction; if (typeof del != 'number') del = 0; if (typeof res != 'boolean') 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.pauseduration + del; dur2 = dur1 - tmrs.timepassed; perc = 100 - math.ceil(dur2 * 100 / dur1); tmrs.auto = settimeout(function() { if (opts.auto.onpauseend) { opts.auto.onpauseend.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.onpausestart) { opts.auto.onpausestart.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) { 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 if (opts.items.minimum >= itms.total) { e.stopimmediatepropagation(); return debug(conf, 'not enough items ('+itms.total+', '+opts.items.minimum+' needed): not scrolling.'); } // get config var v = [obj, num, clb], t = ['object', 'number/string', 'function'], a = cf_sortparams(v, t); var obj = a[0], num = a[1], clb = a[2]; var etype = e.type.substr(conf.events.prefix.length); if (typeof obj != 'object' || obj == null) obj = opts[etype]; if (typeof clb == 'function') obj.onafter = clb; if (typeof num != 'number') { var arr = [num, obj.items, opts[etype].items]; for (var a = 0, l = arr.length; a < l; a++) { if (typeof arr[a] == 'number' || arr[a] == 'page' || arr[a] == 'visible') { num = arr[a]; break; } } switch(num) { case 'page': e.stopimmediatepropagation(); return $cfs.triggerhandler(etype+'page', [obj, clb]); break; case 'visible': if (!opts.items.visibleconf.variable) { 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) $cfs.trigger(cf_e('queue', conf), [etype, [obj, num, clb]]); e.stopimmediatepropagation(); return debug(conf, 'carousel currently scrolling.'); } } // test conditions callback if (obj.conditions && !obj.conditions.call($tt0)) { e.stopimmediatepropagation(); return debug(conf, 'callback "conditions" returned false.'); } tmrs.timepassed = 0; $cfs.trigger('_cfs_slide_'+etype, [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][1]) c[0] = s[j][0].triggerhandler('_cfs_configuration', etype); if (!s[j][2]) d = (d == 'prev') ? 'next' : 'prev'; c[1] = num + s[j][3]; s[j][0].trigger('_cfs_slide_'+d, c); } } return true; }); // prev event, accessible from outside $cfs.bind(cf_e('_cfs_slide_prev', conf, false), 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(); } } if (opts.usepadding) sz_resetmargin(a_itm, opts); // find number of items to scroll if (typeof ni != 'number') { if (opts.items.visibleconf.variable) { ni = gn_getvisibleitemsprev(a_itm, opts, itms.total-1); } 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 if (opts.items.visibleconf.variable) { var vi = gn_getvisibleitemsnext(a_itm, opts, itms.total-ni); if (opts.items.visible+ni <= vi && ni < itms.total) { ni++; vi = gn_getvisibleitemsnext(a_itm, opts, itms.total-ni); } opts.items.visibleconf.old = opts.items.visible; opts.items.visible = cf_getitemsadjust(vi, opts, opts.items.visibleconf.adjust, $tt0); } if (opts.usepadding) 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); 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(), c_old = gi_getolditemsprev(a_itm, opts, ni), c_new = gi_getnewitemsprev(a_itm, opts), l_cur = a_itm.eq(ni-1), l_old = c_old.last(), l_new = c_new.last(); if (opts.usepadding) sz_resetmargin(a_itm, opts); if (opts.align) { var p = cf_getalignpadding(c_new, opts), pl = p[0], pr = p[1]; } else { var pl = 0, pr = 0; } var ol = (pl < 0) ? opts.padding[opts.d[3]] : 0; // hide items for fx directscroll if (so.fx == 'directscroll' && opts.items.visible < ni) { var hiddenitems = a_itm.slice(opts.items.visibleconf.old, ni).hide(), orgw = opts.items[opts.d['width']]; opts.items[opts.d['width']] = 'variable'; } else { var hiddenitems = false; } // save new sizes var i_siz = ms_gettotalsize(a_itm.slice(0, ni), opts, 'width'), w_siz = cf_mapwrappersizes(ms_getsizes(c_new, opts, true), opts, !opts.usepadding); if (hiddenitems) opts.items[opts.d['width']] = orgw; if (opts.usepadding) { sz_resetmargin(a_itm, opts, true); if (pr >= 0) { sz_resetmargin(l_old, opts, opts.padding[opts.d[1]]); } sz_resetmargin(l_cur, opts, opts.padding[opts.d[3]]); } if (opts.align) { opts.padding[opts.d[1]] = pr; opts.padding[opts.d[3]] = pl; } // animation configuration var a_cfs = {}, a_dur = so.duration; if (so.fx == 'none') a_dur = 0; else if (a_dur == 'auto') a_dur = opts.scroll.duration / opts.scroll.items * ni; else if (a_dur <= 0) a_dur = 0; else if (a_dur < 10) a_dur = i_siz / a_dur; scrl = sc_setscroll(a_dur, so.easing); // animate wrapper if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable') { scrl.anims.push([$wrp, w_siz]); } // animate items if (opts.usepadding) { var new_m = opts.padding[opts.d[3]]; if (l_new.not(l_cur).length) { var a_cur = {}; a_cur[opts.d['marginright']] = l_cur.data('cfs_origcssmargin'); if (pl < 0) l_cur.css(a_cur); else scrl.anims.push([l_cur, a_cur]); } if (l_new.not(l_old).length) { var a_old = {}; a_old[opts.d['marginright']] = l_old.data('cfs_origcssmargin'); scrl.anims.push([l_old, a_old]); } if (pr >= 0) { var a_new = {}; a_new[opts.d['marginright']] = l_new.data('cfs_origcssmargin') + opts.padding[opts.d[1]]; scrl.anims.push([l_new, a_new]); } } else { var new_m = 0; } // animate carousel a_cfs[opts.d['left']] = new_m; // onbefore callback var args = [c_old, c_new, w_siz, a_dur]; if (so.onbefore) so.onbefore.apply($tt0, args); clbk.onbefore = sc_callcallbacks(clbk.onbefore, $tt0, args); // alternative effects // extra animation arrays switch(so.fx) { case 'fade': case 'crossfade': case 'cover': case 'uncover': scrl.pre = sc_setscroll(scrl.duration, scrl.easing); scrl.post = sc_setscroll(scrl.duration, scrl.easing); scrl.duration = 0; break; } // create copy switch(so.fx) { case 'crossfade': case 'cover': case 'uncover': var $cf2 = $cfs.clone().appendto($wrp); break; } switch(so.fx) { case 'uncover': $cf2.children().slice(0, ni).remove(); case 'crossfade': case 'cover': $cf2.children().slice(opts.items.visible).remove(); break; } // animations switch(so.fx) { case 'fade': scrl.pre.anims.push([$cfs, { 'opacity': 0 }]); break; case 'crossfade': $cf2.css({ 'opacity': 0 }); scrl.pre.anims.push([$cfs, { 'width': '+=0' }, function() { $cf2.remove(); }]); scrl.post.anims.push([$cf2, { 'opacity': 1 }]); break; case 'cover': scrl = fx_cover(scrl, $cfs, $cf2, opts, true); break; case 'uncover': scrl = fx_uncover(scrl, $cfs, $cf2, opts, true, ni); break; } // /alternative effects // complete callback var a_complete = function() { var overfill = opts.items.visible+ni-itms.total; if (overfill > 0) { $cfs.children().slice(itms.total).remove(); c_old = $cfs.children().slice(itms.total-(ni-overfill)).get().concat( $cfs.children().slice(0, overfill).get() ); } if (hiddenitems) hiddenitems.show(); 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')); } scrl.anims = []; if (scrl.pre) scrl.pre = sc_setscroll(scrl.orgduration, scrl.easing); var fn = function() { switch(so.fx) { case 'fade': case 'crossfade': $cfs.css('filter', ''); break; } scrl.post = sc_setscroll(0, null); crsl.isscrolling = false; var args = [c_old, c_new, w_siz]; if (so.onafter) so.onafter.apply($tt0, args); clbk.onafter = sc_callcallbacks(clbk.onafter, $tt0, args); if (queu.length) { $cfs.trigger(cf_e(queu[0][0], conf), queu[0][1]); queu.shift(); } if (!crsl.ispaused) $cfs.trigger(cf_e('play', conf)); }; switch(so.fx) { case 'fade': scrl.pre.anims.push([$cfs, { 'opacity': 1 }, fn]); sc_startscroll(scrl.pre); break; case 'uncover': scrl.pre.anims.push([$cfs, { 'width': '+=0' }, fn]); sc_startscroll(scrl.pre); break; default: fn(); break; } }; scrl.anims.push([$cfs, a_cfs, a_complete]); crsl.isscrolling = true; $cfs.css(opts.d['left'], -(i_siz-ol)); tmrs = sc_cleartimers(tmrs); sc_startscroll(scrl); cf_setcookie(opts.cookie, $cfs.triggerhandler(cf_e('currentposition', conf))); $cfs.trigger(cf_e('updatepagestatus', conf), [false, w_siz]); return true; }); // next event, accessible from outside $cfs.bind(cf_e('_cfs_slide_next', conf, false), 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(); } } if (opts.usepadding) sz_resetmargin(a_itm, opts); // find number of items to scroll if (typeof ni != 'number') { 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 if (opts.items.visibleconf.variable) { var vi = gn_getvisibleitemsnexttestcircular(a_itm, opts, ni, lastitemnr); while (opts.items.visible-ni >= vi && ni < itms.total) { ni++; vi = gn_getvisibleitemsnexttestcircular(a_itm, opts, ni, lastitemnr); } opts.items.visibleconf.old = opts.items.visible; opts.items.visible = cf_getitemsadjust(vi, opts, opts.items.visibleconf.adjust, $tt0); } if (opts.usepadding) 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); 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(), c_old = gi_getolditemsnext(a_itm, opts), c_new = gi_getnewitemsnext(a_itm, opts, ni), l_cur = a_itm.eq(ni-1), l_old = c_old.last(), l_new = c_new.last(); if (opts.usepadding) sz_resetmargin(a_itm, opts); if (opts.align) { var p = cf_getalignpadding(c_new, opts), pl = p[0], pr = p[1]; } else { var pl = 0, pr = 0; } // hide items for fx directscroll if (so.fx == 'directscroll' && opts.items.visibleconf.old < ni) { var hiddenitems = a_itm.slice(opts.items.visibleconf.old, ni).hide(), orgw = opts.items[opts.d['width']]; opts.items[opts.d['width']] = 'variable'; } else { var hiddenitems = false; } // save new sizes var i_siz = ms_gettotalsize(a_itm.slice(0, ni), opts, 'width'), w_siz = cf_mapwrappersizes(ms_getsizes(c_new, opts, true), opts, !opts.usepadding); if (hiddenitems) opts.items[opts.d['width']] = orgw; if (opts.align) { if (opts.padding[opts.d[1]] < 0) { opts.padding[opts.d[1]] = 0; } } if (opts.usepadding) { sz_resetmargin(a_itm, opts, true); sz_resetmargin(l_old, opts, opts.padding[opts.d[1]]); } if (opts.align) { opts.padding[opts.d[1]] = pr; opts.padding[opts.d[3]] = pl; } // animation configuration var a_cfs = {}, a_dur = so.duration; if (so.fx == 'none') a_dur = 0; else if (a_dur == 'auto') a_dur = opts.scroll.duration / opts.scroll.items * ni; else if (a_dur <= 0) a_dur = 0; else if (a_dur < 10) a_dur = i_siz / a_dur; scrl = sc_setscroll(a_dur, so.easing); // animate wrapper if (opts[opts.d['width']] == 'variable' || opts[opts.d['height']] == 'variable') { scrl.anims.push([$wrp, w_siz]); } // animate items if (opts.usepadding) { var l_new_m = l_new.data('cfs_origcssmargin'); if (pr >= 0) { l_new_m += opts.padding[opts.d[1]]; } l_new.css(opts.d['marginright'], l_new_m); if (l_cur.not(l_old).length) { var a_old = {}; a_old[opts.d['marginright']] = l_old.data('cfs_origcssmargin'); scrl.anims.push([l_old, a_old]); } var c_new_m = l_cur.data('cfs_origcssmargin'); if (pl >= 0) { c_new_m += opts.padding[opts.d[3]]; } var a_cur = {}; a_cur[opts.d['marginright']] = c_new_m; scrl.anims.push([l_cur, a_cur]); } // animate carousel a_cfs[opts.d['left']] = -i_siz; if (pl < 0) { a_cfs[opts.d['left']] += pl; } // onbefore callback var args = [c_old, c_new, w_siz, a_dur]; if (so.onbefore) so.onbefore.apply($tt0, args); clbk.onbefore = sc_callcallbacks(clbk.onbefore, $tt0, args); // alternative effects // extra animation arrays switch(so.fx) { case 'fade': case 'crossfade': case 'cover': case 'uncover': scrl.pre = sc_setscroll(scrl.duration, scrl.easing); scrl.post = sc_setscroll(scrl.duration, scrl.easing); scrl.duration = 0; break; } // create copy switch(so.fx) { case 'crossfade': case 'cover': case 'uncover': var $cf2 = $cfs.clone().appendto($wrp); break; } switch(so.fx) { case 'uncover': $cf2.children().slice(opts.items.visibleconf.old).remove(); break; case 'crossfade': case 'cover': $cf2.children().slice(0, ni).remove(); $cf2.children().slice(opts.items.visible).remove(); break; } // animations switch(so.fx) { case 'fade': scrl.pre.anims.push([$cfs, { 'opacity': 0 }]); break; case 'crossfade': $cf2.css({ 'opacity': 0 }); scrl.pre.anims.push([$cfs, { 'width': '+=0' }, function() { $cf2.remove(); }]); scrl.post.anims.push([$cf2, { 'opacity': 1 }]); break; case 'cover': scrl = fx_cover(scrl, $cfs, $cf2, opts, false); break; case 'uncover': scrl = fx_uncover(scrl, $cfs, $cf2, opts, false, ni); break; } // /alternative effects // complete callback var a_complete = function() { var overfill = opts.items.visible+ni-itms.total, new_m = (opts.usepadding) ? opts.padding[opts.d[3]] : 0; $cfs.css(opts.d['left'], new_m); if (overfill > 0) { $cfs.children().slice(itms.total).remove(); } var l_itm = $cfs.children().slice(0, ni).appendto($cfs).last(); if (overfill > 0) { c_new = gi_getcurrentitems(a_itm, opts); } if (hiddenitems) hiddenitems.show(); if (opts.usepadding) { if (itms.total < opts.items.visible+ni) { var l_cur = $cfs.children().eq(opts.items.visible-1); l_cur.css(opts.d['marginright'], l_cur.data('cfs_origcssmargin') + opts.padding[opts.d[3]]); } l_itm.css(opts.d['marginright'], l_itm.data('cfs_origcssmargin')); } scrl.anims = []; if (scrl.pre) scrl.pre = sc_setscroll(scrl.orgduration, scrl.easing); var fn = function() { switch(so.fx) { case 'fade': case 'crossfade': $cfs.css('filter', ''); break; } scrl.post = sc_setscroll(0, null); crsl.isscrolling = false; var args = [c_old, c_new, w_siz]; if (so.onafter) so.onafter.apply($tt0, args); clbk.onafter = sc_callcallbacks(clbk.onafter, $tt0, args); if (queu.length) { $cfs.trigger(cf_e(queu[0][0], conf), queu[0][1]); queu.shift(); } if (!crsl.ispaused) $cfs.trigger(cf_e('play', conf)); }; switch(so.fx) { case 'fade': scrl.pre.anims.push([$cfs, { 'opacity': 1 }, fn]); sc_startscroll(scrl.pre); break; case 'uncover': scrl.pre.anims.push([$cfs, { 'width': '+=0' }, fn]); sc_startscroll(scrl.pre); break; default: fn(); break; } }; scrl.anims.push([$cfs, a_cfs, a_complete]); crsl.isscrolling = true; tmrs = sc_cleartimers(tmrs); sc_startscroll(scrl); cf_setcookie(opts.cookie, $cfs.triggerhandler(cf_e('currentposition', 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); var obj = a[3], dir = a[4], clb = a[5]; num = gn_getitemindex(a[0], a[1], a[2], itms, $cfs); if (num == 0) return; if (typeof obj != 'object') obj = false; if (crsl.isscrolling) { if (typeof obj != 'object' || obj.duration > 0) return false; } if (dir != 'prev' && dir != 'next') { if (opts.circular) { if (num <= itms.total / 2) dir = 'next'; else dir = 'prev'; } else { if (itms.first == 0 || itms.first > num) dir = 'next'; else dir = '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 (typeof pag != 'number') pag = $cfs.triggerhandler(cf_e('currentpage', conf)); var ipp = opts.pagination.items || opts.items.visible, max = math.floor(itms.total / ipp); 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) { 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 (typeof dir == 'function') { dir.call($tt0, queu); } else if (is_array(dir)) { queu = dir; } else if (typeof dir != 'undefined') { 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); var itm = a[0], num = a[1], org = a[2], dev = a[3]; if (typeof itm == 'object' && typeof itm.jquery == 'undefined') itm = $(itm); if (typeof itm == 'string') itm = $(itm); if (typeof itm != 'object' || typeof itm.jquery == 'undefined' || itm.length == 0) return debug(conf, 'not a valid object.'); if (typeof num == 'undefined') num = 'end'; if (opts.usepadding) { itm.each(function() { var m = parseint($(this).css(opts.d['marginright'])); if (isnan(m)) m = 0; $(this).data('cfs_origcssmargin', m); }); } 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); } if (orgnum != 'end' && !org) { if (num < itms.first) itms.first += itm.length; } if (itms.first >= itms.total) itms.first -= itms.total; var $cit = $cfs.children().eq(num); if ($cit.length) { $cit[before](itm); } else { $cfs.append(itm); } itms.total = $cfs.children().length; var sz = sz_setsizes($cfs, opts); nv_shownavi(opts, itms.total, conf); nv_enablenavi(opts, itms.first, conf); $cfs.trigger(cf_e('linkanchors', conf)); $cfs.trigger(cf_e('updatepagestatus', conf), [true, sz]); 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); var num = a[0], org = a[1], dev = a[2]; if (typeof num == 'undefined' || num == 'end') { $cfs.children().last().remove(); } else { num = gn_getitemindex(num, dev, org, itms, $cfs); var $cit = $cfs.children().eq(num); if ($cit.length){ if (num < itms.first) itms.first -= $cit.length; $cit.remove(); } } itms.total = $cfs.children().length; var sz = sz_setsizes($cfs, opts); nv_shownavi(opts, itms.total, conf); nv_enablenavi(opts, itms.first, conf); $cfs.trigger(cf_e('updatepagestatus', conf), [true, sz]); return true; }); // onbefore and onafter event $cfs.bind(cf_e('onbefore', conf)+' '+cf_e('onafter', conf), function(e, fn) { e.stoppropagation(); var etype = e.type.substr(conf.events.prefix.length); if (is_array(fn)) clbk[etype] = fn; if (typeof fn == 'function') clbk[etype].push(fn); return clbk[etype]; }); // currentposition event, accessible from outside $cfs.bind(cf_e('_cfs_currentposition', conf, false), function(e, fn) { e.stoppropagation(); return $cfs.triggerhandler(cf_e('currentposition', conf), fn); }); $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 (typeof fn == 'function') 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; var max = math.ceil(itms.total/ipp-1); if (itms.first == 0) var nr = 0; else if (itms.first < itms.total % ipp) var nr = 0; else if (itms.first == ipp && !opts.circular) var nr = max; else var nr = math.round((itms.total-itms.first)/ipp); if (nr < 0) nr = 0; if (nr > max) nr = max; if (typeof fn == 'function') fn.call($tt0, nr); return nr; }); // currentvisible event $cfs.bind(cf_e('currentvisible', conf), function(e, fn) { e.stoppropagation(); $i = gi_getcurrentitems($cfs.children(), opts); if (typeof fn == 'function') 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.substr(conf.events.prefix.length); if (typeof fn == 'function') fn.call($tt0, crsl[etype]); return crsl[etype]; }); // configuration event, accessible from outside $cfs.bind(cf_e('_cfs_configuration', conf, false), function(e, a, b, c) { e.stoppropagation(); return $cfs.triggerhandler(cf_e('configuration', conf), [a, b, c]); }); $cfs.bind(cf_e('configuration', conf), function(e, a, b, c) { e.stoppropagation(); var reinit = false; // return entire configuration-object if (typeof a == 'function') { a.call($tt0, opts); // set multiple options via object } else if (typeof a == 'object') { opts_orig = $.extend(true, {}, opts_orig, a); if (b !== false) reinit = true; else opts = $.extend(true, {}, opts, a); } else if (typeof a != 'undefined') { // callback function for specific option if (typeof b == 'function') { var val = eval('opts.'+a); if (typeof val == 'undefined') val = ''; b.call($tt0, val); // set individual option } else if (typeof b != 'undefined') { 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 siz = sz_setsizes($cfs, opts); $cfs.trigger(cf_e('updatepagestatus', conf), [true, siz]); } return opts; }); // linkanchors event $cfs.bind(cf_e('linkanchors', conf), function(e, $con, sel) { e.stoppropagation(); if (typeof $con == 'undefined' || $con.length == 0) $con = $('body'); else if (typeof $con == 'string') $con = $($con); if (typeof $con != 'object') return debug(conf, 'not a valid object.'); if (typeof sel != 'string' || sel.length == 0) 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; if (typeof build == 'boolean' && build) { opts.pagination.container.children().remove(); var ipp = opts.pagination.items || opts.items.visible; for (var a = 0, l = math.ceil(itms.total/ipp); a < l; a++) { var i = $cfs.children().eq( gn_getitemindex(a*ipp, 0, true, itms, $cfs) ); opts.pagination.container.append(opts.pagination.anchorbuilder(a+1, i)); } 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, 0, true, opts.pagination]); }); }); }); } opts.pagination.container.each(function() { $(this).children().removeclass(cf_c('selected', conf)).eq($cfs.triggerhandler(cf_e('currentpage', conf))).addclass(cf_c('selected', conf)); }); return true; }); // destroy event, accessible from outside $cfs.bind(cf_e('_cfs_destroy', conf, false), function(e, orgorder) { e.stoppropagation(); $cfs.trigger(cf_e('destroy', conf), orgorder); return true; }); $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)); } if (opts.usepadding) { sz_resetmargin($cfs.children(), opts); } $cfs.css($cfs.data('cfs_origcss')); $cfs._cfs_unbind_events(); $cfs._cfs_unbind_buttons(); $wrp.replacewith($cfs); return true; }); }; // /bind_events $cfs._cfs_unbind_events = function() { $cfs.unbind(cf_e('', conf, false)); }; // /unbind_events $cfs._cfs_bind_buttons = function() { $cfs._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[0], pc[1]]); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } if (opts.auto.button) { opts.auto.button.bind(cf_e(opts.auto.event, conf, false), function(e) { e.preventdefault(); var ev = (crsl.ispaused) ? 'play' : 'pause'; $cfs.trigger(cf_e(ev, conf)); }); } 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[0], pc[1]]); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } } 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[0], pc[1]]); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } } if ($.fn.mousewheel) { if (opts.prev.mousewheel) { if (!crsl.mousewheelprev) { crsl.mousewheelprev = true; $wrp.mousewheel(function(e, delta) { if (delta > 0) { e.preventdefault(); var num = bt_mousesheelnumber(opts.prev.mousewheel); $cfs.trigger(cf_e('prev', conf), num); } }); } } if (opts.next.mousewheel) { if (!crsl.mousewheelnext) { crsl.mousewheelnext = true; $wrp.mousewheel(function(e, delta) { if (delta < 0) { e.preventdefault(); var num = bt_mousesheelnumber(opts.next.mousewheel); $cfs.trigger(cf_e('next', conf), num); } }); } } } if ($.fn.touchwipe) { var wp = (opts.prev.wipe) ? function() { $cfs.trigger(cf_e('prev', conf)) } : null, wn = (opts.next.wipe) ? function() { $cfs.trigger(cf_e('next', conf)) } : null; if (wn || wn) { if (!crsl.touchwipe) { crsl.touchwipe = true; var twops = { 'min_move_x': 30, 'min_move_y': 30, 'preventdefaultevents': true }; switch (opts.direction) { case 'up': case 'down': twops.wipeup = wn; twops.wipedown = wp; break; default: twops.wipeleft = wn; twops.wiperight = wp; } $wrp.touchwipe(twops); } } } 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[0], pc[1]]); }) .bind(cf_e('mouseleave', conf, false), function() { $cfs.trigger(cf_e('resume', conf)); }); } } if (opts.prev.key || opts.next.key) { $(document).bind(cf_e('keyup', conf, false), 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)); } }); } if (opts.pagination.keys) { $(document).bind(cf_e('keyup', conf, false), 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]); } } }); } if (opts.auto.play) { $cfs.trigger(cf_e('play', conf), opts.auto.delay); } }; // /bind_buttons $cfs._cfs_unbind_buttons = function() { var ns = cf_e('', conf, false); $(document).unbind(ns); $wrp.unbind(ns); if (opts.auto.button) opts.auto.button.unbind(ns); if (opts.prev.button) opts.prev.button.unbind(ns); if (opts.next.button) opts.next.button.unbind(ns); if (opts.pagination.container) opts.pagination.container.unbind(ns); if (opts.pagination.container) opts.pagination.container.children().remove(); nv_shownavi(opts, 'hide', conf); nv_enablenavi(opts, 'removeclass', conf); }; // /unbind_buttons // start var crsl = { 'direction' : 'next', 'ispaused' : true, 'isscrolling' : false, 'isstopped' : false, 'mousewheelnext': false, 'mousewheelprev': false, 'touchwipe' : false }, itms = { 'total' : $cfs.children().length, 'first' : 0 }, tmrs = { 'timer' : null, 'auto' : null, 'queue' : 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 = options, $wrp = $cfs.wrap('<'+conf.wrapper.element+' class="'+conf.wrapper.classname+'" />').parent(); conf.selector = $cfs.selector; // create carousel $cfs._cfs_init(opts_orig, true, starting_position); $cfs._cfs_build(); $cfs._cfs_bind_events(); $cfs._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(cf_readcookie(opts.cookie)); } 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, false), itm = gi_getcurrentitems($cfs.children(), opts); if (opts.oncreate) { opts.oncreate.call($tt0, itm, siz); } $cfs.trigger(cf_e('updatepagestatus', conf), [true, siz]); $cfs.trigger(cf_e('linkanchors', conf)); return $cfs; }; // global public $.fn.caroufredsel.defaults = { 'synchronise' : false, 'infinite' : true, 'circular' : true, 'direction' : 'left', 'items' : { 'start' : 0 }, 'scroll' : { 'easing' : 'swing', 'duration' : 500, 'pauseonhover' : false, 'mousewheel' : false, 'wipe' : false, 'event' : 'click', 'queue' : false } }; $.fn.caroufredsel.configs = { 'debug' : false, 'events' : { 'prefix' : '', 'namespace' : 'cfs' }, 'wrapper' : { 'element' : 'div', 'classname' : 'caroufredsel_wrapper' }, 'classnames' : {} }; $.fn.caroufredsel.pageanchorbuilder = function(nr, itm) { return ''+nr+''; }; // global private // scrolling functions function sc_setscroll(d, e) { return { anims : [], duration : d, orgduration : d, easing : e, starttime : gettime() }; } function sc_startscroll(s) { if (typeof s.pre == 'object') { sc_startscroll(s.pre); } for (var a = 0, l = s.anims.length; a < l; a++) { var b = s.anims[a]; if (!b) continue; if (b[3]) b[0].stop(); b[0].animate(b[1], { complete: b[2], duration: s.duration, easing: s.easing }); } if (typeof s.post == 'object') { sc_startscroll(s.post); } } function sc_stopscroll(s, finish) { if (typeof finish != 'boolean') finish = true; if (typeof s.pre == 'object') { 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 (typeof b[2] == 'function') b[2](); } } if (typeof s.post == 'object') { sc_stopscroll(s.post, finish); } } function sc_cleartimers(t) { if (t.auto) cleartimeout(t.auto); return t; } function sc_callcallbacks(cbs, t, args) { if (cbs.length) { for (var a = 0, l = cbs.length; a < l; a++) { cbs[a].apply(t, args); } } return []; } // fx functions function fx_fade(so, c, x, d, f) { var o = { 'duration' : d, 'easing' : so.easing }; if (typeof f == 'function') o.complete = f; c.animate({ opacity: x }, o); } function fx_cover(sc, c1, c2, o, prev) { var old_w = ms_getsizes(gi_getolditemsnext(c1.children(), o), o, true)[0], new_w = ms_getsizes(c2.children(), o, true)[0], cur_l = (prev) ? -new_w : old_w, css_o = {}, ani_o = {}; css_o[o.d['width']] = new_w; css_o[o.d['left']] = cur_l; ani_o[o.d['left']] = 0; sc.pre.anims.push([c1, { 'opacity': 1 }]); sc.post.anims.push([c2, ani_o, function() { $(this).remove(); }]); c2.css(css_o); return sc; } function fx_uncover(sc, c1, c2, o, prev, n) { var new_w = ms_getsizes(gi_getnewitemsnext(c1.children(), o, n), o, true)[0], old_w = ms_getsizes(c2.children(), o, true)[0], cur_l = (prev) ? -old_w : new_w, css_o = {}, ani_o = {}; css_o[o.d['width']] = old_w; css_o[o.d['left']] = 0; ani_o[o.d['left']] = cur_l; sc.post.anims.push([c2, ani_o, function() { $(this).remove(); }]); c2.css(css_o); return sc; } // navigation functions function nv_shownavi(o, t, c) { if (t == 'show' || t == 'hide') { var f = t; } else if (o.items.minimum >= t) { debug(c, 'not enough items: hiding navigation ('+t+' items, '+o.items.minimum+' needed).'); 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 (typeof obj == 'function') obj = obj.call($tt); if (typeof obj == 'undefined') obj = {}; return obj; } function go_getnaviobject($tt, obj, type) { if (typeof type != 'string') type = ''; obj = go_getobject($tt, obj); if (typeof obj == 'string') { var temp = cf_getkeycode(obj); if (temp == -1) obj = $(obj); else obj = temp; } // pagination if (type == 'pagination') { if (typeof obj == 'boolean') obj = { 'keys': obj }; if (typeof obj.jquery != 'undefined') obj = { 'container': obj }; if (typeof obj.container == 'function') obj.container = obj.container.call($tt); if (typeof obj.container == 'string') obj.container = $(obj.container); if (typeof obj.items != 'number') obj.items = false; // auto } else if (type == 'auto') { if (typeof obj.jquery != 'undefined') obj = { 'button': obj }; if (typeof obj == 'boolean') obj = { 'play': obj }; if (typeof obj == 'number') obj = { 'pauseduration': obj }; if (typeof obj.button == 'function') obj.button = obj.button.call($tt); if (typeof obj.button == 'string') obj.button = $(obj.button); // prev + next } else { if (typeof obj.jquery != 'undefined') obj = { 'button': obj }; if (typeof obj == 'number') obj = { 'key': obj }; if (typeof obj.button == 'function') obj.button = obj.button.call($tt); if (typeof obj.button == 'string') obj.button = $(obj.button); if (typeof obj.key == 'string') obj.key = cf_getkeycode(obj.key); } return obj; } // get number functions function gn_getitemindex(num, dev, org, items, $cfs) { if (typeof num == 'string') { if (isnan(num)) num = $(num); else num = parseint(num); } if (typeof num == 'object') { if (typeof num.jquery == 'undefined') num = $(num); num = $cfs.children().index(num); if (num == -1) num = 0; if (typeof org != 'boolean') org = false; } else { if (typeof org != 'boolean') org = true; } if (isnan(num)) num = 0; else num = parseint(num); if (isnan(dev)) dev = 0; else dev = parseint(dev); 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; } 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.maxdimention) return x; if (a == 0) a = i.length; x++; } } 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.maxdimention) return x; if (a == l) a = -1; x++; } } 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; } // 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_resetmargin(i, o, m) { var x = (typeof m == 'boolean') ? m : false; if (typeof m != 'number') m = 0; i.each(function() { var j = $(this); var t = parseint(j.css(o.d['marginright'])); if (isnan(t)) t = 0; j.data('cfs_tempcssmargin', t); j.css(o.d['marginright'], ((x) ? j.data('cfs_tempcssmargin') : m + j.data('cfs_origcssmargin'))); }); } function sz_setsizes($c, o, p) { var $w = $c.parent(), $i = $c.children(), $v = gi_getcurrentitems($i, o), sz = cf_mapwrappersizes(ms_getsizes($v, o, true), o, p); $w.css(sz); if (o.usepadding) { var p = o.padding, r = p[o.d[1]]; if (o.align) { if (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) { var s1 = ms_gettotalsize(i, o, 'width', wrapper), s2 = ms_getlargestsize(i, o, 'height', wrapper); return [s1, s2]; } function ms_getlargestsize(i, o, dim, wrapper) { if (typeof wrapper != 'boolean') wrapper = false; if (typeof o[o.d[dim]] == 'number' && wrapper) return o[o.d[dim]]; if (typeof o.items[o.d[dim]] == 'number') return o.items[o.d[dim]]; var di2 = (dim.tolowercase().indexof('width') > -1) ? 'outerwidth' : 'outerheight'; return ms_gettruelargestsize(i, o, di2); } 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[o.d[dim]](true); if (s < m) s = m; } return s; } function ms_gettrueinnersize($el, o, dim) { var siz = $el[o.d[dim]](), arr = (o.d[dim].tolowercase().indexof('width') > -1) ? ['paddingleft', 'paddingright'] : ['paddingtop', 'paddingbottom']; for (var a = 0, l = arr.length; a < l; a++) { var m = parseint($el.css(arr[a])); siz -= (isnan(m)) ? 0 : m; } return siz; } function ms_gettotalsize(i, o, dim, wrapper) { if (typeof wrapper != 'boolean') wrapper = false; if (typeof o[o.d[dim]] == 'number' && wrapper) return o[o.d[dim]]; if (typeof o.items[o.d[dim]] == 'number') 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_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; } // config functions function cf_e(n, c, pf, ns) { if (typeof pf != 'boolean') pf = true; if (typeof ns != 'boolean') ns = true; if (pf) n = c.events.prefix + n; if (ns) n = n +'.'+ c.events.namespace; return n; } function cf_c(n, c) { return (typeof c.classnames[n] == 'string') ? c.classnames[n] : n; } function cf_mapwrappersizes(ws, o, p) { if (typeof p != 'boolean') 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 && typeof arr[b] == 'undefined') { arr[b] = vals[a]; break; } } } return arr; } function cf_getpadding(p) { if (typeof p == 'undefined') return [0, 0, 0, 0]; if (typeof p == 'number') return [p, p, p, p]; else if (typeof p == 'string') 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]); } 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 = (typeof o[o.d['width']] == 'number') ? 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_getadjust(x, o, a, $t) { var v = x; if (typeof a == 'function') { v = a.call($t, v); } else if (typeof a == 'string') { 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); if (!isnan(adj)) { if (neg) adj = -adj; v += adj; } } if (typeof v != 'number') v = 1; if (v < 1) v = 1; return v; } function cf_getitemsadjust(x, o, a, $t) { var v = cf_getadjust(x, o, a, $t), i = o.items.visibleconf; if (typeof i.min == 'number' && v < i.min) v = i.min; if (typeof i.max == 'number' && 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 (typeof s[j][0] == 'string') s[j][0] = $(s[j][0]); if (typeof s[j][1] != 'boolean') s[j][1] = true; if (typeof s[j][2] != 'boolean') s[j][2] = true; if (typeof s[j][3] != 'number') 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, v) { if (n) document.cookie = n+'='+v+'; path=/'; } function cf_readcookie(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.substring(1, c.length); } if (c.indexof(n) == 0) { return c.substring(n.length, c.length); } } return 0; } // buttons functions function bt_pauseonhoverconfig(p) { if (p && typeof p == 'string') { 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 (typeof mw == 'number') ? mw : null } // helper functions function is_array(a) { return typeof(a) == 'object' && (a instanceof array); } function gettime() { return new date().gettime(); } function debug(d, m) { if (typeof d == 'object') { var s = ' ('+d.selector+')'; d = d.debug; } else { var s = ''; } if (!d) return false; if (typeof m == 'string') m = 'caroufredsel'+s+': ' + m; else m = ['caroufredsel'+s+':', m]; if (window.console && window.console.log) window.console.log(m); return false; } $.fn.caroufredsel = function(o) { return this.caroufredsel(o); }; })(jquery);