@@ -52,14 +52,36 @@ function editorPaste(e, editor) {
5252function registerEditorShortcuts ( editor ) {
5353 // Headers
5454 for ( let i = 1 ; i < 5 ; i ++ ) {
55- editor . addShortcut ( 'meta+' + i , '' , [ 'FormatBlock' , false , 'h' + i ] ) ;
55+ editor . shortcuts . add ( 'meta+' + i , '' , [ 'FormatBlock' , false , 'h' + ( i + 1 ) ] ) ;
5656 }
5757
5858 // Other block shortcuts
59- editor . addShortcut ( 'meta+q' , '' , [ 'FormatBlock' , false , 'blockquote' ] ) ;
60- editor . addShortcut ( 'meta+d' , '' , [ 'FormatBlock' , false , 'p' ] ) ;
61- editor . addShortcut ( 'meta+e' , '' , [ 'codeeditor' , false , 'pre' ] ) ;
62- editor . addShortcut ( 'meta+shift+E' , '' , [ 'FormatBlock' , false , 'code' ] ) ;
59+ editor . shortcuts . add ( 'meta+5' , '' , [ 'FormatBlock' , false , 'p' ] ) ;
60+ editor . shortcuts . add ( 'meta+d' , '' , [ 'FormatBlock' , false , 'p' ] ) ;
61+ editor . shortcuts . add ( 'meta+6' , '' , [ 'FormatBlock' , false , 'blockquote' ] ) ;
62+ editor . shortcuts . add ( 'meta+q' , '' , [ 'FormatBlock' , false , 'blockquote' ] ) ;
63+ editor . shortcuts . add ( 'meta+7' , '' , [ 'codeeditor' , false , 'pre' ] ) ;
64+ editor . shortcuts . add ( 'meta+e' , '' , [ 'codeeditor' , false , 'pre' ] ) ;
65+ editor . shortcuts . add ( 'meta+8' , '' , [ 'FormatBlock' , false , 'code' ] ) ;
66+ editor . shortcuts . add ( 'meta+shift+E' , '' , [ 'FormatBlock' , false , 'code' ] ) ;
67+ // Loop through callout styles
68+ editor . shortcuts . add ( 'meta+9' , '' , function ( ) {
69+ let selectedNode = editor . selection . getNode ( ) ;
70+ let formats = [ 'info' , 'success' , 'warning' , 'danger' ] ;
71+
72+ if ( ! selectedNode || selectedNode . className . indexOf ( 'callout' ) === - 1 ) {
73+ editor . formatter . apply ( 'calloutinfo' ) ;
74+ return ;
75+ }
76+
77+ for ( let i = 0 ; i < formats . length ; i ++ ) {
78+ if ( selectedNode . className . indexOf ( formats [ i ] ) === - 1 ) continue ;
79+ let newFormat = ( i === formats . length - 1 ) ? formats [ 0 ] : formats [ i + 1 ] ;
80+ editor . formatter . apply ( 'callout' + newFormat ) ;
81+ return ;
82+ }
83+ editor . formatter . apply ( 'p' ) ;
84+ } ) ;
6385}
6486
6587
@@ -120,7 +142,7 @@ function codePlugin() {
120142 $codeMirrorContainer . replaceWith ( $pre ) ;
121143 }
122144
123- window . tinymce . PluginManager . add ( 'codeeditor' , ( editor , url ) => {
145+ window . tinymce . PluginManager . add ( 'codeeditor' , function ( editor , url ) {
124146
125147 let $ = editor . $ ;
126148
@@ -173,7 +195,32 @@ function codePlugin() {
173195 } ) ;
174196}
175197
198+ function hrPlugin ( ) {
199+ window . tinymce . PluginManager . add ( 'customhr' , function ( editor ) {
200+ editor . addCommand ( 'InsertHorizontalRule' , function ( ) {
201+ let hrElem = document . createElement ( 'hr' ) ;
202+ let cNode = editor . selection . getNode ( ) ;
203+ let parentNode = cNode . parentNode ;
204+ parentNode . insertBefore ( hrElem , cNode ) ;
205+ } ) ;
206+
207+ editor . addButton ( 'hr' , {
208+ icon : 'hr' ,
209+ tooltip : 'Horizontal line' ,
210+ cmd : 'InsertHorizontalRule'
211+ } ) ;
212+
213+ editor . addMenuItem ( 'hr' , {
214+ icon : 'hr' ,
215+ text : 'Horizontal line' ,
216+ cmd : 'InsertHorizontalRule' ,
217+ context : 'insert'
218+ } ) ;
219+ } ) ;
220+ }
221+
176222module . exports = function ( ) {
223+ hrPlugin ( ) ;
177224 codePlugin ( ) ;
178225 let settings = {
179226 selector : '#html-editor' ,
@@ -207,10 +254,10 @@ module.exports = function() {
207254 { title : "Code Block" , icon : "code" , cmd : 'codeeditor' , format : 'codeeditor' } ,
208255 { title : "Inline Code" , icon : "code" , inline : "code" } ,
209256 { title : "Callouts" , items : [
210- { title : "Success " , block : 'p' , exact : true , attributes : { 'class' : 'callout success' } } ,
211- { title : "Info " , block : 'p' , exact : true , attributes : { 'class' : 'callout info' } } ,
212- { title : "Warning" , block : 'p' , exact : true , attributes : { 'class' : 'callout warning' } } ,
213- { title : "Danger" , block : 'p' , exact : true , attributes : { 'class' : 'callout danger' } }
257+ { title : "Info " , format : 'calloutinfo' } ,
258+ { title : "Success " , format : 'calloutsuccess' } ,
259+ { title : "Warning" , format : 'calloutwarning' } ,
260+ { title : "Danger" , format : 'calloutdanger' }
214261 ] } ,
215262 ] ,
216263 style_formats_merge : false ,
@@ -219,6 +266,10 @@ module.exports = function() {
219266 alignleft : { selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img' , classes : 'align-left' } ,
220267 aligncenter : { selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img' , classes : 'align-center' } ,
221268 alignright : { selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img' , classes : 'align-right' } ,
269+ calloutsuccess : { block : 'p' , exact : true , attributes : { class : 'callout success' } } ,
270+ calloutinfo : { block : 'p' , exact : true , attributes : { class : 'callout info' } } ,
271+ calloutwarning : { block : 'p' , exact : true , attributes : { class : 'callout warning' } } ,
272+ calloutdanger : { block : 'p' , exact : true , attributes : { class : 'callout danger' } }
222273 } ,
223274 file_browser_callback : function ( field_name , url , type , win ) {
224275
0 commit comments