I am working on a project where I need to pass the data selection made before the Ckeditor get loaded.
/** * Get text selection. */ Drupal.xeditor.getSelection = function() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } return text; };
I created a plugin called 'selection' to get the data from
Drupal.xeditor.getSelection()
and highlight it inside the Ckeditor.
/** * @file plugin.js * Manage selection in Ckeditor. */ ( function($) { CKEDITOR.plugins.add( 'selection', { icons: 'selection', init: function( editor ) { //console.log(XEDITOR.current_selection); //console.log(CKEDITOR); editor.addCommand( 'selection', { exec : function( editor ) { // } }); editor.ui.addButton( 'selection', { label: 'Content selection', command: 'selection', icon: this.path + 'icons/selection.png' }); editor.config.contentsCss = this.path + 'css/selection.css'; }, afterInit: function (editor) { console.log(Drupal.xeditor.getSelection()); // Auto highlight the string/word selected by the user earlier. } }); })(jQuery);
However, I have difficulty in achieving what I want. Please see the screenshot below for more details.
Step 1.
On mouseup, I will load the Ckeditor automatically. As you can see in the image below it says that "Loading..."
Step 2.
Step 3.
In step 3 the Ckeditor is fully loaded. In this part I want also the word I selected in Step 1 to be highlighted so user can proceed on formatting and avoid to annoy the user by highlighting again.