(function() { var ssbuttons = { /** * Returns information about the plugin as a name/value array. * The current keys are longname, author, authorurl, infourl and version. * * @returns Name/value array containing information about the plugin. * @type Array */ getInfo : function() { return { longname : 'Special buttons for SilverStripe CMS', author : 'Sam Minnée', authorurl : 'http://www.siverstripe.com/', infourl : 'http://www.silverstripe.com/', version : "1.0" }; }, init : function(ed) { ed.addButton('sslink', { icon : 'link', title : 'Insert Link', cmd : 'sslink' }); ed.addMenuItem('sslink', { icon : 'link', text : 'Insert Link', cmd : 'sslink' }); ed.addButton('ssmedia', { icon : 'image', title : 'Insert Media', cmd : 'ssmedia' }); ed.addMenuItem('ssmedia', { icon : 'image', text : 'Insert Media', cmd : 'ssmedia' }); ed.addCommand('sslink', function(ed) { // See HtmlEditorField.js jQuery('#' + this.id).entwine('ss').openLinkDialog(); }); ed.addCommand('ssmedia', function(ed) { // See HtmlEditorField.js jQuery('#' + this.id).entwine('ss').openMediaDialog(); }); // Replace the mceAdvLink and mceLink commands with the sslink command, and // the mceAdvImage and mceImage commands with the ssmedia command ed.on('BeforeExecCommand', function(e){ cmd = e.command; ui = e.ui; val = e.value; if (cmd == 'mceAdvLink' || cmd == 'mceLink'){ e.preventDefault(); ed.execCommand('sslink', ui, val); } else if (cmd == 'mceAdvImage' || cmd == 'mceImage'){ e.preventDefault(); ed.execCommand('ssmedia', ui, val); } }); ed.on('SaveContent', function(o) { var content = jQuery(o.content); content.find('.ss-htmleditorfield-file.embed').each(function() { var el = jQuery(this); var shortCode = '[embed width="' + el.attr('width') + '"' + ' height="' + el.attr('height') + '"' + ' class="' + el.data('cssclass') + '"' + ' thumbnail="' + el.data('thumbnail') + '"' + ']' + el.data('url') + '[/embed]'; el.replaceWith(shortCode); }); // Insert outerHTML in order to retain all nodes incl.