Fixed bug #16124: htmlArea RTE: Links are incorrectly updated in Google Chrome
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 25 Nov 2010 04:24:19 +0000 (04:24 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 25 Nov 2010 04:24:19 +0000 (04:24 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-3@9618 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/htmlarea/plugins/TYPO3Link/typo3link.js

index 04c4fd4..e5e7c9e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
+2010-11-24  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Fixed bug #16124: htmlArea RTE: Links are incorrectly updated in Google Chrome
+
 2010-11-23  Steffen Ritter  <typo3@steffen-ritter.net>
+
        * Fixed bug #16517: t3lib_beFunc::getRecordWSOL() does not use it's param $useDeleteClause in else branch
 
 2010-11-12  Ernesto Baschny  <ernst@cron-it.de>
index ed30ce4..df28673 100644 (file)
@@ -1,3 +1,7 @@
+2010-11-24  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Fixed bug #16124: htmlArea RTE: Links are incorrectly updated in Google Chrome
+
 2010-11-11  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Fixed bug #16314: Incorrect use of is_dir in class.tx_rtehtmlarea_clearrtecache.php (Thanks to Juergen Deisenroth)
index 1bf18b5..ea6d781 100644 (file)
@@ -162,53 +162,68 @@ TYPO3Link = HTMLArea.Plugin.extend({
                var selection, range, anchorClass, imageNode = null, addIconAfterLink;
                this.editor.focusEditor();
                var node = this.editor.getParentElement();
-               var el = HTMLArea.getElementObject(node, "a");
-               if (el != null && /^a$/i.test(el.nodeName)) node = el;
-               if (node != null && /^a$/i.test(node.nodeName)) this.editor.selectNode(node);
-                       // Clean images from existing anchors otherwise Mozilla may create nested anchors
-               if (HTMLArea.classesAnchorSetup) {
+               var el = HTMLArea.getElementObject(node, 'a');
+               if (el != null && /^a$/i.test(el.nodeName)) {
+                       node = el;
+               }
+               if (HTMLArea.classesAnchorSetup && cur_class) {
+                       for (var i = HTMLArea.classesAnchorSetup.length; --i >= 0;) {
+                               anchorClass = HTMLArea.classesAnchorSetup[i];
+                               if (anchorClass.name == cur_class && anchorClass.image) {
+                                       imageNode = this.editor._doc.createElement('img');
+                                       imageNode.src = anchorClass.image;
+                                       imageNode.alt = anchorClass.altText;
+                                       addIconAfterLink = anchorClass.addIconAfterLink;
+                                       break;
+                               }
+                       }
+               }
+               if (node != null && /^a$/i.test(node.nodeName)) {
+                               // Update existing link
+                       this.editor.selectNode(node);
                        selection = this.editor._getSelection();
                        range = this.editor._createRange(selection);
-                       this.cleanAllLinks(node, range, true);
-               }
-                       // In FF, if the url is the same except for upper/lower case of a file name, the link is not updated.
-                       // Therefore, we remove the link before creating a new one.
-               if (HTMLArea.is_gecko && node != null && /^a$/i.test(node.nodeName)) {
-                               // If the class attribute is not removed, UnLink folowed by CreateLink will create a span element inside the new link
-                       node.removeAttribute("class");
-                               // Moreover, the selection is sometimes lost after the unlink operation
+                               // Clean images
+                       if (HTMLArea.classesAnchorSetup) {
+                               this.cleanAllLinks(node, range, true);
+                       }
+                               // Update link href
+                       node.href = (HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera) ? encodeURI(theLink) : theLink;
+                               // Update link attributes
+                       this.setLinkAttributes(node, range, cur_target, cur_class, cur_title, imageNode, addIconAfterLink, additionalValues);
+               } else {
+                               // Create new link
+                               // Clean existing anchors otherwise Mozilla may create nested anchors
                        selection = this.editor._getSelection();
                        range = this.editor._createRange(selection);
+                               // Selection may be lost when cleaning links
                        var bookmark = this.editor.getBookmark(range);
-                       this.editor._doc.execCommand("UnLink", false, null);
+                       this.cleanAllLinks(node, range);
                        this.editor.selectRange(this.editor.moveToBookmark(bookmark));
-               }
-               if (HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera) {
-                       this.editor._doc.execCommand("CreateLink", false, encodeURI(theLink));
-               } else {
-                       this.editor._doc.execCommand("CreateLink", false, theLink);
-               }
-               
-               selection = this.editor._getSelection();
-               range = this.editor._createRange(selection);
-               node = this.editor.getParentElement();
-               el = HTMLArea.getElementObject(node, "a");
-               if (el != null && /^a$/i.test(el.nodeName)) node = el;
-               if (node) {
-                       if (HTMLArea.classesAnchorSetup && cur_class) {
-                               for (var i = HTMLArea.classesAnchorSetup.length; --i >= 0;) {
-                                       anchorClass = HTMLArea.classesAnchorSetup[i];
-                                       if (anchorClass.name == cur_class && anchorClass.image) {
-                                               imageNode = this.editor._doc.createElement("img");
-                                               imageNode.src = anchorClass.image;
-                                               imageNode.alt = anchorClass.altText;
-                                               addIconAfterLink = anchorClass.addIconAfterLink;
-                                               break;
+                       if (HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera) {
+                               this.editor._doc.execCommand('CreateLink', false, encodeURI(theLink));
+                       } else {
+                               this.editor._doc.execCommand('CreateLink', false, theLink);
+                       }
+                               // Get the created link
+                       selection = this.editor._getSelection();
+                       range = this.editor._createRange(selection);
+                       node = this.editor.getParentElement();
+                       el = HTMLArea.getElementObject(node, 'a');
+                       if (el != null && /^a$/i.test(el.nodeName)) {
+                               node = el;
+                       }
+                       if (node) {
+                                       // Export trailing br that IE may include in the link
+                               if (HTMLArea.is_ie) {
+                                       if (node.lastChild && /^br$/i.test(node.lastChild.nodeName)) {
+                                               HTMLArea.removeFromParent(node.lastChild);
+                                               node.parentNode.insertBefore(this.editor._doc.createElement('br'), node.nextSibling);
                                        }
                                }
+                                       // We may have created multiple links in as many blocks
+                               this.setLinkAttributes(node, range, cur_target, cur_class, cur_title, imageNode, addIconAfterLink, additionalValues);
                        }
-                               // We may have created multiple links in as many blocks
-                       this.setLinkAttributes(node, range, cur_target, cur_class, cur_title, imageNode, addIconAfterLink, additionalValues);
                }
                this.dialog.close();
        },