Skip to content

Commit

Permalink
Add custom |outlineloaded| and |attachmentsloaded| events to the view…
Browse files Browse the repository at this point in the history
…er (bug 1112947)
  • Loading branch information
Snuffleupagus committed Mar 21, 2015
1 parent 2d11266 commit 94cc731
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
19 changes: 18 additions & 1 deletion web/pdf_attachment_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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');
Expand All @@ -80,6 +95,8 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
div.appendChild(button);
this.container.appendChild(div);
}

this._dispatchEvent(attachmentsCount);
}
};

Expand Down
16 changes: 16 additions & 0 deletions web/pdf_outline_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}

Expand All @@ -87,8 +100,11 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
}

levelData.parent.appendChild(div);
outlineCount++;
}
}

this._dispatchEvent(outlineCount);
}
};

Expand Down

0 comments on commit 94cc731

Please sign in to comment.