Create non-visual TinyMCE Plugin: Paste as Plain Text

For a customer we wanted the TinyMCE editor in EPiServer to paste everything from the clipboard as Plain Text. The customer copy/pastes from Word alot and didn't want the formatting to transcend into EPiServer.

Create a new class and apply the attribute TinyMCEPluginNonVisual to it. This class can be placed anywhere in the project since EPiServer scans all loaded assemblies for classes with Plugin-attributes.

using EPiServer.Editor.TinyMCE;

namespace Customer.Util.Editor.TinyMCE.Plugins
{
    [TinyMCEPluginNonVisual(
        PlugInName = "PlainTextPastePlugin", 
        Description = "Removes all formatting when pasting from clipboard.",
        DisplayName = "PlainTextPaste",
        DefaultEnabled = true,
        EditorInitConfigurationOptions = 
        @"{
            paste_text_sticky : true
        }"
        )]
    public class PlainTextPastePlugin
    {
    }
}

We configured the plugin to be DefaultEnabled so that it affects all the text fields.
The magic is in the EditorInitConfigurationOptions and paste_text_sticky : true. This will remove all formatting from the Paste.

After a testrun in IE everything seemed to work just fine. But in Firefox the whole TinyMCE editor crashed! It did not even display, i.e. uneditable.

Quick-look in FireBug we could see that TinyMCE still wanted a editor_plugin.js file, even though it's a NonVisual plugin.

The file TinyMCE was looking for was /util/Editor/TinyMCE/Plugins/PlainTextPastePlugin/editor_plugin.js
We are using this default location in this example.
Folderview for editor_plugin.js

We added this to the project structure to override the VPP folder in c:\program files...

editor_plugin.js

(function (tinymce) {
    tinymce.create('tinymce.plugins.PlainTextPastePlugin', {
        init: function (ed, url) {
        },

        getInfo: function () {
            return {
                longname: 'Plain Text Paste',
                author: 'SoftResource AB',
                authorurl: 'http://www.softresource.se',
                infourl: 'http://www.softresource.se',
                version: tinymce.majorVersion + "." + tinymce.minorVersion
            };
        }
    });

    // Register plugin
    tinymce.PluginManager.add('PlainTextPastePlugin', tinymce.plugins.PlainTextPastePlugin);
})(tinymce);

This is just an "empty" script file which you normally would use in a Visual Plugin, which will be covered later on.