X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=inline;f=_source%2Fplugins%2Fpanel%2Fplugin.js;h=ae712c0d780a5710aae3dd60f844d022188b99ca;hb=8f6c203fdaa543c3bca40baea6ae4ddcdf1a77f5;hp=ec682a622d9256984b2499db1d700ab37670caaf;hpb=8761695d9b70afe75905deaac88f78c1f8aeb32d;p=ckeditor.git diff --git a/_source/plugins/panel/plugin.js b/_source/plugins/panel/plugin.js index ec682a6..ae712c0 100644 --- a/_source/plugins/panel/plugin.js +++ b/_source/plugins/panel/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -31,7 +31,7 @@ CKEDITOR.ui.panel = function( document, definition ) css : [] }); - this.id = CKEDITOR.tools.getNextNumber(); + this.id = CKEDITOR.tools.getNextId(); this.document = document; this._ = @@ -73,16 +73,18 @@ CKEDITOR.ui.panel.prototype = */ render : function( editor, output ) { - var id = 'cke_' + this.id; + var id = this.id; output.push( '
, so it (body) becames immediatelly // available. (#3031) - '' + - '<\/html>' ); - doc.$.close(); + CKEDITOR.tools.buildStyleHtml( this.css ) + + '<\/html>'; + + doc.write( data ); var win = doc.getWindow(); // Register the CKEDITOR global. win.$.CKEDITOR = CKEDITOR; - doc.on( 'keydown', function( evt ) + // Arrow keys for scrolling is only preventable with 'keypress' event in Opera (#4534). + doc.on( 'key' + ( CKEDITOR.env.opera? 'press':'down' ), function( evt ) { - var keystroke = evt.data.getKeystroke(); + var keystroke = evt.data.getKeystroke(), + dir = this.document.getById( this.id ).getAttribute( 'dir' ); // Delegate key processing to block. if ( this._.onKeyDown && this._.onKeyDown( keystroke ) === false ) @@ -180,15 +178,21 @@ CKEDITOR.ui.panel.prototype = return; } - if ( keystroke == 27 ) // ESC - this.onEscape && this.onEscape(); + // ESC/ARROW-LEFT(ltr) OR ARROW-RIGHT(rtl) + if ( keystroke == 27 || keystroke == ( dir == 'rtl' ? 39 : 37 ) ) + { + if ( this.onEscape && this.onEscape( keystroke ) === false ) + evt.data.preventDefault(); + } }, this ); holder = doc.getBody(); + holder.unselectable(); + CKEDITOR.env.air && CKEDITOR.tools.callFunction( onLoad ); } else - holder = this.document.getById( 'cke_' + this.id ); + holder = this.document.getById( this.id ); this._.holder = holder; } @@ -198,7 +202,8 @@ CKEDITOR.ui.panel.prototype = addBlock : function( name, block ) { - block = this._.blocks[ name ] = block || new CKEDITOR.ui.panel.block( this.getHolderElement() ); + block = this._.blocks[ name ] = block instanceof CKEDITOR.ui.panel.block ? block + : new CKEDITOR.ui.panel.block( this.getHolderElement(), block ); if ( !this._.currentBlock ) this.showBlock( name ); @@ -215,34 +220,64 @@ CKEDITOR.ui.panel.prototype = { var blocks = this._.blocks, block = blocks[ name ], - current = this._.currentBlock; + current = this._.currentBlock, + holder = this.forceIFrame ? + this.document.getById( this.id + '_frame' ) + : this._.holder; + + // Disable context menu for block panel. + holder.getParent().getParent().disableContextMenu(); if ( current ) + { + // Clean up the current block's effects on holder. + holder.removeAttributes( current.attributes ); current.hide(); + } this._.currentBlock = block; + holder.setAttributes( block.attributes ); + CKEDITOR.fire( 'ariaWidget', holder ); + // Reset the focus index, so it will always go into the first one. block._.focusIndex = -1; this._.onKeyDown = block.onKeyDown && CKEDITOR.tools.bind( block.onKeyDown, block ); + block.onMark = function( item ) + { + holder.setAttribute( 'aria-activedescendant', item.getId() + '_option' ); + }; + + block.onUnmark = function() + { + holder.removeAttribute( 'aria-activedescendant' ); + }; + block.show(); return block; + }, + + destroy : function() + { + this.element && this.element.remove(); } }; CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass( { - $ : function( blockHolder ) + $ : function( blockHolder, blockDefinition ) { this.element = blockHolder.append( blockHolder.getDocument().createElement( 'div', { attributes : { - 'class' : 'cke_panel_block' + 'tabIndex' : -1, + 'class' : 'cke_panel_block', + 'role' : 'presentation' }, styles : { @@ -250,6 +285,13 @@ CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass( } }) ); + // Copy all definition properties to this object. + if ( blockDefinition ) + CKEDITOR.tools.extend( this, blockDefinition ); + + if ( !this.attributes.title ) + this.attributes.title = this.attributes[ 'aria-label' ]; + this.keys = {}; this._.focusIndex = -1; @@ -258,7 +300,27 @@ CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass( this.element.disableContextMenu(); }, - _ : {}, + _ : { + + /** + * Mark the item specified by the index as current activated. + */ + markItem: function( index ) + { + if ( index == -1 ) + return; + var links = this.element.getElementsByTag( 'a' ); + var item = links.getItem( this._.focusIndex = index ); + + // Safari need focus on the iframe window first(#3389), but we need + // lock the blur to avoid hiding the panel. + if ( CKEDITOR.env.webkit || CKEDITOR.env.opera ) + item.getDocument().getWindow().focus(); + item.focus(); + + this.onMark && this.onMark( item ); + } + }, proto : { @@ -331,3 +393,10 @@ CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass( } } }); + +/** + * Fired when a panel is added to the document + * @name CKEDITOR#ariaWidget + * @event + * @param {Object} holder The element wrapping the panel + */