X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fmenu%2Fplugin.js;h=ac45279db93cf509c7d915594bf4806bfce352ea;hp=ed91d1c6b85b70a624ee374350b459bf28fb3d24;hb=059b4c2fef02528bf1af189f7996e80652faddfb;hpb=c6e377a02b54abc07129d72b632763c727476a15 diff --git a/_source/plugins/menu/plugin.js b/_source/plugins/menu/plugin.js index ed91d1c..ac45279 100644 --- a/_source/plugins/menu/plugin.js +++ b/_source/plugins/menu/plugin.js @@ -46,14 +46,27 @@ CKEDITOR.plugins.add( 'menu', { CKEDITOR.menu = CKEDITOR.tools.createClass( { - $ : function( editor, level ) + $ : function( editor, definition ) { + definition = this._.definition = definition || {}; this.id = 'cke_' + CKEDITOR.tools.getNextNumber(); this.editor = editor; this.items = []; - this._.level = level || 1; + this._.level = definition.level || 1; + + var panelDefinition = CKEDITOR.tools.extend( {}, definition.panel, + { + css : editor.skin.editor.css, + level : this._.level - 1, + block : {} + } ); + + var attrs = panelDefinition.block.attributes = ( panelDefinition.attributes || {} ); + // Provide default role of 'menu'. + !attrs.role && ( attrs.role = 'menu' ); + this._.panelDefinition = panelDefinition; }, _ : @@ -72,15 +85,22 @@ CKEDITOR.plugins.add( 'menu', return; } + // Record parent menu focused item first (#3389). + var block = this._.panel.getBlock( this.id ); + block._.focusIndex = index; + // Create the submenu, if not available, or clean the existing // one. if ( menu ) menu.removeAll(); else { - menu = this._.subMenu = new CKEDITOR.menu( this.editor, this._.level + 1 ); + menu = this._.subMenu = new CKEDITOR.menu( this.editor, + CKEDITOR.tools.extend( {}, this._.definition, { level : this._.level + 1 }, true ) ); menu.parent = this; menu.onClick = CKEDITOR.tools.bind( this.onClick, this ); + // Sub menu use their own scope for binding onEscape. + menu.onEscape = this.onEscape; } // Add all submenu items to the menu. @@ -130,18 +150,15 @@ CKEDITOR.plugins.add( 'menu', // Create the floating panel for this menu. if ( !panel ) { - panel = this._.panel = new CKEDITOR.ui.floatPanel( this.editor, CKEDITOR.document.getBody(), - { - css : editor.skin.editor.css, - level : this._.level - 1, - className : editor.skinClass + ' cke_contextmenu' - }, - this._.level); + panel = this._.panel = new CKEDITOR.ui.floatPanel( this.editor, + CKEDITOR.document.getBody(), + this._.panelDefinition, + this._.level ); - panel.onEscape = CKEDITOR.tools.bind( function() + panel.onEscape = CKEDITOR.tools.bind( function( keystroke ) { - this.onEscape && this.onEscape(); - this.hide(); + if ( this.onEscape && this.onEscape( keystroke ) === false ) + return false; }, this ); @@ -152,7 +169,7 @@ CKEDITOR.plugins.add( 'menu', this ); // Create an autosize block inside the panel. - var block = panel.addBlock( this.id ); + var block = panel.addBlock( this.id, this._.panelDefinition.block ); block.autoSize = true; var keys = block.keys; @@ -161,7 +178,7 @@ CKEDITOR.plugins.add( 'menu', keys[ 38 ] = 'prev'; // ARROW-UP keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB keys[ 32 ] = 'click'; // SPACE - keys[ 39 ] = 'click'; // ARROW-RIGHT + keys[ ( editor.lang.dir == 'rtl' ? 37 : 39 ) ] = 'click'; // ARROW-RIGHT/ARROW-LEFT(rtl) element = this._.element = block.element; element.addClass( editor.skinClass ); @@ -205,7 +222,7 @@ CKEDITOR.plugins.add( 'menu', sortItems( items ); // Build the HTML that composes the menu and its items. - var output = [ '
' ]; + var output = [ '