From 14029b67f4f605a9be2be707a0739a18fcef467f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 22 Jul 2016 14:26:32 +0200 Subject: [PATCH] Fixed support for custom block elements --- com.woltlab.wcf/templates/wysiwyg.tpl | 9 +++- .../redactor2/plugins/WoltLabBlock.js | 7 ++- .../redactor2/plugins/WoltLabKeydown.js | 47 +++++++++++++++++++ wcfsetup/install/files/js/WCF.Message.js | 2 +- .../js/WoltLab/WCF/Ui/Redactor/Spoiler.js | 3 +- 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 4538c1875f..516f3714ec 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -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}', @@ -145,12 +146,18 @@ 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', diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js index f64d35a13e..fece7b12d3 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js @@ -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 index 0000000000..03f4f2807d --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -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; + } + } +}; diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 43ee77248d..7280c185a6 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -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(); }); } diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Spoiler.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Spoiler.js index b598ab02bd..23044fe6f9 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Spoiler.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Spoiler.js @@ -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'; -- 2.20.1