I had difficulty getting this to work even with all your guidance here so I will try to post as much help as possible on this. Chances are that its not the final solution but maybe this can help anyone looking to try and get a button added.
I had difficulty even getting a button to show so I reduced it all to virtually nothing to figure it out.
var nicYouTubeOptions = {
buttons : {
'youtube': {name : 'YouTube Link', type : 'nicYouTubeButton'}
},
iconFiles: {
'youtube': 'images/youtube.gif'
}
};
So this first section of code sets up your button details. In other words the image you use for the button and the text you see when you hover over it. The final part listed next to type is 'nicYouTubeButton'
and this declares what function is to be called when the button is pressed.
var nicYouTubeButton = nicEditorAdvancedButton.extend({
});
This is just simply the function (currently empty) which does everything.
nicEditors.registerPlugin(nicPlugin,nicYouTubeOptions);
This final line registers the plugin using the OPTIONS function and not the BUTTON function.
To get this working in the editor now, you need to add the button (declared as 'youtube', note lowercase here) which has been created in the OPTIONS variable. To do this you need to modify the line near the top of the file marked like so:
buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor','xhtml','table','youtube'],
As you can see, I have already added 'youtube' to the list making sure to add that comma between items.
Simply add the following code in your EMPTY function nicYouTubeButton
:
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();
}
Be sure not to remove any of the } or {
Hope this helps any of you having difficulty getting it to show up like me.