// // iWeb - HeaderControls.js // Copyright (c) 2007 Apple Inc. All rights reserved. // function HeaderControls(instanceID) {if(instanceID!=null) {Widget.apply(this,arguments);NotificationCenter.addObserver(this,HeaderControls.prototype.p_prevPage,"PreviousPage",this.p_mediaGridID());NotificationCenter.addObserver(this,HeaderControls.prototype.p_nextPage,"NextPage",this.p_mediaGridID());NotificationCenter.addObserver(this,HeaderControls.prototype.p_setPage,"SetPage",this.p_mediaGridID());this.mRange=new IWPageRange(0,5);this.p_updateRange();}} HeaderControls.prototype=new Widget();HeaderControls.prototype.constructor=HeaderControls;HeaderControls.prototype.widgetIdentifier="com-apple-iweb-widget-headercontrols";HeaderControls.prototype.onload=function() {var defaults={showBackToIndex:true,showAddPhoto:true,showSubscribe:true,showSlideshow:true,mediaIndex:false,entriesPerPage:99,entryCount:0};this.initializeDefaultPreferences(defaults);this.setPage(0);this.updateFromPreferences();if(this.preferences&&this.preferences.postNotification) {this.preferences.postNotification("BLWidgetIsSafeToDrawNotification",1);}} HeaderControls.prototype.onunload=function() {} HeaderControls.prototype.startup=function() {this.p_updateCanvasControls();this.p_updateBackToIndex();this.p_updatePaginationControls();this.p_updateAddPhoto();this.p_updateSubscribe();this.p_updateSlideshow();if(this.p_mediaIndex()) {this.getElementById("media_index_only").show();} else {this.getElementById("album_only").show();}} HeaderControls.prototype.changedPreferenceForKey=function(key) {if(key=="entriesPerPage"||key=="entryCount"||key=="x-currentPage") {this.p_updateRange();this.p_updatePaginationControls();} else if(key=="showBackToIndex") {this.p_updateBackToIndex();} else if(key=="showAddPhoto") {this.p_updateAddPhoto();} else if(key=="showSubscribe") {this.p_updateSubscribe();} else if(key=="showSlideshow") {this.p_updateSlideshow();} else if(key=="canvas controls") {this.p_updateCanvasControls();} else if(this.runningInApp) {if(key=="x-nextPage") {this.nextPage();} else if(key=="x-previousPage") {this.prevPage();} else if(key=="x-setPage") {this.setPage(this.p_setPagePreference());}}} HeaderControls.prototype.updateFromPreferences=function() {this.startup();} HeaderControls.prototype.prevPage=function() {NotificationCenter.postNotification(new IWNotification("PreviousPage",this.p_mediaGridID(),null));} HeaderControls.prototype.nextPage=function() {NotificationCenter.postNotification(new IWNotification("NextPage",this.p_mediaGridID(),null));} HeaderControls.prototype.setPage=function(pageIndex) {NotificationCenter.postNotification(new IWNotification("SetPage",this.p_mediaGridID(),{pageIndex:pageIndex}));} HeaderControls.prototype.playSlideshow=function() {if(this.mPlaySlideshowFunction) {this.mPlaySlideshowFunction();}} HeaderControls.prototype.setPlaySlideshowFunction=function(playSlideshow) {this.mPlaySlideshowFunction=playSlideshow;} HeaderControls.prototype.p_canNavigateToPrev=function() {return(this.p_currentPage()>0);} HeaderControls.prototype.p_prevPage=function(notification) {if(this.p_canNavigateToPrev()) {this.setPage(this.p_currentPage()-1);}} HeaderControls.prototype.p_canNavigateToNext=function() {return(this.p_currentPage()";controls+=imgMarkup(leftArrowSrc,'','','');controls+=" ";} else {var leftArrowSrc=canvasControlURLs['canvas_arrow-left-D'];controls+=imgMarkup(leftArrowSrc,'','','')+" ";} for(var i=this.mRange.min();i ";} else {controls+=""+(i+1)+" ";}} if(this.p_canNavigateToNext()) {var rightArrowSrc=canvasControlURLs['canvas_arrow-right'];controls+="";controls+=imgMarkup(rightArrowSrc,'','','');controls+="";} else {var rightArrowSrc=canvasControlURLs['canvas_arrow-right-D'];controls+=imgMarkup(rightArrowSrc,'','','');}} var template=new Template(controls);var myControls=template.evaluate({WIDGET_ID:this.instanceID});this.getElementById("pagination_controls").update(myControls);widgetDiv.select('.paginated_only').invoke(this.p_isPaginated()?'show':'hide');widgetDiv.select('.non_paginated_only').invoke(this.p_isPaginated()?'hide':'show');if(this.runningInApp) {this.setPreferenceForKey(controls,"x-paginationSpanContents");} else {NotificationCenter.postNotification(new IWNotification("paginationSpanContents",this.p_mediaGridID(),{controls:controls}));}} HeaderControls.prototype.p_setAnchorsUnderElementToHREF=function(element,href) {var links=element.getElementsByTagName("a");for(var i=0;ithis.p_entriesPerPage());} HeaderControls.prototype.p_pageCount=function() {return Math.ceil(this.p_entryCount()/this.p_entriesPerPage());} HeaderControls.prototype.p_updateRange=function() {var pageCount=this.p_pageCount();var currentPage=this.p_currentPage();if(currentPage>=pageCount) {currentPage=pageCount-1;this.setPreferenceForKey(currentPage,"x-currentPage");} if(pageCount<=5||this.mRange.length()<3||this.mRange.max()>pageCount) {this.mRange.setMax(Math.min(5,pageCount));} if(currentPage=this.mRange.max()) {this.mRange.shift(currentPage-this.mRange.max()+1);}}