]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/elementspath/plugin.js
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md 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.
16 exec: function( editor
) {
17 var idBase
= editor
._
.elementsPath
.idBase
;
18 var element
= CKEDITOR
.document
.getById( idBase
+ '0' );
20 // Make the first button focus accessible for IE. (#3417)
21 // Adobe AIR instead need while of delay.
22 element
&& element
.focus( CKEDITOR
.env
.ie
|| CKEDITOR
.env
.air
);
27 var emptyHtml
= '<span class="cke_path_empty"> </span>';
31 // Some browsers don't cancel key events in the keydown but in the
33 // TODO: Check if really needed.
34 if ( CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.mac
)
35 extra
+= ' onkeypress="return false;"';
37 // With Firefox, we need to force the button to redraw, otherwise it
38 // will remain in the focus state.
39 if ( CKEDITOR
.env
.gecko
)
40 extra
+= ' onblur="this.style.cssText = this.style.cssText;"';
42 var pathItemTpl
= CKEDITOR
.addTemplate( 'pathItem', '<a' +
46 ' class="cke_path_item"' +
49 ' hidefocus="true" ' +
50 ' onkeydown="return CKEDITOR.tools.callFunction({keyDownFn},{index}, event );"' +
51 ' onclick="CKEDITOR.tools.callFunction({clickFn},{index}); return false;"' +
52 ' role="button" aria-label="{label}">' +
56 CKEDITOR
.plugins
.add( 'elementspath', {
57 // jscs:disable maximumLineLength
58 lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
59 // jscs:enable maximumLineLength
60 init: function( editor
) {
61 editor
._
.elementsPath
= {
62 idBase: 'cke_elementspath_' + CKEDITOR
.tools
.getNextNumber() + '_',
66 editor
.on( 'uiSpace', function( event
) {
67 if ( event
.data
.space
== 'bottom' )
68 initElementsPath( editor
, event
.data
);
73 function initElementsPath( editor
, bottomSpaceData
) {
74 var spaceId
= editor
.ui
.spaceId( 'path' ),
76 getSpaceElement = function() {
78 spaceElement
= CKEDITOR
.document
.getById( spaceId
);
81 elementsPath
= editor
._
.elementsPath
,
82 idBase
= elementsPath
.idBase
;
84 bottomSpaceData
.html
+= '<span id="' + spaceId
+ '_label" class="cke_voice_label">' + editor
.lang
.elementspath
.eleLabel
+ '</span>' +
85 '<span id="' + spaceId
+ '" class="cke_path" role="group" aria-labelledby="' + spaceId
+ '_label">' + emptyHtml
+ '</span>';
87 // Register the ui element to the focus manager.
88 editor
.on( 'uiReady', function() {
89 var element
= editor
.ui
.space( 'path' );
90 element
&& editor
.focusManager
.add( element
, 1 );
93 function onClick( elementIndex
) {
94 var element
= elementsPath
.list
[ elementIndex
];
95 if ( element
.equals( editor
.editable() ) || element
.getAttribute( 'contenteditable' ) == 'true' ) {
96 var range
= editor
.createRange();
97 range
.selectNodeContents( element
);
100 editor
.getSelection().selectElement( element
);
103 // It is important to focus() *after* the above selection
104 // manipulation, otherwise Firefox will have troubles. #10119
108 elementsPath
.onClick
= onClick
;
110 var onClickHanlder
= CKEDITOR
.tools
.addFunction( onClick
),
111 onKeyDownHandler
= CKEDITOR
.tools
.addFunction( function( elementIndex
, ev
) {
112 var idBase
= elementsPath
.idBase
,
115 ev
= new CKEDITOR
.dom
.event( ev
);
117 var rtl
= editor
.lang
.dir
== 'rtl';
118 switch ( ev
.getKeystroke() ) {
119 case rtl
? 39 : 37: // LEFT-ARROW
121 element
= CKEDITOR
.document
.getById( idBase
+ ( elementIndex
+ 1 ) );
123 element
= CKEDITOR
.document
.getById( idBase
+ '0' );
127 case rtl
? 37 : 39: // RIGHT-ARROW
128 case CKEDITOR
.SHIFT
+ 9: // SHIFT + TAB
129 element
= CKEDITOR
.document
.getById( idBase
+ ( elementIndex
- 1 ) );
131 element
= CKEDITOR
.document
.getById( idBase
+ ( elementsPath
.list
.length
- 1 ) );
139 case 13: // ENTER // Opera
141 onClick( elementIndex
);
147 editor
.on( 'selectionChange', function() {
149 elementsList
= elementsPath
.list
= [],
151 filters
= elementsPath
.filters
,
152 isContentEditable
= true,
154 // Use elementPath to consider children of editable only (#11124).
155 elementsChain
= editor
.elementPath().elements
,
158 // Starts iteration from body element, skipping html.
159 for ( var j
= elementsChain
.length
; j
--; ) {
160 var element
= elementsChain
[ j
],
163 if ( element
.data( 'cke-display-name' ) )
164 name
= element
.data( 'cke-display-name' );
165 else if ( element
.data( 'cke-real-element-type' ) )
166 name
= element
.data( 'cke-real-element-type' );
168 name
= element
.getName();
170 isContentEditable
= element
.hasAttribute( 'contenteditable' ) ?
171 element
.getAttribute( 'contenteditable' ) == 'true' : isContentEditable
;
173 // If elem is non-contenteditable, and it's not specifying contenteditable
174 // attribute - then elem should be ignored.
175 if ( !isContentEditable
&& !element
.hasAttribute( 'contenteditable' ) )
178 for ( var i
= 0; i
< filters
.length
; i
++ ) {
179 var ret
= filters
[ i
]( element
, name
);
180 if ( ret
=== false ) {
188 elementsList
.unshift( element
);
189 namesList
.unshift( name
);
193 for ( var iterationLimit
= elementsList
.length
, index
= 0; index
< iterationLimit
; index
++ ) {
194 name
= namesList
[ index
];
195 var label
= editor
.lang
.elementspath
.eleTitle
.replace( /%1/, name
),
196 item
= pathItemTpl
.output( {
200 jsTitle: 'javascript:void(\'' + name
+ '\')', // jshint ignore:line
202 keyDownFn: onKeyDownHandler
,
203 clickFn: onClickHanlder
206 html
.unshift( item
);
209 var space
= getSpaceElement();
210 space
.setHtml( html
.join( '' ) + emptyHtml
);
211 editor
.fire( 'elementsPathUpdate', { space: space
} );
215 spaceElement
&& spaceElement
.setHtml( emptyHtml
);
216 delete elementsPath
.list
;
219 editor
.on( 'readOnly', empty
);
220 editor
.on( 'contentDomUnload', empty
);
222 editor
.addCommand( 'elementsPathFocus', commands
.toolbarFocus
);
223 editor
.setKeystroke( CKEDITOR
.ALT
+ 122 /*F11*/, 'elementsPathFocus' );
228 * Fired when the contents of the elementsPath are changed.
230 * @event elementsPathUpdate
231 * @member CKEDITOR.editor
232 * @param {CKEDITOR.editor} editor This editor instance.
234 * @param {CKEDITOR.dom.element} data.space The elementsPath container.