2 Copyright (c) 2003-2010, 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.
17 exec : function( editor
)
19 var idBase
= editor
._
.elementsPath
.idBase
;
20 var element
= CKEDITOR
.document
.getById( idBase
+ '0' );
28 var emptyHtml
= '<span class="cke_empty"> </span>';
30 CKEDITOR
.plugins
.add( 'elementspath',
32 requires
: [ 'selection' ],
34 init : function( editor
)
36 var spaceId
= 'cke_path_' + editor
.name
;
38 var getSpaceElement = function()
41 spaceElement
= CKEDITOR
.document
.getById( spaceId
);
45 var idBase
= 'cke_elementspath_' + CKEDITOR
.tools
.getNextNumber() + '_';
47 editor
._
.elementsPath
= { idBase
: idBase
, filters
: [] };
49 editor
.on( 'themeSpace', function( event
)
51 if ( event
.data
.space
== 'bottom' )
54 '<span id="' + spaceId
+ '_label" class="cke_voice_label">' + editor
.lang
.elementsPath
.eleLabel
+ '</span>' +
55 '<div id="' + spaceId
+ '" class="cke_path" role="group" aria-labelledby="' + spaceId
+ '_label">' + emptyHtml
+ '</div>';
59 editor
.on( 'selectionChange', function( ev
)
61 var env
= CKEDITOR
.env
,
62 selection
= ev
.data
.selection
,
63 element
= selection
.getStartElement(),
66 elementsList
= editor
._
.elementsPath
.list
= [],
67 filters
= editor
._
.elementsPath
.filters
;
72 for ( var i
= 0; i
< filters
.length
; i
++ )
74 if ( filters
[ i
]( element
) === false )
83 var index
= elementsList
.push( element
) - 1;
85 if ( element
.getAttribute( '_cke_real_element_type' ) )
86 name
= element
.getAttribute( '_cke_real_element_type' );
88 name
= element
.getName();
90 // Use this variable to add conditional stuff to the
91 // HTML (because we are doing it in reverse order... unshift).
94 // Some browsers don't cancel key events in the keydown but in the
96 // TODO: Check if really needed for Gecko+Mac.
97 if ( env
.opera
|| ( env
.gecko
&& env
.mac
) )
98 extra
+= ' onkeypress="return false;"';
100 // With Firefox, we need to force the button to redraw, otherwise it
101 // will remain in the focus state.
103 extra
+= ' onblur="this.style.cssText = this.style.cssText;"';
105 var label
= editor
.lang
.elementsPath
.eleTitle
.replace( /%1/, name
);
108 ' id="', idBase
, index
, '"' +
109 ' href="javascript:void(\'', name
, '\')"' +
111 ' title="', label
, '"' +
112 ( ( CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.version
< 10900 ) ?
113 ' onfocus="event.preventBubble();"' : '' ) +
114 ' hidefocus="true" ' +
115 ' onkeydown="return CKEDITOR._.elementsPath.keydown(\'', editor
.name
, '\',', index
, ', event);"' +
117 ' onclick="return CKEDITOR._.elementsPath.click(\'', editor
.name
, '\',', index
, ');"',
118 ' role="button" aria-labelledby="' + idBase
+ index
+ '_label">',
120 '<span id="', idBase
, index
, '_label" class="cke_label">' + label
+ '</span>',
125 if ( name
== 'body' )
128 element
= element
.getParent();
131 getSpaceElement().setHtml( html
.join('') + emptyHtml
);
134 editor
.on( 'contentDomUnload', function()
136 getSpaceElement().setHtml( emptyHtml
);
139 editor
.addCommand( 'elementsPathFocus', commands
.toolbarFocus
);
145 * Handles the click on an element in the element path.
148 CKEDITOR
._
.elementsPath
=
150 click : function( instanceName
, elementIndex
)
152 var editor
= CKEDITOR
.instances
[ instanceName
];
155 var element
= editor
._
.elementsPath
.list
[ elementIndex
];
156 editor
.getSelection().selectElement( element
);
161 keydown : function( instanceName
, elementIndex
, ev
)
163 var instance
= CKEDITOR
.ui
.button
._
.instances
[ elementIndex
];
164 var editor
= CKEDITOR
.instances
[ instanceName
];
165 var idBase
= editor
._
.elementsPath
.idBase
;
169 ev
= new CKEDITOR
.dom
.event( ev
);
171 switch ( ev
.getKeystroke() )
173 case 37 : // LEFT-ARROW
175 element
= CKEDITOR
.document
.getById( idBase
+ ( elementIndex
+ 1 ) );
177 element
= CKEDITOR
.document
.getById( idBase
+ '0' );
181 case 39 : // RIGHT-ARROW
182 case CKEDITOR
.SHIFT
+ 9 : // SHIFT + TAB
183 element
= CKEDITOR
.document
.getById( idBase
+ ( elementIndex
- 1 ) );
185 element
= CKEDITOR
.document
.getById( idBase
+ ( editor
._
.elementsPath
.list
.length
- 1 ) );
193 case 13 : // ENTER // Opera
195 this.click( instanceName
, elementIndex
);
199 // alert( ev.getKeystroke() );