1// 2// iWeb - iWebBlog.js 3// Copyright 2007 Apple Inc. 4// All rights reserved. 5// 6 7function BlogRootURLString(inUrlString) 8{var urlString=inUrlString.urlStringByDeletingQueryAndFragment();var index=urlString.search(/\/\d{4}\/\d{1,2}\//);if(index!=-1) 9{return urlString.substr(0,index).stringByDeletingLastPathComponent();} 10return urlString.substr(0,urlString.lastIndexOf("/"));} 11function BlogRootURL(inUrlString) 12{return new IWURL(BlogRootURLString(inUrlString));} 13function BlogFixupPreviousNext() 14{var currentUrl=locationHRef().urlStringByDeletingQueryAndFragment();window.blogFeed=new BlogFeed(BlogRootURLString(locationHRef()),window.iWebBlogFeedType,true,function() 15{var prevNextLinks=$$(".iWebBlogPrev",".iWebBlogNext");prevNextLinks.each(function(anchor) 16{var targetItem=null;if(anchor.className.indexOf("iWebBlogPrev")!=-1) 17{targetItem=window.blogFeed.itemBefore(currentUrl);} 18else if(anchor.className.indexOf("iWebBlogNext")!=-1) 19{targetItem=window.blogFeed.itemAfter(currentUrl);} 20if(targetItem) 21{anchor.href=targetItem.absoluteURL.toURLString();anchor.title=targetItem.title;}});});} 22function BlogPreviousPage() 23{var currentUrlString=locationHRef().urlStringByDeletingQueryAndFragment();var targetUrlString=window.blogFeed.itemBefore(currentUrlString);location.href=targetUrlString;} 24function BlogNextPage() 25{var currentUrlString=locationHRef().urlStringByDeletingQueryAndFragment();var targetUrlString=window.blogFeed.itemAfter(currentUrlString);location.href=targetUrlString;} 26function BlogMainPageItem() 27{var blogURLString=BlogRootURLString(locationHRef());if(window.iWebBlogMainPageName===undefined) 28{window.iWebBlogMainPageTitle=blogURLString.lastPathComponent();window.iWebBlogMainPageName=window.iWebBlogMainPageTitle+".html";} 29blogURLString=blogURLString.stringByAppendingPathComponent(window.iWebBlogMainPageName);return{absoluteURL:new IWURL(blogURLString),title:window.iWebBlogMainPageTitle};} 30function BlogArchivePageItem() 31{var blogURLString=BlogRootURLString(locationHRef());if(window.iWebBlogArchivePageName===undefined) 32{window.iWebBlogArchivePageTitle="Archive";window.iWebBlogArchivePageName=window.iWebBlogArchivePageTitle+".html";} 33blogURLString=blogURLString.stringByAppendingPathComponent(window.iWebBlogArchivePageName);return{absoluteURL:new IWURL(blogURLString),title:window.iWebBlogArchivePageTitle};} 34function BlogFeed(inBlogUrlString,inFeedType,inIsArchive,inCallback) 35{this.mBlogURL=new IWURL(inBlogUrlString);this.mFeedType=inFeedType;this.mIsArchive=inIsArchive;var feedUrlString=inIsArchive?"blog-archive.xml":"blog-main.xml";if(this.mFeedType=="dynamic") 36{feedUrlString=inBlogUrlString+"?webdav-method=truthget&feedfmt="+(inIsArchive?"blogarchive":"blogsummary");} 37else 38{feedUrlString=inBlogUrlString.stringByAppendingPathComponent(feedUrlString);} 39delete this.mItems;makeXmlHttpRequest(feedUrlString,makeAjaxHandler(function(request,successful) 40{if(successful) 41{this.p_parseFeed(ajaxGetDocumentElement(request));} 42if(inCallback) 43{inCallback();}}.bind(this)));} 44Object.extend(BlogFeed,{iwebNS:"http://www.apple.com/iweb",getiWebElement:function(itemNode,propertyName) 45{return getFirstChildElementByTagNameNS(itemNode,BlogFeed.iwebNS,"iweb",propertyName);},getiWebElementText:function(itemNode,propertyName) 46{return getChildElementTextByTagNameNS(itemNode,BlogFeed.iwebNS,"iweb",propertyName);},fixupURL:function(url) 47{return url.replace("file://localhost/","file:///");},FeedItem:function(itemNode) 48{var child=itemNode.firstChild;while(child) 49{if(child.nodeType==Node.ELEMENT_NODE) 50{if(child.tagName=='title') 51{this.title=getTextFromNode(child);} 52else if(child.tagName=='link') 53{this.p_linkText=getTextFromNode(child);this.absoluteURL=new IWURL(this.p_linkText);} 54else if(child.tagName=='description') 55{this.description=getTextFromNode(child);} 56else if(child.tagName=='pubDate') 57{var dateText=getTextFromNode(child);if(dateText&&dateText.length>0) 58this.date=new Date(dateText);} 59else if(child.tagName=='iweb:image') 60{this.imageUrlString=child.getAttribute("href");this.imageURL=new IWURL(this.imageUrlString);} 61else if(child.tagName=='iweb:comment') 62{this.commentCount=child.getAttribute("count");this.commentingEnabled=(child.getAttribute("enabled")==1);this.commentURL=new IWURL(child.getAttribute("link"));}} 63child=child.nextSibling;} 64this.title=this.title||"";this.absoluteURL=this.absoluteURL||new IWURL();this.date=this.date||new Date();this.commentingEnabled=this.commentingEnabled||false;this.commentCount=this.commentCount||0;}});Object.extend(BlogFeed.prototype,{p_parseFeed:function(rssDoc) 65{this.mDateFormat="EEEE, MMMM d, yyyy";this.mBaseURL=new IWURL();this.mMaximumSummaryItems=10;this.mItems=[];var channel=rssDoc.getElementsByTagName("channel")[0];
65var dateFormat=BlogFeed.getiWebElementText(channel,"dateFormat");var maximumSummaryItems=BlogFeed.getiWebElementText(channel,"maximumSummaryItems");var baseURLString=BlogFeed.getiWebElementText(channel,"baseURL");if(dateFormat) 66this.mDateFormat=dateFormat;if(maximumSummaryItems) 67this.mMaximumSummaryItems=maximumSummaryItems;if(baseURLString) 68{this.mBaseURL=new IWURL(baseURLString);} 69var itemNodes=rssDoc.getElementsByTagName("item");for(var i=0;i<itemNodes.length;++i) 70{var itemNode=itemNodes[i];var item;try 71{item=new BlogFeed.FeedItem(itemNode);if(this.mBaseURL) 72{item.relativeURL=item.absoluteURL.relativize(this.mBaseURL);item.absoluteURL=item.relativeURL.resolve(this.mBlogURL);if(item.commentURL) 73{item.relativeCommentURL=item.commentURL.relativize(this.mBaseURL);}} 74this.mItems.push(item);} 75catch(e) 76{debugPrintException(e);}}},itemCount:function() 77{if(this.mItems===undefined) 78return 0;return this.mItems.length;},itemAtIndex:function(index) 79{return this.mItems[index];},dateFormat:function() 80{return this.mDateFormat;},maximumItemsToDisplay:function() 81{var result=this.itemCount();if(!this.mIsArchive&&(this.mMaximumSummaryItems>0)&&(this.mMaximumSummaryItems<result)) 82{result=this.mMaximumSummaryItems;} 83return result;},dumpFeed:function() 84{print("dumping a %s feed with %s items",this.mFeedType,this.itemCount());for(var i=0;i<this.itemCount();++i) 85{printObject(this.itemAtIndex(i));}},itemAfter:function(urlString) 86{var afterIndex=null;var url=new IWURL(urlString);for(var i=0;i<this.mItems.length;++i) 87{if(url.isEqual(this.mItems[i].absoluteURL)) 88{afterIndex=i-1;break;}} 89if(afterIndex<0) 90return BlogArchivePageItem();else 91return this.mItems[afterIndex];},itemBefore:function(urlString) 92{var beforeIndex=null;var url=new IWURL(urlString);for(var i=0;i<this.mItems.length;++i) 93{if(url.isEqual(this.mItems[i].absoluteURL)) 94{beforeIndex=i+1;break;}} 95if(beforeIndex<this.mItems.length) 96return this.mItems[beforeIndex];else 97return BlogMainPageItem();}});function iWebInitSearch() 98{try 99{setLocale();initSearch();} 100catch(e) 101{}} 102function dynamicallyPopulate() 103{var contentXml=getContentXmlURL();if(contentXml==null) 104{var baseUrl=String(this.location).urlStringByDeletingQueryAndFragment();contentXml=String(baseUrl).replace(/\.html$/,'.xml');} 105var populateDomWithContentFromXML=function(request,successful) 106{if(successful) 107{var contentDoc=ajaxGetDocumentElement(request);var textBoxes=contentDoc.getElementsByTagName('textBox');for(var i=0;i<textBoxes.length;i++) 108{dynamicallyPopulateTextBox(textBoxes[i]);} 109var images=contentDoc.getElementsByTagName('image');for(var i=0;i<images.length;i++) 110{dynamicallyPopulateImage(images[i]);}}};makeXmlHttpRequest(contentXml,makeAjaxHandler(populateDomWithContentFromXML));} 111function dynamicallyPopulateTextBox(textBoxElement) 112{if(textBoxElement) 113{var id=textBoxElement.getAttribute('id');var htmlElement=document.getElementById(id);if(htmlElement) 114{var htmlParent=htmlElement.parentNode;if(textBoxElement.getAttribute('visible')=='yes') 115{if(textBoxElement.getAttribute('dynamic')=='yes') 116{var content=String(getChildElementTextByTagName(textBoxElement,'richText'));htmlElement.innerHTML=content;htmlParent.innerHTML=htmlElement.outerHTML;} 117htmlParent.style.visibility='visible';}}}} 118function dynamicallyPopulateImage(imageElement) 119{if(imageElement) 120{var id=imageElement.getAttribute('id');var htmlElement=document.getElementById(id);if(htmlElement) 121{if(imageElement.getAttribute('visible')=='yes') 122{if(imageElement.getAttribute('dynamic')=='yes') 123{htmlElement.src=imageElement.getAttribute('src');htmlElement.style.left=imageElement.getAttribute('left');htmlElement.style.top=imageElement.getAttribute('top');htmlElement.style.width=imageElement.getAttribute('width');htmlElement.style.height=imageElement.getAttribute('height');} 124htmlElement.style.visibility='visible';}}}} 125function getContentXmlURL() 126{var url=null;var query=window.location.search;if(query) 127{if(query.match(/[&\+\?]content=([^&\+]*)/)) 128{url=RegExp.$1;}} 129return url;}
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.