From 94cc731616272f1118d4c9ea2010303813285a31 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 21 Mar 2015 13:07:01 +0100 Subject: [PATCH] Add custom |outlineloaded| and |attachmentsloaded| events to the viewer (bug 1112947) --- web/pdf_attachment_view.js | 19 ++++++++++++++++++- web/pdf_outline_view.js | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/web/pdf_attachment_view.js b/web/pdf_attachment_view.js index ad1b7dfe4..df98b71f5 100644 --- a/web/pdf_attachment_view.js +++ b/web/pdf_attachment_view.js @@ -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 */ @@ -59,17 +70,21 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() { render: function PDFAttachmentView_render() { var attachments = this.attachments; + var attachmentsCount = 0; this.reset(); if (!attachments) { + this._dispatchEvent(attachmentsCount); return; } var names = Object.keys(attachments).sort(function(a, b) { 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 filename = getFileName(item.filename); var div = document.createElement('div'); @@ -80,6 +95,8 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() { div.appendChild(button); this.container.appendChild(div); } + + this._dispatchEvent(attachmentsCount); } }; diff --git a/web/pdf_outline_view.js b/web/pdf_outline_view.js index 41995a885..311a27011 100644 --- a/web/pdf_outline_view.js +++ b/web/pdf_outline_view.js @@ -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 */ @@ -60,10 +71,12 @@ var PDFOutlineView = (function PDFOutlineViewClosure() { render: function PDFOutlineView_render() { var outline = this.outline; + var outlineCount = 0; this.reset(); if (!outline) { + this._dispatchEvent(outlineCount); return; } @@ -87,8 +100,11 @@ var PDFOutlineView = (function PDFOutlineViewClosure() { } levelData.parent.appendChild(div); + outlineCount++; } } + + this._dispatchEvent(outlineCount); } };