2013-01-23 20 views
1

我目前正在嘗試使用CKEditor來添加XML條目。我修改了示例插件的代碼:CKEditor for XML?

CKEDITOR.dialog.add('abbrDialog', function(editor) { 
return { 
    title: 'Abbreviation Properties', 
    minWidth: 400, 
    minHeight: 200, 
    contents: [ 
     { 
      id: 'tab-basic', 
      label: 'Basic Settings', 
      elements: [ 
       { 
        type: 'text', 
        id: 'abbr', 
        label: 'Title', 
        validate: CKEDITOR.dialog.validate.notEmpty("Title cannot be empty") 
       }, 
       { 
        type: 'text', 
        id: 'title', 
        label: 'Price', 
        validate: CKEDITOR.dialog.validate.notEmpty("Price cannot be empty") 
       }  
      ] 
     }, 
     { 
      id: 'tab-adv', 
      label: 'Advanced Settings', 
      elements: [ 
       { 
        type: 'text', 
        id: 'id', 
        label: 'Id' 
       } 
      ] 
     } 
    ],   
    onOk: function() { 
     var dialog = this; 

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

     var id = dialog.getValueOf('tab-adv', 'id'); 
     if (id) 
      abbr.setAttribute('id', id); 

     editor.insertElement(abbr); 
    } 
}; 

});

但是,當我再次單擊編輯器以添加更多項目時,標籤變爲嵌套狀態。這是不希望的。我如何限制其他標籤內不會有任何標籤?由於

回答

1

這將檢索該元素的插入符號下:

var selectedElement = editor.getSelection().getStartElement(); 

而與此您可以檢索特定類型的最近方興未艾:

selectedElement.getAscendant('abbr', 1); 

基本上,當有一個,不要」 t插入任何東西和/或更新selectedElement以及新的屬性,屬性等。


BTW:

selectedElement.getParents(); 
+0

謝謝您的回覆:如果你想有一個更具體的過濾這會給你的父元素(對DOM根)的迭代陣列。什麼方法可以防止用戶編輯/更新? – Yangrui