[BUGFIX] RTE context menu adds unwanted id attribute to target
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Sep 2011 14:23:22 +0000 (10:23 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Sep 2011 14:23:09 +0000 (16:23 +0200)
The context menu plugin uses Ext.get on the target element. ExtJs thus adds an unwanted id attribute to content.

Solution: Use Ext.fly rather than Ext.get.

Change-Id: I02d706badc8c3cacbb9ed39baf1ae058359c0a23
Resolves: #29421
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/4721
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
typo3/sysext/rtehtmlarea/htmlarea/plugins/ContextMenu/context-menu.js

index 946b800..8141892 100644 (file)
@@ -168,7 +168,7 @@ HTMLArea.ContextMenu = HTMLArea.Plugin.extend({
         * Handler when the menu gets hidden
         */
        onHide: function () {
-               this.menu.mon(Ext.get(this.editor.document.documentElement), 'contextmenu', this.show, this);
+               this.menu.mon(Ext.get(this.editor.document.documentElement), 'contextmenu', this.show, this, {single: true});
                this.menu.mun(Ext.get(this.editor.document.documentElement), 'mousedown', this.menu.hide, this.menu);
        },
        /*
@@ -189,7 +189,8 @@ HTMLArea.ContextMenu = HTMLArea.Plugin.extend({
                        this.ranges = this.editor.getSelectionRanges();
                }
                var iframeEl = this.editor.iframe.getEl();
-               this.menu.showAt([Ext.get(target).getX() + iframeEl.getX(), Ext.get(target).getY() + iframeEl.getY()]);
+                       // Show the context menu
+               this.menu.showAt([Ext.fly(target).getX() + iframeEl.getX(), Ext.fly(target).getY() + iframeEl.getY()]);
        },
        /*
         * Show items depending on context
@@ -204,26 +205,26 @@ HTMLArea.ContextMenu = HTMLArea.Plugin.extend({
                        } else if (xtype === 'menuitem') {
                                var button = this.getButton(menuItem.getItemId());
                                if (button) {
-                                       menuItem.setText(button.contextMenuTitle ? button.contextMenuTitle : button.tooltip.title);
+                                       var text = button.contextMenuTitle ? button.contextMenuTitle : button.tooltip.title;
+                                       if (menuItem.text != text) {
+                                               menuItem.setText(text);
+                                       }
                                        menuItem.helpText = button.helpText ? button.helpText : menuItem.helpText;
                                        menuItem.setVisible(!button.disabled);
                                        lastIsButton = lastIsButton || !button.disabled;
                                } else {
                                                // Special target delete item
-                                       this.deleteTarget = Ext.get(target);
+                                       this.deleteTarget = target;
                                        if (/^(html|body)$/i.test(target.nodeName)) {
                                                this.deleteTarget = null;
                                        } else if (/^(table|thead|tbody|tr|td|th|tfoot)$/i.test(target.nodeName)) {
-                                               var targetAncestor = this.deleteTarget.findParent('table');
+                                               this.deleteTarget = Ext.fly(target).findParent('table');
                                        } else if (/^(ul|ol|dl|li|dd|dt)$/i.test(target.nodeName)) {
-                                               var targetAncestor = this.deleteTarget.findParent('ul') || this.deleteTarget.findParent('ol') || this.deleteTarget.findParent('dl');
-                                       }
-                                       if (targetAncestor) {
-                                               this.deleteTarget = Ext.get(targetAncestor);
+                                               this.deleteTarget = Ext.fly(target).findParent('ul') || Ext.fly(target).findParent('ol') || Ext.fly(target).findParent('dl');
                                        }
                                        if (this.deleteTarget) {
                                                menuItem.setVisible(true);
-                                               menuItem.setText(this.localize('Remove the') + ' &lt;' + this.deleteTarget.dom.nodeName.toLowerCase() + '&gt; ');
+                                               menuItem.setText(this.localize('Remove the') + ' &lt;' + this.deleteTarget.nodeName.toLowerCase() + '&gt; ');
                                                lastIsButton = true;
                                        } else {
                                                menuItem.setVisible(false);
@@ -251,21 +252,21 @@ HTMLArea.ContextMenu = HTMLArea.Plugin.extend({
                        button.fireEvent('HTMLAreaEventContextMenu', button, event);
                } else if (item.getItemId() === 'DeleteTarget') {
                                // Do not leave a non-ie table cell empty
-                       var parent = this.deleteTarget.parent().dom;
+                       var parent = this.deleteTarget.parentNode;
                        parent.normalize();
                        if (!Ext.isIE && /^(td|th)$/i.test(parent.nodeName) && parent.childNodes.length == 1) {
                                        // Do not leave a non-ie table cell empty
-                               this.deleteTarget.insertSibling(this.editor.document.createElement('br'));
+                               parent.appendChild(this.editor.document.createElement('br'));
                        }
                                // Try to find a reasonable replacement selection
-                       var nextSibling = this.deleteTarget.dom.nextSibling;
-                       var previousSibling = this.deleteTarget.dom.previousSibling;
+                       var nextSibling = this.deleteTarget.nextSibling;
+                       var previousSibling = this.deleteTarget.previousSibling;
                        if (nextSibling) {
                                this.editor.selectNode(nextSibling, true);
                        } else if (previousSibling) {
                                this.editor.selectNode(previousSibling, false);
                        }
-                       this.deleteTarget.remove();
+                       HTMLArea.removeFromParent(this.deleteTarget);
                        this.editor.updateToolbar();
                }
        },