2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR
.dialog
.add( 'specialchar', function( editor
)
9 * Simulate "this" of a dialog for non-dialog events.
10 * @type {CKEDITOR.dialog}
13 lang
= editor
.lang
.specialChar
;
15 var onChoice = function( evt
)
19 target
= evt
.data
.getTarget();
21 target
= new CKEDITOR
.dom
.element( evt
);
23 if ( target
.getName() == 'a' && ( value
= target
.getChild( 0 ).getHtml() ) )
25 target
.removeClass( "cke_light_background" );
28 // We must use "insertText" here to keep text styled.
29 var span
= editor
.document
.createElement( 'span' );
30 span
.setHtml( value
);
31 editor
.insertText( span
.getText() );
35 var onClick
= CKEDITOR
.tools
.addFunction( onChoice
);
39 var onFocus = function( evt
, target
)
42 target
= target
|| evt
.data
.getTarget();
44 if ( target
.getName() == 'span' )
45 target
= target
.getParent();
47 if ( target
.getName() == 'a' && ( value
= target
.getChild( 0 ).getHtml() ) )
49 // Trigger blur manually if there is focused node.
51 onBlur( null, focusedNode
);
53 var htmlPreview
= dialog
.getContentElement( 'info', 'htmlPreview' ).getElement();
55 dialog
.getContentElement( 'info', 'charPreview' ).getElement().setHtml( value
);
56 htmlPreview
.setHtml( CKEDITOR
.tools
.htmlEncode( value
) );
57 target
.getParent().addClass( "cke_light_background" );
59 // Memorize focused node.
64 var onBlur = function( evt
, target
)
66 target
= target
|| evt
.data
.getTarget();
68 if ( target
.getName() == 'span' )
69 target
= target
.getParent();
71 if ( target
.getName() == 'a' )
73 dialog
.getContentElement( 'info', 'charPreview' ).getElement().setHtml( ' ' );
74 dialog
.getContentElement( 'info', 'htmlPreview' ).getElement().setHtml( ' ' );
75 target
.getParent().removeClass( "cke_light_background" );
77 focusedNode
= undefined;
81 var onKeydown
= CKEDITOR
.tools
.addFunction( function( ev
)
83 ev
= new CKEDITOR
.dom
.event( ev
);
85 // Get an Anchor element.
86 var element
= ev
.getTarget();
87 var relative
, nodeToMove
;
88 var keystroke
= ev
.getKeystroke(),
89 rtl
= editor
.lang
.dir
== 'rtl';
96 if ( ( relative
= element
.getParent().getParent().getPrevious() ) )
98 nodeToMove
= relative
.getChild( [element
.getParent().getIndex(), 0] );
100 onBlur( null, element
);
101 onFocus( null, nodeToMove
);
108 if ( ( relative
= element
.getParent().getParent().getNext() ) )
110 nodeToMove
= relative
.getChild( [ element
.getParent().getIndex(), 0 ] );
111 if ( nodeToMove
&& nodeToMove
.type
== 1 )
114 onBlur( null, element
);
115 onFocus( null, nodeToMove
);
121 // ENTER is already handled as onClick
123 onChoice( { data
: ev
} );
132 if ( ( relative
= element
.getParent().getNext() ) )
134 nodeToMove
= relative
.getChild( 0 );
135 if ( nodeToMove
.type
== 1 )
138 onBlur( null, element
);
139 onFocus( null, nodeToMove
);
140 ev
.preventDefault( true );
143 onBlur( null, element
);
146 else if ( ( relative
= element
.getParent().getParent().getNext() ) )
148 nodeToMove
= relative
.getChild( [ 0, 0 ] );
149 if ( nodeToMove
&& nodeToMove
.type
== 1 )
152 onBlur( null, element
);
153 onFocus( null, nodeToMove
);
154 ev
.preventDefault( true );
157 onBlur( null, element
);
164 case CKEDITOR
.SHIFT
+ 9 :
166 if ( ( relative
= element
.getParent().getPrevious() ) )
168 nodeToMove
= relative
.getChild( 0 );
170 onBlur( null, element
);
171 onFocus( null, nodeToMove
);
172 ev
.preventDefault( true );
175 else if ( ( relative
= element
.getParent().getParent().getPrevious() ) )
177 nodeToMove
= relative
.getLast().getChild( 0 );
179 onBlur( null, element
);
180 onFocus( null, nodeToMove
);
181 ev
.preventDefault( true );
184 onBlur( null, element
);
187 // Do not stop not handled events.
196 buttons
: [ CKEDITOR
.dialog
.cancelButton
],
200 var columns
= this.definition
.charColumns
,
201 extraChars
= editor
.config
.extraSpecialChars
,
202 chars
= editor
.config
.specialChars
;
204 var charsTableLabel
= CKEDITOR
.tools
.getNextId() + '_specialchar_table_label';
205 var html
= [ '<table role="listbox" aria-labelledby="' + charsTableLabel
+ '"' +
206 ' style="width: 320px; height: 100%; border-collapse: separate;"' +
207 ' align="center" cellspacing="2" cellpadding="2" border="0">' ];
216 html
.push( '<tr>' ) ;
218 for ( var j
= 0 ; j
< columns
; j
++, i
++ )
220 if ( ( character
= chars
[ i
] ) )
224 if ( character
instanceof Array
)
226 charDesc
= character
[ 1 ];
227 character
= character
[ 0 ];
231 var _tmpName
= character
.toLowerCase().replace( '&', '' ).replace( ';', '' ).replace( '#', '' );
233 // Use character in case description unavailable.
234 charDesc
= lang
[ _tmpName
] || character
;
237 var charLabelId
= 'cke_specialchar_label_' + i
+ '_' + CKEDITOR
.tools
.getNextNumber();
240 '<td class="cke_dark_background" style="cursor: default" role="presentation">' +
241 '<a href="javascript: void(0);" role="option"' +
242 ' aria-posinset="' + ( i
+1 ) + '"',
243 ' aria-setsize="' + size
+ '"',
244 ' aria-labelledby="' + charLabelId
+ '"',
245 ' style="cursor: inherit; display: block; height: 1.25em; margin-top: 0.25em; text-align: center;" title="', CKEDITOR
.tools
.htmlEncode( charDesc
), '"' +
246 ' onkeydown="CKEDITOR.tools.callFunction( ' + onKeydown
+ ', event, this )"' +
247 ' onclick="CKEDITOR.tools.callFunction(' + onClick
+ ', this); return false;"' +
249 '<span style="margin: 0 auto;cursor: inherit">' +
252 '<span class="cke_voice_label" id="' + charLabelId
+ '">' +
257 html
.push( '<td class="cke_dark_background"> ' );
259 html
.push( '</td>' );
261 html
.push( '</tr>' );
264 html
.push( '</tbody></table>', '<span id="' + charsTableLabel
+ '" class="cke_voice_label">' + lang
.options
+'</span>' );
266 this.getContentElement( 'info', 'charContainer' ).getElement().setHtml( html
.join( '' ) );
271 label
: editor
.lang
.common
.generalTab
,
272 title
: editor
.lang
.common
.generalTab
,
279 widths
: [ '320px', '90px' ],
284 id
: 'charContainer',
286 onMouseover
: onFocus
,
290 var firstChar
= this.getElement().getElementsByTag( 'a' ).getItem( 0 );
291 setTimeout( function()
294 onFocus( null, firstChar
);
299 var firstChar
= this.getElement().getChild( [ 0, 0, 0, 0, 0 ] );
300 setTimeout( function()
303 onFocus( null, firstChar
);
306 onLoad : function( event
)
308 dialog
= event
.sender
;
329 className
: 'cke_dark_background',
330 style
: 'border:1px solid #eeeeee;font-size:28px;height:40px;width:70px;padding-top:9px;font-family:\'Microsoft Sans Serif\',Arial,Helvetica,Verdana;text-align:center;',
331 html
: '<div> </div>'
336 className
: 'cke_dark_background',
337 style
: 'border:1px solid #eeeeee;font-size:14px;height:20px;width:70px;padding-top:2px;font-family:\'Microsoft Sans Serif\',Arial,Helvetica,Verdana;text-align:center;',
338 html
: '<div> </div>'