Update ckeditor to version 3.2.1
[gopost.git] / ckeditor / _source / plugins / elementspath / plugin.js
blob6dd23c8a74c56d4bd3ceee184346feee80862b36
1 /*
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 /**
7 * @fileOverview The "elementspath" plugin. It shows all elements in the DOM
8 * parent tree relative to the current selection in the editing area.
9 */
11 (function()
13 var commands =
15 toolbarFocus :
17 exec : function( editor )
19 var idBase = editor._.elementsPath.idBase;
20 var element = CKEDITOR.document.getById( idBase + '0' );
22 if ( element )
23 element.focus();
28 var emptyHtml = '<span class="cke_empty">&nbsp;</span>';
30 CKEDITOR.plugins.add( 'elementspath',
32 requires : [ 'selection' ],
34 init : function( editor )
36 var spaceId = 'cke_path_' + editor.name;
37 var spaceElement;
38 var getSpaceElement = function()
40 if ( !spaceElement )
41 spaceElement = CKEDITOR.document.getById( spaceId );
42 return spaceElement;
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' )
53 event.data.html +=
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>';
57 });
59 editor.on( 'selectionChange', function( ev )
61 var env = CKEDITOR.env,
62 selection = ev.data.selection,
63 element = selection.getStartElement(),
64 html = [],
65 editor = ev.editor,
66 elementsList = editor._.elementsPath.list = [],
67 filters = editor._.elementsPath.filters;
69 while ( element )
71 var ignore = 0;
72 for ( var i = 0; i < filters.length; i++ )
74 if ( filters[ i ]( element ) === false )
76 ignore = 1;
77 break;
81 if ( !ignore )
83 var index = elementsList.push( element ) - 1;
84 var name;
85 if ( element.getAttribute( '_cke_real_element_type' ) )
86 name = element.getAttribute( '_cke_real_element_type' );
87 else
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).
92 var extra = '';
94 // Some browsers don't cancel key events in the keydown but in the
95 // keypress.
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.
102 if ( env.gecko )
103 extra += ' onblur="this.style.cssText = this.style.cssText;"';
105 var label = editor.lang.elementsPath.eleTitle.replace( /%1/, name );
106 html.unshift(
107 '<a' +
108 ' id="', idBase, index, '"' +
109 ' href="javascript:void(\'', name, '\')"' +
110 ' tabindex="-1"' +
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);"' +
116 extra ,
117 ' onclick="return CKEDITOR._.elementsPath.click(\'', editor.name, '\',', index, ');"',
118 ' role="button" aria-labelledby="' + idBase + index + '_label">',
119 name,
120 '<span id="', idBase, index, '_label" class="cke_label">' + label + '</span>',
121 '</a>' );
125 if ( name == 'body' )
126 break;
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 );
142 })();
145 * Handles the click on an element in the element path.
146 * @private
148 CKEDITOR._.elementsPath =
150 click : function( instanceName, elementIndex )
152 var editor = CKEDITOR.instances[ instanceName ];
153 editor.focus();
155 var element = editor._.elementsPath.list[ elementIndex ];
156 editor.getSelection().selectElement( element );
158 return false;
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;
167 var element;
169 ev = new CKEDITOR.dom.event( ev );
171 switch ( ev.getKeystroke() )
173 case 37 : // LEFT-ARROW
174 case 9 : // TAB
175 element = CKEDITOR.document.getById( idBase + ( elementIndex + 1 ) );
176 if ( !element )
177 element = CKEDITOR.document.getById( idBase + '0' );
178 element.focus();
179 return false;
181 case 39 : // RIGHT-ARROW
182 case CKEDITOR.SHIFT + 9 : // SHIFT + TAB
183 element = CKEDITOR.document.getById( idBase + ( elementIndex - 1 ) );
184 if ( !element )
185 element = CKEDITOR.document.getById( idBase + ( editor._.elementsPath.list.length - 1 ) );
186 element.focus();
187 return false;
189 case 27 : // ESC
190 editor.focus();
191 return false;
193 case 13 : // ENTER // Opera
194 case 32 : // SPACE
195 this.click( instanceName, elementIndex );
196 return false;
198 //default :
199 // alert( ev.getKeystroke() );
201 return true;