Fix event handler leak for modals and notifications

Also add support for passing custom variables into notifications.

Fixes #1694
This commit is contained in:
Jermolene
2015-05-06 08:07:12 +01:00
parent 03f3b1fdb4
commit 86e901f375
2 changed files with 21 additions and 13 deletions

View File

@@ -29,6 +29,7 @@ Options include:
Modal.prototype.display = function(title,options) {
options = options || {};
var self = this,
refreshHandler,
duration = $tw.utils.getAnimationDuration(),
tiddler = this.wiki.getTiddler(title);
// Don't do anything if the tiddler doesn't exist
@@ -83,9 +84,6 @@ Modal.prototype.display = function(title,options) {
variables: variables
});
headerWidgetNode.render(headerTitle,null);
this.wiki.addEventListener("change",function(changes) {
headerWidgetNode.refresh(changes,modalHeader,null);
});
// Render the body of the message
var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{
parentWidget: $tw.rootWidget,
@@ -93,9 +91,6 @@ Modal.prototype.display = function(title,options) {
variables: variables
});
bodyWidgetNode.render(modalBody,null);
this.wiki.addEventListener("change",function(changes) {
bodyWidgetNode.refresh(changes,modalBody,null);
});
// Setup the link if present
if(options.downloadLink) {
modalLink.href = options.downloadLink;
@@ -135,11 +130,17 @@ Modal.prototype.display = function(title,options) {
variables: variables
});
footerWidgetNode.render(modalFooterButtons,null);
this.wiki.addEventListener("change",function(changes) {
// Set up the refresh handler
refreshHandler = function(changes) {
headerWidgetNode.refresh(changes,modalHeader,null);
bodyWidgetNode.refresh(changes,modalBody,null);
footerWidgetNode.refresh(changes,modalFooterButtons,null);
});
};
this.wiki.addEventListener("change",refreshHandler);
// Add the close event handler
var closeHandler = function(event) {
// Remove our refresh handler
self.wiki.removeEventListener("change",refreshHandler);
// Decrease the modal count and adjust the body class
self.modalCount--;
self.adjustPageClass();