Permalink
Browse files

OR-10457 firefox queryCommandState can throw exception if the iframe …

…is not fully ready when the query is requested. This can happen during dynamic content's basic->full transition.
  • Loading branch information...
1 parent e84f7c7 commit efdb20e6c849a7a1a1840d3e000ef7d5607a0240 @acroyear acroyear committed with etgryphon Mar 30, 2011
Showing with 35 additions and 16 deletions.
  1. +35 −16 frameworks/foundation/views/content_editable.js
@@ -702,17 +702,43 @@ SCUI.ContentEditableView = SC.WebView.extend(SC.Editable,
return SC.none(selection) ? '': selection.toString();
}.property('selection').cacheable(),
+ // [JS]: Firefox throws exceptions under certain circumstances
+ // 1) justify being queried if an iframe is not actually rendered on the screen
+ // 2) query for font or color and the CSS state is different from the tags
+ // e.g., if the color is set by div.style = { color: ... }, an exception will fire if it first sees the older <span color=>
+ // there are enough of these oddities that will show up in imported (and migrated) pages to make it worth catching for now and addressing later
+ // rather than letting the exception destabilize the system
+ _queryCommandState: function(doc, prop) {
+ var e = null;
+ try {
+ return doc.queryCommandState(prop);
+ } catch (e) {
+ SC.Logger.warn("queryCommandState got exception for property " + prop);
+ return NO;
+ }
+ },
+
+ _queryCommandValue: function(doc, prop) {
+ var e = null;
+ try {
+ return doc.queryCommandValue(prop);
+ } catch (e) {
+ SC.Logger.warn("queryCommandState got exception for property " + prop);
+ return null;
+ }
+ },
+
_selectionIsSomething: function(key, val, something) {
- var editor = this._document;
- if (!editor) return NO;
+ var doc = this._document;
+ if (!doc) return NO;
if (val !== undefined) {
- if (editor.execCommand(something, false, val)) {
+ if (doc.execCommand(something, false, val)) {
this.set('isEditing', YES);
}
}
- return editor.queryCommandState(something);
+ return this._queryCommandState(doc, something);
},
selectionIsBold: function(key, val) {
@@ -745,14 +771,7 @@ SCUI.ContentEditableView = SC.WebView.extend(SC.Editable,
this.querySelection();
this.set('isEditing', YES);
}
- // [JS]: Firefox throws exception if this is called while the iframe is hidden
- // this happens when transitioning from full to regular edit in dynamic content
- // and sometimes when transitioning from src view to content-editable view in the other editors
- try {
- return doc.queryCommandState(justify);
- } catch (e) {
- return NO;
- }
+ return this._queryCommandState(doc, justify);
},
selectionIsCenterJustified: function(key, val) {
@@ -822,7 +841,7 @@ SCUI.ContentEditableView = SC.WebView.extend(SC.Editable,
this.set('isEditing', YES);
}
- return doc.queryCommandState('insertorderedlist');
+ return this._queryCommandState(doc, 'insertorderedlist');
}.property('selection').cacheable(),
selectionIsUnorderedList: function(key, val) {
@@ -840,7 +859,7 @@ SCUI.ContentEditableView = SC.WebView.extend(SC.Editable,
this.set('isEditing', YES);
}
- return doc.queryCommandState('insertunorderedlist');
+ return this._queryCommandState(doc, 'insertunorderedlist');
}.property('selection').cacheable(),
_createListForIE: function(tag) {
@@ -1044,7 +1063,7 @@ SCUI.ContentEditableView = SC.WebView.extend(SC.Editable,
if (this._last_font_color_cache) {
ret = this._last_font_color_cache;
} else {
- var color = doc.queryCommandValue('forecolor');
+ var color = this._queryCommandValue(doc, 'forecolor');
if (color) {
this._last_font_color_cache = SC.browser.msie ? this.convertBgrToHex(color) : SC.parseColor(color);
ret = this._last_font_color_cache;
@@ -1089,7 +1108,7 @@ SCUI.ContentEditableView = SC.WebView.extend(SC.Editable,
if (this._last_background_color_cache) {
ret = this._last_background_color_cache;
} else {
- var color = doc.queryCommandValue(prop);
+ var color = this._queryCommandValue(doc, prop);
if (color !== 'transparent') {
color = SC.browser.msie ? this.convertBgrToHex(color) : SC.parseColor(color);
if (color) {

0 comments on commit efdb20e

Please sign in to comment.