Fixed caret behavior for inserted tables
authorAlexander Ebert <ebert@woltlab.com>
Thu, 5 Jan 2017 12:43:18 +0000 (13:43 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 5 Jan 2017 12:54:57 +0000 (13:54 +0100)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/acp/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js [new file with mode: 0644]

index 0e60cf9c78f9397e809ee65f677519f6d81caa75..e1b9aef2294148f52a6f8039f6294dd4f6ddb911 100644 (file)
@@ -40,6 +40,7 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSource.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSpoiler.js?v={@LAST_UPDATE_TIME}',
+                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabTable.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabUtils.js?v={@LAST_UPDATE_TIME}'
                {else}
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.min.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabSmiley',
                                        'WoltLabSource',
                                        'WoltLabSpoiler',
+                                       'WoltLabTable',
                                        'WoltLabUtils'
                                ],
                                toolbarFixed: false,
index 0e60cf9c78f9397e809ee65f677519f6d81caa75..e1b9aef2294148f52a6f8039f6294dd4f6ddb911 100644 (file)
@@ -40,6 +40,7 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSource.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSpoiler.js?v={@LAST_UPDATE_TIME}',
+                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabTable.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabUtils.js?v={@LAST_UPDATE_TIME}'
                {else}
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.min.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabSmiley',
                                        'WoltLabSource',
                                        'WoltLabSpoiler',
+                                       'WoltLabTable',
                                        'WoltLabUtils'
                                ],
                                toolbarFixed: false,
index 9a4e1feac487c9e9cc3f5535dbe445deaac523ba..e8afa1779fc574f68c8c873a4ef8cfa29adb1ebb 100644 (file)
@@ -32,8 +32,8 @@ $.Redactor.prototype.WoltLabBlock = function() {
                        var mpFormatCollapsed = this.block.formatCollapsed;
                        this.block.formatCollapsed = (function(tag, attr, value, type) {
                                var block = this.selection.block();
-                               if (block && block.nodeName === 'LI') {
-                                       // lists cannot contain other block elements
+                               if (block && (block.nodeName === 'LI' || block.nodeName === 'TD')) {
+                                       // tables/lists cannot contain other block elements
                                        return;
                                }
                                
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js
new file mode 100644 (file)
index 0000000..06fed19
--- /dev/null
@@ -0,0 +1,20 @@
+$.Redactor.prototype.WoltLabTable = function() {
+       "use strict";
+       
+       return {
+               init: function() {
+                       this.WoltLabEvent.register('insertedTable', (function() {
+                               window.setTimeout((function () {
+                                       var node = this.selection.block() || this.selection.current();
+                                       if (node.nodeName === 'TBODY') {
+                                               // find first <td> and set the caret inside it
+                                               var td = elBySel('td', node);
+                                               if (td) {
+                                                       this.caret.end(td);
+                                               }
+                                       }
+                               }).bind(this), 10);
+                       }).bind(this));
+               }
+       }
+};