Fixing javascript errors when closing dialog.

This commit is contained in:
Sipke Schoorstra
2014-10-29 23:13:34 -07:00
parent 49c18d82c2
commit 372e56a2af
3 changed files with 29 additions and 17 deletions

View File

@@ -43,6 +43,7 @@
} }
self.renderGraph(targetContainer, graph, self.settings.domOperations.append); self.renderGraph(targetContainer, graph, self.settings.domOperations.append);
self.element.find("a.add.start").removeClass("start").hide(); self.element.find("a.add.start").removeClass("start").hide();
dialog.close(); dialog.close();
} }
}); });

View File

@@ -1,6 +1,15 @@
(function ($) { (function ($) {
var closedDialogs = [];
var disposeClosedDialogs = function() {
$.each(closedDialogs, function() {
this.dispose();
});
};
var Dialog = function (templateElementSelector) { var Dialog = function (templateElementSelector) {
var self = this; var self = this;
this.template = $(templateElementSelector); this.template = $(templateElementSelector);
this.root = null; this.root = null;
this.element = null; this.element = null;
@@ -9,6 +18,8 @@
this.isVisible = false; this.isVisible = false;
this._title = this.template.find(".title").html(); this._title = this.template.find(".title").html();
disposeClosedDialogs();
this.title = function (value) { this.title = function (value) {
var titleElement = this.root.find(".title"); var titleElement = this.root.find(".title");
this._title = value; this._title = value;
@@ -37,8 +48,9 @@
$(document).on("keyup", onKeyUp); $(document).on("keyup", onKeyUp);
this.frame.element.on("load", function(e) { this.frame.element.on("load", function (e) {
updateDialog(self.frame.getDocument()); if(self.isVisible)
updateDialog(self.frame.getDocument());
}); });
} }
@@ -47,14 +59,11 @@
if (this.root) { if (this.root) {
$(window).off("resize", resizeIFrame); $(window).off("resize", resizeIFrame);
this.root.remove(); this.root.hide();
} }
this.root = null;
this.element = null;
this.frame = null;
$(document).off("keyup", onKeyUp); $(document).off("keyup", onKeyUp);
closedDialogs.push(self);
}; };
this.load = function (url, data, method) { this.load = function (url, data, method) {
@@ -74,6 +83,11 @@
}); });
}; };
this.dispose = function() {
if (this.root)
this.root.remove();
};
this.setHtml = function(html) { this.setHtml = function(html) {
this.frame.element.hide(); this.frame.element.hide();
this.view.show(); this.view.show();

View File

@@ -30,16 +30,13 @@
using (Script.Foot()) { using (Script.Foot()) {
<script type="text/javascript"> <script type="text/javascript">
jQuery(function () { jQuery(function () {
// Adding a small delay to prevent certain third party scripts from throwing up when the window is destroyed. window.parent.currentDialog.trigger("command", {
setTimeout(function () { command: "@command",
window.parent.currentDialog.trigger("command", { element: {
command: "@command", typeName: "@Model.TypeName",
element: { state: "@Url.Encode(Model.ElementState)"
typeName: "@Model.TypeName", }
state: "@Url.Encode(Model.ElementState)" });
}
});
}, 50);
}); });
</script> </script>
} }