/** * jQuery fancyzoom plugin. * This is an adaptation of the fancyzoom effect as a jQuery plugin * * Author: Mathieu Vilaplana * Date: March 2008 * rev 1.0 * rev: 1.1 * Add title if alt in the img */ (function($){var strImgDir='ressources/';var oImgZoomBox=$('
');var oImgClose=$('').css({position:'absolute',top:0,left:0,cursor:'pointer',zIndex:102});$.fn.fancyzoom=function(userOptions){var oOverlay=$('
').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,cursor:"wait"});function openZoomBox(imgSrc,o){if(o.showoverlay){oOverlay.appendTo('body').click(function(){closeZoomBox(o)})}pos=imgSrc.offset();o=$.extend(o,{dimOri:{width:imgSrc.outerWidth(),height:imgSrc.outerHeight(),left:pos.left,top:pos.top,'opacity':0}});var oImgDisplay=$('img',oImgZoomBox);oImgZoomBox.css({'opacity':0,'text-align':'center','border':'0px solid red'}).appendTo('body');var iWidth=oImgZoomBox.outerWidth();var iHeight=oImgZoomBox.outerHeight();dimBoxTarget=$.extend({},{width:iWidth,height:iHeight,'opacity':1},__posCenter((iWidth+15),(iHeight+30)));oImgClose.css({left:(dimBoxTarget.left+dimBoxTarget.width-22-(dimBoxTarget.width-oImgDisplay.width())/2),top:dimBoxTarget.top});var $fctEnd=function(){if($.fn.shadow&&!$.browser.msie){$('img:first',oImgZoomBox).shadow(o.shadowOpts)}if(o.Speed>0&&!$.browser.msie){oImgClose.fadeIn('slow');$('div',oImgZoomBox).fadeIn('slow')}else{oImgClose.show();$('div',oImgZoomBox).show()}};$('div',oImgZoomBox).hide();if(o.Speed>0){oImgZoomBox.css(o.dimOri).animate(dimBoxTarget,o.Speed,$fctEnd)}else{oImgZoomBox.css(dimBoxTarget);$fctEnd()}}function closeZoomBox(o){oImgClose.remove();if(o.Speed>0){oImgZoomBox.animate(o.dimOri,o.Speed,function(){$(this).empty().remove()});if(o.showoverlay){oOverlay.animate({'opacity':0},o.Speed,function(){$(this).empty().remove()})}}else{oImgZoomBox.empty().remove();if(o.showoverlay){oOverlay.empty().remove()}}}return this.each(function(){var $this=$(this);var imgTarget=$this.is('img')?$this:$('img:first',$this);var imgTargetSrc=null;if($this.attr('href')){imgTargetSrc=$this.attr('href')}if($this.is('img')){imgTargetSrc=$this.attr('src');$this.css('cursor','pointer')}var opts=$.extend({},$.fn.fancyzoom.defaultsOptions,userOptions||{},{dimOri:{},oImgZoomBoxProp:{position:'absolute',left:0,top:0}});oOverlay.css({opacity:opts.overlay,background:opts.overlayColor});if(!/\.jpg|\.png|\.gif/i.test(imgTargetSrc)||($('img',$this).size()===0&&!$this.is('img'))){return}$this.click(function(){if(oLoading&&oLoading.is(':visible')||timerLoadingImg){if(oImgZoomBox&&$('img:first',oImgZoomBox).attr('src')!=imgTargetSrc){__cancelLoading()}else{return false}}var o=$.extend({},opts,userOptions);if(oImgZoomBox&&oImgZoomBox.parent().size()>0){var imCurrent=$('img:first',oImgZoomBox);if(imgTargetSrc==imCurrent.attr('src')){pos=imgTarget.offset();o=$.extend(o,{dimOri:{width:imgTarget.outerWidth(),height:imgTarget.outerHeight(),left:pos.left,top:pos.top,'opacity':0}});closeZoomBox(o);return false}else{oImgClose.remove();oImgZoomBox.empty().remove()}}if(o.showoverlay&&oOverlay){oOverlay.empty().remove().css({'opacity':o.overlay})}oImgClose.attr('src',o.imgDir+'closebox.png').appendTo('body').hide();if($.fn.ifixpng){$.ifixpng(o.imgDir+'blank.gif');oImgClose.ifixpng(o.imgDir+'blank.gif')}oImgClose.unbind('click').click(function(){closeZoomBox(o)});oImgZoomBox=$('
').empty().css(o.oImgZoomBoxProp);var strTitle=imgTarget.attr('alt');if(strTitle){var oTitle=$('
'+strTitle+'
').css({marginTop:10,marginRight:15});var tdL=oTitle.find('td:first').css({'background':'url('+o.imgDir+'zoom-caption-l.png)',width:'13px',height:'26px'});var tdR=oTitle.find('td:last').css({'background':'url('+o.imgDir+'zoom-caption-r.png)',width:'13px',height:'26px'});var tdC=$('.fancyTitle',oTitle).css({'background':'url('+o.imgDir+'zoom-caption-fill.png)','padding':'0px 20px',color:'#FFF','font-size':'14px'});if($.fn.ifixpng){tdL.ifixpng(o.imgDir+'blank.gif');tdR.ifixpng(o.imgDir+'blank.gif');tdC.ifixpng(o.imgDir+'blank.gif')}oTitle.appendTo(oImgZoomBox)}var oImgZoom=$('').attr('src',imgTargetSrc).css({zIndex:100,marginTop:15,marginRight:15}).click(function(){closeZoomBox(o)}).prependTo(oImgZoomBox);var imgPreload=new Image();imgPreload.src=imgTargetSrc;var $fctEndLoading=function(){if(bCancelLoading){bCancelLoading=false}else{if(__getFileName(imgPreload.src)==__getFileName($('img:first',oImgZoomBox).attr('src'))){fctCalculateImageSize();openZoomBox(imgTarget,o);__stoploading()}}};var fctCalculateImageSize=function(){var divCalculate=$('
').css({position:'absolute','top':0,'left':0,opacity:0,'border':'0px solid red'});oImgZoom.appendTo(divCalculate);divCalculate.appendTo('body');imWidth=oImgZoom.width();imHeight=oImgZoom.height();maxWidth=$(window).width()*0.9;maxHeight=$(window).height()*0.8;if(maxHeight
').css({width:50,height:50,position:'absolute','background':'transparent',opacity:8/10,color:'#FFF',padding:'5px','font-size':'10px'})}oLoading.css(__posCenter(50,50)).html('').click(function(){__cancelLoading()}).appendTo('body').show();timerLoadingImg=setTimeout(__changeimageLoading,400)}function __cancelLoading(){bCancelLoading=true;__stoploading()}function __stoploading(){oLoading.hide().remove();if(timerLoadingImg){clearTimeout(timerLoadingImg);timerLoadingImg=null}}function __changeimageLoading(){if(!oLoading.is(':visible')){timerLoadingImg=null;return}var $im=$('img',oLoading);if(!$im.attr('src')||/blank\.gif/.test($im.attr('src'))){strImgSrc=$.fn.fancyzoom.defaultsOptions.imgDir+"zoom-spin-1.png"}else{tab=$im.attr('src').split(/[- .]+/);iImg=parseInt(tab[2]);iImg=(iImg<12)?(iImg+1):1;strImgSrc=tab[0]+"-"+tab[1]+"-"+iImg+"."+tab[3]}var pLoad=new Image();pLoad.src=strImgSrc;var $fct=function(){oLoading.css(__posCenter(50,50));$im.attr('src',strImgSrc);timerLoadingImg=setTimeout(__changeimageLoading,100)};if(pLoad.complete){$fct()}else{pLoad.onload=$fct}}function __getFileName(strPath){if(!strPath){return false}var tabPath=strPath.split('/');return((tabPath.length<1)?strPath:tabPath[(tabPath.length-1)])}})(jQuery);