Fixed an issue with multiple CKEditor instances
authorAlexander Ebert <ebert@woltlab.com>
Tue, 19 Nov 2013 18:37:44 +0000 (19:37 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 19 Nov 2013 18:37:44 +0000 (19:37 +0100)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/WCF.Message.js

index 6a84f02bbefbe33501f08c7edc4769292c5fea56..5a29ba63cef3a80295dd5015372119ef0760d651 100644 (file)
@@ -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;
+       });
 });
 //]]>
 </script>
index 24649094185342feffc8e6401eb842868d3d9912..0e15139946641c38de84f3a936070ee468ddcf96 100644 (file)
@@ -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);