814e107d080e07428639825c557cbb5092d12545
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview The "elementspath" plugin. It shows all elements in the DOM
8 * parent tree relative to the current selection in the editing area.
19 exec : function( editor
)
21 var idBase
= editor
._
.elementsPath
.idBase
;
22 var element
= CKEDITOR
.document
.getById( idBase
+ '0' );
24 // Make the first button focus accessible for IE. (#3417)
25 // Adobe AIR instead need while of delay.
26 element
&& element
.focus( CKEDITOR
.env
.ie
|| CKEDITOR
.env
.air
);
31 var emptyHtml
= '<span class="cke_empty"> </span>';
33 CKEDITOR
.plugins
.add( 'elementspath',
35 requires
: [ 'selection' ],
37 init : function( editor
)
39 var spaceId
= 'cke_path_' + editor
.name
;
41 var getSpaceElement = function()
44 spaceElement
= CKEDITOR
.document
.getById( spaceId
);
48 var idBase
= 'cke_elementspath_' + CKEDITOR
.tools
.getNextNumber() + '_';
50 editor
._
.elementsPath
= { idBase
: idBase
, filters
: [] };
52 editor
.on( 'themeSpace', function( event
)
54 if ( event
.data
.space
== 'bottom' )
57 '<span id="' + spaceId
+ '_label" class="cke_voice_label">' + editor
.lang
.elementsPath
.eleLabel
+ '</span>' +
58 '<div id="' + spaceId
+ '" class="cke_path" role="group" aria-labelledby="' + spaceId
+ '_label">' + emptyHtml
+ '</div>';
62 function onClick( elementIndex
)
65 var element
= editor
._
.elementsPath
.list
[ elementIndex
];
66 if ( element
.is( 'body' ) )
68 var range
= new CKEDITOR
.dom
.range( editor
.document
);
69 range
.selectNodeContents( element
);
73 editor
.getSelection().selectElement( element
);
76 var onClickHanlder
= CKEDITOR
.tools
.addFunction( onClick
);
78 var onKeyDownHandler
= CKEDITOR
.tools
.addFunction( function( elementIndex
, ev
)
80 var idBase
= editor
._
.elementsPath
.idBase
,
83 ev
= new CKEDITOR
.dom
.event( ev
);
85 var rtl
= editor
.lang
.dir
== 'rtl';
86 switch ( ev
.getKeystroke() )
88 case rtl
? 39 : 37 : // LEFT-ARROW
90 element
= CKEDITOR
.document
.getById( idBase
+ ( elementIndex
+ 1 ) );
92 element
= CKEDITOR
.document
.getById( idBase
+ '0' );
96 case rtl
? 37 : 39 : // RIGHT-ARROW
97 case CKEDITOR
.SHIFT
+ 9 : // SHIFT + TAB
98 element
= CKEDITOR
.document
.getById( idBase
+ ( elementIndex
- 1 ) );
100 element
= CKEDITOR
.document
.getById( idBase
+ ( editor
._
.elementsPath
.list
.length
- 1 ) );
108 case 13 : // ENTER // Opera
110 onClick( elementIndex
);
116 editor
.on( 'selectionChange', function( ev
)
118 var env
= CKEDITOR
.env
,
119 selection
= ev
.data
.selection
,
120 element
= selection
.getStartElement(),
123 elementsList
= editor
._
.elementsPath
.list
= [],
124 filters
= editor
._
.elementsPath
.filters
;
131 if ( element
.data( 'cke-display-name' ) )
132 name
= element
.data( 'cke-display-name' );
133 else if ( element
.data( 'cke-real-element-type' ) )
134 name
= element
.data( 'cke-real-element-type' );
136 name
= element
.getName();
138 for ( var i
= 0; i
< filters
.length
; i
++ )
140 var ret
= filters
[ i
]( element
, name
);
151 var index
= elementsList
.push( element
) - 1;
153 // Use this variable to add conditional stuff to the
154 // HTML (because we are doing it in reverse order... unshift).
157 // Some browsers don't cancel key events in the keydown but in the
159 // TODO: Check if really needed for Gecko+Mac.
160 if ( env
.opera
|| ( env
.gecko
&& env
.mac
) )
161 extra
+= ' onkeypress="return false;"';
163 // With Firefox, we need to force the button to redraw, otherwise it
164 // will remain in the focus state.
166 extra
+= ' onblur="this.style.cssText = this.style.cssText;"';
168 var label
= editor
.lang
.elementsPath
.eleTitle
.replace( /%1/, name
);
171 ' id="', idBase
, index
, '"' +
172 ' href="javascript:void(\'', name
, '\')"' +
174 ' title="', label
, '"' +
175 ( ( CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.version
< 10900 ) ?
176 ' onfocus="event.preventBubble();"' : '' ) +
177 ' hidefocus="true" ' +
178 ' onkeydown="return CKEDITOR.tools.callFunction(', onKeyDownHandler
, ',', index
, ', event );"' +
180 ' onclick="CKEDITOR.tools.callFunction('+ onClickHanlder
, ',', index
, '); return false;"',
181 ' role="button" aria-labelledby="' + idBase
+ index
+ '_label">',
183 '<span id="', idBase
, index
, '_label" class="cke_label">' + label
+ '</span>',
188 if ( name
== 'body' )
191 element
= element
.getParent();
194 var space
= getSpaceElement();
195 space
.setHtml( html
.join('') + emptyHtml
);
196 editor
.fire( 'elementsPathUpdate', { space
: space
} );
201 spaceElement
&& spaceElement
.setHtml( emptyHtml
);
202 delete editor
._
.elementsPath
.list
;
205 editor
.on( 'readOnly', empty
);
206 editor
.on( 'contentDomUnload', empty
);
208 editor
.addCommand( 'elementsPathFocus', commands
.toolbarFocus
);
214 * Fired when the contents of the elementsPath are changed
215 * @name CKEDITOR.editor#elementsPathUpdate
217 * @param {Object} eventData.space The elementsPath container