1// 2// iWeb - iWebImage.js 3// Copyright 2007 Apple Inc. 4// All rights reserved. 5// 6 7var IWAllImages={};var IWAllImageObjects={};function IWCreateImage(url) 8{var image=IWAllImages[url];if(image==null) 9{image=new IWImage(url);} 10return image;} 11var IWNamedImages={};function IWImageNamed(name) 12{var image=null;var url=IWNamedImages[name];if(url) 13{image=IWCreateImage(url);} 14return image;} 15function IWRegisterNamedImage(name,url) 16{IWNamedImages[name]=url;} 17function IWImage(url) 18{if(IWAllImages.hasOwnProperty(url)) 19{iWLog("warning -- use IWCreateImage rather than new IWImage and you'll get better performance");} 20this.mPreventUnloading=0;this.mLoading=false;this.mLoaded=false;this.mURL=url;this.mCallbacks=[];IWAllImages[url]=this;} 21IWImage.prototype.sourceURL=function() 22{return this.mURL;} 23IWImage.prototype.loaded=function() 24{return this.mLoaded;} 25IWImage.prototype.load=function(callback,delayCallbackIfLoaded) 26{if(this.mLoaded) 27{if(callback!=null) 28{delayCallbackIfLoaded?setTimeout(callback,0):callback();}} 29else 30{if(callback!=null) 31{this.mCallbacks.push(callback);} 32if(this.mLoading==false) 33{this.mLoading=true;var img=new Image();IWAllImageObjects[this.sourceURL()]=img;img.onload=this.p_onload.bind(this);img.src=this.mURL;}}} 34detectBrowser();var IWImageEnableUnload=isiPhone;IWImage.prototype.unload=function(evenIfNotEnabled) 35{if((evenIfNotEnabled||IWImageEnableUnload)&&this.mLoaded) 36{if(this.mPreventUnloading<=0) 37{this.mLoaded=false;this.mLoading=false;IWAllImageObjects[this.sourceURL()]=null;} 38else 39{this.mPreventedUnload=true;}}} 40IWImage.prototype.preventUnloading=function() 41{if(this.mPreventUnloading==0) 42{this.mPreventedUnload=false;} 43++this.mPreventUnloading;} 44IWImage.prototype.allowUnloading=function() 45{--this.mPreventUnloading;if(this.mPreventUnloading<=0&&this.mPreventedUnload) 46{this.unload();}} 47IWImage.prototype.naturalSize=function() 48{(function(){return this.mNaturalSize!==undefined}).bind(this).assert();return this.mNaturalSize;} 49IWImage.prototype.imgObject=function() 50{return IWAllImageObjects[this.sourceURL()];} 51IWImage.prototype.p_onload=function() 52{this.preventUnloading();this.mLoaded=true;if(this.mNaturalSize===undefined) 53{var imgObject=this.imgObject();(function(){return imgObject!==undefined}).assert();this.mNaturalSize=new IWSize(imgObject.width,imgObject.height);} 54for(var i=0;i<this.mCallbacks.length;++i) 55{this.mCallbacks[i]();} 56this.mCallbacks=[];this.allowUnloading();} 57IWImage.prototype.toString=function() 58{return"IWImage("+this.mNaturalSize+", "+this.mURL+")";} 59function IWCreateLoadingArea() 60{if(IWSharedLoadingAreaManager==null) 61{IWSharedLoadingAreaManager=new IWLoadingAreaManager();} 62return IWSharedLoadingAreaManager.createLoadingArea();} 63function IWLoadingAreaManager() 64{var div=document.createElement("div");div.style.visibility="hidden";div.style.position="absolute";div.style.width="0px";div.style.height="0px";div.style.overflow="hidden";document.body.appendChild(div);this.mCurrentLoadingArea=div;} 65IWLoadingAreaManager.prototype.createLoadingArea=function() 66{var loadingArea=document.createElement('div');this.mCurrentLoadingArea.appendChild(loadingArea);return loadingArea;} 67var IWSharedLoadingAreaManager=null;var IWSharedEffectRegistry=null;function IWCreateEffectRegistry() 68{if(IWSharedEffectRegistry==null) 69{IWSharedEffectRegistry=new IWEffectRegistry();} 70return IWSharedEffectRegistry;} 71function IWEffectRegistry() 72{this.mEffects=null;} 73IWEffectRegistry.prototype.registerEffects=function(effects) 74{this.mEffects=effects;} 75IWEffectRegistry.prototype.applyEffects=function() 76{var effectQueue=[];effectQueue=effectQueue.concat(this.p_generateQueueForEffectType("crop"));effectQueue=effectQueue.concat(this.p_generateQueueForEffectType("stroke"));effectQueue=effectQueue.concat(this.p_generateQueueForEffectType("reflection"));effectQueue=effectQueue.concat(this.p_generateQueueForEffectType("shadow"));this.p_applyEffectsFromQueue(effectQueue);} 77IWEffectRegistry.prototype.p_generateQueueForEffectType=function(effectType) 78{var effectQueue=[];var i=0;var effectClass=effectType+"_"+i++;while(effect=this.mEffects[effectClass]) 79{effectQueue=effectQueue.concat(this.p_generateQueueForEffectClass(effect,effectClass));effectClass=effectType+"_"+i++;} 80return effectQueue;} 81IWEffectRegistry.prototype.p_generateQueueForEffectClass=function(effect,effectClass,elementList) 82{var effectQueue=[];var elements=elementList||$$('.'+effectClass);while(elements&&elements.length>0) 83{var element=elements.shift();var children=$(element).select('.'+effectClass);if(children.length>0) 84{elements.minusArray(children);effectQueue=effectQueue.concat(this.p_generateQueueForEffectClass(effect,effectClass,children));} 85effectQueue.push({element:element,effect:effect});} 86return effectQueue;} 87var allStyleSheetsLoaded=false;var timeStyleSheetsAppearedInDOM=undefined;IWEffectRegistry.prototype.p_allStyleSheetsLoaded=function() 88{if(isCamino||isFirefox)
89{if(timeStyleSheetsAppearedInDOM!==undefined) 90{duration=(new Date().getTime())-timeStyleSheetsAppearedInDOM;if(duration>100) 91{allStyleSheetsLoaded=true;timeStyleSheetsAppearedInDOM=undefined;}} 92else if(!allStyleSheetsLoaded) 93{for(var i=0,sheetCount=document.styleSheets.length;i<sheetCount;i++) 94{var styleSheet=document.styleSheets[i];if(styleSheet.href&&styleSheet.href.indexOf("Moz.css")!=-1) 95{timeStyleSheetsAppearedInDOM=new Date().getTime();}}}} 96else 97{allStyleSheetsLoaded=true;} 98return allStyleSheetsLoaded;} 99IWEffectRegistry.prototype.p_applyEffectsFromQueue=function(queue) 100{var startTime=new Date().getTime();var duration=0;var readyToApplyEffects=this.p_allStyleSheetsLoaded();while(queue.length>0&&duration<100&&readyToApplyEffects) 101{var queueEntry=queue.shift();if(queueEntry&&queueEntry.effect&&queueEntry.element) 102{queueEntry.effect.applyToElement(queueEntry.element);} 103duration=(new Date().getTime())-startTime;} 104if(queue.length>0) 105{setTimeout(this.p_applyEffectsFromQueue.bind(this,queue),0);} 106else 107{performPostEffectsFixups();}} 108function IWChildOffset(child,parent,positionedOnly) 109{var l=0;var t=0;if(parent) 110{var current=child;while(current&¤t!=parent) 111{if(!positionedOnly||(current.style.position=="absolute")||(current.style.position=="relative")) 112{l+=current.offsetLeft;t+=current.offsetTop;} 113current=current.parentNode;}} 114return new IWPoint(l,t);} 115function IWImageExtents(ancestor,images,left,top,right,bottom) 116{var unionedBounds=new IWRect(left,top,right-left,bottom-top);for(var e=0;e<images.length;++e) 117{var imageClippedBounds=new IWRect(images[e].offsetLeft,images[e].offsetTop,images[e].offsetWidth,images[e].offsetHeight);if(ancestor) 118{var current=images[e].parentNode;while(current&¤t!=ancestor) 119{if((current.style.position=="absolute")||(current.style.position=="relative")) 120{imageClippedBounds.origin.x+=current.offsetLeft||0;imageClippedBounds.origin.y+=current.offsetTop||0;} 121var testForHidden=function(str) 122{return str=='hidden';};var clipX=[current.style.overflow,current.style.overflowX].any(testForHidden);var clipY=[current.style.overflow,current.style.overflowY].any(testForHidden);if(clipX||clipY) 123{var currentRect=new IWRect(clipX?current.offsetLeft:imageClippedBounds.origin.x,clipY?current.offsetTop:imageClippedBounds.origin.y,clipX?current.offsetWidth:imageClippedBounds.size.width,clipY?current.offsetHeight:imageClippedBounds.size.height);imageClippedBounds=imageClippedBounds.intersection(currentRect);} 124current=current.parentNode;}} 125if((imageClippedBounds.size.width>0)&&(imageClippedBounds.size.height>0)) 126{if((unionedBounds.size.width>0)&&(unionedBounds.size.height>0)) 127{unionedBounds=unionedBounds.union(imageClippedBounds);} 128else 129{unionedBounds=imageClippedBounds.clone();}}} 130var extents={left:unionedBounds.origin.x,top:unionedBounds.origin.y,right:unionedBounds.origin.x+unionedBounds.size.width,bottom:unionedBounds.origin.y+unionedBounds.size.height};return extents;} 131function IWImageChildren(element) 132{var allImgs=element.getElementsByTagName("img");var inlineRegex=new RegExp('\\b'+'inline-block'+'\\b');var badgeRegex=new RegExp('\\b'+'badge-overlay'+'\\b');var imgs=new Array();for(var e=0;e<allImgs.length;++e) 133{var current=allImgs[e];var isIgnored=(current.className.match(badgeRegex)?true:false);while(!isIgnored&¤t&¤t!=element) 134{isIgnored|=(current.className.match(inlineRegex)?true:false);current=current.parentNode;} 135if(!isIgnored) 136{imgs.push(allImgs[e]);}} 137return imgs;} 138function IWClippingNode(node) 139{if(node) 140{if(node.style&&(node.style.overflow||node.style.overflowX||node.style.overflowY)) 141{if([node.style.overflow,node.style.overflowX,node.style.overflowY].include('hidden')) 142return node;} 143else 144{return IWClippingNode(node.parentNode);}} 145return null;} 146function IWShadow(params) 147{this.mBlurRadius=params.blurRadius;this.mOffset=params.offset;this.mColor=params.color;this.mOpacity=params.opacity;} 148IWShadow.prototype.applyToElement=function(shadowed) 149{var framePos=new IWPoint(shadowed.offsetLeft,shadowed.offsetTop);var frameSize=new IWSize(shadowed.offsetWidth,shadowed.offsetHeight);var opacity=1.0;if(shadowed!=null) 150{shadowed=$(shadowed);
150opacity=shadowed.getStyle('opacity');if(windowsInternetExplorer) 151{var newRoot=shadowed.cloneNode(false);shadowed.parentNode.insertBefore(newRoot,shadowed);var shadow=document.createElement('DIV');var shadowContents=shadowed.cloneNode(true);shadow.appendChild(shadowContents);$A(shadow.getElementsByTagName('map')).each(function(mapElement){mapElement.parentNode.removeChild(mapElement);});newRoot.appendChild(shadow);newRoot.appendChild(shadowed);shadowed.style.top=0+"px";shadowed.style.left=0+"px";var blurRadius=this.mBlurRadius*0.5;var xOffset=this.mOffset.x-(this.mBlurRadius*0.6);var yOffset=this.mOffset.y-(this.mBlurRadius*0.6);shadow.style.position="absolute";shadow.style.left=(xOffset-500)+"px";shadow.style.top=(yOffset-500)+"px";shadow.style.width=(frameSize.width+1000)+"px";shadow.style.height=(frameSize.height+1000)+"px";shadowContents.style.position="absolute";shadowContents.style.left=500+"px";shadowContents.style.top=500+"px";shadowContents.style.padding="0px";shadowContents.style.margin="0px";shadow.style.filter="progid:DXImageTransform.Microsoft.MaskFilter()"+" progid:DXImageTransform.Microsoft.MaskFilter(color="+this.mColor+")"+" progid:DXImageTransform.Microsoft.Alpha(opacity="+this.mOpacity*opacity*100+")"+" progid:DXImageTransform.Microsoft.Blur(pixelradius="+blurRadius+")";if(newRoot.className.indexOf("inline-block")!=-1) 152{var rootTop=newRoot.style.top;var rootMarginTop=newRoot.style.marginTop;if(rootTop&&!rootMarginTop) 153{rootTop=(toPixelsAtElement(newRoot,rootTop,true));newRoot.style.marginTop=-rootTop+"px";} 154else if(!rootTop&&rootMarginTop) 155{rootMarginTop=(toPixelsAtElement(newRoot,rootMarginTop,true));newRoot.style.rootTop=-rootMarginTop+"px";} 156else if(rootTop&&rootMarginTop) 157{rootTop=(toPixelsAtElement(newRoot,rootTop,true));rootMarginTop=(toPixelsAtElement(newRoot,rootMarginTop,true));if(rootTop!=rootMarginTop) 158{newRoot.style.rootTop=-rootMarginTop+"px";}}} 159if(shadowed.offsetTop!=0) 160{var top=shadowed.style.top;top=top?(toPixelsAtElement(shadowed,top,true)):0;top-=shadowed.offsetTop;shadowed.style.top=top+"px";}} 161else 162{var sourceImgs=IWImageChildren(shadowed);var extents=IWImageExtents(shadowed,sourceImgs,0,0,frameSize.width,frameSize.height);var canvas=undefined;if(shadowed.sandwich&&shadowed.sandwich.canvas) 163{canvas=shadowed.sandwich.canvas;} 164extents.left-=Math.max(this.mBlurRadius-this.mOffset.x,0);extents.top-=Math.max(this.mBlurRadius-this.mOffset.y,0);extents.right+=Math.max(this.mBlurRadius+this.mOffset.x,0);extents.bottom+=Math.max(this.mBlurRadius+this.mOffset.y,0);extents.left=Math.floor(extents.left);extents.top=Math.floor(extents.top);extents.right=Math.ceil(extents.right);extents.bottom=Math.ceil(extents.bottom);var leftOffset=extents.left;var topOffset=extents.top;extents.right-=extents.left;extents.bottom-=extents.top;extents.left=0;extents.top=0;var width=extents.right-extents.left;var height=extents.bottom-extents.top;if(canvas===undefined) 165{canvas=document.createElement("canvas");} 166var context=canvas.getContext?canvas.getContext("2d"):null;var canvasCanDrawShadow=context?context.shadowColor:false;if(canvasCanDrawShadow) 167{canvas.setAttribute("width",width);canvas.setAttribute("height",height);canvas.style.position="absolute";canvas.style.top=topOffset+"px";canvas.style.left=leftOffset+"px";var workingCanvas=undefined;if(shadowed.sandwich&&shadowed.sandwich.workingCanvas) 168{workingCanvas=shadowed.sandwich.workingCanvas;} 169if(workingCanvas===undefined) 170{workingCanvas=canvas.cloneNode(false);} 171var self=this;var sandwich=shadowed.sandwich||{};sandwich.loadedImgs=[];sandwich.imgCount=sourceImgs.length;sandwich.loadedImgCount=0;sandwich.canvas=canvas;sandwich.workingCanvas=workingCanvas;shadowed.sandwich=sandwich;sandwich.onImageLoad=function(j,img,image) 172{var offset=IWChildOffset(img,shadowed,true);this.loadedImgs[j]={imgObject:image.imgObject(),left:offset.x-leftOffset,top:offset.y-topOffset,width:img.offsetWidth,height:img.offsetHeight};this.loadedImgCount++;
172if(this.loadedImgCount==this.imgCount) 173{this.renderShadow()}} 174sandwich.renderShadow=function() 175{if(canvas.parentNode===null) 176{shadowed.insertBefore(canvas,shadowed.firstChild);} 177canvas.parentNode.insertBefore(workingCanvas,canvas);var context=workingCanvas.getContext("2d");new IWRect(0,0,width,height).clear(context);var bgImage=shadowed.getStyle('background-image');var hasBGImage=bgImage&&bgImage.indexOf('url(')==0;var bgColor=shadowed.getStyle('background-color');var alphaComponent=self.p_alphaComponent(bgColor);IWAssert(function(){return alphaComponent==0||alphaComponent==1},"alpha must be 0 or 1 for background color if shadow is applied");var fillBackground=(hasBGImage||alphaComponent>0);var divBounds=new IWRect(-leftOffset,-topOffset,frameSize.width,frameSize.height).round();if(fillBackground) 178{context.fillStyle='rgba(0,0,0,1)';divBounds.fill(context);} 179for(var k=0;k<this.loadedImgs.length;++k) 180{var loadedImg=this.loadedImgs[k];var clipper=IWClippingNode(sourceImgs[k]);if(nodeIsChildOf(clipper,shadowed)) 181{var clipToShadow=IWChildOffset(clipper,shadowed,true);context.save();context.rect(clipToShadow.x-leftOffset,clipToShadow.y-topOffset,clipper.offsetWidth,clipper.offsetHeight);context.clip();context.drawImage(loadedImg.imgObject,loadedImg.left,loadedImg.top,loadedImg.width,loadedImg.height);context.restore();} 182else 183{context.drawImage(loadedImg.imgObject,loadedImg.left,loadedImg.top,loadedImg.width,loadedImg.height);}} 184context=canvas.getContext("2d");new IWRect(0,0,width,height).clear(context);var drawImageUnshadowed=true;context.globalAlpha=opacity;if(context.shadowColor) 185{var usingShadowAlpha=true;context.save();usingShadowAlpha=!(isWebKit&&isEarlyWebKitVersion);if(usingShadowAlpha) 186{var components=self.mColor.toLowerCase().match(/#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/);if(components&&components.length>=4) 187{context.shadowColor="rgba("+parseInt(components[1],16)+", "+parseInt(components[2],16)+", "+parseInt(components[3],16)+", "+self.mOpacity+")";} 188else 189{components=self.mColor.match(/rgb\(([0-9\.]+),[ ]*([0-9\.]+),[ ]*([0-9\.]+)\)/);if(components&&components.length>=4) 190{context.shadowColor="rgba("+components[1]+", "+components[2]+", "+components[3]+", "+self.mOpacity+")";} 191else 192{iWLog("not using shadow alpha, failed to match "+self.mColor);usingShadowAlpha=false;}}} 193if(usingShadowAlpha==false) 194{context.globalAlpha*=self.mOpacity;context.shadowColor=self.mColor;} 195context.shadowBlur=self.mBlurRadius;context.shadowOffsetX=self.mOffset.x;context.shadowOffsetY=self.mOffset.y;context.drawImage(workingCanvas,0,0);context.restore();if(usingShadowAlpha==false) 196{drawImageUnshadowed=self.mOpacity<1.0;} 197else 198{drawImageUnshadowed=false;}} 199if(drawImageUnshadowed) 200{context.drawImage(workingCanvas,0,0);} 201if(fillBackground) 202{divBounds.clear(context);context.save();context.globalAlpha=opacity;context.rect(divBounds.origin.x,divBounds.origin.y,divBounds.size.width,divBounds.size.height);context.clip();for(var k=0;k<this.loadedImgs.length;++k) 203{var loadedImg=this.loadedImgs[k];context.drawImage(loadedImg.imgObject,loadedImg.left,loadedImg.top,loadedImg.width,loadedImg.height);} 204context.restore();} 205if(workingCanvas.parentNode) 206{workingCanvas.parentNode.removeChild(workingCanvas);delete this.workingCanvas;this.workingCanvas=null;} 207for(var j=0;j<sourceImgs.length;++j) 208{sourceImgs[j].style.opacity=0.0;}};if(sourceImgs.length>0) 209{for(var j=0;j<sourceImgs.length;++j) 210{var img=sourceImgs[j];var image=IWCreateImage(img.src);image.load(sandwich.onImageLoad.bind(sandwich,j,img,image));}} 211else 212{sandwich.renderShadow();} 213workingCanvas.style.visibility="hidden";}}}} 214IWShadow.prototype.p_alphaComponent=function(color) 215{var alpha=1.0;if(color&&color.indexOf('rgba(')!=-1) 216{if(color.match(/rgba\((?:\s*\S+\s*,\s*){3}(\S+)\s*\)/)) 217{alpha=RegExp.$1;}} 218return alpha;} 219function IWReflection(parameters) 220{this.mOpacity=parameters.opacity;this.mOffset=Math.max(parameters.offset,1);this.mFadeSustain=0.4;this.mMaxSustain=120;} 221IWReflection.prototype.applyToElement=function(div) 222{var bounds=new IWRect(div.offsetLeft,div.offsetTop,div.offsetWidth,div.offsetHeight);var reflectionHeight=Math.min(div.offsetHeight*this.mFadeSustain,this.mMaxSustain)*0.75;if(div!=null) 223{var imgs=IWImageChildren(div);var extents=IWImageExtents(div,imgs,0,0,bounds.size.width,bounds.size.height);var leftOffset=extents.left;var topOffset=extents.top;var bottomOffset=extents.bottom-extents.top-bounds.size.height;if(windowsInternetExplorer) 224{var reflection=document.createElement("div");var cloned=div.cloneNode(true);reflection.appendChild(cloned);reflection.style.position="absolute";reflection.style.left=extents.left+"px";reflection.style.top=bounds.size.height+"px";reflection.style.marginTop=this.mOffset+"px";reflection.style.width=(extents.right-extents.left)+"px";reflection.style.height=(extents.bottom-extents.top)+"px";reflection.className+=" IWReflection ";cloned.style.left=-extents.left+"px";cloned.style.top=-extents.top+"px";cloned.style.position="absolute";cloned.className=cloned.className.replace(/(shadow_\d+)/g,'');var finishy=reflectionHeight/div.offsetHeight*100;reflection.style.filter='flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(this.mOpacity*100)+', style=1, finishOpacity=0, startx=0, start
224y='+0+', finishx=0, finishy='+finishy+')';div.insertBefore(reflection,div.firstChild);} 225else 226{var reflection=document.createElement("canvas");extents.right-=extents.left;extents.bottom-=extents.top;extents.left=0;extents.top=0;reflection.setAttribute("width",extents.right-extents.left);reflection.setAttribute("height",reflectionHeight+this.mOffset/2);reflection.style.position="absolute";reflection.style.top=bounds.size.height+"px";reflection.style.marginTop=this.mOffset+"px";reflection.style.left=leftOffset+"px";div.insertBefore(reflection,div.firstChild);var context=reflection.getContext("2d");context.clearRect(0,0,reflection.width,reflection.height);var sandwich={};sandwich.loadedImgs=[];sandwich.imgCount=imgs.length;var self=this;sandwich.onImageLoad=function(j,img,image) 227{var offset=IWChildOffset(img,div,true);this.loadedImgs[j]={imgObject:image.imgObject(),left:offset.x-leftOffset,top:offset.y-topOffset-bottomOffset,width:img.offsetWidth,height:img.offsetHeight};var allImagesLoaded=false;if(this.loadedImgs.length>=this.imgCount) 228{allImagesLoaded=true;for(var k=0;allImagesLoaded&&k<this.loadedImgs.length;++k) 229{if(this.loadedImgs[k]===undefined) 230{allImagesLoaded=false;}}} 231if(allImagesLoaded) 232{context.save();context.translate(0,bounds.size.height-1);context.scale(1,-1);for(var k=0;k<this.loadedImgs.length;++k) 233{var loadedImg=this.loadedImgs[k];var clipper=IWClippingNode(imgs[k]);if(nodeIsChildOf(clipper,div)) 234{var clipOffset=IWChildOffset(clipper,div,true);context.save();context.rect(clipOffset.x-leftOffset,clipOffset.y-topOffset-bottomOffset,clipper.offsetWidth,clipper.offsetHeight);context.clip();context.drawImage(loadedImg.imgObject,loadedImg.left,loadedImg.top,loadedImg.width,loadedImg.height);context.restore();} 235else 236{context.drawImage(loadedImg.imgObject,loadedImg.left,loadedImg.top,loadedImg.width,loadedImg.height);}} 237context.restore();context.save();context.globalCompositeOperation="destination-out";var gradient=context.createLinearGradient(0,0,0,reflection.height);gradient.addColorStop(1,"rgba(255, 255, 255, 1.0)");gradient.addColorStop(0,"rgba(255, 255, 255, "+(1-self.mOpacity)+")");context.fillStyle=gradient;if(navigator.appVersion.indexOf('WebKit')!=-1) 238{context.rect(0,0,reflection.width,reflection.height*2);context.fill();} 239else 240{context.fillRect(0,0,reflection.width,reflection.height*2);} 241context.restore();}};for(var j=0;j<imgs.length;++j) 242{var img=imgs[j];var image=IWCreateImage(img.src);image.load(sandwich.onImageLoad.bind(sandwich,j,img,image));}}}} 243function IWStrokeParts(strokeParts,maxImageSize,shouldClip,strokeWidth) 244{this.mStrokeParts=strokeParts;this.mMaxImageSize=maxImageSize;this.mShouldClip=shouldClip;if(shouldClip) 245{this.mStrokeWidth=strokeWidth;}} 246var kLeft=0,kTopLeft=1,kTop=2,kTopRight=3,kRight=4,kBottomRight=5,kBottom=6,kBottomLeft=7,kPartCount=8;IWStrokeParts.prototype.p_imageLayout=function(imageSize) 247{var strokeParts=this.mStrokeParts;var hDelta=this.mMaxImageSize.width-imageSize.width;var vDelta=this.mMaxImageSize.height-imageSize.height;var topLeft=strokeParts[kTopLeft].rect;var topRight=strokeParts[kTopRight].rect.offset(-hDelta,0);var bottomRight=strokeParts[kBottomRight].rect.offset(-hDelta,-vDelta);var bottomLeft=strokeParts[kBottomLeft].rect.offset(0,-vDelta);var top=strokeParts[kTop].rect;top.size.width=topRight.origin.x-top.origin.x;var right=strokeParts[kRight].rect.offset(-hDelta,0);right.size.height=bottomRight.origin.y-right.origin.y;var bottom=strokeParts[kBottom].rect.offset(0,-vDelta);bottom.size.width=bottomRight.origin.x-bottom.origin.x;var left=strokeParts[kLeft].rect;left.size.height=bottomLeft.origin.y-left.origin.y;return[left,topLeft,top,topRight,right,bottomRight,bottom,bottomLeft];} 248IWStrokeParts.prototype.p_imageMarkup=function(imageSize,zIndex) 249{var markup='';var layoutRects=this.p_imageLayout(imageSize);for(var index=kLeft;index<kPartCount;++index) 250{var style=layoutRects[index].position();if(zIndex) 251{style+='z-index: '+zIndex+';';} 252markup+=imgMarkup(this.mStrokeParts[index].url,style);} 253return markup;} 254IWStrokeParts.prototype.markupForImageStreamEntry=function(imageStreamEntry,imageSize) 255{var rect=new IWRect(0,0,imageSize.width,imageSize.height);var clippingDivPre='';var clippingDivPost='';var thumbRect=rect.clone();if(this.mShouldClip) 256{var left=(this.mStrokeWidth/2+1);var top=(this.mStrokeWidth/2+1);var clippingRect=new IWRect(left,top,(imageSize.width-this.mStrokeWidth-2),(imageSize.height-this.mStrokeWidth-2));clippingDivPre='<div style="overflow: hidden; '+clippingRect.position()+'">';clippingDivPost='</div>';thumbRect.origin.x-=left;thumbRect.origin.y-=top;} 257var markup='<div class="framedImage" style="'+rect.position()+'">';markup+=clippingDivPre;markup+=imageStreamEntry.thumbnailMarkupForRect(thumbRect);markup+=clippingDivPost;markup+=this.p_imageMarkup(imageSize,2);markup+='</div>';return markup;} 258IWStrokeParts.prototype.applyToElement=function(div) 259{if(div!=null) 260{var size=new IWSize(div.offsetWidth,div.offsetHeight);$(div).appendChildrenFromMarkup(this.p_imageMarkup(size));if(div.className.indexOf("flowDefining")<0) 261{if(div.style.position!='absolute') 262{var divRect=new IWRect(0,0,div.offsetWidth,div.offsetHeight);var unionRect=IWZeroRect();var layoutRects=this.p_imageLayout(size);layoutRects.each(function(r) 263{unionRect=unionRect.union(r);});var padding=divRect.paddingToRect(unionRect);var marginLeft=Element.getStyle(div,"marginLeft");marginLeft=marginLeft?(toPixelsAtElement(div,marginLeft,false)):0;var marginTop=Element.getStyle(div,"marginTop");marginTop=marginTop?(toPixelsAtElement(div,marginTop,true)):0;var marginRight=Element.getStyle(div,"marginRight");marginRight=marginRight?(toPixelsAtElement(div,marginRight,false)):0;var marginBottom=Element.getStyle(div,"marginBottom");marginBottom=marginBottom?(toPixelsAtElement(div,marginBottom,true)):0;detectBrowser();if(windowsInternetExplorer) 264{div.style.marginLeft=px(Math.max(0,padding.left-1)+marginLeft);div.style.marginTop=px(Math.max(0,padding.top-1)+marginTop);div.style.marginRight=px(Math.max(0,padding.right-1)+marginRight);div.style.marginBottom=px(Math.max(0,padding.bottom-1)+marginBottom);if(browserVersion==7) 265{updateListOfIE7FloatsFix(div);}} 266else 267{div.style.marginLeft=px(padding.left+marginLeft);div.style.marginTop=px(padding.top+marginTop);div.style.marginRight=px(padding.right+marginRight);div.style.marginBottom=px(padding.bottom+marginBottom);}}}}} 268IWStrokeParts.prototype.strokeExtra=function(imageSize) 269{if(!imageSize) 270{imageSize=this.mMaxImageSize;} 271rect=new IWRect(IWZeroPoint(),imageSize);var layout=this.p_imageLayout(rect.size);var unionRect=IWZeroRect();layout.each(function(r) 272{unionRect=unionRect.union(r);});return rect.paddingToRect(unionRect);} 273function IWStroke(strokeURL,strokeRect,maxImageSize) 274{this.mStrokeURL=strokeURL;this.mStrokeRect=strokeRect;this.mMaxImageSize=maxImageSize;} 275IWStroke.prototype.p_strokeRect=function(imageSize) 276{var hScale=imageSize.width/this.mMaxImageSize.width;var vScale=imageSize.height/this.mMaxImageSize.height;var strokeRect=this.mStrokeRect.scale(hScale,vScale,true);return strokeRect;} 277IWStroke.prototype.p_imageMarkup=function(imageSize,zIndex) 278{var style=this.p_strokeRect(imageSize).position();if(zIndex) 279{style+='z-index: '+zIndex+';';} 280return imgMarkup(this.mStrokeURL,style);} 281IWStroke.prototype.markupForImageStreamEntry=function(imageStreamEntry,imageSize) 282{var rect=new IWRect(0,0,imageSize.width,imageSize.height);var markup='<div class="framedImage" style="'+rect.position()+'">';markup+=imageStreamEntry.thumbnailMarkupForRect(rect);markup+=this.p_imageMarkup(imageSize,2);markup+='</div>';return markup;} 283IWStroke.prototype.applyToElement=function(div) 284{if(div!=null) 285{var size=new IWSize(div.offsetWidth,div.offsetHeight);$(div).appendChildrenFromMarkup(this.p_imageMarkup(size));if(div.className.indexOf("flowDefining")<0) 286{if(div.style.position!='absolute') 287{var divRect=new IWRect(0,0,div.offsetWidth,div.offsetHeight);var padding=divRect.paddingToRect(this.mStrokeRect);var marginLeft=Element.getStyle(div,"marginLeft");marginLeft=marginLeft?(toPixelsAtElement(div,marginLeft,false)):0;var marginTop=Element.getStyle(div,"marginTop");marginTop=marginTop?(toPixelsAtElement(div,marginTop,true)):0;var marginRight=Element.getStyle(div,"marginRight");marginRight=marginRight?(toPixelsAtElement(div,marginRight,false)):0;var marginBottom=Element.getStyle(div,"marginBottom");marginBottom=marginBottom?(toPixelsAtElement(div,marginBottom,true)):0;div.style.marginLeft=px(padding.left+marginLeft);div.style.marginTop=px(padding.top+marginTop);div.style.marginRight=px(padding.right+marginRight);div.style.marginBottom=px(padding.bottom+marginBottom);detectBrowser();if(windowsInternetExplorer&&browserVersion==7) 288{updateListOfIE7FloatsFix(div);}}}}} 289IWStroke.prototype.strokeExtra=function(imageSize) 290{if(imageSize===undefined) 291{imageSize=this.mMaxImageSize;} 292var imageRect=new IWRect(IWZeroPoint(),imageSize);return imageRect.paddingToRect(this.p_strokeRect(imageSize));} 293function IWEmptyStroke() 294{} 295IWEmptyStroke.prototype.markupForImageStreamEntry=function(imageStreamEntry,imageSize) 296{var rect=new IWRect(0,0,imageSize.width,imageSize.height);var markup='<div class="framedImage" style="'+rect.position()+'">';markup+=imageStreamEntry.thumbnailMarkupForRect(rect);markup+='</div>';return markup;} 297IWEmptyStroke.prototype.applyToElement=function(div) 298{} 299IWEmptyStroke.prototype.strokeExtra=function() 300{return new IWPadding(0,0,0,0);}
301var kSFRFrameTopLeft=0;var kSFRFrameTop=1;var kSFRFrameTopRight=2;var kSFRFrameRight=3;var kSFRFrameBottomRight=4;var kSFRFrameBottom=5;var kSFRFrameBottomLeft=6;var kSFRFrameLeft=7;var kSFRFrameClip=0;var kSFRFrameStretchEvenly=1;var kSFRFrameStretchToFit=2;function IWPhotoFrame(images,maskImages,tilingMode,assetScale,leftInset,topInset,rightInset,bottomInset,unscaledLeftWidth,unscaledTopHeight,unscaledRightWidth,unscaledBottomHeight,leftTileHeight,topTileWidth,rightTileHeight,bottomTileWidth,adornmentURL,adornmentPosition,adornmentSize,minimumAssetScale) 302{this.mImages=images;this.mMaskImages=maskImages;this.mTilingMode=tilingMode;this.mLeftInset=leftInset;this.mTopInset=topInset;this.mRightInset=rightInset;this.mBottomInset=bottomInset;this.mUnscaledLeftWidth=unscaledLeftWidth;this.mUnscaledTopHeight=unscaledTopHeight;this.mUnscaledRightWidth=unscaledRightWidth;this.mUnscaledBottomHeight=unscaledBottomHeight;this.mLeftTileHeight=leftTileHeight;this.mTopTileWidth=topTileWidth;this.mRightTileHeight=rightTileHeight;this.mBottomTileWidth=bottomTileWidth;this.mAdornmentURL=adornmentURL;this.mAdornmentPosition=adornmentPosition;this.mAdornmentSize=adornmentSize;this.mMinimumAssetScale=minimumAssetScale;this.setAssetScale(assetScale);} 303IWPhotoFrame.prototype.setAssetScale=function(assetScale) 304{assetScale=Math.min(assetScale,1.0);assetScale=Math.max(this.mMinimumAssetScale,assetScale);this.mAssetScale=assetScale;this.mLeftWidth=this.scaledValue(this.mUnscaledLeftWidth);this.mTopHeight=this.scaledValue(this.mUnscaledTopHeight);this.mRightWidth=this.scaledValue(this.mUnscaledRightWidth);this.mBottomHeight=this.scaledValue(this.mUnscaledBottomHeight);} 305IWPhotoFrame.prototype.scaledValue=function(valueToScale) 306{return Math.ceil(valueToScale*this.mAssetScale);} 307IWPhotoFrame.prototype.markupForImageStreamEntry=function(imageStreamEntry,size) 308{var oldAssetScale=this.mAssetScale;var maximumScale=this.maximumAssetScaleForImageSize(size);if((maximumScale<oldAssetScale)&&(maximumScale>=this.mMinimumAssetScale)) 309{this.setAssetScale(maximumScale);} 310var coverageRect=this.coverageRect(new IWRect(0,0,size.width,size.height));var imageRect=new IWRect(-coverageRect.origin.x,-coverageRect.origin.y,size.width,size.height);coverageRect=coverageRect.offsetToOrigin();var markup='<div class="framedImage" style="'+coverageRect.position()+'">';markup+=imageStreamEntry.thumbnailMarkupForRect(imageRect);if(maximumScale>=this.mMinimumAssetScale) 311{if(this.mImages!=null) 312{markup+=this.p_buildFrame(this.mImages,coverageRect.size,2);} 313if(this.mAdornmentURL!=null) 314{markup+=this.p_adornmentMarkupForRect(imageRect,2);} 315if(this.mMaskImages) 316{}} 317markup+='</div>';if(oldAssetScale!=this.mAssetScale)this.setAssetScale(oldAssetScale);return markup;} 318IWPhotoFrame.prototype.strokeExtra=function() 319{var adornmentExtraTopMargin=0;if(this.mAdornmentURL) 320{adornmentExtraTopMargin=Math.max(0,(this.scaledValue(this.mAdornmentSize.height)-this.mTopHeight)/2.0-this.mAdornmentPosition.y);} 321return new IWPadding(this.mLeftWidth-this.scaledValue(this.mLeftInset),this.mTopHeight-this.scaledValue(this.mTopInset)+adornmentExtraTopMargin,this.mRightWidth-this.scaledValue(this.mRightInset),this.mBottomHeight-this.scaledValue(this.mBottomInset));} 322IWPhotoFrame.prototype.applyToElement=function(div) 323{if(div!=null) 324{var markup='';var divRect=new IWRect(0,0,div.offsetWidth,div.offsetHeight);if((divRect.size.width>=(this.scaledValue(this.mLeftInset)+this.scaledValue(this.mRightInset)))&&(divRect.size.height>=(this.scaledValue(this.mTopInset)+this.scaledValue(this.mTopInset)))) 325{if(this.mImages!=null) 326{var coverageRect=this.coverageRect(divRect);var containerRect=new IWRect(coverageRect.origin.x,coverageRect.origin.y,0,0);markup+='<div style="'+containerRect.position()+'">';markup+=this.p_buildFrame(this.mImages,coverageRect.size);markup+='</div>';} 327if(this.mAdornmentURL!=null) 328{markup+=this.p_adornmentMarkupForRect(divRect);}} 329$(div).appendChildrenFromMarkup(markup);if(div.className.indexOf("flowDefining")<0) 330{if(div.style.position!='absolute') 331{var frameExtra=this.strokeExtra();var marginLeft=Element.getStyle(div,"marginLeft");marginLeft=marginLeft?(toPixelsAtElement(div,marginLeft,false)):0;var marginTop=Element.getStyle(div,"marginTop");marginTop=marginTop?(toPixelsAtElement(div,marginTop,true)):0;var marginRight=Element.getStyle(div,"marginRight");marginRight=marginRight?(toPixelsAtElement(div,marginRight,false)):0;var marginBottom=Element.getStyle(div,"marginBottom");marginBottom=marginBottom?(toPixelsAtElement(div,marginBottom,true)):0;div.style.marginLeft=px(frameExtra.left+marginLeft);div.style.marginTop=px(frameExtra.top+marginTop);div.style.marginRight=px(frameExtra.right+marginRight);div.style.marginBottom=px(frameExtra.bottom+marginBottom);detectBrowser();if(windowsInternetExplorer&&browserVersion==7) 332{updateListOfIE7FloatsFix(div);}}}}} 333IWPhotoFrame.prototype.maximumAssetScaleForImageSize=function(in_imgSize) 334{var maxScale=1;if((in_imgSize.width>this.mLeftInset+this.mRightInset)&&(in_imgSize.height>this.mTopInset+this.mBottomInset)) 335{maxScale=1;} 336else if((in_imgSize.width<Math.ceil(this.mLeftInset*this.mMinimumAssetScale)+Math.ceil(this.mRightInset*this.mMinimumAssetScale))||(in_imgSize.height<Math.ceil(this.mTopInset*this.mMinimumAssetScale)+Math.ceil(this.mBottomInset*this.mMinimumAssetScale))) 337{maxScale=0;} 338else 339{var maxWidthScale=1;var floatEpsilon=0.0000001;if(((this.mLeftInset+this.mRightInset)>=in_imgSize.width)&&((this.mLeftInset+this.mRightInset)>0)) 340{var leftChunkRatio=Math.floor(this.mLeftInset/(this.mLeftInset+this.mRightInset)*in_imgSize.width)/this.mLeftInset;var rightChunkRatio=Math.floor(this.mRightInset/(this.mLeftInset+this.mRightInset)*in_imgSize.width)/this.mRightInset;leftChunkRatio-=floatEpsilon;rightChunkRatio-=floatEpsilon;maxWidthScale=Math.max(leftChunkRatio,rightChunkRatio);if(in_imgSize.width<(Math.ceil(this.mLeftInset*maxWidthScale)+Math.ceil(this.mRightInset*maxWidthScale))) 341{maxWidthScale=Math.min(leftChunkRatio,rightChunkRatio);} 342if((maxWidthScale<this.mMinimumAssetScale)||in_imgSize.width<(Math.ceil(this.mLeftInset*maxWidthScale)+Math.ceil(this.mRightInset*maxWidthScale))) 343{maxWidthScale=this.mMinimumAssetScale;}} 344var maxHeightScale=1;if(((this.mTopInset+this.mBottomInset)>=in_imgSize.height)&&((this.mTopInset+this.mBottomInset)>0)) 345{var topChunkRatio=Math.floor(this.mTopInset/(this.mTopInset+this.mBottomInset)*in_imgSize.height)/this.mTopInset;var bottomChunkRatio=Math.floor(this.mBottomInset/(this.mTopInset+this.mBottomInset)*in_imgSize.height)/this.mBottomInset;topChunkRatio-=floatEpsilon;bottomChunkRatio-=floatEpsilon;maxHeightScale=Math.max(topChunkRatio,bottomChunkRatio);if(in_imgSize.height<(Math.ceil(this.mTopInset*maxHeightScale)+Math.ceil(this.mBottomInset*maxHeightScale))) 346{maxHeightScale=Math.min(topChunkRatio,bottomChunkRatio);} 347if((maxHeightScale<this.mMinimumAssetScale)||in_imgSize.height<(Math.ceil(this.mTopInset*maxHeightScale)+Math.ceil(this.mBottomInset*maxHeightScale))) 348{maxHeightScale=this.mMinimumAssetScale;}} 349maxScale=Math.min(maxWidthScale,maxHeightScale);} 350return maxScale;} 351IWPhotoFrame.prototype.coverageRect=function(rect) 352{var left=rect.origin.x+this.scaledValue(this.mLeftInset);var top=rect.origin.y+this.scaledValue(this.mTopInset);var right=rect.maxX()-this.scaledValue(this.mRightInset);var bottom=rect.maxY()-this.scaledValue(this.mBottomInset);left-=this.mLeftWidth;right+=this.mRightWidth;top-=this.mTopHeight;bottom+=this.mBottomHeight;return(new IWRect(left,top,right-left,bottom-top)).round();} 353IWPhotoFrame.prototype.p_buildFrame=function(images,size,zIndex) 354{var width=size.width;var height=size.height;var startX=this.mLeftWidth;var endX=width-this.mRightWidth;var startY=this.mTopHeight;var endY=height-this.mBottomHeight;var markup="";var zIndexStyle=zIndex?('z-index: '+zIndex+';'):'';
354if((startX<=endX+1)&&(startY<=endY+1)) 355{var imageRect=new IWRect(0.0,0.0,this.mLeftWidth,this.mTopHeight);markup=imgMarkup(images[kSFRFrameTopLeft].sourceURL(),imageRect.position()+zIndexStyle);imageRect=new IWRect(0.0,(height-this.mBottomHeight),this.mLeftWidth,this.mBottomHeight);markup+=imgMarkup(images[kSFRFrameBottomLeft].sourceURL(),imageRect.position()+zIndexStyle);imageRect=new IWRect((width-this.mRightWidth),0.0,this.mRightWidth,this.mTopHeight);markup+=imgMarkup(images[kSFRFrameTopRight].sourceURL(),imageRect.position()+zIndexStyle);imageRect=new IWRect((width-this.mRightWidth),(height-this.mBottomHeight),this.mRightWidth,this.mBottomHeight);markup+=imgMarkup(images[kSFRFrameBottomRight].sourceURL(),imageRect.position()+zIndexStyle);var naturalSize=new IWSize(this.mLeftWidth,this.scaledValue(this.mLeftTileHeight));imageRect=new IWRect(0.0,startY,naturalSize.width,naturalSize.height);markup+=this.p_tiles(images[kSFRFrameLeft].sourceURL(),imageRect,startY,endY,true,zIndex);naturalSize=new IWSize(this.mRightWidth,this.scaledValue(this.mRightTileHeight));imageRect=new IWRect(width-this.mRightWidth,startY,naturalSize.width,naturalSize.height);markup+=this.p_tiles(images[kSFRFrameRight].sourceURL(),imageRect,startY,endY,true,zIndex);naturalSize=new IWSize(this.scaledValue(this.mTopTileWidth),this.mTopHeight);imageRect=new IWRect(startX,0.0,naturalSize.width,naturalSize.height);markup+=this.p_tiles(images[kSFRFrameTop].sourceURL(),imageRect,startX,endX,false,zIndex);naturalSize=new IWSize(this.scaledValue(this.mBottomTileWidth),this.mBottomHeight);imageRect=new IWRect(startX,height-this.mBottomHeight,naturalSize.width,naturalSize.height);markup+=this.p_tiles(images[kSFRFrameBottom].sourceURL(),imageRect,startX,endX,false,zIndex);} 356return markup;} 357IWPhotoFrame.prototype.p_adornmentRectForRect=function(rect) 358{var adornmentCenter=new IWPoint();rect=this.coverageRect(rect);adornmentCenter.x=(rect.size.width-(this.mLeftWidth+this.mRightWidth))*this.mAdornmentPosition.x;adornmentCenter.x+=rect.origin.x+this.mLeftWidth;adornmentCenter.y=this.mTopHeight/2.0+(rect.origin.y+this.mAdornmentPosition.y);var scaledAdornmentSize=new IWSize(this.scaledValue(this.mAdornmentSize.width),this.scaledValue(this.mAdornmentSize.height));var adornmentOrigin=new IWPoint(adornmentCenter.x-(scaledAdornmentSize.width/2.0),adornmentCenter.y-(scaledAdornmentSize.height/2.0));var adornmentRect=new IWRect(adornmentOrigin,scaledAdornmentSize);return adornmentRect;} 359IWPhotoFrame.prototype.p_adornmentMarkupForRect=function(rect,zIndex) 360{var zIndexStyle=zIndex?('z-index: '+zIndex+';'):'';return imgMarkup(this.mAdornmentURL,this.p_adornmentRectForRect(rect).position()+zIndexStyle);} 361IWPhotoFrame.prototype.p_tiles=function(imageURL,imageRect,start,end,vertical,zIndex) 362{var markup="";if(start<end) 363{var zIndexStyle=zIndex?('z-index: '+zIndex+';'):'';var tileRect=imageRect.clone();var tilingMode=this.mTilingMode;if(vertical) 364{tileRect.size.height=Math.ceil(end-start);if(imageRect.size.height==1) 365{tilingMode=kSFRFrameStretchToFit;}} 366else 367{tileRect.size.width=Math.ceil(end-start);if(imageRect.size.width==1) 368{tilingMode=kSFRFrameStretchToFit;}} 369if(tilingMode==kSFRFrameStretchToFit) 370{markup+=imgMarkup(imageURL,tileRect.position()+zIndexStyle);} 371else 372{var naturalSize=imageRect.size;var offset=(vertical?naturalSize.height:naturalSize.width);var maxTiles=Math.ceil((end-start)/offset);if(offset<5||maxTiles>20) 373{IWAssert(function(){return true},"Please remove this assert and the surrouding block.");iWLog("Too many frame image tiles are getting generated. Performance may be affected.");} 374if(tilingMode==kSFRFrameStretchEvenly) 375{offset=(end-start)/maxTiles;if(vertical) 376{imageRect.size.height=offset;} 377else 378{imageRect.size.width=offset;}} 379else if(tilingMode==kSFRFrameClip) 380{markup+='<div style="'+tileRect.position()+'overflow: hidden; ">';imageRect.origin.x=0;imageRect.origin.y=0;} 381for(var i=0;i<maxTiles;++i) 382{var left=Math.round(imageRect.origin.x);var right=Math.round(imageRect.origin.x+imageRect.size.width);var top=Math.round(imageRect.origin.y);var bottom=Math.round(imageRect.origin.y+imageRect.size.height);var roundedRect=new IWRect(left,top,(right-left),(bottom-top));markup+=imgMarkup(imageURL,roundedRect.position()+zIndexStyle);if(vertical) 383{imageRect=imageRect.offset(0.0,offset);} 384else 385{imageRect=imageRect.offset(offset,0.0);}} 386if(tilingMode==kSFRFrameClip) 387{markup+="</div>";}}} 388return markup;}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.