(function() { // TinyMCE will stop loading if it encounters non-existent external script file // when included through tiny_mce_gzip.php. Only load the external lang package if it is available. var availableLangs = ['en', 'de']; if(jQuery.inArray(tinymce.settings.language, availableLangs) != -1) { tinymce.PluginManager.requireLangPack("ssbuttons"); } var each = tinymce.each; tinymce.create('tinymce.plugins.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, url) { ed.addButton('sslink', {title : ed.getLang('tinymce_ssbuttons.insertlink'), cmd : 'sslink', 'class' : 'mce_link'}); ed.addButton('ssmedia', {title : ed.getLang('tinymce_ssbuttons.insertmedia'), cmd : 'ssmedia', 'class' : 'mce_image'}); ed.addCommand('sslink', function(ed) { jQuery('#' + this.id).entwine('ss').openLinkDialog(); }); ed.addCommand('ssmedia', function(ed) { 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.onBeforeExecCommand.add(function(ed, cmd, ui, val, a){ if (cmd == 'mceAdvLink' || cmd == 'mceLink'){ ed.execCommand('sslink', ui, val, a); a.terminate = true; } else if (cmd == 'mceAdvImage' || cmd == 'mceImage'){ ed.execCommand('ssmedia', ui, val, a); a.terminate = true; } }); // Disable link button when no link is selected ed.onNodeChange.add(function(ed, cm, n, co) { cm.setDisabled('sslink', co && n.nodeName != 'A'); cm.setActive('sslink', n.nodeName == 'A' && !n.name); }); ed.onSaveContent.add(function(ed, 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.