2016-06-03 4 views
1

Ich schrieb ein Plugin für CKEditor.Ich möchte Inhalt des Editors zwischen div mit benutzerdefinierten Stil zu wickeln.CKEditor :: Wrap Inhalt von benutzerdefinierten Tag

In diesem Fall habe ich dialog für Stil div Tag verwendet. Wie kann ich Inhalte-Editor innerhalb div wickeln:

onOk: function() { 
      var dialog = this; 
      var color = dialog.getValueOf('tab1', 'color'); 
      // other styles 
      var tag= '<div style="'; 
      tag += 'color:' + color + ';'; 
      // ... other styles 
      tag += '">'; 
      // tag += contents ; 
      tag += "</div>"; 
      editor.insertHtml(tag) 
     }, 
     contents: [{ ... 
+0

Wie wäre es ein div mit document.createElement zu schaffen und seine innerHTML- zu CKEDITOR.instances.name_of_editor.getData Einstellung(); –

+0

danke, ich habe die Lösung gefunden – smoqadam

Antwort

0

Ok fand ich die Lösung:

zuerst in config.js legte die folgenden Zeile:

config.allowedContent = 'div{*}'; // this is important 

siehe here und here.

dann in onOk Funktion wie folgt vorgehen:

onOk: function() { 
      contents = editor.document.getBody().getHtml(); // get the content of CKEditor 
      var dialog = this; 
      var color = dialog.getValueOf('tab1', 'color'); 
      // other styles 
      var tag= '<div style="'; 
      tag += 'color:' + color + ';'; 
      // ... other styles 
      tag += '">'; 
      tag += contents ; 
      tag += "</div>"; 
      editor.setData(tag); 
     }, 
     contents: [{ ...