X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Felementspath%2Fplugin.js;h=1fb54350f89c76931befc792a5a0c4504b79d3c1;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=75fc4ee7b609511adcb557f2a5ae012635ab47dc;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/elementspath/plugin.js b/_source/plugins/elementspath/plugin.js index 75fc4ee..1fb5435 100644 --- a/_source/plugins/elementspath/plugin.js +++ b/_source/plugins/elementspath/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -14,13 +14,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { toolbarFocus : { + editorFocus : false, + readOnly : 1, exec : function( editor ) { 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 ); } } }; @@ -44,62 +47,143 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var idBase = 'cke_elementspath_' + CKEDITOR.tools.getNextNumber() + '_'; - editor._.elementsPath = { idBase : idBase }; + editor._.elementsPath = { idBase : idBase, filters : [] }; editor.on( 'themeSpace', function( event ) { if ( event.data.space == 'bottom' ) - event.data.html += '
' + emptyHtml + '
'; + { + event.data.html += + '' + editor.lang.elementsPath.eleLabel + '' + + '
' + emptyHtml + '
'; + } }); - editor.on( 'selectionChange', function( ev ) + 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 env = CKEDITOR.env; + var idBase = editor._.elementsPath.idBase, + element; - var selection = ev.data.selection; + ev = new CKEDITOR.dom.event( ev ); - var element = selection.getStartElement(), + 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, + selection = ev.data.selection, + element = selection.getStartElement(), html = [], - elementsList = this._.elementsPath.list = []; + editor = ev.editor, + elementsList = editor._.elementsPath.list = [], + filters = editor._.elementsPath.filters; while ( element ) { - var index = elementsList.push( element ) - 1; - var name; - if ( element.getAttribute( '_cke_real_element_type' ) ) - name = element.getAttribute( '_cke_real_element_type' ); + var ignore = 0, + name; + + if ( element.data( 'cke-display-name' ) ) + name = element.data( 'cke-display-name' ); + else if ( element.data( 'cke-real-element-type' ) ) + name = element.data( 'cke-real-element-type' ); else name = element.getName(); - // Use this variable to add conditional stuff to the - // HTML (because we are doing it in reverse order... unshift). - var extra = ''; - - // Some browsers don't cancel key events in the keydown but in the - // keypress. - // TODO: Check if really needed for Gecko+Mac. - if ( env.opera || ( env.gecko && env.mac ) ) - extra += ' onkeypress="return false;"'; - - // With Firefox, we need to force the button to redraw, otherwise it - // will remain in the focus state. - if ( env.gecko ) - extra += ' onblur="this.style.cssText = this.style.cssText;"'; - - html.unshift( - '', - name, - '' ); + for ( var i = 0; i < filters.length; i++ ) + { + var ret = filters[ i ]( element, name ); + if ( ret === false ) + { + ignore = 1; + break; + } + name = ret || name; + } + + if ( !ignore ) + { + var index = elementsList.push( element ) - 1; + + // Use this variable to add conditional stuff to the + // HTML (because we are doing it in reverse order... unshift). + var extra = ''; + + // Some browsers don't cancel key events in the keydown but in the + // keypress. + // TODO: Check if really needed for Gecko+Mac. + if ( env.opera || ( env.gecko && env.mac ) ) + extra += ' onkeypress="return false;"'; + + // With Firefox, we need to force the button to redraw, otherwise it + // will remain in the focus state. + if ( env.gecko ) + extra += ' onblur="this.style.cssText = this.style.cssText;"'; + + var label = editor.lang.elementsPath.eleTitle.replace( /%1/, name ); + html.unshift( + '', + name, + '' + label + '', + '' ); + + } if ( name == 'body' ) break; @@ -107,13 +191,19 @@ 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 ); - }); + function empty() + { + spaceElement && spaceElement.setHtml( emptyHtml ); + delete editor._.elementsPath.list; + } + + editor.on( 'readOnly', empty ); + editor.on( 'contentDomUnload', empty ); editor.addCommand( 'elementsPathFocus', commands.toolbarFocus ); } @@ -121,62 +211,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; - } -};