// // iWeb - iWebImage.js // Copyright 2007 Apple Inc. // All rights reserved. // var IWAllImages={};var IWAllImageObjects={};function IWCreateImage(url) {var image=IWAllImages[url];if(image==null) {image=new IWImage(url);} return image;} var IWNamedImages={};function IWImageNamed(name) {var image=null;var url=IWNamedImages[name];if(url) {image=IWCreateImage(url);} return image;} function IWRegisterNamedImage(name,url) {IWNamedImages[name]=url;} function IWImage(url) {if(IWAllImages.hasOwnProperty(url)) {iWLog("warning -- use IWCreateImage rather than new IWImage and you'll get better performance");} this.mPreventUnloading=0;this.mLoading=false;this.mLoaded=false;this.mURL=url;this.mCallbacks=[];IWAllImages[url]=this;} IWImage.prototype.sourceURL=function() {return this.mURL;} IWImage.prototype.loaded=function() {return this.mLoaded;} IWImage.prototype.load=function(callback,delayCallbackIfLoaded) {if(this.mLoaded) {if(callback!=null) {delayCallbackIfLoaded?setTimeout(callback,0):callback();}} else {if(callback!=null) {this.mCallbacks.push(callback);} if(this.mLoading==false) {this.mLoading=true;var img=new Image();IWAllImageObjects[this.sourceURL()]=img;img.onload=this.p_onload.bind(this);img.src=this.mURL;}}} detectBrowser();var IWImageEnableUnload=isiPhone;IWImage.prototype.unload=function(evenIfNotEnabled) {if((evenIfNotEnabled||IWImageEnableUnload)&&this.mLoaded) {if(this.mPreventUnloading<=0) {this.mLoaded=false;this.mLoading=false;IWAllImageObjects[this.sourceURL()]=null;} else {this.mPreventedUnload=true;}}} IWImage.prototype.preventUnloading=function() {if(this.mPreventUnloading==0) {this.mPreventedUnload=false;} ++this.mPreventUnloading;} IWImage.prototype.allowUnloading=function() {--this.mPreventUnloading;if(this.mPreventUnloading<=0&&this.mPreventedUnload) {this.unload();}} IWImage.prototype.naturalSize=function() {(function(){return this.mNaturalSize!==undefined}).bind(this).assert();return this.mNaturalSize;} IWImage.prototype.imgObject=function() {return IWAllImageObjects[this.sourceURL()];} IWImage.prototype.p_onload=function() {this.preventUnloading();this.mLoaded=true;if(this.mNaturalSize===undefined) {var imgObject=this.imgObject();(function(){return imgObject!==undefined}).assert();this.mNaturalSize=new IWSize(imgObject.width,imgObject.height);} for(var i=0;i0) {var element=elements.shift();var children=$(element).select('.'+effectClass);if(children.length>0) {elements.minusArray(children);effectQueue=effectQueue.concat(this.p_generateQueueForEffectClass(effect,effectClass,children));} effectQueue.push({element:element,effect:effect});} return effectQueue;} var allStyleSheetsLoaded=false;var timeStyleSheetsAppearedInDOM=undefined;IWEffectRegistry.prototype.p_allStyleSheetsLoaded=function() {if(isCamino||isFirefox) {if(timeStyleSheetsAppearedInDOM!==undefined) {duration=(new Date().getTime())-timeStyleSheetsAppearedInDOM;if(duration>100) {allStyleSheetsLoaded=true;timeStyleSheetsAppearedInDOM=undefined;}} else if(!allStyleSheetsLoaded) {for(var i=0,sheetCount=document.styleSheets.length;i0&&duration<100&&readyToApplyEffects) {var queueEntry=queue.shift();if(queueEntry&&queueEntry.effect&&queueEntry.element) {queueEntry.effect.applyToElement(queueEntry.element);} duration=(new Date().getTime())-startTime;} if(queue.length>0) {setTimeout(this.p_applyEffectsFromQueue.bind(this,queue),0);} else {performPostEffectsFixups();}} function IWChildOffset(child,parent,positionedOnly) {var l=0;var t=0;if(parent) {var current=child;while(current&¤t!=parent) {if(!positionedOnly||(current.style.position=="absolute")||(current.style.position=="relative")) {l+=current.offsetLeft;t+=current.offsetTop;} current=current.parentNode;}} return new IWPoint(l,t);} function IWImageExtents(ancestor,images,left,top,right,bottom) {var unionedBounds=new IWRect(left,top,right-left,bottom-top);for(var e=0;e0)&&(imageClippedBounds.size.height>0)) {if((unionedBounds.size.width>0)&&(unionedBounds.size.height>0)) {unionedBounds=unionedBounds.union(imageClippedBounds);} else {unionedBounds=imageClippedBounds.clone();}}} var 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;} function IWImageChildren(element) {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;e0);var divBounds=new IWRect(-leftOffset,-topOffset,frameSize.width,frameSize.height).round();if(fillBackground) {context.fillStyle='rgba(0,0,0,1)';divBounds.fill(context);} for(var k=0;k=4) {context.shadowColor="rgba("+parseInt(components[1],16)+", "+parseInt(components[2],16)+", "+parseInt(components[3],16)+", "+self.mOpacity+")";} else {components=self.mColor.match(/rgb\(([0-9\.]+),[ ]*([0-9\.]+),[ ]*([0-9\.]+)\)/);if(components&&components.length>=4) {context.shadowColor="rgba("+components[1]+", "+components[2]+", "+components[3]+", "+self.mOpacity+")";} else {iWLog("not using shadow alpha, failed to match "+self.mColor);usingShadowAlpha=false;}}} if(usingShadowAlpha==false) {context.globalAlpha*=self.mOpacity;context.shadowColor=self.mColor;} context.shadowBlur=self.mBlurRadius;context.shadowOffsetX=self.mOffset.x;context.shadowOffsetY=self.mOffset.y;context.drawImage(workingCanvas,0,0);context.restore();if(usingShadowAlpha==false) {drawImageUnshadowed=self.mOpacity<1.0;} else {drawImageUnshadowed=false;}} if(drawImageUnshadowed) {context.drawImage(workingCanvas,0,0);} if(fillBackground) {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;k0) {for(var j=0;j=this.imgCount) {allImagesLoaded=true;for(var k=0;allImagesLoaded&&k';clippingDivPost='';thumbRect.origin.x-=left;thumbRect.origin.y-=top;} var markup='
';markup+=clippingDivPre;markup+=imageStreamEntry.thumbnailMarkupForRect(thumbRect);markup+=clippingDivPost;markup+=this.p_imageMarkup(imageSize,2);markup+='
';return markup;} IWStrokeParts.prototype.applyToElement=function(div) {if(div!=null) {var size=new IWSize(div.offsetWidth,div.offsetHeight);$(div).appendChildrenFromMarkup(this.p_imageMarkup(size));if(div.className.indexOf("flowDefining")<0) {if(div.style.position!='absolute') {var divRect=new IWRect(0,0,div.offsetWidth,div.offsetHeight);var unionRect=IWZeroRect();var layoutRects=this.p_imageLayout(size);layoutRects.each(function(r) {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) {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) {updateListOfIE7FloatsFix(div);}} else {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);}}}}} IWStrokeParts.prototype.strokeExtra=function(imageSize) {if(!imageSize) {imageSize=this.mMaxImageSize;} rect=new IWRect(IWZeroPoint(),imageSize);var layout=this.p_imageLayout(rect.size);var unionRect=IWZeroRect();layout.each(function(r) {unionRect=unionRect.union(r);});return rect.paddingToRect(unionRect);} function IWStroke(strokeURL,strokeRect,maxImageSize) {this.mStrokeURL=strokeURL;this.mStrokeRect=strokeRect;this.mMaxImageSize=maxImageSize;} IWStroke.prototype.p_strokeRect=function(imageSize) {var hScale=imageSize.width/this.mMaxImageSize.width;var vScale=imageSize.height/this.mMaxImageSize.height;var strokeRect=this.mStrokeRect.scale(hScale,vScale,true);return strokeRect;} IWStroke.prototype.p_imageMarkup=function(imageSize,zIndex) {var style=this.p_strokeRect(imageSize).position();if(zIndex) {style+='z-index: '+zIndex+';';} return imgMarkup(this.mStrokeURL,style);} IWStroke.prototype.markupForImageStreamEntry=function(imageStreamEntry,imageSize) {var rect=new IWRect(0,0,imageSize.width,imageSize.height);var markup='
';markup+=imageStreamEntry.thumbnailMarkupForRect(rect);markup+=this.p_imageMarkup(imageSize,2);markup+='
';return markup;} IWStroke.prototype.applyToElement=function(div) {if(div!=null) {var size=new IWSize(div.offsetWidth,div.offsetHeight);$(div).appendChildrenFromMarkup(this.p_imageMarkup(size));if(div.className.indexOf("flowDefining")<0) {if(div.style.position!='absolute') {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) {updateListOfIE7FloatsFix(div);}}}}} IWStroke.prototype.strokeExtra=function(imageSize) {if(imageSize===undefined) {imageSize=this.mMaxImageSize;} var imageRect=new IWRect(IWZeroPoint(),imageSize);return imageRect.paddingToRect(this.p_strokeRect(imageSize));} function IWEmptyStroke() {} IWEmptyStroke.prototype.markupForImageStreamEntry=function(imageStreamEntry,imageSize) {var rect=new IWRect(0,0,imageSize.width,imageSize.height);var markup='
';markup+=imageStreamEntry.thumbnailMarkupForRect(rect);markup+='
';return markup;} IWEmptyStroke.prototype.applyToElement=function(div) {} IWEmptyStroke.prototype.strokeExtra=function() {return new IWPadding(0,0,0,0);} var 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) {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);} IWPhotoFrame.prototype.setAssetScale=function(assetScale) {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);} IWPhotoFrame.prototype.scaledValue=function(valueToScale) {return Math.ceil(valueToScale*this.mAssetScale);} IWPhotoFrame.prototype.markupForImageStreamEntry=function(imageStreamEntry,size) {var oldAssetScale=this.mAssetScale;var maximumScale=this.maximumAssetScaleForImageSize(size);if((maximumScale=this.mMinimumAssetScale)) {this.setAssetScale(maximumScale);} var 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='
';markup+=imageStreamEntry.thumbnailMarkupForRect(imageRect);if(maximumScale>=this.mMinimumAssetScale) {if(this.mImages!=null) {markup+=this.p_buildFrame(this.mImages,coverageRect.size,2);} if(this.mAdornmentURL!=null) {markup+=this.p_adornmentMarkupForRect(imageRect,2);} if(this.mMaskImages) {}} markup+='
';if(oldAssetScale!=this.mAssetScale)this.setAssetScale(oldAssetScale);return markup;} IWPhotoFrame.prototype.strokeExtra=function() {var adornmentExtraTopMargin=0;if(this.mAdornmentURL) {adornmentExtraTopMargin=Math.max(0,(this.scaledValue(this.mAdornmentSize.height)-this.mTopHeight)/2.0-this.mAdornmentPosition.y);} return 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));} IWPhotoFrame.prototype.applyToElement=function(div) {if(div!=null) {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)))) {if(this.mImages!=null) {var coverageRect=this.coverageRect(divRect);var containerRect=new IWRect(coverageRect.origin.x,coverageRect.origin.y,0,0);markup+='
';markup+=this.p_buildFrame(this.mImages,coverageRect.size);markup+='
';} if(this.mAdornmentURL!=null) {markup+=this.p_adornmentMarkupForRect(divRect);}} $(div).appendChildrenFromMarkup(markup);if(div.className.indexOf("flowDefining")<0) {if(div.style.position!='absolute') {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) {updateListOfIE7FloatsFix(div);}}}}} IWPhotoFrame.prototype.maximumAssetScaleForImageSize=function(in_imgSize) {var maxScale=1;if((in_imgSize.width>this.mLeftInset+this.mRightInset)&&(in_imgSize.height>this.mTopInset+this.mBottomInset)) {maxScale=1;} else if((in_imgSize.width=in_imgSize.width)&&((this.mLeftInset+this.mRightInset)>0)) {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))) {maxWidthScale=Math.min(leftChunkRatio,rightChunkRatio);} if((maxWidthScale=in_imgSize.height)&&((this.mTopInset+this.mBottomInset)>0)) {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))) {maxHeightScale=Math.min(topChunkRatio,bottomChunkRatio);} if((maxHeightScale20) {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.");} if(tilingMode==kSFRFrameStretchEvenly) {offset=(end-start)/maxTiles;if(vertical) {imageRect.size.height=offset;} else {imageRect.size.width=offset;}} else if(tilingMode==kSFRFrameClip) {markup+='
';imageRect.origin.x=0;imageRect.origin.y=0;} for(var i=0;i