Loading ckeditor_textindent.info.yml +3 −3 Original line number Diff line number Diff line name: CKEditor TextIndent type: module description: 'Provides integration of the CKEditor TextIndent plugin with the Drupal 8 CKEditor.' description: 'Provides integration of the CKEditor TextIndent plugin with the Drupal CKEditor.' package: CKEditor # core: 8.x Loading @@ -9,6 +9,6 @@ dependencies: - drupal:system (>= 8.1) version: '8.x-1.0' core: '8.x' core_version_requirement: ^8 || ^9 project: 'ckeditor_textindent' datestamp: 1507249145 datestamp: 1654572554 js/plugins/textindent/lang/zh-hans.js 0 → 100644 +3 −0 Original line number Diff line number Diff line CKEDITOR.plugins.setLang( 'textindent', 'zh-hans', { labelName: '首行缩进' }); js/plugins/textindent/plugin.js +57 −33 Original line number Diff line number Diff line CKEDITOR.plugins.add( 'textindent', { icons: 'textindent', availableLangs: {'pt-br':1, 'en':1}, lang: 'pt-br, en', availableLangs: {'pt-br':1, 'en':1, 'zh-hans':1}, lang: 'zh-hans, en, pt-br', init: function( editor ) { var indentation = editor.config.indentation; var indentationKey = editor.config.indentationKey; if(typeof(indentation) == 'undefined') indentation = '2em'; else if(indentation.match(/^\d+$/)) { indentation = indentation + 'px'; } indentation = '50px'; if(typeof(indentationKey) == 'undefined') indentationKey = 'tab'; if(editor.ui.addButton){ editor.ui.addButton( 'textindent', { label: editor.lang.textindent.labelName, command: 'insert', toolbar: 'insert' command: 'ident-paragraph', }); } if( indentationKey !== false){ editor.on('key', function(ev) { if(ev.data.domEvent.$.key.toLowerCase() === indentationKey.toLowerCase().trim() || ev.data.keyCode === indentationKey){ editor.execCommand('ident-paragraph'); ev.cancel(); } }); } Loading @@ -32,41 +41,56 @@ CKEDITOR.plugins.add( 'textindent', { }); if( style_textindente.checkActive(editor.elementPath(), editor) ) editor.getCommand('insert').setState(CKEDITOR.TRISTATE_ON); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_ON); else editor.getCommand('insert').setState(CKEDITOR.TRISTATE_OFF); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_OFF); }) }); editor.addCommand("insert", { editor.addCommand("ident-paragraph", { allowedContent: 'p{text-indent}', requiredContent: 'p', exec: function() { exec: function(evt) { var style_textindente = new CKEDITOR.style({ element: 'p', styles: { 'text-indent': indentation }, overrides: [{ element: 'text-indent', attributes: { 'size': '0'} }] }); var range = editor.getSelection().getRanges()[0]; var style_no_textindente = new CKEDITOR.style({ element: 'p', styles: { 'text-indent': '0' }, overrides: [{ element: 'text-indent', attributes: { 'size': indentation } }] }); var walker = new CKEDITOR.dom.walker( range ), node; if( style_textindente.checkActive(editor.elementPath(), editor) ){ var state = editor.getCommand('ident-paragraph').state; while ( ( node = walker.next() ) ) { if ( node.type == CKEDITOR.NODE_ELEMENT ) { if(node.getName() === "p"){ editor.fire('saveSnapshot'); editor.applyStyle(style_no_textindente); if( state == CKEDITOR.TRISTATE_ON){ node.removeStyle("text-indent"); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_OFF); } else{ node.setStyle( "text-indent", indentation ); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_ON); } } } } if(node === null){ node = editor.getSelection().getStartElement().getAscendant('p', true); editor.fire('saveSnapshot'); editor.applyStyle(style_textindente); if( state == CKEDITOR.TRISTATE_ON){ node.removeStyle("text-indent"); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_OFF); } else{ node.setStyle( "text-indent", indentation ); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_ON); } } } }); Loading src/Plugin/CKEditorPlugin/TextIndent.php +8 −2 Original line number Diff line number Diff line Loading @@ -31,12 +31,17 @@ class TextIndent extends CKEditorPluginBase implements CKEditorPluginContextualI * NOTE: The keys of the returned array corresponds to the CKEditor button * names. They are the first argument of the editor.ui.addButton() or * editor.ui.addRichCombo() functions in the plugin.js file. * * add by Douglas.lai 2022-06-07 * drupal_get_path() and drupal_get_filename() have been deprecated in favor of extension listing services * see also:https://www.drupal.org/node/2940438 */ public function getButtons() { return [ 'textindent' => [ 'label' => $this->t('Text Indent'), 'image' => drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/icons/textindent.png', #'image' => drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/icons/textindent.png', 'image' => \Drupal::service('extension.list.module')->getPath('ckeditor_textindent') . '/js/plugins/textindent/icons/textindent.png', ], ]; } Loading @@ -45,7 +50,8 @@ class TextIndent extends CKEditorPluginBase implements CKEditorPluginContextualI * {@inheritdoc} */ public function getFile() { return drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/plugin.js'; #return drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/plugin.js'; return \Drupal::service('extension.list.module')->getPath('ckeditor_textindent') . '/js/plugins/textindent/plugin.js'; } /** Loading Loading
ckeditor_textindent.info.yml +3 −3 Original line number Diff line number Diff line name: CKEditor TextIndent type: module description: 'Provides integration of the CKEditor TextIndent plugin with the Drupal 8 CKEditor.' description: 'Provides integration of the CKEditor TextIndent plugin with the Drupal CKEditor.' package: CKEditor # core: 8.x Loading @@ -9,6 +9,6 @@ dependencies: - drupal:system (>= 8.1) version: '8.x-1.0' core: '8.x' core_version_requirement: ^8 || ^9 project: 'ckeditor_textindent' datestamp: 1507249145 datestamp: 1654572554
js/plugins/textindent/lang/zh-hans.js 0 → 100644 +3 −0 Original line number Diff line number Diff line CKEDITOR.plugins.setLang( 'textindent', 'zh-hans', { labelName: '首行缩进' });
js/plugins/textindent/plugin.js +57 −33 Original line number Diff line number Diff line CKEDITOR.plugins.add( 'textindent', { icons: 'textindent', availableLangs: {'pt-br':1, 'en':1}, lang: 'pt-br, en', availableLangs: {'pt-br':1, 'en':1, 'zh-hans':1}, lang: 'zh-hans, en, pt-br', init: function( editor ) { var indentation = editor.config.indentation; var indentationKey = editor.config.indentationKey; if(typeof(indentation) == 'undefined') indentation = '2em'; else if(indentation.match(/^\d+$/)) { indentation = indentation + 'px'; } indentation = '50px'; if(typeof(indentationKey) == 'undefined') indentationKey = 'tab'; if(editor.ui.addButton){ editor.ui.addButton( 'textindent', { label: editor.lang.textindent.labelName, command: 'insert', toolbar: 'insert' command: 'ident-paragraph', }); } if( indentationKey !== false){ editor.on('key', function(ev) { if(ev.data.domEvent.$.key.toLowerCase() === indentationKey.toLowerCase().trim() || ev.data.keyCode === indentationKey){ editor.execCommand('ident-paragraph'); ev.cancel(); } }); } Loading @@ -32,41 +41,56 @@ CKEDITOR.plugins.add( 'textindent', { }); if( style_textindente.checkActive(editor.elementPath(), editor) ) editor.getCommand('insert').setState(CKEDITOR.TRISTATE_ON); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_ON); else editor.getCommand('insert').setState(CKEDITOR.TRISTATE_OFF); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_OFF); }) }); editor.addCommand("insert", { editor.addCommand("ident-paragraph", { allowedContent: 'p{text-indent}', requiredContent: 'p', exec: function() { exec: function(evt) { var style_textindente = new CKEDITOR.style({ element: 'p', styles: { 'text-indent': indentation }, overrides: [{ element: 'text-indent', attributes: { 'size': '0'} }] }); var range = editor.getSelection().getRanges()[0]; var style_no_textindente = new CKEDITOR.style({ element: 'p', styles: { 'text-indent': '0' }, overrides: [{ element: 'text-indent', attributes: { 'size': indentation } }] }); var walker = new CKEDITOR.dom.walker( range ), node; if( style_textindente.checkActive(editor.elementPath(), editor) ){ var state = editor.getCommand('ident-paragraph').state; while ( ( node = walker.next() ) ) { if ( node.type == CKEDITOR.NODE_ELEMENT ) { if(node.getName() === "p"){ editor.fire('saveSnapshot'); editor.applyStyle(style_no_textindente); if( state == CKEDITOR.TRISTATE_ON){ node.removeStyle("text-indent"); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_OFF); } else{ node.setStyle( "text-indent", indentation ); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_ON); } } } } if(node === null){ node = editor.getSelection().getStartElement().getAscendant('p', true); editor.fire('saveSnapshot'); editor.applyStyle(style_textindente); if( state == CKEDITOR.TRISTATE_ON){ node.removeStyle("text-indent"); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_OFF); } else{ node.setStyle( "text-indent", indentation ); editor.getCommand('ident-paragraph').setState(CKEDITOR.TRISTATE_ON); } } } }); Loading
src/Plugin/CKEditorPlugin/TextIndent.php +8 −2 Original line number Diff line number Diff line Loading @@ -31,12 +31,17 @@ class TextIndent extends CKEditorPluginBase implements CKEditorPluginContextualI * NOTE: The keys of the returned array corresponds to the CKEditor button * names. They are the first argument of the editor.ui.addButton() or * editor.ui.addRichCombo() functions in the plugin.js file. * * add by Douglas.lai 2022-06-07 * drupal_get_path() and drupal_get_filename() have been deprecated in favor of extension listing services * see also:https://www.drupal.org/node/2940438 */ public function getButtons() { return [ 'textindent' => [ 'label' => $this->t('Text Indent'), 'image' => drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/icons/textindent.png', #'image' => drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/icons/textindent.png', 'image' => \Drupal::service('extension.list.module')->getPath('ckeditor_textindent') . '/js/plugins/textindent/icons/textindent.png', ], ]; } Loading @@ -45,7 +50,8 @@ class TextIndent extends CKEditorPluginBase implements CKEditorPluginContextualI * {@inheritdoc} */ public function getFile() { return drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/plugin.js'; #return drupal_get_path('module', 'ckeditor_textindent') . '/js/plugins/textindent/plugin.js'; return \Drupal::service('extension.list.module')->getPath('ckeditor_textindent') . '/js/plugins/textindent/plugin.js'; } /** Loading