Merge pull request #5868 from Snuffleupagus/bug-1112947

Add custom |outlineloaded| and |attachmentsloaded| events to the viewer (bug 1112947)
This commit is contained in:
Yury Delendik 2015-03-25 14:15:24 -05:00
commit 185067e0cf
2 changed files with 34 additions and 1 deletions

View File

@ -47,6 +47,17 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
} }
}, },
/**
* @private
*/
_dispatchEvent: function PDFAttachmentView_dispatchEvent(attachmentsCount) {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('attachmentsloaded', true, true, {
attachmentsCount: attachmentsCount
});
this.container.dispatchEvent(event);
},
/** /**
* @private * @private
*/ */
@ -59,17 +70,21 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
render: function PDFAttachmentView_render() { render: function PDFAttachmentView_render() {
var attachments = this.attachments; var attachments = this.attachments;
var attachmentsCount = 0;
this.reset(); this.reset();
if (!attachments) { if (!attachments) {
this._dispatchEvent(attachmentsCount);
return; return;
} }
var names = Object.keys(attachments).sort(function(a, b) { var names = Object.keys(attachments).sort(function(a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase()); return a.toLowerCase().localeCompare(b.toLowerCase());
}); });
for (var i = 0, len = names.length; i < len; i++) { attachmentsCount = names.length;
for (var i = 0; i < attachmentsCount; i++) {
var item = attachments[names[i]]; var item = attachments[names[i]];
var filename = getFileName(item.filename); var filename = getFileName(item.filename);
var div = document.createElement('div'); var div = document.createElement('div');
@ -80,6 +95,8 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
div.appendChild(button); div.appendChild(button);
this.container.appendChild(div); this.container.appendChild(div);
} }
this._dispatchEvent(attachmentsCount);
} }
}; };

View File

@ -46,6 +46,17 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
} }
}, },
/**
* @private
*/
_dispatchEvent: function PDFOutlineView_dispatchEvent(outlineCount) {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('outlineloaded', true, true, {
outlineCount: outlineCount
});
this.container.dispatchEvent(event);
},
/** /**
* @private * @private
*/ */
@ -60,10 +71,12 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
render: function PDFOutlineView_render() { render: function PDFOutlineView_render() {
var outline = this.outline; var outline = this.outline;
var outlineCount = 0;
this.reset(); this.reset();
if (!outline) { if (!outline) {
this._dispatchEvent(outlineCount);
return; return;
} }
@ -87,8 +100,11 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
} }
levelData.parent.appendChild(div); levelData.parent.appendChild(div);
outlineCount++;
} }
} }
this._dispatchEvent(outlineCount);
} }
}; };