Added feature #14058: htmlArea RTE: update some WebKit dom methods.
authorStanislas Rolland <typo3@sjbr.ca>
Sat, 10 Apr 2010 23:13:43 +0000 (23:13 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Sat, 10 Apr 2010 23:13:43 +0000 (23:13 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7280 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/htmlarea/htmlarea-gecko.js

index cf42017..c93204e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@
 
        * Added feature #14051: htmlArea RTE: Streamline the RTE loading process
        * Added feature #14057: htmlArea RTE: Extjize the RTE ajax requests.
+       * Added feature #14058: htmlArea RTE: update some WebKit dom methods.
 
 2010-04-09  Michael Stucki  <michael@typo3.org>
 
index e11b234..ecd28ce 100644 (file)
@@ -2,6 +2,7 @@
 
        * Added feature #14051: htmlArea RTE: Streamline the RTE loading process
        * Added feature #14057: htmlArea RTE: Extjize the RTE ajax requests.
+       * Added feature #14058: htmlArea RTE: update some WebKit dom methods.
 
 2010-04-08  Stanislas Rolland  <typo3@sjbr.ca>
 
index 1637fe4..8ac4522 100644 (file)
@@ -53,8 +53,12 @@ HTMLArea.Editor.prototype._getSelection = function() {
  * Empty the selection object
  */
 HTMLArea.Editor.prototype.emptySelection = function(selection) {
-       if (HTMLArea.is_safari) {
-               selection.empty();
+       if (Ext.isWebKit) {
+               if (Ext.isFunction(selection.removeAllRanges)) {
+                       selection.removeAllRanges();
+               } else {
+                       selection.empty();
+               }
        } else {
                selection.removeAllRanges();
        }
@@ -67,8 +71,12 @@ HTMLArea.Editor.prototype.emptySelection = function(selection) {
  * Add a range to the selection
  */
 HTMLArea.Editor.prototype.addRangeToSelection = function(selection, range) {
-       if (HTMLArea.is_safari) {
-               selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
+       if (Ext.isWebKit) {
+               if (Ext.isFunction(selection.addRange)) {
+                       selection.addRange(range);
+               } else {
+                       selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
+               }
        } else {
                selection.addRange(range);
        }
@@ -114,7 +122,12 @@ HTMLArea.Editor.prototype.selectNode = function(node, endPoint) {
        var selection = this._getSelection();
        var range = this._doc.createRange();
        if (node.nodeType == 1 && node.nodeName.toLowerCase() == "body") {
-               range.selectNodeContents(node);
+               if (Ext.isWebKit) {
+                       range.setStart(node, 0);
+                       range.setEnd(node, node.childNodes.length);
+               } else {
+                       range.selectNodeContents(node);
+               }
        } else {
                range.selectNode(node);
        }
@@ -124,7 +137,6 @@ HTMLArea.Editor.prototype.selectNode = function(node, endPoint) {
        this.emptySelection(selection);
        this.addRangeToSelection(selection, range);
 };
-
 /*
  * Select ONLY the contents inside the given node
  */
@@ -132,7 +144,16 @@ HTMLArea.Editor.prototype.selectNodeContents = function(node, endPoint) {
        this.focusEditor();
        var selection = this._getSelection();
        var range = this._doc.createRange();
-       range.selectNodeContents(node);
+       if (Ext.isWebKit) {
+               range.setStart(node, 0);
+               if (node.nodeType == 3 || node.nodeType == 8 || node.nodeType == 4) {
+                       range.setEnd(node, node.textContent.length);
+               } else {
+                       range.setEnd(node, node.childNodes.length);
+               }
+       } else {
+               range.selectNodeContents(node);
+       }
        if (typeof(endPoint) !== "undefined") {
                range.collapse(endPoint);
        }
@@ -145,9 +166,18 @@ HTMLArea.Editor.prototype.rangeIntersectsNode = function(range, node) {
        try {
                nodeRange.selectNode(node);
        } catch (e) {
-               nodeRange.selectNodeContents(node);
+               if (Ext.isWebKit) {
+                       nodeRange.setStart(node, 0);
+                       if (node.nodeType == 3 || node.nodeType == 8 || node.nodeType == 4) {
+                               nodeRange.setEnd(node, node.textContent.length);
+                       } else {
+                               nodeRange.setEnd(node, node.childNodes.length);
+                       }
+               } else {
+                       nodeRange.selectNodeContents(node);
+               }
        }
-               // Note: sometimes Safari inverts the end points
+               // Note: sometimes WebKit inverts the end points
        return (range.compareBoundaryPoints(range.END_TO_START, nodeRange) == -1 && range.compareBoundaryPoints(range.START_TO_END, nodeRange) == 1) ||
                (range.compareBoundaryPoints(range.END_TO_START, nodeRange) == 1 && range.compareBoundaryPoints(range.START_TO_END, nodeRange) == -1);
 };