From 3eeb57142531a811362a54a5442573f121713c01 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Tue, 27 Jan 2015 22:38:45 +0100 Subject: [PATCH 1/4] Rename document_outline_view.js to pdf_outline_view.js --- web/{document_outline_view.js => pdf_outline_view.js} | 0 web/viewer.html | 2 +- web/viewer.js | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename web/{document_outline_view.js => pdf_outline_view.js} (100%) diff --git a/web/document_outline_view.js b/web/pdf_outline_view.js similarity index 100% rename from web/document_outline_view.js rename to web/pdf_outline_view.js diff --git a/web/viewer.html b/web/viewer.html index 1aa78dda1..1a6a406cb 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -75,7 +75,7 @@ http://sourceforge.net/adobe/cmap/wiki/License/ - + diff --git a/web/viewer.js b/web/viewer.js index d47962d01..3b5e6175a 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -86,6 +86,7 @@ var mozL10n = document.mozL10n || document.webL10n; //#include document_properties.js //#include pdf_viewer.js //#include pdf_thumbnail_viewer.js +//#include pdf_outline_view.js var PDFViewerApplication = { initialBookmark: document.location.hash.substring(1), @@ -1390,7 +1391,6 @@ var PDFViewerApplication = { window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias //#endif -//#include document_outline_view.js //#include document_attachments_view.js //#if CHROME From b17da309ed2207b8ffb86d3c713b65bbd8ef01fc Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Tue, 27 Jan 2015 22:40:12 +0100 Subject: [PATCH 2/4] Rename DocumentOutlineView to PDFOutlineView --- web/pdf_outline_view.js | 2 +- web/viewer.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/pdf_outline_view.js b/web/pdf_outline_view.js index 5a3ccd315..1b018603d 100644 --- a/web/pdf_outline_view.js +++ b/web/pdf_outline_view.js @@ -17,7 +17,7 @@ 'use strict'; -var DocumentOutlineView = function documentOutlineView(options) { +var PDFOutlineView = function documentOutlineView(options) { var outline = options.outline; var outlineView = options.outlineView; while (outlineView.firstChild) { diff --git a/web/viewer.js b/web/viewer.js index 3b5e6175a..b6c1403d3 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -19,7 +19,7 @@ PDFHistory, Preferences, SidebarView, ViewHistory, Stats, PDFThumbnailViewer, URL, noContextMenuHandler, SecondaryToolbar, PasswordPrompt, PresentationMode, HandTool, Promise, - DocumentProperties, DocumentOutlineView, DocumentAttachmentsView, + DocumentProperties, PDFOutlineView, DocumentAttachmentsView, OverlayManager, PDFFindController, PDFFindBar, getVisibleElements, watchScroll, PDFViewer, PDFRenderingQueue, PresentationModeState, RenderingStates, DEFAULT_SCALE, UNKNOWN_SCALE, @@ -967,7 +967,7 @@ var PDFViewerApplication = { Promise.all(promises).then(function() { pdfDocument.getOutline().then(function(outline) { var outlineView = document.getElementById('outlineView'); - self.outline = new DocumentOutlineView({ + self.outline = new PDFOutlineView({ outline: outline, outlineView: outlineView, linkService: self From ea1d37eb0d2f931b4ab6baf2d7ec585fe72c37e7 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Tue, 27 Jan 2015 22:51:39 +0100 Subject: [PATCH 3/4] Refactor PDFAttachmentView to be more class-like and to separate functionality into methods --- web/pdf_outline_view.js | 87 ++++++++++++++++++++++++----------------- web/viewer.js | 7 ++-- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/web/pdf_outline_view.js b/web/pdf_outline_view.js index 1b018603d..f8fcc0498 100644 --- a/web/pdf_outline_view.js +++ b/web/pdf_outline_view.js @@ -17,48 +17,63 @@ 'use strict'; -var PDFOutlineView = function documentOutlineView(options) { - var outline = options.outline; - var outlineView = options.outlineView; - while (outlineView.firstChild) { - outlineView.removeChild(outlineView.firstChild); +var PDFOutlineView = (function PDFOutlineViewClosure() { + function PDFOutlineView(options) { + this.container = options.container; + this.outline = options.outline; + this.linkService = options.linkService; } - if (!outline) { - return; - } + PDFOutlineView.prototype = { + reset: function PDFOutlineView_reset() { + var container = this.container; + while (container.firstChild) { + container.removeChild(container.firstChild); + } + }, - var linkService = options.linkService; + _bindLink: function PDFOutlineView_bindLink(element, item) { + var linkService = this.linkService; + element.href = linkService.getDestinationHash(item.dest); + element.onclick = function goToDestination(e) { + linkService.navigateTo(item.dest); + return false; + }; + }, - function bindItemLink(domObj, item) { - domObj.href = linkService.getDestinationHash(item.dest); - domObj.onclick = function documentOutlineViewOnclick(e) { - linkService.navigateTo(item.dest); - return false; - }; - } + render: function PDFOutlineView_render() { + var outline = this.outline; - var queue = [{parent: outlineView, items: outline}]; - while (queue.length > 0) { - var levelData = queue.shift(); - var i, n = levelData.items.length; - for (i = 0; i < n; i++) { - var item = levelData.items[i]; - var div = document.createElement('div'); - div.className = 'outlineItem'; - var a = document.createElement('a'); - bindItemLink(a, item); - a.textContent = item.title; - div.appendChild(a); + this.reset(); - if (item.items.length > 0) { - var itemsDiv = document.createElement('div'); - itemsDiv.className = 'outlineItems'; - div.appendChild(itemsDiv); - queue.push({parent: itemsDiv, items: item.items}); + if (!outline) { + return; } - levelData.parent.appendChild(div); + var queue = [{ parent: this.container, items: this.outline }]; + while (queue.length > 0) { + var levelData = queue.shift(); + for (var i = 0, len = levelData.items.length; i < len; i++) { + var item = levelData.items[i]; + var div = document.createElement('div'); + div.className = 'outlineItem'; + var element = document.createElement('a'); + this._bindLink(element, item); + element.textContent = item.title; + div.appendChild(element); + + if (item.items.length > 0) { + var itemsDiv = document.createElement('div'); + itemsDiv.className = 'outlineItems'; + div.appendChild(itemsDiv); + queue.push({ parent: itemsDiv, items: item.items }); + } + + levelData.parent.appendChild(div); + } + } } - } -}; + }; + + return PDFOutlineView; +})(); diff --git a/web/viewer.js b/web/viewer.js index b6c1403d3..ac3a49079 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -966,15 +966,16 @@ var PDFViewerApplication = { var promises = [pagesPromise, this.animationStartedPromise]; Promise.all(promises).then(function() { pdfDocument.getOutline().then(function(outline) { - var outlineView = document.getElementById('outlineView'); + var container = document.getElementById('outlineView'); self.outline = new PDFOutlineView({ + container: container, outline: outline, - outlineView: outlineView, linkService: self }); + self.outline.render(); document.getElementById('viewOutline').disabled = !outline; - if (!outline && !outlineView.classList.contains('hidden')) { + if (!outline && !container.classList.contains('hidden')) { self.switchSidebarView('thumbs'); } if (outline && From f4dbc994836467dfe9725d733b60baeaa3c13e81 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Tue, 27 Jan 2015 22:54:14 +0100 Subject: [PATCH 4/4] Add JSDoc comments to PDFOutlineView --- web/pdf_outline_view.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/web/pdf_outline_view.js b/web/pdf_outline_view.js index f8fcc0498..41995a885 100644 --- a/web/pdf_outline_view.js +++ b/web/pdf_outline_view.js @@ -17,7 +17,21 @@ 'use strict'; +/** + * @typedef {Object} PDFOutlineViewOptions + * @property {HTMLDivElement} container - The viewer element. + * @property {Array} outline - An array of outline objects. + * @property {IPDFLinkService} linkService - The navigation/linking service. + */ + +/** + * @class + */ var PDFOutlineView = (function PDFOutlineViewClosure() { + /** + * @constructs PDFOutlineView + * @param {PDFOutlineViewOptions} options + */ function PDFOutlineView(options) { this.container = options.container; this.outline = options.outline; @@ -32,6 +46,9 @@ var PDFOutlineView = (function PDFOutlineViewClosure() { } }, + /** + * @private + */ _bindLink: function PDFOutlineView_bindLink(element, item) { var linkService = this.linkService; element.href = linkService.getDestinationHash(item.dest);