From c65fe7d3b6f3c1ec747e97f7d27243d348b066fe Mon Sep 17 00:00:00 2001 From: Brian Osborne Date: Wed, 17 Sep 2014 10:40:34 -0400 Subject: [PATCH 1/2] Modify plugin behavior to match what the core plugin 'basicstyles' does, so we can properly use the styleCommand functionality and toggle the button on and off --- plugin.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugin.js b/plugin.js index 802f768..97eae90 100644 --- a/plugin.js +++ b/plugin.js @@ -1,15 +1,25 @@ CKEDITOR.plugins.add( 'codeTag', { icons: 'code', init: function( editor ) { - editor.addCommand( 'wrapCode', { - exec: function( editor ) { - editor.insertHtml( '' + editor.getSelection().getSelectedText() + '' ); - } - }); - editor.ui.addButton( 'Code', { - label: 'Wrap code', - command: 'wrapCode', - toolbar: 'insert' - }); + + var style = new CKEDITOR.style( { element: 'code' } ); + + // Listen to contextual style activation. + editor.attachStyleStateChange( style, function (state) { + console.log(state); + !editor.readOnly && editor.getCommand( 'wrapCode').setState(state); + }) + + // Create the command. + editor.addCommand( 'wrapCode', new CKEDITOR.styleCommand( style ) ); + + // Register the button, if the button plugin is enabled. + if ( editor.ui.addButton ) { + editor.ui.addButton( 'Code', { + label: 'Code', + command: 'wrapCode', + toolbar: 'insert' + } ); + } } -}); \ No newline at end of file +}); From e459194d52142143ea11f9e78d08f11d324b62fe Mon Sep 17 00:00:00 2001 From: Brian Osborne Date: Wed, 17 Sep 2014 10:44:39 -0400 Subject: [PATCH 2/2] removing debug line --- plugin.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin.js b/plugin.js index 97eae90..d63b80c 100644 --- a/plugin.js +++ b/plugin.js @@ -6,9 +6,8 @@ CKEDITOR.plugins.add( 'codeTag', { // Listen to contextual style activation. editor.attachStyleStateChange( style, function (state) { - console.log(state); !editor.readOnly && editor.getCommand( 'wrapCode').setState(state); - }) + } ); // Create the command. editor.addCommand( 'wrapCode', new CKEDITOR.styleCommand( style ) );