Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
themeEmacs
window.WEBSPELLCHECKER_CONFIG = {
    ...
    onLoad: function(instance) {
        var container = instance.getContainerNode(), // Link to the editable container
            isCkeditor4 = container.classList.contains('cke_editable'); // DirtyUncommon check for CKEditor 4.

        if (isCkeditor4) {
            container.savedWscInstance = instance; // Save link on the WebSpellCheckerWProofreader instance to the editable DOM element.
        }
    },
    ...
};

2. Once config is defined, please do the following: 

Code Block
languagejs
themeEmacs
// Subscribe to the CKEditor 4 'instanceReady' event
CKEDITOR.on('instanceReady', function(event) {
    var editor = event.editor;

    // Subscribe to the CKEditor 4 'beforeSetMode' event
    editor.on('beforeSetMode', function(e) {
        // If a user switches from switchthe CKEditorWYSIWYG 4mode to the 'sorce'source mode of CKEditor 4
        if (e.data === 'source') {
            var container = editor.editable().$,
                parent = container.parentNode,
                links = parent.getElementsByTagName('link'),
                styleName = 'wsc.css',
                link;

            if (!container.savedWscInstance) {
                return;
            }

            // Destroy the WProofreader instance and remove the link onto it
            container.savedWscInstance.destroy();
            container.savedWscInstance = null;

            // Go through all links and remove link to the WSCwsc.css CSSstyle file.
            for (var i = 0; i < links.length; i++) {
                link = links[i];

                if (link.href.indexOf(styleName) !== -1 && link.parentNode) {
                    link.parentNode.removeChild(link);
                }
            }
        }
    });
});

...