From 691bba94876e20518bed339fa3b86bf4520a1f3b Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Thu, 23 Mar 2006 11:10:16 +0000 Subject: [PATCH] some try/catch for htmlarea, thanks to Jay Bertrandt --- htmlarea/htmlarea.js | 62 ++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/htmlarea/htmlarea.js b/htmlarea/htmlarea.js index f22e114..0818f88 100644 --- a/htmlarea/htmlarea.js +++ b/htmlarea/htmlarea.js @@ -734,9 +734,23 @@ HTMLArea.prototype.generate = function () { // add a handler for the "back/forward" case -- on body.unload we save // the HTML content into the original textarea. try { - window.onunload = function() { + + function addWYSIWYGUnloadEvent(func) { + var oldonunload = window.onunload; + if (typeof window.onunload != 'function') { + window.onunload = func; + } else { + window.onunload = function() { + oldonunload(); + func(); + } + } + } + + addWYSIWYGUnloadEvent(function() { editor._textArea.value = editor.getHTML(); - }; + }); + } catch(e) {}; // creates & appends the toolbar @@ -858,13 +872,15 @@ HTMLArea.prototype.generate = function () { // check if any plugins have registered refresh handlers for (var i in editor.plugins) { - var plugin = editor.plugins[i].instance; - if (typeof plugin.onGenerate == "function") - plugin.onGenerate(); - if (typeof plugin.onGenerateOnce == "function") { - plugin.onGenerateOnce(); - plugin.onGenerateOnce = null; - } + try { + var plugin = editor.plugins[i].instance; + if (typeof plugin.onGenerate == "function") + plugin.onGenerate(); + if (typeof plugin.onGenerateOnce == "function") { + plugin.onGenerateOnce(); + plugin.onGenerateOnce = null; + } + }catch(e) { /*alert(e);*/ } } setTimeout(function() { @@ -925,8 +941,10 @@ HTMLArea.prototype.setMode = function(mode) { this.focusEditor(); for (var i in this.plugins) { - var plugin = this.plugins[i].instance; - if (typeof plugin.onMode == "function") plugin.onMode(mode); + try { + var plugin = this.plugins[i].instance; + if (typeof plugin.onMode == "function") plugin.onMode(mode); + } catch(e) { /*alert(e);*/ }; } }; @@ -1296,14 +1314,16 @@ HTMLArea.prototype.updateToolbar = function(noStatus) { } } } + try { btn.state("enabled", (!text || btn.text) && inContext); + } catch(e) { /*alert(e);*/ } if (typeof cmd == "function") { continue; } // look-it-up in the custom dropdown boxes var dropdown = this.config.customSelects[cmd]; if ((!text || btn.text) && (typeof dropdown != "undefined")) { - dropdown.refresh(this); + try { dropdown.refresh(this); } catch(e) { /*alert(e);*/ } continue; } switch (cmd) { @@ -1379,9 +1399,11 @@ HTMLArea.prototype.updateToolbar = function(noStatus) { // check if any plugins have registered refresh handlers for (var i in this.plugins) { - var plugin = this.plugins[i].instance; - if (typeof plugin.onUpdateToolbar == "function") - plugin.onUpdateToolbar(); + try { + var plugin = this.plugins[i].instance; + if (typeof plugin.onUpdateToolbar == "function") + plugin.onUpdateToolbar(); + } catch(e) { /*alert(e);*/ } } }; @@ -1866,10 +1888,12 @@ HTMLArea.prototype._editorEvent = function(ev) { if (keyEvent) for (var i in editor.plugins) { - var plugin = editor.plugins[i].instance; - if (typeof plugin.onKeyPress == "function") - if (plugin.onKeyPress(ev)) - return false; + try { + var plugin = editor.plugins[i].instance; + if (typeof plugin.onKeyPress == "function") + if (plugin.onKeyPress(ev)) + return false; + } catch(e) { /*alert(e);*/ } } if (keyEvent && ev.ctrlKey && !ev.altKey) { var sel = null; -- 2.39.5