/*! * CrossSlide jQuery plugin v0.6.2 * * Copyright 2007-2010 by Tobia Conforto * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ (function(){var $=jQuery,animate=($.fn.startAnimation?'startAnimation':'animate'),pause_missing='pause plugin missing.';function format(str){for(var i=1;i3)throw new Error();if(tokens[0]=='center') if(tokens.length==1) tokens=['center','center'];else if(tokens.length==2&&tokens[1].match(/^[\d.]+x$/i)) tokens=['center','center',tokens[1]];if(tokens.length==3) zoom=parseFloat(tokens[2].match(/^([\d.]+)x$/i)[1]);var pos=tokens[0]+' '+tokens[1];if(pos=='left top'||pos=='top left') return{xrel:0,yrel:0,zoom:zoom};if(pos=='left center'||pos=='center left') return{xrel:0,yrel:.5,zoom:zoom};if(pos=='left bottom'||pos=='bottom left') return{xrel:0,yrel:1,zoom:zoom};if(pos=='center top'||pos=='top center') return{xrel:.5,yrel:0,zoom:zoom};if(pos=='center center') return{xrel:.5,yrel:.5,zoom:zoom};if(pos=='center bottom'||pos=='bottom center') return{xrel:.5,yrel:1,zoom:zoom};if(pos=='right top'||pos=='top right') return{xrel:1,yrel:0,zoom:zoom};if(pos=='right center'||pos=='center right') return{xrel:1,yrel:.5,zoom:zoom};if(pos=='right bottom'||pos=='bottom right') return{xrel:1,yrel:1,zoom:zoom};return{xrel:parseInt(tokens[0].match(/^(\d+)%$/)[1])/100,yrel:parseInt(tokens[1].match(/^(\d+)%$/)[1])/100,zoom:zoom};} $.fn.crossSlide=function(opts,plan,callback) {var self=this,self_width=this.width(),self_height=this.height();if(self.length!=1) abort('crossSlide() must be called on exactly 1 element') self.get(0).crossSlideArgs=[opts,plan,callback];plan=$.map(plan,function(p){return $.extend({},p);});if(!opts.easing) opts.easing=opts.variant?'swing':'linear';if(!callback) callback=function(){};(function(proceed){var n_loaded=0;function loop(i,img){img.onload=function(e){n_loaded++;plan[i].width=img.width;plan[i].height=img.height;if(n_loaded==plan.length) proceed();} img.src=plan[i].src;if(i+1',p.src));if(p.href) elm=$(format('',p.href)).append(img);if(p.onclick) elm.click(p.onclick);if(p.alt) img.attr('alt',p.alt);if(p.rel) elm.attr('rel',p.rel);if(p.href&&p.target) elm.attr('target',p.target);elm.appendTo(self);} delete speed;function position_to_css(p,phase){var pos=[0,fade_ms/(p.time_ms+2*fade_ms),1-fade_ms/(p.time_ms+2*fade_ms),1][phase];return{left:Math.round(p.from.left+pos*(p.to.left-p.from.left)),top:Math.round(p.from.top+pos*(p.to.top-p.from.top)),width:Math.round(p.from.width+pos*(p.to.width-p.from.width)),height:Math.round(p.from.height+pos*(p.to.height-p.from.height))};} var imgs=self.find('img').css({position:'absolute',visibility:'hidden',top:0,left:0,border:0});imgs.eq(0).css({visibility:'visible'});if(!sleep) imgs.eq(0).css(position_to_css(plan[0],opts.variant?0:1));var countdown=opts.loop;function create_chain(i,chainf){if(i%2==0){if(sleep){var i_sleep=i/2,i_hide=(i_sleep-1+plan.length)%plan.length,img_sleep=imgs.eq(i_sleep),img_hide=imgs.eq(i_hide);var newf=function(){callback(i_sleep,img_sleep.get(0));img_hide.css('visibility','hidden');setTimeout(chainf,sleep);};}else{var i_slide=i/2,i_hide=(i_slide-1+plan.length)%plan.length,img_slide=imgs.eq(i_slide),img_hide=imgs.eq(i_hide),time=plan[i_slide].time_ms,slide_anim=position_to_css(plan[i_slide],opts.variant?3:2);var newf=function(){callback(i_slide,img_slide.get(0));img_hide.css('visibility','hidden');img_slide[animate](slide_anim,time,opts.easing,chainf);};}}else{var i_from=Math.floor(i/2),i_to=Math.ceil(i/2)%plan.length,img_from=imgs.eq(i_from),img_to=imgs.eq(i_to),from_anim={},to_init={visibility:'visible'},to_anim={};if(i_to>i_from){to_init.opacity=0;to_anim.opacity=1;if(opts.doubleFade) from_anim.opacity=0;}else{from_anim.opacity=0;if(opts.doubleFade){to_init.opacity=0;to_anim.opacity=1;}} if(!sleep){$.extend(to_init,position_to_css(plan[i_to],0));if(!opts.variant){$.extend(from_anim,position_to_css(plan[i_from],3));$.extend(to_anim,position_to_css(plan[i_to],1));}} if($.isEmptyObject(to_anim)){var newf=function(){callback(i_to,img_to.get(0),i_from,img_from.get(0));img_to.css(to_init);img_from[animate](from_anim,fade_ms,'linear',chainf);};}else if($.isEmptyObject(from_anim)){var newf=function(){callback(i_to,img_to.get(0),i_from,img_from.get(0));img_to.css(to_init);img_to[animate](to_anim,fade_ms,'linear',chainf);};}else{var newf=function(){callback(i_to,img_to.get(0),i_from,img_from.get(0));img_to.css(to_init);img_to[animate](to_anim,fade_ms,'linear');img_from[animate](from_anim,fade_ms,'linear',chainf);};}} if(opts.loop&&i==plan.length*2-2){var newf_orig=newf;newf=function(){if(--countdown)newf_orig();}} if(i>0) return create_chain(i-1,newf);else return newf;} var animation=create_chain(plan.length*2-1,function(){return animation();});animation();});return self;};$.fn.crossSlideFreeze=function() {this.find('img').stop();} $.fn.crossSlideStop=function() {this.find('img').stop().remove();} $.fn.crossSlideRestart=function() {this.find('img').stop().remove();$.fn.crossSlide.apply(this,this.get(0).crossSlideArgs);} $.fn.crossSlidePause=function() {if(!$.fn.pause) abort(pause_missing);this.find('img').pause();} $.fn.crossSlideResume=function() {if(!$.fn.pause) abort(pause_missing);this.find('img').resume();}})();