Skip to content

Commit

Permalink
Merge pull request mozilla#7038 from Snuffleupagus/refactor-sidebar
Browse files Browse the repository at this point in the history
Move the sidebar related code from viewer.js into `PDFSidebar`
  • Loading branch information
timvandermeij committed Feb 28, 2016
2 parents 7cb3c36 + 67a1dfc commit 9ff6c83
Show file tree
Hide file tree
Showing 6 changed files with 468 additions and 212 deletions.
44 changes: 29 additions & 15 deletions web/pdf_attachment_view.js → web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@
'use strict';

/**
* @typedef {Object} PDFAttachmentViewOptions
* @typedef {Object} PDFAttachmentViewerOptions
* @property {HTMLDivElement} container - The viewer element.
* @property {Array} attachments - An array of attachment objects.
* @property {DownloadManager} downloadManager - The download manager.
*/

/**
* @typedef {Object} PDFAttachmentViewerRenderParameters
* @property {Array|null} attachments - An array of attachment objects.
*/

/**
* @class
*/
var PDFAttachmentView = (function PDFAttachmentViewClosure() {
var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
/**
* @constructs PDFAttachmentView
* @param {PDFAttachmentViewOptions} options
* @constructs PDFAttachmentViewer
* @param {PDFAttachmentViewerOptions} options
*/
function PDFAttachmentView(options) {
function PDFAttachmentViewer(options) {
this.attachments = null;
this.container = options.container;
this.attachments = options.attachments;
this.downloadManager = options.downloadManager;
}

PDFAttachmentView.prototype = {
reset: function PDFAttachmentView_reset() {
PDFAttachmentViewer.prototype = {
reset: function PDFAttachmentViewer_reset() {
this.attachments = null;

var container = this.container;
while (container.firstChild) {
container.removeChild(container.firstChild);
Expand All @@ -48,7 +54,8 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
/**
* @private
*/
_dispatchEvent: function PDFAttachmentView_dispatchEvent(attachmentsCount) {
_dispatchEvent:
function PDFAttachmentViewer_dispatchEvent(attachmentsCount) {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('attachmentsloaded', true, true, {
attachmentsCount: attachmentsCount
Expand All @@ -59,18 +66,25 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
/**
* @private
*/
_bindLink: function PDFAttachmentView_bindLink(button, content, filename) {
_bindLink:
function PDFAttachmentViewer_bindLink(button, content, filename) {
button.onclick = function downloadFile(e) {
this.downloadManager.downloadData(content, filename, '');
return false;
}.bind(this);
},

render: function PDFAttachmentView_render() {
var attachments = this.attachments;
/**
* @param {PDFAttachmentViewerRenderParameters} params
*/
render: function PDFAttachmentViewer_render(params) {
var attachments = (params && params.attachments) || null;
var attachmentsCount = 0;

this.reset();
if (this.attachments) {
this.reset();
}
this.attachments = attachments;

if (!attachments) {
this._dispatchEvent(attachmentsCount);
Expand Down Expand Up @@ -98,5 +112,5 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
}
};

return PDFAttachmentView;
return PDFAttachmentViewer;
})();
56 changes: 36 additions & 20 deletions web/pdf_outline_view.js → web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,46 @@
var DEFAULT_TITLE = '\u2013';

/**
* @typedef {Object} PDFOutlineViewOptions
* @typedef {Object} PDFOutlineViewerOptions
* @property {HTMLDivElement} container - The viewer element.
* @property {Array} outline - An array of outline objects.
* @property {IPDFLinkService} linkService - The navigation/linking service.
*/

/**
* @typedef {Object} PDFOutlineViewerRenderParameters
* @property {Array|null} outline - An array of outline objects.
*/

/**
* @class
*/
var PDFOutlineView = (function PDFOutlineViewClosure() {
var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
/**
* @constructs PDFOutlineView
* @param {PDFOutlineViewOptions} options
* @constructs PDFOutlineViewer
* @param {PDFOutlineViewerOptions} options
*/
function PDFOutlineView(options) {
function PDFOutlineViewer(options) {
this.outline = null;
this.lastToggleIsShow = true;
this.container = options.container;
this.outline = options.outline;
this.linkService = options.linkService;
this.lastToggleIsShow = true;
}

PDFOutlineView.prototype = {
reset: function PDFOutlineView_reset() {
PDFOutlineViewer.prototype = {
reset: function PDFOutlineViewer_reset() {
this.outline = null;
this.lastToggleIsShow = true;

var container = this.container;
while (container.firstChild) {
container.removeChild(container.firstChild);
}
this.lastToggleIsShow = true;
},

/**
* @private
*/
_dispatchEvent: function PDFOutlineView_dispatchEvent(outlineCount) {
_dispatchEvent: function PDFOutlineViewer_dispatchEvent(outlineCount) {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('outlineloaded', true, true, {
outlineCount: outlineCount
Expand All @@ -63,7 +69,7 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
/**
* @private
*/
_bindLink: function PDFOutlineView_bindLink(element, item) {
_bindLink: function PDFOutlineViewer_bindLink(element, item) {
if (item.url) {
PDFJS.addLinkAttributes(element, { url: item.url });
return;
Expand All @@ -82,7 +88,7 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
*
* @private
*/
_addToggleButton: function PDFOutlineView_addToggleButton(div) {
_addToggleButton: function PDFOutlineViewer_addToggleButton(div) {
var toggler = document.createElement('div');
toggler.className = 'outlineItemToggler';
toggler.onclick = function(event) {
Expand All @@ -106,7 +112,8 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
*
* @private
*/
_toggleOutlineItem: function PDFOutlineView_toggleOutlineItem(root, show) {
_toggleOutlineItem:
function PDFOutlineViewer_toggleOutlineItem(root, show) {
this.lastToggleIsShow = show;
var togglers = root.querySelectorAll('.outlineItemToggler');
for (var i = 0, ii = togglers.length; i < ii; ++i) {
Expand All @@ -117,15 +124,24 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
/**
* Collapse or expand all subtrees of the outline.
*/
toggleOutlineTree: function PDFOutlineView_toggleOutlineTree() {
toggleOutlineTree: function PDFOutlineViewer_toggleOutlineTree() {
if (!this.outline) {
return;
}
this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
},

render: function PDFOutlineView_render() {
var outline = this.outline;
/**
* @param {PDFOutlineViewerRenderParameters} params
*/
render: function PDFOutlineViewer_render(params) {
var outline = (params && params.outline) || null;
var outlineCount = 0;

this.reset();
if (this.outline) {
this.reset();
}
this.outline = outline;

if (!outline) {
this._dispatchEvent(outlineCount);
Expand Down Expand Up @@ -174,5 +190,5 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
}
};

return PDFOutlineView;
return PDFOutlineViewer;
})();
Loading

0 comments on commit 9ff6c83

Please sign in to comment.