2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The "elementspath" plugin. It shows all elements in the DOM
\r
8 * parent tree relative to the current selection in the editing area.
\r
17 editorFocus : false,
\r
18 exec : function( editor )
\r
20 var idBase = editor._.elementsPath.idBase;
\r
21 var element = CKEDITOR.document.getById( idBase + '0' );
\r
23 // Make the first button focus accessible for IE. (#3417)
\r
24 // Adobe AIR instead need while of delay.
\r
25 element && element.focus( CKEDITOR.env.ie || CKEDITOR.env.air );
\r
30 var emptyHtml = '<span class="cke_empty"> </span>';
\r
32 CKEDITOR.plugins.add( 'elementspath',
\r
34 requires : [ 'selection' ],
\r
36 init : function( editor )
\r
38 var spaceId = 'cke_path_' + editor.name;
\r
40 var getSpaceElement = function()
\r
42 if ( !spaceElement )
\r
43 spaceElement = CKEDITOR.document.getById( spaceId );
\r
44 return spaceElement;
\r
47 var idBase = 'cke_elementspath_' + CKEDITOR.tools.getNextNumber() + '_';
\r
49 editor._.elementsPath = { idBase : idBase, filters : [] };
\r
51 editor.on( 'themeSpace', function( event )
\r
53 if ( event.data.space == 'bottom' )
\r
56 '<span id="' + spaceId + '_label" class="cke_voice_label">' + editor.lang.elementsPath.eleLabel + '</span>' +
\r
57 '<div id="' + spaceId + '" class="cke_path" role="group" aria-labelledby="' + spaceId + '_label">' + emptyHtml + '</div>';
\r
61 function onClick( elementIndex )
\r
64 var element = editor._.elementsPath.list[ elementIndex ];
\r
65 if ( element.is( 'body' ) )
\r
67 var range = new CKEDITOR.dom.range( editor.document );
\r
68 range.selectNodeContents( element );
\r
72 editor.getSelection().selectElement( element );
\r
75 var onClickHanlder = CKEDITOR.tools.addFunction( onClick );
\r
77 var onKeyDownHandler = CKEDITOR.tools.addFunction( function( elementIndex, ev )
\r
79 var idBase = editor._.elementsPath.idBase,
\r
82 ev = new CKEDITOR.dom.event( ev );
\r
84 var rtl = editor.lang.dir == 'rtl';
\r
85 switch ( ev.getKeystroke() )
\r
87 case rtl ? 39 : 37 : // LEFT-ARROW
\r
89 element = CKEDITOR.document.getById( idBase + ( elementIndex + 1 ) );
\r
91 element = CKEDITOR.document.getById( idBase + '0' );
\r
95 case rtl ? 37 : 39 : // RIGHT-ARROW
\r
96 case CKEDITOR.SHIFT + 9 : // SHIFT + TAB
\r
97 element = CKEDITOR.document.getById( idBase + ( elementIndex - 1 ) );
\r
99 element = CKEDITOR.document.getById( idBase + ( editor._.elementsPath.list.length - 1 ) );
\r
107 case 13 : // ENTER // Opera
\r
109 onClick( elementIndex );
\r
115 editor.on( 'selectionChange', function( ev )
\r
117 var env = CKEDITOR.env,
\r
118 selection = ev.data.selection,
\r
119 element = selection.getStartElement(),
\r
121 editor = ev.editor,
\r
122 elementsList = editor._.elementsPath.list = [],
\r
123 filters = editor._.elementsPath.filters;
\r
128 for ( var i = 0; i < filters.length; i++ )
\r
130 if ( filters[ i ]( element ) === false )
\r
139 var index = elementsList.push( element ) - 1;
\r
141 if ( element.data( 'cke-real-element-type' ) )
\r
142 name = element.data( 'cke-real-element-type' );
\r
144 name = element.getName();
\r
146 // Use this variable to add conditional stuff to the
\r
147 // HTML (because we are doing it in reverse order... unshift).
\r
150 // Some browsers don't cancel key events in the keydown but in the
\r
152 // TODO: Check if really needed for Gecko+Mac.
\r
153 if ( env.opera || ( env.gecko && env.mac ) )
\r
154 extra += ' onkeypress="return false;"';
\r
156 // With Firefox, we need to force the button to redraw, otherwise it
\r
157 // will remain in the focus state.
\r
159 extra += ' onblur="this.style.cssText = this.style.cssText;"';
\r
161 var label = editor.lang.elementsPath.eleTitle.replace( /%1/, name );
\r
164 ' id="', idBase, index, '"' +
\r
165 ' href="javascript:void(\'', name, '\')"' +
\r
167 ' title="', label, '"' +
\r
168 ( ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) ?
\r
169 ' onfocus="event.preventBubble();"' : '' ) +
\r
170 ' hidefocus="true" ' +
\r
171 ' onkeydown="return CKEDITOR.tools.callFunction(', onKeyDownHandler, ',', index, ', event );"' +
\r
173 ' onclick="CKEDITOR.tools.callFunction('+ onClickHanlder, ',', index, '); return false;"',
\r
174 ' role="button" aria-labelledby="' + idBase + index + '_label">',
\r
176 '<span id="', idBase, index, '_label" class="cke_label">' + label + '</span>',
\r
181 if ( name == 'body' )
\r
184 element = element.getParent();
\r
187 var space = getSpaceElement();
\r
188 space.setHtml( html.join('') + emptyHtml );
\r
189 editor.fire( 'elementsPathUpdate', { space : space } );
\r
192 editor.on( 'contentDomUnload', function()
\r
194 // If the spaceElement hasn't been initialized, don't try to do it at this time
\r
195 // Only reuse existing reference.
\r
196 spaceElement && spaceElement.setHtml( emptyHtml );
\r
199 editor.addCommand( 'elementsPathFocus', commands.toolbarFocus );
\r
205 * Fired when the contents of the elementsPath are changed
\r
206 * @name CKEDITOR.editor#elementsPathUpdate
\r
208 * @param {Object} eventData.space The elementsPath container
\r