X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Felementspath%2Fplugin.js;h=51ac62ba73d33d90635f1c347db31675dc8ea48c;hb=48b1db88210b4160dce439c6e3e32e14af8c106b;hp=6dd23c8a74c56d4bd3ceee184346feee80862b36;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/elementspath/plugin.js b/_source/plugins/elementspath/plugin.js index 6dd23c8..51ac62b 100644 --- a/_source/plugins/elementspath/plugin.js +++ b/_source/plugins/elementspath/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, 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 */ @@ -19,8 +19,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var idBase = editor._.elementsPath.idBase; var element = CKEDITOR.document.getById( idBase + '0' ); - if ( element ) - element.focus(); + // Make the first button focus accessible for IE. (#3417) + // Adobe AIR instead need while of delay. + element && element.focus( CKEDITOR.env.ie || CKEDITOR.env.air ); } } }; @@ -56,6 +57,60 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }); + function onClick( elementIndex ) + { + editor.focus(); + var element = editor._.elementsPath.list[ elementIndex ]; + if ( element.is( 'body' ) ) + { + var range = new CKEDITOR.dom.range( editor.document ); + range.selectNodeContents( element ); + range.select(); + } + else + editor.getSelection().selectElement( element ); + } + + var onClickHanlder = CKEDITOR.tools.addFunction( onClick ); + + var onKeyDownHandler = CKEDITOR.tools.addFunction( function( elementIndex, ev ) + { + var idBase = editor._.elementsPath.idBase, + element; + + ev = new CKEDITOR.dom.event( ev ); + + var rtl = editor.lang.dir == 'rtl'; + switch ( ev.getKeystroke() ) + { + case rtl ? 39 : 37 : // LEFT-ARROW + case 9 : // TAB + element = CKEDITOR.document.getById( idBase + ( elementIndex + 1 ) ); + if ( !element ) + element = CKEDITOR.document.getById( idBase + '0' ); + element.focus(); + return false; + + case rtl ? 37 : 39 : // RIGHT-ARROW + case CKEDITOR.SHIFT + 9 : // SHIFT + TAB + element = CKEDITOR.document.getById( idBase + ( elementIndex - 1 ) ); + if ( !element ) + element = CKEDITOR.document.getById( idBase + ( editor._.elementsPath.list.length - 1 ) ); + element.focus(); + return false; + + case 27 : // ESC + editor.focus(); + return false; + + case 13 : // ENTER // Opera + case 32 : // SPACE + onClick( elementIndex ); + return false; + } + return true; + }); + editor.on( 'selectionChange', function( ev ) { var env = CKEDITOR.env, @@ -82,8 +137,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var index = elementsList.push( element ) - 1; var name; - if ( element.getAttribute( '_cke_real_element_type' ) ) - name = element.getAttribute( '_cke_real_element_type' ); + if ( element.data( 'cke-real-element-type' ) ) + name = element.data( 'cke-real-element-type' ); else name = element.getName(); @@ -112,9 +167,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license ( ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) ? ' onfocus="event.preventBubble();"' : '' ) + ' hidefocus="true" ' + - ' onkeydown="return CKEDITOR._.elementsPath.keydown(\'', editor.name, '\',', index, ', event);"' + + ' onkeydown="return CKEDITOR.tools.callFunction(', onKeyDownHandler, ',', index, ', event );"' + extra , - ' onclick="return CKEDITOR._.elementsPath.click(\'', editor.name, '\',', index, ');"', + ' onclick="CKEDITOR.tools.callFunction('+ onClickHanlder, ',', index, '); return false;"', ' role="button" aria-labelledby="' + idBase + index + '_label">', name, '' + label + '', @@ -128,12 +183,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license element = element.getParent(); } - getSpaceElement().setHtml( html.join('') + emptyHtml ); + var space = getSpaceElement(); + space.setHtml( html.join('') + emptyHtml ); + editor.fire( 'elementsPathUpdate', { space : space } ); }); editor.on( 'contentDomUnload', function() { - getSpaceElement().setHtml( emptyHtml ); + // If the spaceElement hasn't been initialized, don't try to do it at this time + // Only reuse existing reference. + spaceElement && spaceElement.setHtml( emptyHtml ); }); editor.addCommand( 'elementsPathFocus', commands.toolbarFocus ); @@ -142,62 +201,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license })(); /** - * Handles the click on an element in the element path. - * @private + * Fired when the contents of the elementsPath are changed + * @name CKEDITOR.editor#elementsPathUpdate + * @event + * @param {Object} eventData.space The elementsPath container */ -CKEDITOR._.elementsPath = -{ - click : function( instanceName, elementIndex ) - { - var editor = CKEDITOR.instances[ instanceName ]; - editor.focus(); - - var element = editor._.elementsPath.list[ elementIndex ]; - editor.getSelection().selectElement( element ); - - return false; - }, - - keydown : function( instanceName, elementIndex, ev ) - { - var instance = CKEDITOR.ui.button._.instances[ elementIndex ]; - var editor = CKEDITOR.instances[ instanceName ]; - var idBase = editor._.elementsPath.idBase; - - var element; - - ev = new CKEDITOR.dom.event( ev ); - - switch ( ev.getKeystroke() ) - { - case 37 : // LEFT-ARROW - case 9 : // TAB - element = CKEDITOR.document.getById( idBase + ( elementIndex + 1 ) ); - if ( !element ) - element = CKEDITOR.document.getById( idBase + '0' ); - element.focus(); - return false; - - case 39 : // RIGHT-ARROW - case CKEDITOR.SHIFT + 9 : // SHIFT + TAB - element = CKEDITOR.document.getById( idBase + ( elementIndex - 1 ) ); - if ( !element ) - element = CKEDITOR.document.getById( idBase + ( editor._.elementsPath.list.length - 1 ) ); - element.focus(); - return false; - - case 27 : // ESC - editor.focus(); - return false; - - case 13 : // ENTER // Opera - case 32 : // SPACE - this.click( instanceName, elementIndex ); - return false; - - //default : - // alert( ev.getKeystroke() ); - } - return true; - } -};