Fixed support for custom block elements
authorAlexander Ebert <ebert@woltlab.com>
Fri, 22 Jul 2016 12:26:32 +0000 (14:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 22 Jul 2016 12:26:38 +0000 (14:26 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js [new file with mode: 0644]
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Spoiler.js

index 4538c1875f4bcaa0b190a48c84585eff009ec2a9..516f3714ecb427ff8020ed7c314051624a433b11 100644 (file)
@@ -28,6 +28,7 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabEvent.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabImage.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInlineCode.js?v={@LAST_UPDATE_TIME}',
+                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}',
                                linkSize: 0xBADC0DED, // some random value to disable truncating
                                minHeight: 200,
                                plugins: [
+                                       // Imperavi
                                        'alignment',
                                        'source',
                                        'table',
+                                       
+                                       // WoltLab specials
+                                       'WoltLabBlock',
+                                       'WoltLabKeydown',
+                                       
+                                       // WoltLab core
                                        'WoltLabAlignment',
                                        'WoltLabAttachment',
-                                       'WoltLabBlock',
                                        'WoltLabCode',
                                        'WoltLabColor',
                                        'WoltLabDropdown',
index f64d35a13eae69a83b9a6c1c22516fa1ed6b882a..fece7b12d30f1b6b17d2ae3a5d84d85ace51060d 100644 (file)
@@ -30,18 +30,23 @@ $.Redactor.prototype.WoltLabBlock = function() {
                        }).bind(this);
                },
                
-               register: function(tag) {
+               register: function(tag, arrowKeySupport) {
                        if (this.block.tags.indexOf(tag) !== -1) {
                                return;
                        }
                        
                        this.block.tags.push(tag);
+                       this.opts.paragraphizeBlocks.push(tag);
                        
                        if (this.opts.blockTags.indexOf(tag) === -1) {
                                this.opts.blockTags.push(tag);
                                
                                this.reIsBlock = new RegExp('^(' + this.opts.blockTags.join('|').toUpperCase() + ')$', 'i');
                        }
+                       
+                       if (arrowKeySupport) {
+                               this.WoltLabKeydown.register(tag);
+                       }
                }
        }
 };
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js
new file mode 100644 (file)
index 0000000..03f4f28
--- /dev/null
@@ -0,0 +1,47 @@
+$.Redactor.prototype.WoltLabKeydown = function() {
+       "use strict";
+       
+       var _tags = [];
+       
+       return {
+               init: function () {
+                       this.keydown.onArrowDown = (function() {
+                               var tags = this.WoltLabKeydown._getBlocks();
+                               
+                               for (var i = 0; i < tags.length; i++) {
+                                       if (tags[i]) {
+                                               this.keydown.insertAfterLastElement(tags[i]);
+                                               return false;
+                                       }
+                               }
+                       }).bind(this);
+                       
+                       this.keydown.onArrowUp = (function() {
+                               var tags = this.WoltLabKeydown._getBlocks();
+                               
+                               for (var i = 0; i < tags.length; i++) {
+                                       if (tags[i]) {
+                                               this.keydown.insertBeforeFirstElement(tags[i]);
+                                               return false;
+                                       }
+                               }
+                       }).bind(this);
+               },
+               
+               register: function (tag) {
+                       if (_tags.indexOf(tag) === -1) {
+                               _tags.push(tag);
+                       }
+               },
+               
+               _getBlocks: function () {
+                       var tags = [this.keydown.blockquote, this.keydown.pre, this.keydown.figcaption];
+                       
+                       for (var i = 0, length = _tags.length; i < length; i++) {
+                               tags.push(this.utils.isTag(this.keydown.current, _tags[i]))
+                       }
+                       
+                       return tags;
+               }
+       }
+};
index 43ee77248dc38f988c1ea0d74db16b7a1533f1c7..7280c185a660d77cf0e07b79b9aeb2927d82e2a6 100644 (file)
@@ -248,7 +248,7 @@ WCF.Message.FormGuard = Class.extend({
                });
                
                // restore buttons, prevents disabled buttons on back navigation in Opera
-               $(window).unload(function() {
+               $(window).on('unload',function() {
                        $forms.find('.formSubmit input[type=submit]').enable();
                });
        }
index b598ab02bd4d67e7e087e3eebabaa13e850d5d2f..23044fe6f9133d136a8d78adba2492fce8d890e0 100644 (file)
@@ -31,8 +31,7 @@ define(['EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util', 'Ui/Di
                        EventHandler.add('com.woltlab.wcf.redactor2', 'observe_load_' + this._elementId, this._observeLoad.bind(this));
                        
                        // register custom block element
-                       this._editor.WoltLabBlock.register('woltlab-spoiler');
-                       this._editor.block.tags.push('woltlab-spoiler');
+                       this._editor.WoltLabBlock.register('woltlab-spoiler', true);
                        
                        // support for active button marking
                        this._editor.opts.activeButtonsStates['woltlab-spoiler'] = 'woltlabSpoiler';