Refactor PDFAttachmentView to be more class-like and to separate functionality into methods
This commit is contained in:
parent
b17da309ed
commit
ea1d37eb0d
@ -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;
|
||||
}
|
||||
|
||||
PDFOutlineView.prototype = {
|
||||
reset: function PDFOutlineView_reset() {
|
||||
var container = this.container;
|
||||
while (container.firstChild) {
|
||||
container.removeChild(container.firstChild);
|
||||
}
|
||||
},
|
||||
|
||||
_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;
|
||||
};
|
||||
},
|
||||
|
||||
render: function PDFOutlineView_render() {
|
||||
var outline = this.outline;
|
||||
|
||||
this.reset();
|
||||
|
||||
if (!outline) {
|
||||
return;
|
||||
}
|
||||
|
||||
var linkService = options.linkService;
|
||||
|
||||
function bindItemLink(domObj, item) {
|
||||
domObj.href = linkService.getDestinationHash(item.dest);
|
||||
domObj.onclick = function documentOutlineViewOnclick(e) {
|
||||
linkService.navigateTo(item.dest);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
var queue = [{parent: outlineView, items: outline}];
|
||||
var queue = [{ parent: this.container, items: this.outline }];
|
||||
while (queue.length > 0) {
|
||||
var levelData = queue.shift();
|
||||
var i, n = levelData.items.length;
|
||||
for (i = 0; i < n; i++) {
|
||||
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 a = document.createElement('a');
|
||||
bindItemLink(a, item);
|
||||
a.textContent = item.title;
|
||||
div.appendChild(a);
|
||||
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});
|
||||
queue.push({ parent: itemsDiv, items: item.items });
|
||||
}
|
||||
|
||||
levelData.parent.appendChild(div);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return PDFOutlineView;
|
||||
})();
|
||||
|
@ -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 &&
|
||||
|
Loading…
Reference in New Issue
Block a user