CKEditor: Fixes für texteditor in popup_dialog
authorSven Schöling <s.schoeling@linet-services.de>
Tue, 5 Sep 2017 08:30:21 +0000 (10:30 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Tue, 5 Sep 2017 08:32:22 +0000 (10:32 +0200)
- data field kanonisch auf data('ckeditorInstance') geändert
- jQuery style $.ckeditor hooks auf editor.on('loaded') geändert, der
  Adapter unterstützt kein inline
- mehrfachinitialisierung unterbunden
- selectall und focus Funktionalität in zwei Funktionen getrennt
- focus auf die API Methode .focus() umgestellt

js/kivi.js

index b4608c9..4e415d9 100644 (file)
@@ -157,41 +157,39 @@ namespace("kivi", function(ns) {
   };
 
   ns.focus_ckeditor_when_ready = function(element) {
-    $(element).ckeditor(function() { ns.focus_ckeditor(element); });
+    $(element).data('ckeditorInstance').on('instanceReady', function() { ns.focus_ckeditor(element); });
   };
 
   ns.focus_ckeditor = function(element) {
-    var editor   = $(element).ckeditorGet();
-               var editable = editor.editable();
-
-               if (editable.is('textarea')) {
-                       var textarea = editable.$;
-
-                       if (CKEDITOR.env.ie)
-                               textarea.createTextRange().execCommand('SelectAll');
-                       else {
-                               textarea.selectionStart = 0;
-                               textarea.selectionEnd   = textarea.value.length;
-                       }
-
-                       textarea.focus();
-
-               } else {
-                       if (editable.is('body'))
-                               editor.document.$.execCommand('SelectAll', false, null);
+    $(element).data('ckeditorInstance').focus();
+  };
 
-                       else {
-                               var range = editor.createRange();
-                               range.selectNodeContents(editable);
-                               range.select();
-                       }
+  ns.selectall_ckeditor = function(element) {
+    var editor   = $(element).ckeditorGet();
+    var editable = editor.editable();
+    if (editable.is('textarea')) {
+      var textarea = editable.$;
+
+      if (CKEDITOR.env.ie)
+        textarea.createTextRange().execCommand('SelectAll');
+      else {
+        textarea.selectionStart = 0;
+        textarea.selectionEnd   = textarea.value.length;
+      }
+    } else {
+      if (editable.is('body'))
+        editor.document.$.execCommand('SelectAll', false, null);
 
-                       editor.forceNextSelectionCheck();
-                       editor.selectionChange();
+      else {
+        var range = editor.createRange();
+        range.selectNodeContents(editable);
+        range.select();
+      }
 
-      editor.focus();
-               }
-  };
+      editor.forceNextSelectionCheck();
+      editor.selectionChange();
+    }
+  }
 
   ns.init_tabwidget = function(element) {
     var $element   = $(element);
@@ -228,14 +226,14 @@ namespace("kivi", function(ns) {
       title:         false
     };
 
-   config.height = $e.height();
-   config.width  = $e.width();
+    config.height = $e.height();
+    config.width  = $e.width();
 
     var editor = CKEDITOR.inline($e.get(0), config);
-    $e.data('editor', editor);
+    $e.data('ckeditorInstance', editor);
 
     if ($e.hasClass('texteditor-autofocus'))
-      $e.ckeditor(function() { ns.focus_ckeditor($e); });
+      editor.on('instanceReady', function() { ns.focus_ckeditor($e); });
   };
 
   ns.reinit_widgets = function() {