/* * mopHover 3.0 * By Hiroki Miura (http://www.mopstudio.jp) * Copyright (c) 2009 mopStudio * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php * February 6, 2012 */ jQuery.fn.extend({ mopHover:function(setting){ var fastSrc,newSrc0,newSrc1,newSrc2; var target; var slide; var check; var d; var slideTarget; if(!setting){ setting={}; target="this"; }else if(!setting.target){ target="this"; }else{ target=setting.target; } var mopHoverVer={ func0:function(){ if(fasrSrc){ newSrc0=fasrSrc.slice(0,-4); } }, func1:function(){ mopHoverVer.func0(); check=newSrc0.slice(-3); newSrc1=newSrc0.slice(0,-3); if(check==='_no'){ newSrc1=newSrc1+'_on' }else if(check==='_on'){ newSrc1=newSrc1+'_no' }else{ newSrc1=newSrc1+'_no' } }, func2:function(){ newSrc2=fasrSrc.slice(-4); if(newSrc2===".png"){ newSrc2=".png" }else if(newSrc2===".jpg"){ newSrc2=".jpg" }else if(newSrc2===".gif"){ newSrc2=".gif" } }, func3:function(){ mopHoverVer.func0(); check=newSrc0.slice(-6,-3); newSrc0=newSrc0.slice(0,-6); if(check==='_dn'){ newSrc1=newSrc0+'_up_xx' }else{ newSrc1=newSrc0+'_dn_on' } }, hover:function(t){ if(target==='this'){ fasrSrc=$(t).attr("src"); mopHoverVer.func1(); mopHoverVer.func2(); $(t).attr({src:newSrc1+newSrc2}); }else if(target==='next'){ fasrSrc=$(t).next().attr("src"); mopHoverVer.func1(); mopHoverVer.func2(); $(t).next().attr({src:newSrc1+newSrc2}); }else if(target==='child'){ fasrSrc=$(t).children().attr("src"); mopHoverVer.func1(); mopHoverVer.func2(); $(t).children().attr({src:newSrc1+newSrc2}); }else if(target==='childNext'){ fasrSrc=$(t).children().next().attr("src"); mopHoverVer.func1(); mopHoverVer.func2(); $(t).children().next().attr({src:newSrc1+newSrc2}); }else{ fasrSrc=$(target).attr("src"); mopHoverVer.func1(); mopHoverVer.func2(); $(target).attr({src:newSrc1+newSrc2}); } }, slide:function(t){ if(slideTarget==='parentNext'){ $(t).parent().next().slideToggle('fast'); }else if(slideTarget==='next'){ $(t).next().slideToggle('fast'); }else{ $(slideTarget).slideToggle('fast'); }; } }; if(setting.slideTarget){ slideTarget=setting.slideTarget; }; $(this).hover( function(){ mopHoverVer.hover(this); }, function(){ mopHoverVer.hover(this); } ); $(this).click( function(){ if(slideTarget){ if(target==='this'){ fasrSrc=$(this).attr("src"); mopHoverVer.func3(); mopHoverVer.slide(this); $(this).attr({src:newSrc1+newSrc2}); }else if(target==='next'){ fasrSrc=$(this).next().attr("src"); mopHoverVer.func3(); mopHoverVer.slide(this); $(this).next().attr({src:newSrc1+newSrc2}); }else if(target==='child'){ fasrSrc=$(this).children().attr("src"); mopHoverVer.func3(); mopHoverVer.slide(this); $(this).children().attr({src:newSrc1+newSrc2}); }else if(target==='childNext'){ fasrSrc=$(this).children().next().attr("src"); mopHoverVer.func3(); mopHoverVer.slide(this); $(this).children().next().attr({src:newSrc1+newSrc2}); }else{ fasrSrc=$(target).attr("src"); mopHoverVer.func3(); mopHoverVer.slide(this); $(target).attr({src:newSrc1+newSrc2}); }; } } ); } });