From 3d6f65420f7a75f27104bf48dfa2189947f6fe08 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 19 Nov 2013 19:37:44 +0100 Subject: [PATCH] Fixed an issue with multiple CKEditor instances --- com.woltlab.wcf/templates/wysiwyg.tpl | 41 +++++++++++---------- wcfsetup/install/files/js/WCF.Message.js | 46 ++++++++++++++---------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 6a84f02bbe..5a29ba63ce 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -15,21 +15,14 @@ $(function() { if (navigator.userAgent.match(/[aA]ndroid/)) { return; } + + var $editorName = '{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}'; + var $callbackIdentifier = 'CKEditor'; + if ($editorName != 'text') { + $callbackIdentifier += '_' + $editorName; + } - head.load([ - { CKEditorCore: '{@$__wcf->getPath()}js/3rdParty/ckeditor/ckeditor.js' }, - { CKEditor: '{@$__wcf->getPath()}js/3rdParty/ckeditor/adapters/jquery.js' } - {event name='javascriptFiles'} - ], function() { - WCF.System.Dependency.Manager.invoke('CKEditor'); - }); - - head.ready('CKEditorCore', function() { - // prevent double editor initialization if used in combination with divarea-plugin - CKEDITOR.disableAutoInline = true; - }); - - WCF.System.Dependency.Manager.setup('CKEditor', function() { + WCF.System.Dependency.Manager.setup($callbackIdentifier, function() { {include file='wysiwygToolbar'} if (__CKEDITOR_BUTTONS.length) { @@ -78,12 +71,24 @@ $(function() { CKEDITOR.dom.element.prototype.disableContextMenu = function() { }; } - var $editor = CKEDITOR.instances['{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}']; + var $editor = CKEDITOR.instances[$editorName]; if ($editor) $editor.destroy(true); - //CKEDITOR.replace('{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}'); - $('{if $wysiwygSelector|isset}#{$wysiwygSelector|encodeJS}{else}#text{/if}').ckeditor($config); - }) + $('#' + $editorName).ckeditor($config); + }); + + head.load([ + { CKEditorCore: '{@$__wcf->getPath()}js/3rdParty/ckeditor/ckeditor.js' }, + { CKEditor: '{@$__wcf->getPath()}js/3rdParty/ckeditor/adapters/jquery.js' } + {event name='javascriptFiles'} + ], function() { + WCF.System.Dependency.Manager.invoke($callbackIdentifier); + }); + + head.ready('CKEditorCore', function() { + // prevent double editor initialization if used in combination with divarea-plugin + CKEDITOR.disableAutoInline = true; + }); }); //]]> diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 2464909418..0e15139946 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -690,28 +690,19 @@ WCF.Message.QuickReply = Class.extend({ if (this._quoteManager) { // check if message field is empty var $empty = true; - if ($.browser.touch) { - $empty = (!this._messageField.val().length); + if (CKEDITOR) { + var self = this; + this._messageField.ckeditor(function() { + $empty = (!$.trim(this.getData()).length); + self._ckeditorCallback($empty); + }); + } else { - $empty = (!$.trim(this._messageField.ckeditorGet().getData()).length); - } - - if ($empty) { - this._quoteManager.insertQuotes(this._getClassName(), this._getObjectID(), $.proxy(this._insertQuotes, this)); + $empty = (!this._messageField.val().length); + this._ckeditorCallback($empty); } } - - new WCF.PeriodicalExecuter($.proxy(function(pe) { - pe.stop(); - - if ($.browser.mobile) { - this._messageField.focus(); - } - else { - this._messageField.ckeditorGet().ui.editor.focus(); - } - }, this), 250); } // discard event @@ -721,6 +712,23 @@ WCF.Message.QuickReply = Class.extend({ } }, + _ckeditorCallback: function(isEmpty) { + if (isEmpty) { + this._quoteManager.insertQuotes(this._getClassName(), this._getObjectID(), $.proxy(this._insertQuotes, this)); + } + + /*new WCF.PeriodicalExecuter($.proxy(function(pe) { + pe.stop(); + */ + if (CKEDITOR) { + this._messageField.ckeditorGet().ui.editor.focus(); + } + else { + this._messageField.focus(); + } + //}, this), 250); + }, + /** * Returns container element. * @@ -1329,7 +1337,7 @@ WCF.Message.InlineEditor = Class.extend({ pe.stop(); var $ckEditor = $('#' + this._messageEditorIDPrefix + this._container[this._activeElementID].data('objectID')); - $ckEditor.ckeditorGet().ui.editor.focus(); + $ckEditor.ckeditor(function() { this.ui.editor.focus(); }); if (this._quoteManager) { this._quoteManager.setAlternativeCKEditor($ckEditor); -- 2.20.1