2017-10-27 7 views
0

itemprop属性を編集できるカスタムプラグインを作成しています。 リロード時にプロパティが取り除かれる以外は素晴らしいです。 私が間違っていることは何ですか?CKeditorカスタムプラグインallowedContent not working

私はこの例を含むドキュメントで見つけることができるすべてを読む:私はACFを無効にした場合、それが動作https://github.com/ckeditor/ckeditor-docs-samples/blob/master/tutorial-abbr-acf/abbr/plugin.js#L24

を。

export default CKEDITOR => { 
 
    CKEDITOR.plugins.add('itemprop', { 
 
     init(editor) { 
 
      editor.addCommand('itemprop', new CKEDITOR.dialogCommand('itempropDialog', { 
 
       allowedContent: '*[itemprop]' 
 
      })); 
 

 
      CKEDITOR.dialog.add('itempropDialog', editor => { 
 
       return { 
 
        title: 'Itemprop', 
 
        contents: [ 
 
         { 
 
          id: 'tab-main', 
 
          label: 'Itemprop', 
 
          elements: [ 
 
           { 
 
            type: 'text', 
 
            id: 'itemprop', 
 
            label: 'Itemprop', 
 
            setup(element) { 
 
             this.setValue(element.getAttribute('itemprop')); 
 
            }, 
 
            commit(element) { 
 
             element.setAttribute('itemprop', this.getValue()); 
 
            } 
 
           } 
 
          ] 
 
         } 
 
        ], 
 
        onShow() { 
 
         const selection = editor.getSelection(); 
 
         const element = selection.getStartElement(); 
 
         this.element = element; 
 
         this.setupContent(this.element); 
 
        }, 
 
        onOk() { 
 
         this.commitContent(this.element); 
 
        } 
 
       }; 
 
      }); 
 
     } 
 
    }); 
 
};

+0

今の私がすることができました'extraAllowedContent( '* [itemprop]')'を使って動作させてください。ただし、私は自動化された解決策を働かせたいと思っています。 – Dmitri

答えて

2

私はそれはCKEditorバージョンではこのバグに関連するかもしれない疑いがある:https://github.com/ckeditor/ckeditor-dev/issues/678

私は簡単なテストを行い、ツールバーにボタンを追加すると、コードが機能し始めます。 itempropエントリの許可されたコンテンツも、エディタ設定で定義することなく、CKEditorの許可フィルタに表示されます。最も簡単な解決策は、あなたのプラグインにボタンを追加することになる理由です:次のように

editor.ui.addButton('itemprop', { 
    label: 'Item Prop', 
    command: 'itemprop' 
}); 

全体のプラグインの定義は次のようになります。

CKEDITOR.plugins.add('itemprop', { 
    init(editor) { 

    editor.ui.addButton('itemprop', { 
     label: 'Item Prop', 
     command: 'itemprop' 
    }); 

    editor.addCommand('itemprop', new CKEDITOR.dialogCommand('itempropDialog', { 
     allowedContent: '*[itemprop]' 
    })); 

    CKEDITOR.dialog.add('itempropDialog', editor => { 
     return { 
     title: 'Itemprop', 
     contents: [ 
      { 
      id: 'tab-main', 
      label: 'Itemprop', 
      elements: [ 
       { 
       type: 'text', 
       id: 'itemprop', 
       label: 'Itemprop', 
       setup(element) { 
        this.setValue(element.getAttribute('itemprop')); 
       }, 
       commit(element) { 
        element.setAttribute('itemprop', this.getValue()); 
       } 
       } 
      ] 
      } 
     ], 
     onShow() { 
      const selection = editor.getSelection(); 
      const element = selection.getStartElement(); 
      this.element = element; 
      this.setupContent(this.element); 
     }, 
     onOk() { 
      this.commitContent(this.element); 
     } 
     }; 
    }); 
    } 
}); 

ここでは例の作業:https://codepen.io/msamsel/pen/RjbOpP?editors=1010

+0

私はCKEditorバグとは関係ないと思っていますが、ACFへのレポート作成の仕方を単純化しています。プラグインにボタンがある場合、コマンド定義でACFに内容を報告できます:https://github.com/ckeditor/ckeditor-dev/blob/major/plugins/image/plugin.js#L38。プラグインがコンボの場合、ドロップダウン定義でコンテンツを報告する必要があります:https://github.com/ckeditor/ckeditor-dev/blob/major/plugins/font/plugin.js#L40。 –

+0

もしプラグインがなければ、 'extraAllowedContent'を除いて何かをACFに追加する方法はないようです。 'console.log(JSON.stringify(CKEDITOR.instances.editor1.filter.allowedContent、null、 '\ t')); 'を試してみると、出力に' itemprop'は表示されません。この場合の解決策は、ボタンを追加するか、または「extraAllowedContent」を使用することです。 –

+0

ありがとう!しかし、私はコマンドを追加しています。私は9行目でどのように動作するのでしょうか? – Dmitri