2016-04-01 2 views
0

Я делаю плагин в CKeditor с выбором ['Description', 'Value'].Создание простого плагина CKEditor - выбор раскрывающегося списка

ckeditor root/ 
    plugins/ 
    span/ 
     icons/ 
      span.png 
     dialogs/ 
      span.js 
     plugin.js 

plugin.js

> CKEDITOR.plugins.add('span', { 
>  icons: 'span', 
>  init: function(editor) { 
>   editor.addCommand('span', new CKEDITOR.dialogCommand('spanDialog')); 
>   editor.ui.addButton('Span', { 
>    label: 'Insert Reserved Word', 
>    command: 'span', 
>    toolbar: 'insert' 
>   }); 
>   CKEDITOR.dialog.add('spanDialog', this.path + 'dialogs/span.js'); 
>  } }); 

диалоговые окна/span.js

CKEDITOR.dialog.add('spanDialog', function(editor) { 
    return { 
     title: 'Palavras Reservadas', 
     minWidth: 400, 
     minHeight: 200, 
     contents: [ 
      { 
       id: 'tab-basic', 
       label: 'Basic Settings', 
       elements: [ 
        { 
         type: 'select', 
         id: 'span', 
         label: 'Reserved Words Available', 
         items: [ [ 'example 1', '#exanple1#' ], [ 'example 2', '#example2#' ] ], 
         validate: CKEDITOR.dialog.validate.notEmpty("Field can not be empty."), 
         setup: function(a) { 
          this.setValue(a.getAttribute("value") || "") 
         } 
        } 
       ] 
      } 
     ], 
     onOk: function() { 
      var dialog = this; 

      var span = editor.document.createElement('span'); 
      span.setAttribute('title', dialog.getValueOf('tab-basic', 'title')); 

      editor.insertElement(span); 
     } 
    }; 
}); 

В функции OnOK()

 onOk: function() { 
      var dialog = this; 

      var span = editor.document.createElement('span'); 
      span.setAttribute('title', dialog.getValueOf('tab-basic', 'title')); 

      editor.insertElement(span); 
     } 

Я хотел бы добавить к читателю после

<span>#example1#</span> //if I select a Exemple 1 

Любые советы о том, как это сделать? Смотрите этот промежуток с текстом набор ... спасибо за сейчас

ответ

1

Решенный;)

span.js

setup: function(element) { 
          element.setText(this.getValue()); 
         }, 

         commit: function(element) { 
          element.setText(this.getValue()); 
         } 

      .... var selection = editor.getSelection(); 
     var element = selection.getStartElement(); 

     if (element) 
      element = element.getAscendant('span', true); 

     if (!element || element.getName() != 'span') { 
      element = editor.document.createElement('span'); 
      this.insertMode = true; 
     } 
     else 
      this.insertMode = false; 

     this.element = element; 
     if (!this.insertMode) 
      this.setupContent(this.element); 
    }, 
    onOk: function() { 
     var dialog = this; 
     var abbr = this.element; 
     this.commitContent(abbr); 

     if (this.insertMode) 
      editor.insertElement(abbr); 
    } 
Смежные вопросы