カスタム nicEdit ボタンの追加
ここで説明されているように、カスタム ボタンを追加する必要があります: http://wiki.nicedit.com/w/page/516/Creating%20a%20Plugin
このドキュメントには、最初に読んだときにわかりにくい部分があるため、機能するボタンを追加する方法を順を追って説明します。
開発版の nicEdit.js を持っている場合は、ファイルの一番下に移動すると、「nicCodeButton」というカスタム ボタンが表示されます。
この下に、次のような独自のカスタム ボタンを追加します。
YouTube ボタン コード
var nicYouTubeButton = nicEditorAdvancedButton.extend({
width: '350px',
addPane: function () {
this.addForm({
'': { type: 'title', txt: 'YouTube Url' },
'youTubeUrl': { type: 'text', txt: 'URL', value: 'http://', style: { width: '150px'} },
'height': { type: 'text', txt: 'Height', value: '560', style: { width: '150px'} },
'width': { type: 'text', txt: 'Width', value: '315', style: { width: '150px'} }
});
},
submit: function (e) {
var code = this.inputs['youTubeUrl'].value;
var width = this.inputs['height'].value;
var height = this.inputs['width'].value;
if (code.indexOf('watch?v=') > 0) {
code = code.replace('watch?v=','embed/');
}
var youTubeCode = '<iframe width="' + width + '" height="' + height + '" src="' + code + '" frameborder="0" allowfullscreen></iframe>';
this.ne.selectedInstance.setContent(this.ne.selectedInstance.getContent() + youTubeCode);
this.removePane();
}
});
次に、ボタンをカスタム構成に追加し、パネルが使用するアイコン画像をファイルの下部に追加する必要があります。完了すると、次のようになります。
あなたのボタンを構成に追加する
/* START CONFIG */
var nicCodeOptions = {
buttons : {
'xhtml': { name: 'Edit HTML', type: 'nicCodeButton' },
'youTube' : {name : 'YouTube', type : 'nicYouTubeButton'}
},
iconFiles: {
'youTube': 'nicEditorIcons2.gif'
}
};
/* END CONFIG */
それでおしまい!
(上記のコードは、使用したい場合はテスト済みです)