Pseudo-hiding root element to prevent an TinyMCE error.

This commit is contained in:
Sipke Schoorstra
2014-10-29 23:37:41 -07:00
parent 372e56a2af
commit ba7c3cd32a

View File

@@ -1,15 +1,17 @@
(function ($) { (function ($) {
var closedDialogs = []; var closedDialogs = [];
var disposeClosedDialogs = function() { var disposeClosedDialogs = function () {
$.each(closedDialogs, function() { $.each(closedDialogs, function () {
this.dispose(); this.dispose();
}); });
closedDialogs = [];
}; };
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;
@@ -49,7 +51,7 @@
$(document).on("keyup", onKeyUp); $(document).on("keyup", onKeyUp);
this.frame.element.on("load", function (e) { this.frame.element.on("load", function (e) {
if(self.isVisible) if (self.isVisible)
updateDialog(self.frame.getDocument()); updateDialog(self.frame.getDocument());
}); });
} }
@@ -59,9 +61,19 @@
if (this.root) { if (this.root) {
$(window).off("resize", resizeIFrame); $(window).off("resize", resizeIFrame);
this.root.hide();
// Hiding is tricky - TinyMCE throws an exception in FF when we hide the root element.
// To avoid this, move the dialog out of view. The next time a Dialog is instantiated, it will be disposed of.
this.overlay.css({
position: "absolute",
left: "0",
top: "0",
width: "0",
height: "0",
overflow: "hidden"
});
} }
$(document).off("keyup", onKeyUp); $(document).off("keyup", onKeyUp);
closedDialogs.push(self); closedDialogs.push(self);
}; };
@@ -83,12 +95,12 @@
}); });
}; };
this.dispose = function() { this.dispose = function () {
if (this.root) if (this.root)
this.root.remove(); 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();
this.view.html(html); this.view.html(html);
@@ -126,7 +138,7 @@
self.view.width($(window).width() * .75); self.view.width($(window).width() * .75);
}; };
var onKeyUp = function(e) { var onKeyUp = function (e) {
var esc = 27; var esc = 27;
if (e.keyCode == esc) { if (e.keyCode == esc) {
self.close(); self.close();
@@ -165,7 +177,7 @@
}); });
}; };
var updateDialog = function(scope) { var updateDialog = function (scope) {
//var document = self.frame.getDocument(); //var document = self.frame.getDocument();
var dialogSettings = scope.find(".dialog-settings"); var dialogSettings = scope.find(".dialog-settings");
var title = dialogSettings.find(".title"); var title = dialogSettings.find(".title");