// // iWeb - WidgetCommon.js // Copyright (c) 2007-2008 Apple Inc. All rights reserved. // var widgets=[];var identifiersToStringLocalizations=[];var Widget=Class.create({initialize:function(instanceID,widgetPath,sharedPath,sitePath,preferences,runningInApp) {if(instanceID) {this.instanceID=instanceID;this.widgetPath=widgetPath;this.sharedPath=sharedPath;this.sitePath=sitePath;this.preferences=preferences;this.runningInApp=(runningInApp===undefined)?false:runningInApp;this.onloadReceived=false;if(this.preferences&&this.runningInApp==true) {this.preferences.widget=this;setTransparentGifURL(this.sharedPath.stringByAppendingPathComponent("None.gif"));} this.div().widget=this;window[instanceID]=this;widgets.push(this);widgets[instanceID]=this;if(!this.constructor.instances) {this.constructor.instances=new Array();} this.constructor.instances.push(this);}},div:function() {var divID=this.instanceID;if(arguments.length==1) {divID=this.instanceID+"-"+arguments[0];} return $(divID);},onload:function() {this.onloadReceived=true;},onunload:function() {},didBecomeSelected:function() {},didBecomeDeselected:function() {},didBeginEditing:function() {},didEndEditing:function() {},setNeedsDisplay:function() {},preferenceForKey:function(key) {var value;if(this.preferences) value=this.preferences[key];return value;},initializeDefaultPreferences:function(prefs) {var self=this;$H(prefs).each(function(pair) {if(self.preferenceForKey(pair.key)===undefined) {self.setPreferenceForKey(pair.value,pair.key,false);}});},setPreferenceForKey:function(preference,key,registerUndo) {if(this.runningInApp) {if(registerUndo===undefined) registerUndo=true;if((registerUndo==false)&&this.preferences.disableUndoRegistration) this.preferences.disableUndoRegistration();this.preferences[key]=preference;if((registerUndo==false)&&this.preferences.enableUndoRegistration) this.preferences.enableUndoRegistration();} else {this.preferences[key]=preference;this.changedPreferenceForKey(key);}},changedPreferenceForKey:function(key) {},postNotificationWithNameAndUserInfo:function(name,userInfo) {if(window.NotificationCenter!==undefined) {NotificationCenter.postNotification(new IWNotification(name,null,userInfo));}},sizeWillChange:function() {},sizeDidChange:function() {},widgetWidth:function() {var enclosingDiv=this.div();if(enclosingDiv) return enclosingDiv.offsetWidth;else return null;},widgetHeight:function() {var enclosingDiv=this.div();if(enclosingDiv) return enclosingDiv.offsetHeight;else return null;},getInstanceId:function(id) {var fullId=this.instanceID+"-"+id;if(arguments.length==2) {fullId+=("$"+arguments[1]);} return fullId;},getElementById:function(id) {var fullId=this.getInstanceId.apply(this,arguments);return $(fullId);},localizedString:function(string) {return LocalizedString(this.widgetIdentifier,string);},showView:function(viewName) {var futureView=this.m_views[viewName];if((futureView!=this.m_currentView)&&(futureView!=this.m_futureView)) {this.m_futureView=futureView;if(this.m_fadeAnimation) {this.m_fadeAnimation.stop();} var previousView=this.m_currentView;this.m_currentView=futureView;var currentView=this.m_currentView;this.m_futureView=null;this.m_fadeAnimation=new SimpleAnimation(function(){delete this.m_fadeAnimation;}.bind(this));this.m_fadeAnimation.pre=function() {if(previousView) {previousView.ensureDiv().setStyle({zIndex:0,opacity:1});} if(currentView) {currentView.ensureDiv().setStyle({zIndex:1,opacity:0});currentView.show();currentView.render();}} this.m_fadeAnimation.post=function() {!previousView||previousView.hide();!currentView||currentView.ensureDiv().setStyle({zIndex:'',opacity:1});!currentView||!currentView.doneFadingIn||currentView.doneFadingIn();} this.m_fadeAnimation.update=function(now) {!currentView||currentView.ensureDiv().setOpacity(now);!previousView||previousView.ensureDiv().setOpacity(1-now);}.bind(this);this.m_fadeAnimation.start();}}});Widget.onload=function() {for(var i=0;icropped.aspectRatio()) {scaleFactor=cropped.height/natural.height;} var scaled=natural.scale(scaleFactor);var offset=new IWPoint(Math.abs(scaled.width-cropped.width)/2,Math.abs(scaled.height-cropped.height)/2);img.setStyle({width:px(scaled.width),height:px(scaled.height),marginLeft:px(-offset.x),marginTop:px(-offset.y),position:'relative'});cropDiv.setStyle({width:px(cropped.width),height:px(cropped.height),overflow:"hidden",position:'relative'});cropDiv.className="crop";} if(windowsInternetExplorer&&effectiveBrowserVersion<7&&img.src.indexOf(transparentGifURL())!=-1) {var originalImage=new Image();originalImage.src=img.originalSrc;if(originalImage.complete) {croppingDivForImage_helper(originalImage);} else {originalImage.onload=croppingDivForImage_helper.bind(null,originalImage);}} else {croppingDivForImage_helper(null);}} return cropDiv;},applyEffects:function(div) {if(this.sfrShadow||this.sfrReflection||this.sfrStroke) {if((div.offsetWidth===undefined)||(div.offsetHeight===undefined)||(div.offsetWidth===0)||(div.offsetHeight===0)) {setTimeout(JSONFeedRendererWidget.prototype.applyEffects.bind(this,div),0) return;} if(this.sfrStroke&&(div.strokeApplied==false)) {this.sfrStroke.applyToElement(div);div.strokeApplied=true;} if(this.sfrReflection&&(div.reflectionApplied==false)) {this.sfrReflection.applyToElement(div);div.reflectionApplied=true;} if(this.sfrShadow&&(!this.disableShadows)&&(div.shadowApplied==false)) {this.sfrShadow.applyToElement(div);div.shadowApplied=true;} if(this.runningInApp&&(window.webKitVersion<=419)&&this.preferences.setNeedsDisplay) {this.preferences.setNeedsDisplay();}} if(windowsInternetExplorer) {var cropDivs=div.select(".crop");var cropDiv=cropDivs[cropDivs.length-1];if(cropDiv) {cropDiv.onclick=function() {var anchorNode=div.parentNode;var targetHref=locationHRef();while(anchorNode&&(anchorNode.tagName!="A")) {anchorNode=anchorNode.parentNode} if(anchorNode) {targetHref=anchorNode.href;} window.location=targetHref;};cropDiv.onmouseover=function() {this.style.cursor='pointer';}}}},summaryExcerpt:function(descriptionHTML,maxSummaryLength) {var div=document.createElement("div");div.innerHTML=descriptionHTML;if(maxSummaryLength>0) {var model=new HTMLTextModel(div);model.truncateAroundPosition(maxSummaryLength,"...");} else if(maxSummaryLength===0) {div.innerHTML="";} return div.innerHTML;}});var PrefMarkupWidget=Class.create(Widget,{initialize:function($super,instanceID,widgetPath,sharedPath,sitePath,preferences,runningInApp) {if(instanceID) {$super(instanceID,widgetPath,sharedPath,sitePath,preferences,runningInApp);}},onload:function() {if(!this.runningInApp) {this.setUpSubDocumentOnLoad();}},setUpSubDocumentOnLoad:function() {var self=this;var oIFrame=this.getElementById("frame");if(oIFrame) {setTimeout(function(){self.loadedSubDocument()},250);}},loadedSubDocument:function() {var oIFrame=this.getElementById("frame");var oSubDocument=oIFrame.contentWindow||oIFrame.contentDocument;if(oSubDocument.document) {oSubDocument=oSubDocument.document;} if(oSubDocument.body) {this.fixTargetOnElements(oSubDocument,"a");this.fixTargetOnElements(oSubDocument,"form");} else {var self=this;setTimeout(function(){self.loadedSubDocument()},250);}},fixTargetOnElements:function(doc,tagName) {var elements=doc.getElementsByTagName(tagName);for(var i=0;i(self._thumbStart+self._thumbLength)) self.scrollByThumbDelta(deltaScroll);} IWScrollbar.prototype.setScrollArea=function(scrollarea) {if(this.scrollarea) {Event.stopObserving(this.scrollbar,"mousewheel",this.scrollarea._mousewheelScrollHandler,true);Event.stopObserving(this.scrollbar,"DOMMouseScroll",this.scrollarea._mousewheelScrollHandler,true);} this.scrollarea=scrollarea;Event.observe(this.scrollbar,"mousewheel",this.scrollarea._mousewheelScrollHandler,true);Event.observe(this.scrollbar,"DOMMouseScroll",this.scrollarea._mousewheelScrollHandler,true);} IWScrollbar.prototype.refresh=function() {this._trackOffset=this._computeTrackOffset();this._trackLength=this._computeTrackLength();var ratio=this._getViewToContentRatio();if(ratio>=1.0||!this._canScroll()) {if(this.autohide) {this.hide();} this._thumb.style.display="none";this.scrollbar.style.appleDashboardRegion="none";} else {this._thumbLength=Math.max(Math.round(this._trackLength*ratio),this.minThumbSize);this._numScrollablePixels=this._trackLength-this._thumbLength-(2*this.padding);this._setObjectLength(this._thumb,this._thumbLength);if(windowsInternetExplorer) {this._setObjectStart(this._thumb.down().next(),this.thumbStartLength);this._setObjectLength(this._thumb.down().next(),this._thumbLength -this.thumbStartLength-this.thumbEndLength);this._setObjectStart(this._thumb.down().next(1),this._thumbLength-this.thumbEndLength);this._setObjectLength(this._thumb.down().next(1),this.thumbEndLength);if(!this.fixedUpIEPNGBGs) {fixupIEPNGBGsInTree(this._track);Event.stopObserving(this._track,"mousedown",this._mousedownTrackHandler);Event.stopObserving(this._thumb,"mousedown",this._mousedownThumbHandler);Event.observe(this._track,"mousedown",this._mousedownTrackHandler);Event.observe(this._thumb,"mousedown",this._mousedownThumbHandler);this.fixedUpIEPNGBGs=true;}} this._thumb.style.display="block";this.scrollbar.style.appleDashboardRegion="dashboard-region(control rectangle)";this.show();} this.verticalHasScrolled();this.horizontalHasScrolled();} IWScrollbar.prototype.setAutohide=function(autohide) {this.autohide=autohide;if(this._getViewToContentRatio()>=1.0&&autohide) {this.hide();} else {this.show();}} IWScrollbar.prototype.hide=function() {this._track.style.display="none";this.hidden=true;} IWScrollbar.prototype.show=function() {this._track.style.display="block";this.hidden=false;} IWScrollbar.prototype.setSize=function(size) {this.size=size;this._setObjectSize(this.scrollbar,size);this._setObjectSize(this._track.down().next(),size);this._setObjectSize(this._thumb.down().next(),size);} IWScrollbar.prototype.setTrackStart=function(imgpath,length) {this.trackStartPath=imgpath;this.trackStartLength=length;var element=this._track.down();element.style.background="url("+imgpath+") no-repeat top left";this._setObjectLength(element,length);this._setObjectSize(element,this.size);this._setObjectStart(this._track.down().next(),length);} IWScrollbar.prototype.setTrackMiddle=function(imgpath) {this.trackMiddlePath=imgpath;this._track.down().next().style.background="url("+imgpath+") "+this._repeatType+" top left";} IWScrollbar.prototype.setTrackEnd=function(imgpath,length) {this.trackEndPath=imgpath;this.trackEndLength=length;var element=this._track.down().next(1);element.style.background="url("+imgpath+") no-repeat top left";this._setObjectLength(element,length);this._setObjectSize(element,this.size);windowsInternetExplorer||this._setObjectEnd(this._track.down().next(),length);} IWScrollbar.prototype.setThumbStart=function(imgpath,length) {this.thumbStartPath=imgpath;this.thumbStartLength=length;var element=this._thumb.down();element.style.background="url("+imgpath+") no-repeat top left";this._setObjectLength(element,length);this._setObjectSize(element,this.size);this._setObjectStart(this._thumb.down().next(),length);} IWScrollbar.prototype.setThumbMiddle=function(imgpath) {this.thumbMiddlePath=imgpath;this._thumb.down().next().style.background="url("+imgpath+") "+this._repeatType+" top left";} IWScrollbar.prototype.setThumbEnd=function(imgpath,length) {this.thumbEndPath=imgpath;this.thumbEndLength=length;var element=this._thumb.down().next(1);element.style.background="url("+imgpath+") no-repeat top left";this._setObjectLength(element,length);this._setObjectSize(element,this.size);windowsInternetExplorer||this._setObjectEnd(this._thumb.down().next(),length);} IWScrollbar.prototype._contentPositionForThumbPosition=function(thumb_pos) {if(this._getViewToContentRatio()>=1.0) {return 0;} else {return(thumb_pos-this.padding)*((this._getContentLength()-this._getViewLength())/this._numScrollablePixels);}} IWScrollbar.prototype._thumbPositionForContentPosition=function(page_pos) {if(this._getViewToContentRatio()>=1.0) {return this.padding;} else {var result=this.padding+(page_pos/((this._getContentLength()-this._getViewLength())/this._numScrollablePixels));if(isNaN(result)) result=0;return result;}} IWScrollbar.prototype.scrollByThumbDelta=function(deltaScroll) {if(deltaScroll==0) return;this.scrollTo(this._contentPositionForThumbPosition(this._thumbStart+deltaScroll));} function IWVerticalScrollbar(scrollbar) {this.scrollarea=null;this.scrollbar=$(scrollbar);this.minThumbSize=28;this.padding=-1;this.autohide=true;this.hidden=true;this.size=19;this.trackStartPath=transparentGifURL();this.trackStartLength=18;this.trackMiddlePath=transparentGifURL();this.trackEndPath=transparentGifURL();this.trackEndLength=18;this.thumbStartPath=transparentGifURL();this.thumbStartLength=9;this.thumbMiddlePath=transparentGifURL();this.thumbEndPath=transparentGifURL();this.thumbEndLength=9;this._track=null;this._thumb=null;this._trackOffset=0;this._trackLength=0;this._numScrollablePixels=0;this._thumbLength=0;this._repeatType="repeat-y";this._thumbStart=this.padding;var _self=this;this._captureEventHandler=function(event){_self._captureEvent(event);};this._mousedownThumbHandler=function(event){_self._mousedownThumb(event);};this._mousemoveThumbHandler=function(event){_self._mousemoveThumb(event);};this._mouseupThumbHandler=function(event){_self._mouseupThumb(event);};this._mousedownTrackHandler=function(event){_self._mousedownTrack(event);};this._mousemoveTrackHandler=function(event){_self._mousemoveTrack(event);};this._mouseoverTrackHandler=function(event){_self._mouseoverTrack(event);};this._mouseoutTrackHandler=function(event){_self._mouseoutTrack(event);};this._mouseupTrackHandler=function(event){_self._mouseupTrack(event);};this._init();} IWVerticalScrollbar.prototype=new IWScrollbar(null);IWVerticalScrollbar.prototype.scrollTo=function(pos) {this.scrollarea.verticalScrollTo(pos);} IWVerticalScrollbar.prototype._setObjectSize=function(object,size) {object.style.width=size+"px";} IWVerticalScrollbar.prototype._setObjectLength=function(object,length) {object.style.height=length+"px";} IWVerticalScrollbar.prototype._setObjectStart=function(object,start) {object.style.top=start+"px";} IWVerticalScrollbar.prototype._setObjectEnd=function(object,end) {object.style.bottom=end+"px";} IWVerticalScrollbar.prototype._getMousePosition=function(event) {if(event!=undefined) return Event.pointerY(event);else return 0;} IWVerticalScrollbar.prototype._getThumbStartPos=function() {return this._thumb.offsetTop;} IWVerticalScrollbar.prototype._computeTrackOffset=function() {var obj=this.scrollbar;var curtop=0;while(obj.offsetParent) {curtop+=obj.offsetTop;obj=obj.offsetParent;} return curtop;} IWVerticalScrollbar.prototype._computeTrackLength=function() {return this.scrollbar.offsetHeight;} IWVerticalScrollbar.prototype._getViewToContentRatio=function() {return this.scrollarea.viewToContentHeightRatio;} IWVerticalScrollbar.prototype._getContentLength=function() {return this.scrollarea.content.scrollHeight;} IWVerticalScrollbar.prototype._getViewLength=function() {return this.scrollarea.viewHeight;} IWVerticalScrollbar.prototype._canScroll=function() {return this.scrollarea.scrollsVertically;} IWVerticalScrollbar.prototype.verticalHasScrolled=function() {var new_thumb_pos=this._thumbPositionForContentPosition(this.scrollarea.content.scrollTop);this._thumbStart=new_thumb_pos;this._thumb.style.top=new_thumb_pos+"px";} IWVerticalScrollbar.prototype.horizontalHasScrolled=function() {} function IWHorizontalScrollbar(scrollbar) {this.scrollarea=null;this.scrollbar=$(scrollbar);this.minThumbSize=28;this.padding=-1;this.autohide=true;this.hidden=true;this.size=19;this.trackStartPath=transparentGifURL();this.trackStartLength=18;this.trackMiddlePath=transparentGifURL();this.trackEndPath=transparentGifURL();this.trackEndLength=18;this.thumbStartPath=transparentGifURL();this.thumbStartLength=9;this.thumbMiddlePath=transparentGifURL();this.thumbEndPath=transparentGifURL();this.thumbEndLength=9;this._track=null;this._thumb=null;this._trackOffset=0;this._trackLength=0;this._numScrollablePixels=0;this._thumbLength=0;this._repeatType="repeat-x";this._thumbStart=this.padding;var _self=this;this._captureEventHandler=function(event){_self._captureEvent(event);};this._mousedownThumbHandler=function(event){_self._mousedownThumb(event);};this._mousemoveThumbHandler=function(event){_self._mousemoveThumb(event);};this._mouseupThumbHandler=function(event){_self._mouseupThumb(event);};this._mousedownTrackHandler=function(event){_self._mousedownTrack(event);};this._mousemoveTrackHandler=function(event){_self._mousemoveTrack(event);};this._mouseoverTrackHandler=function(event){_self._mouseoverTrack(event);};this._mouseoutTrackHandler=function(event){_self._mouseoutTrack(event);};this._mouseupTrackHandler=function(event){_self._mouseupTrack(event);};this._init();} IWHorizontalScrollbar.prototype=new IWScrollbar(null);IWHorizontalScrollbar.prototype.scrollTo=function(pos) {this.scrollarea.horizontalScrollTo(pos);} IWHorizontalScrollbar.prototype._setObjectSize=function(object,size) {object.style.height=size+"px";} IWHorizontalScrollbar.prototype._setObjectLength=function(object,length) {object.style.width=length+"px";} IWHorizontalScrollbar.prototype._setObjectStart=function(object,start) {object.style.left=start+"px";} IWHorizontalScrollbar.prototype._setObjectEnd=function(object,end) {object.style.right=end+"px";} IWHorizontalScrollbar.prototype._getMousePosition=function(event) {if(event!=undefined) return Event.pointerX(event);else return 0;} IWHorizontalScrollbar.prototype._getThumbStartPos=function() {return this._thumb.offsetLeft;} IWHorizontalScrollbar.prototype._computeTrackOffset=function() {var obj=this.scrollbar;var curtop=0;while(obj.offsetParent) {curtop+=obj.offsetLeft;obj=obj.offsetParent;} return curtop;} IWHorizontalScrollbar.prototype._computeTrackLength=function() {return this.scrollbar.offsetWidth;} IWHorizontalScrollbar.prototype._getViewToContentRatio=function() {return this.scrollarea.viewToContentWidthRatio;} IWHorizontalScrollbar.prototype._getContentLength=function() {return this.scrollarea.content.scrollWidth;} IWHorizontalScrollbar.prototype._getViewLength=function() {return this.scrollarea.viewWidth;} IWHorizontalScrollbar.prototype._canScroll=function() {return this.scrollarea.scrollsHorizontally;} IWHorizontalScrollbar.prototype.verticalHasScrolled=function() {} IWHorizontalScrollbar.prototype.horizontalHasScrolled=function() {var new_thumb_pos=this._thumbPositionForContentPosition(this.scrollarea.content.scrollLeft);this._thumbStart=new_thumb_pos;this._thumb.style.left=new_thumb_pos+"px";} function IWScrollArea(content) {this.content=$(content);this.scrollsVertically=true;this.scrollsHorizontally=true;this.singlepressScrollPixels=10;this.viewHeight=0;this.viewToContentHeightRatio=1.0;this.viewWidth=0;this.viewToContentWidthRatio=1.0;this._scrollbars=new Array();var _self=this;this._refreshHandler=function(){_self.refresh();};this._keyPressedHandler=function(){_self.keyPressed(event);};this._mousewheelScrollHandler=function(event){_self.mousewheelScroll(event);};this.content.style.overflow="hidden";this.content.scrollTop=0;this.content.scrollLeft=0;Event.observe(this.content,"mousewheel",this._mousewheelScrollHandler,true);Event.observe(this.content,"DOMMouseScroll",this._mousewheelScrollHandler,true);this.refresh();var c=arguments.length;for(var i=1;ithis.viewHeight) {this.viewToContentHeightRatio=this.viewHeight/this.content.scrollHeight;this.verticalScrollTo(this.content.scrollTop);} else {this.viewToContentHeightRatio=1.0;this.verticalScrollTo(0);} if(this.content.scrollWidth>this.viewWidth) {this.viewToContentWidthRatio=this.viewWidth/this.content.scrollWidth;this.horizontalScrollTo(this.content.scrollLeft);} else {this.viewToContentWidthRatio=1.0;this.horizontalScrollTo(0);} var scrollbars=this._scrollbars;var c=scrollbars.length;for(var i=0;ibottom) {new_content_top=bottom;} this.content.scrollTop=new_content_top;var scrollbars=this._scrollbars;var c=scrollbars.length;for(var i=0;iright) {new_content_left=right;} this.content.scrollLeft=new_content_left;var scrollbars=this._scrollbars;var c=scrollbars.length;for(var i=0;i"+ this.m_widget.localizedString(this.statusMessageKey)+"";} this.ensureDiv().update(markup);this.resize();},resize:function() {var widgetWidth=(this.runningInApp)?window.innerWidth:this.m_widget.div().offsetWidth;var widgetHeight=(this.runningInApp)?window.innerHeight:this.m_widget.div().offsetHeight;if(this.badgeImage) {var badgeImageEl=$(this.p_badgeImgId());var badgeSize=new IWSize(this.badgeImageWidth,this.badgeImageHeight);if((badgeSize.width>widgetWidth)||(badgeSize.height>widgetHeight)) {var widgetSize=new IWSize(widgetWidth,widgetHeight);badgeSize=badgeSize.scaleToFit(widgetSize);} badgeImageEl.width=badgeSize.width;badgeImageEl.height=badgeSize.height;} var overlayNativeWidth=700;var overlayNativeHeight=286;var overlayWidth=Math.max(widgetWidth,overlayNativeWidth);var overlayHeight=overlayNativeHeight;var overlayTop=Math.min(((widgetHeight/2)-overlayNativeHeight),0);var overlayLeft=Math.min(((widgetWidth/2)-(overlayNativeWidth/2)),0);var overlayImage=$(this.p_overlayImgId());overlayImage.width=overlayWidth;overlayImage.height=overlayHeight;overlayImage.setStyle({left:px(overlayLeft),top:px(overlayTop)});var statusMessageBlock=$(this.p_statusMessageBlockId());if(statusMessageBlock) {var leftValue=px(Math.max(((widgetWidth-statusMessageBlock.offsetWidth)/2),0));var positionStyles={left:leftValue};if(this.statusMessageVerticallyCentered) {var topValue=px(Math.max(((widgetHeight-statusMessageBlock.offsetHeight)/2),0));positionStyles.top=topValue;} statusMessageBlock.setStyle(positionStyles);} if(this.footerView) {this.footerView.resize();}},doneFadingIn:function() {this.m_widget.setPreferenceForKey(true,"x-viewDoneFadingIn",false);},p_badgeImgId:function() {return this.m_widget.getInstanceId(this.m_divId+"-badge");},p_overlayImgId:function() {return this.m_widget.getInstanceId(this.m_divId+"-overlay");},p_statusMessageBlockId:function() {return this.m_widget.getInstanceId(this.m_divId+"-messageBlock");}});