////////////////////////////////////////////////////////////////////////////////// // cloud zoom v1.0.2 // (c) 2010 by r cecco. // mit license // download by http://www.codefans.net // please retain this copyright header in all versions of the software ////////////////////////////////////////////////////////////////////////////////// (function($){ jquery.browser={};(function(){jquery.browser.msie=false; jquery.browser.version=0;if(navigator.useragent.match(/msie ([0-9]+)./)){ jquery.browser.msie=true;jquery.browser.version=regexp.$1;}})(); $(document).ready(function(){$('.cloud-zoom, .cloud-zoom-gallery').cloudzoom()});function format(str){for(var i=1;iloading...',w/3,(w/2)-(w/6))).find(':last').css('opacity',0.5)}},200);var ie6fixremove=function(){if($ie6fix!==null){$ie6fix.remove();$ie6fix=null}};this.removebits=function(){if(lens){lens.remove();lens=null}if($tint){$tint.remove();$tint=null}if(softfocus){softfocus.remove();softfocus=null}ie6fixremove();$('.cloud-zoom-loading',jwin.parent()).remove()};this.destroy=function(){jwin.data('zoom',null);if($mousetrap){$mousetrap.unbind();$mousetrap.remove();$mousetrap=null}if(zoomdiv){zoomdiv.remove();zoomdiv=null}this.removebits()};this.fadedout=function(){if(zoomdiv){zoomdiv.remove();zoomdiv=null}this.removebits()};this.controlloop=function(){if(lens){var x=(mx-simg.offset().left-(cw*0.5))>>0;var y=(my-simg.offset().top-(ch*0.5))>>0;if(x<0){x=0}else if(x>(simg.outerwidth()-cw)){x=(simg.outerwidth()-cw)}if(y<0){y=0}else if(y>(simg.outerheight()-ch)){y=(simg.outerheight()-ch)}lens.css({left:x,top:y});lens.css('background-position',(-x)+'px '+(-y)+'px');destu=(((x)/simg.outerwidth())*zoomimage.width)>>0;destv=(((y)/simg.outerheight())*zoomimage.height)>>0;curru+=(destu-curru)/opts.smoothmove;currv+=(destv-currv)/opts.smoothmove;zoomdiv.css('background-position',(-(curru>>0)+'px ')+(-(currv>>0)+'px'))}controltimer=settimeout(function(){ctx.controlloop()},30)};this.init2=function(img,id){filesloaded++;if(id===1){zoomimage=img}if(filesloaded===2){this.init()}};this.init=function(){$('.cloud-zoom-loading',jwin.parent()).remove();$mousetrap=jwin.parent().append(format("
",simg.outerwidth(),simg.outerheight(),0,0)).find(':last');$mousetrap.bind('mousemove',this,function(event){mx=event.pagex;my=event.pagey});$mousetrap.bind('mouseleave',this,function(event){cleartimeout(controltimer);if(lens){lens.fadeout(299)}if($tint){$tint.fadeout(299)}if(softfocus){softfocus.fadeout(299)}zoomdiv.fadeout(300,function(){ctx.fadedout()});return false});$mousetrap.bind('mouseenter',this,function(event){mx=event.pagex;my=event.pagey;zw=event.data;if(zoomdiv){zoomdiv.stop(true,false);zoomdiv.remove()}var xpos=opts.adjustx,ypos=opts.adjusty;var siw=simg.outerwidth();var sih=simg.outerheight();var w=opts.zoomwidth;var h=opts.zoomheight;if(opts.zoomwidth=='auto'){w=siw}if(opts.zoomheight=='auto'){h=sih}var appendto=jwin.parent();switch(opts.position){case'top':ypos-=h;break;case'right':xpos+=siw;break;case'bottom':ypos+=sih;break;case'left':xpos-=w;break;case'inside':w=siw;h=sih;break;default:appendto=$('#'+opts.position);if(!appendto.length){appendto=jwin;xpos+=siw;ypos+=sih}else{w=appendto.innerwidth();h=appendto.innerheight()}}zoomdiv=appendto.append(format('',xpos,ypos,w,h,zoomimage.src)).find(':last');if(simg.attr('title')&&opts.showtitle){zoomdiv.append(format('
%0
',simg.attr('title'))).find(':last').css('opacity',opts.titleopacity)}if($.browser.msie&&$.browser.version<7){$ie6fix=$('').css({position:"absolute",left:xpos,top:ypos,zindex:99,width:w,height:h}).insertbefore(zoomdiv)}zoomdiv.fadein(500);if(lens){lens.remove();lens=null}cw=(simg.outerwidth()/zoomimage.width)*zoomdiv.width();ch=(simg.outerheight()/zoomimage.height)*zoomdiv.height();lens=jwin.append(format("",cw,ch)).find(':last');$mousetrap.css('cursor',lens.css('cursor'));var notrans=false;if(opts.tint){lens.css('background','url("'+simg.attr('src')+'")');$tint=jwin.append(format('
',simg.outerwidth(),simg.outerheight(),opts.tint)).find(':last');$tint.css('opacity',opts.tintopacity);notrans=true;$tint.fadein(500)}if(opts.softfocus){lens.css('background','url("'+simg.attr('src')+'")');softfocus=jwin.append(format('
',simg.outerwidth()-2,simg.outerheight()-2,opts.tint)).find(':last');softfocus.css('background','url("'+simg.attr('src')+'")');softfocus.css('opacity',0.5);notrans=true;softfocus.fadein(500)}if(!notrans){lens.css('opacity',opts.lensopacity)}if(opts.position!=='inside'){lens.fadein(500)}zw.controlloop();return})};img1=new image();$(img1).load(function(){ctx.init2(this,0)});img1.src=simg.attr('src');img2=new image();$(img2).load(function(){ctx.init2(this,1)});img2.src=jwin.attr('href')}$.fn.cloudzoom=function(options){try{document.execcommand("backgroundimagecache",false,true)}catch(e){}this.each(function(){var relopts,opts;eval('var a = {'+$(this).attr('rel')+'}');relopts=a;if($(this).is('.cloud-zoom')){$(this).css({'position':'relative','display':'block'});$('img',$(this)).css({'display':'block'});if($(this).parent().attr('id')!='wrap'){$(this).wrap('
')}opts=$.extend({},$.fn.cloudzoom.defaults,options);opts=$.extend({},opts,relopts);$(this).data('zoom',new cloudzoom($(this),opts))}else if($(this).is('.cloud-zoom-gallery')){opts=$.extend({},relopts,options);$(this).data('relopts',opts);$(this).bind('click',$(this),function(event){var data=event.data.data('relopts');$('#'+data.usezoom).data('zoom').destroy();$('#'+data.usezoom).attr('href',event.data.attr('href'));$('#'+data.usezoom+' img').attr('src',event.data.data('relopts').smallimage);$('#'+event.data.data('relopts').usezoom).cloudzoom();return false})}});return this};$.fn.cloudzoom.defaults={zoomwidth:'auto',zoomheight:'auto',position:'right',tint:false,tintopacity:0.5,lensopacity:0.5,softfocus:false,smoothmove:3,showtitle:true,titleopacity:0.5,adjustx:0,adjusty:0}})(jquery);