// // iWeb - BlogSummary.js // Copyright 2006-2008 Apple Inc. // All rights reserved. // var BlogSummaryWidget=Class.create(JSONFeedRendererWidget,{widgetIdentifier:"com-apple-iweb-widget-blogSummary",initialize:function($super,instanceID,widgetPath,sharedPath,sitePath,preferences,runningInApp) {if(instanceID) {$super(instanceID,widgetPath,sharedPath,sitePath,preferences,runningInApp);this.contentID="summary-content";this.itemTemplateID="item-template";this.itemID="item";this.separatorTemplateID="separator-template";this.selectState=null;this.sfrShadow=null;this.disableShadows=isEarlyWebKitVersion;this.styleThreeMaximumWidth=0.65;this.debugBorders=(location.href.indexOf("summaryBorders")!=-1);this.debugCompiledHtml=(location.href.indexOf("summaryCompiledHtml")!=-1);this.debugFinalHtml=(location.href.indexOf("summaryFinalHtml")!=-1);this.debugTrace=(location.href.indexOf("summaryTrace")!=-1);if(this.debugTrace)trace=print;if(this.privateInitialize) {this.privateInitialize();} document.blogSummaryWidget=this;this.initializingPreferences=true;this.initializeDefaultPreferences({"htmlTemplate":"","excerpt-length":"100","extraSpace":0,"headerOnTop":false,"imageSize":"25","imageSizeOverride":"","imagePosition":"Left","imageOutside":false,"imageVisibility":true,"rss-for-archive":false,"photoProportions":"Landscape"});delete this.initializingPreferences;this.dotMacAccount=this.preferenceForKey("dotMacAccount")||"";this.updateTemplate();this.applyUpgrades();this.fetchAndRenderRSS();}},sizeDidChange:function() {this.invalidateFeedItems("sizeDidChange");},onload:function($super) {$super();this.changedPreferenceForKey("htmlTemplate");this.changedPreferenceForKey("sfr-stroke");this.changedPreferenceForKey("sfr-reflection");this.changedPreferenceForKey("sfr-shadow");},changedPreferenceForKey:function($super,key) {try {if(this.initializingPreferences) {return;} if(this.privateChangedPreferenceForKey) {this.privateChangedPreferenceForKey(key);} if(key=="htmlTemplate") {this.updateTemplate();} if(key=="rss-for-archive") {this.fetchAndRenderRSS();} if(key=="photoProportions") {this.invalidateFeedItems(key);}} catch(e) {debugPrintException(e);} $super(key);},applyUpgrades:function() {var upgrades=this.preferenceForKey("upgrades");if(upgrades===undefined) {upgrades={};} if((!upgrades["styleThreeWidthScale"])) {if(this.imagePlacementStyle()==3) {var oldImageSize=this.preferenceForKey("imageSize");var newImageSize=Math.floor(oldImageSize/this.styleThreeMaximumWidth);this.setPreferenceForKey(newImageSize,"imageSize",false);trace("Upgrading image size from %s to %s",oldImageSize,newImageSize);} upgrades["styleThreeWidthScale"]=true;this.setPreferenceForKey(upgrades,"upgrades",false);}},updateTemplate:function() {var html=this.preferenceForKey("htmlTemplate");html=html.replace(/
/g,"
");html=html.replace(/
/g,"
");if(html=="") {var markup;if(this.preferenceForKey("rss-for-archive")) markup=BlogSummaryShared.defaultArchiveMarkup;else markup=BlogSummaryShared.defaultSummaryMarkup;trace("** brand-new widget html being compiled from source markup");if(markup) {html=BlogSummaryShared.compileMarkup(markup);}} if(html) {if(html.indexOf("")==-1) {if(html.indexOf("Read more...")!=-1) html=html.replace(/Read more\.\.\./g,"Read more...");else if(html.indexOf("More...")!=-1) html=html.replace(/More\.\.\./g,"More...");} var contentDiv=this.getElementById(this.contentID);if(contentDiv) {if(this.debugCompiledHtml)print("\n\n%s\n\n",html);html=html.replace(/\$WIDGET_ID/g,this.instanceID);contentDiv.innerHTML=html;this.resetRenderingState=true;this.invalidateFeedItems("updateTemplate");optOutOfCSSBackgroundPNGFix(contentDiv);}}},commentCountText:function(count,enabled) {if(count==0) {if(enabled) {return this.localizedString("No Comments");} else {return"";}} else if(count==1) {return this.localizedString("1 Comment");} else {return String.stringWithFormat(this.localizedString("%s Comments"),count);}},replaceLinkTargets:function(node,replaceArray) {var byteToPercentEscapeValue=function(ch) {ch=ch&0xFF;var hiChar="0123456789ABCDEF".charAt(ch/16);var loChar="0123456789ABCDEF".charAt(ch%16);return"%"+hiChar+loChar;};var sanitizeUrlStringForIE6=function(s) {var result="";for(var i=0;i0) {for(var i=0;i0) {var sep=this.getElementById(this.separatorTemplateID,index-1);if(sep) {sep.parentNode.removeChild(sep);}} var node=this.getElementById(this.itemID,index);if(node===null) {break;} node.parentNode.removeChild(node);index++;} var pusherSpan=$("pusher");if(pusherSpan==null) {pusherSpan=document.createElement("span");pusherSpan.innerHTML=" ";pusherSpan.id="pusher";itemTemplateNode.parentNode.insertBefore(pusherSpan,null);} pusherSpan.style.display=(imagePlacementStyle==3)?"":"none";if(windowsInternetExplorer) {fixAllIEPNGs(transparentGifURL());setTimeout(fixupIEPNGBGsInTree.bind(null,contentDiv,true),1);if(effectiveBrowserVersion>=8) {joltLater(this.div());}} if(this.privateSummaryDidRender) {this.privateSummaryDidRender();} if(this.debugFinalHtml) {setTimeout(function() {print(contentDiv.outerHTML);},5000);this.debugFinalHtml=false;} trace(" exit: done",this.blogFeed.itemCount(),"items");},fetchAndRenderRSS:function() {var isArchiveWidget=this.preferenceForKey("rss-for-archive");this.blogFeed=new BlogFeed(BlogRootURLString(location.href),isArchiveWidget,function() {this.invalidateFeedItems("renderSummaryFromRSS");}.bind(this));},fetchCommentCountInfoForItem:function(item,index,itemNode,postRenderCallback) {var commentSummaryURL=item.absoluteURL.toURLString()+"?wsc=summary.js&ts="+new Date().getTime();var renderItemCommentSummary=function(request) {if(request.responseText) {var r=request.responseText.match(/.*= ((true)|(false));.*\n.*= (\d+)/);if(r) {var enabled=(r[1]=="true");var count=Number(r[4]);this.renderCommentCount(itemNode,index,enabled,count);}} postRenderCallback();}.bind(this);new Ajax.Request(commentSummaryURL,{method:'get',onComplete:renderItemCommentSummary});},addBadge:function(badgeType,imageDiv) {if(badgeType=="movie"||badgeType=="audio") {var cropDiv=imageDiv.down('.crop');var kBadgeHeight=16.0;var blackBarElem=new Element('div',{className:'badge-fill'});blackBarElem.setStyle({backgroundColor:'black',opacity:0.75,position:'absolute',left:0,bottom:0,width:px(cropDiv.offsetWidth),height:px(kBadgeHeight)});cropDiv.appendChild(blackBarElem);var badgeImageFilename=((badgeType=="movie")?"Overlay-Movie.png":"Overlay-Audio.png");var badgeSrc=this.widgetPath+"/"+badgeImageFilename;var badgeElem=new Element('img',{className:'badge-overlay',src:badgeSrc});badgeElem.setStyle({position:'absolute',bottom:0,left:0});if(windowsInternetExplorer) {badgeElem.setStyle(" filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+IEConvertURLForPNGFix(badgeSrc)+" ', sizingMethod='scale');");badgeElem.writeAttribute(badgeSrc,transparentGifURL());} cropDiv.appendChild(badgeElem);}}});