| ContentPageToolbar = function(){ |
| |
| this.expandAllImage = null; |
| this.collapseAllImage = null; |
| this.bookmarkImage = null; |
| this.printImage = null; |
| this.backImage = null; |
| this.forwardImage = null; |
| this.dividerImage = null; |
| |
| // hold the toolbar item ids |
| this.toolbarItems = [], |
| |
| this.barItemIdPrefix = "contentbar_"; |
| |
| } |
| |
| ContentPageToolbar.prototype.init = function(imgPath) { |
| |
| this.expandAllImage = contentPage.resolveUrl(imgPath + 'expand_all.gif'); |
| this.collapseAllImage = contentPage.resolveUrl(imgPath + 'collapse_all.gif'); |
| this.bookmarkImage = contentPage.resolveUrl(imgPath + 'bookmark.gif'); |
| this.printImage = contentPage.resolveUrl(imgPath + 'print.gif'); |
| this.backImage = contentPage.resolveUrl(imgPath + 'back.gif'); |
| this.forwardImage = contentPage.resolveUrl(imgPath + 'forward.gif'); |
| this.dividerImage = contentPage.resolveUrl(imgPath + 'divider.gif'); |
| //this.shimImage = contentPage.resolveUrl(imgPath + 'shim.gif'); |
| |
| this._createToolbar(); |
| }; |
| |
| ContentPageToolbar.prototype._createToolbar = function() { |
| var container = document.getElementById("contentPageToolbar"); |
| |
| if ( container == null ) { |
| return; |
| } |
| |
| var html = "<table border='0' cellspacing='0' cellpadding='0' >" + |
| "<tr>" + |
| this._getToolbarItemHtml(this.bookmarkImage, "Bookmark this page") + |
| this._getToolbarItemHtml(this.backImage, "back") + |
| this._getToolbarItemHtml(this.forwardImage, "forward") + |
| this._getToolbarItemHtml(this.expandAllImage , "expand all") + |
| this._getToolbarItemHtml(this.collapseAllImage, "collapse all") + |
| "<td width='10px'><img src='" + this.dividerImage + "' title=''/></td>" + |
| this._getToolbarItemHtml(this.printImage, "print") + |
| "</tr>" + |
| "</table>"; |
| |
| container.innerHTML = html; |
| |
| // attach events |
| for (var i = 0; i < this.toolbarItems.length; i++ ) { |
| var id = this.toolbarItems[i]; |
| var bar = document.getElementById(id); |
| //alert(bar.tagName); |
| |
| var handler = null; |
| if ( id.indexOf(this.bookmarkImage) >= 0 ) { |
| handler = function() { |
| return contentPage.saveAsBookmark(); |
| }; |
| } else if ( id.indexOf(this.backImage) >= 0 ) { |
| handler = function() { |
| //alert("back"); |
| var app = contentPage.getApp(); |
| if ( app != null ) { |
| app.browser.back(); |
| } |
| return false; |
| }; |
| } else if ( id.indexOf(this.forwardImage) >= 0 ) { |
| handler = function() { |
| var app = contentPage.getApp(); |
| if ( app != null ) { |
| app.browser.forward(); |
| } |
| return false; |
| }; |
| } else if ( id.indexOf(this.expandAllImage) >= 0 ) { |
| handler = function() { |
| contentPage.section.expandAll(); |
| return false; |
| }; |
| } else if ( id.indexOf(this.collapseAllImage) >= 0 ) { |
| handler = function() { |
| contentPage.section.collapseAll(); |
| return false; |
| }; |
| } else if ( id.indexOf(this.printImage) >= 0 ) { |
| handler = function() { |
| window.print(); |
| return false; |
| }; |
| } |
| |
| if ( handler != null ) { |
| bar.onclick = handler; |
| } |
| } |
| |
| |
| /* |
| var table = document.createElement("table"); |
| table.border = "2"; |
| table.cellspacing = "0"; |
| table.cellpadding = "0"; |
| container.appendChild(table); |
| |
| var tr = document.createElement("tr"); |
| table.appendChild(tr); |
| */ |
| // create the bar items |
| //tr.appendChild(this._createToolbarItem(this.bookmarkImage, "Bookmark this page", "20px")); |
| /* |
| tr.appendChild(this.createToolbarItem(this.backImage, "back", "20px")); |
| tr.appendChild(this.createToolbarItem(this.forwardImage, "forward", "20px")); |
| tr.appendChild(this.createToolbarItem(this.expandAllImage, "expand All", "20px")); |
| tr.appendChild(this.createToolbarItem(this.collapseAllImage, "collapse All", "20px")); |
| tr.appendChild(this.createToolbarItem(this.dividerImage, "", "10px")); |
| tr.appendChild(this.createToolbarItem(this.printImage, "Print", "20px")); |
| */ |
| |
| }; |
| |
| ContentPageToolbar.prototype._getToolbarItemHtml = function(imgSrc, text) { |
| |
| var index = this.toolbarItems.length; |
| var id = this.barItemIdPrefix + imgSrc; |
| this.toolbarItems[index] = id; |
| |
| var html = "<td width='20px'>" + |
| "<img style='cursor:hand' id='" + id + "' src='" + imgSrc + "' title='" + text + "'/>" + |
| "</td>"; |
| |
| return html; |
| }; |
| |
| ContentPageToolbar.prototype._createToolbarItem = function(imgSrc, text, width) { |
| var td = document.createElement("td"); |
| td.width = width; |
| |
| var img = document.createElement("img"); |
| img.id = this.barItemIdPrefix + imgSrc; |
| |
| img.src = imgSrc; |
| img.title = text; |
| img.alt = text; |
| img.width = '16'; |
| img.height = '16'; |
| img.border = '0'; |
| //img.align = 'absmiddle'; |
| |
| td.appendChild(img); |
| |
| //alert("td: " + td); |
| |
| return td; |
| }; |
| |
| |