﻿function NavBar(b){if(b){Widget.apply(this,arguments);if(!this.preferenceForKey("useStaticFeed")&&this.preferenceForKey("dotMacAccount")){var a=this.preferenceForKey("path-to-root");if(!a||a=="")a="./";this.xml_feed=a+"?webdav-method=truthget&depth=infinity&ns=iweb&filterby=in-navbar"}else{this.xml_feed="feed.xml";if(this.sitePath)this.xml_feed=this.sitePath+"/"+this.xml_feed}this.changedPreferenceForKey("navbar-css");this.regenerate()}}NavBar.prototype=new Widget;NavBar.prototype.constructor=NavBar;NavBar.prototype.widgetIdentifier="com-apple-iweb-widget-NavBar";NavBar.prototype.regenerate=function(){var a=this.PopulateNavItems.bind(this);ajaxRequest(this.xml_feed,a);return true};NavBar.prototype.getStyleElement=function(){if(!this.styleElement){var b=document.getElementsByTagName("head")[0];if(b){var a=document.createElement("style");a.type="text/css";b.appendChild(a);this.styleElement=a}}return this.styleElement};NavBar.prototype.substWidgetPath=function(b){var a=b.replace(/\$WIDGET_PATH/gm,this.widgetPath);return a};NavBar.prototype.addCSSSelectorPrefix=function(a){var b="div#"+this.instanceID+" ";a=a.replace(/\/\*[^*]*\*+([^/][^*]*\*+)*\//gm,"");a=a.replace(/(^\s*|\}\s*)([^{]+)({[^}]*})/gm,function(h,e,g,f){var a=e,d=g.split(",");for(var c=0;c<d.length;c++){a+=b+d[c];if(c+1<d.length)a+=","}a+=f;return a});return a};NavBar.prototype.changedPreferenceForKey=function(d){if(d=="navbar-css"){var a=this.preferenceForKey(d);if(!a)a="";a=this.substWidgetPath(a);a=this.addCSSSelectorPrefix(a);var b=this.getStyleElement();if(b){detectBrowser();if(!windowsInternetExplorer){var c=document.createTextNode(a);if(c){while(b.hasChildNodes())b.removeChild(b.firstChild);b.appendChild(c)}}else b.styleSheet.cssText=a}}};NavBar.prototype.PopulateNavItems=function(n){var f,m;if(isAjaxRequestReady(n)&&(m=ajaxGetDocumentElement(n))){var o=this.getAtomFeedItems(m),f=o.resultArray,k=null,j="NO",g=null;if(this.runningInApp)g=/\.#current#.$/;else{k=this.preferenceForKey("current-page-GUID");j=this.preferenceForKey("isCollectionPage")}var b=this.div("navbar-list"),p=b.parentNode;$(p).ensureHasLayoutForIE();while(b.firstChild)b.removeChild(b.firstChild);var d=this.preferenceForKey("path-to-root");if(!d||d=="")d="./";for(var c=0;c<f.length;c++){var e=document.createElement("li"),h=document.createElement("a"),i=f[c].title,q=f[c].GUID;i=i.replace(/ /g," ")+" ";var a=f[c].url;if(!this.runningInApp&&!a.match(/^http:/i))a=d+a;var l=this.runningInApp&&g.exec(unescape(new String(a)));if(l)a=a.replace(g,"");if(q==k||l){e.className="current-page";if(!this.runningInApp&&j!="YES")a=""}else e.className="noncurrent-page";h.setAttribute("href",a);h.appendChild(document.createTextNode(i));e.appendChild(h);b.appendChild(e)}if(this.preferences&&this.preferences.postNotification)this.preferences.postNotification("BLWidgetIsSafeToDrawNotification",1)}};NavBar.prototype.getAtomFeedItems=function(j){var b=[],f=[];if(j){var m="",i=getFirstElementByTagName(j,"generator");if(i&&i.firstChild)m=allData(i);var c,k;for(var a=j.firstChild;a;a=a.nextSibling){var e=null;if(!c&&(k=findChild(a,"site-navbar","urn:iweb:"))){c=allData(k).split(",");for(var h=0;h<c.length;h++){var g=c[h];f[""+g]=h}}if(a.nodeName=="entry"&&(e=findChild(a,"in-navbar","urn:iweb:"))){if(!e)continue;var g="";if(e.firstChild)g=""+allData(e);else iWLog("no navBarElt child");if(g=="navbar-sort")continue;var l="",d=findChild(a,"title","urn:iweb:");if(!d){iWLog("No iWeb title");d=findChild(a,"title")}if(d&&d.firstChild)l=allData(d);var n=getFirstElementByTagName(a,"link");url=n.getAttribute("href");if(!url&&linkElement.firstChild)url=allData(linkElement);b[b.length]={title:l,url:url,GUID:g}}}}if(c){b=$(b).reject(function(a){return f[a.GUID]===undefined});b.sort(function(a,b){return f[a.GUID]-f[b.GUID]})}return {resultArray:b}};function findChild(e,c,b){var a;for(a=e.firstChild;a;a=a.nextSibling)if(a.localName==c||a.baseName==c){if(!b)return a;var d=a.namespaceURI;if(d==b)return a}return null}function getFirstElementByTagName(c,b){var a=c.getElementsByTagName(b);if(a.length)return a[0];else return findChild(c,b)}function allData(a){a=a.firstChild;var b=a.data;while(a=a.nextSibling)b+=a.data;return b}NavBar.prototype.onload=function(){};NavBar.prototype.onunload=function(){}