2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'smiley', function( editor )
\r
8 var config = editor.config,
\r
9 lang = editor.lang.smiley,
\r
10 images = config.smiley_images,
\r
11 columns = config.smiley_columns || 8,
\r
15 * Simulate "this" of a dialog for non-dialog events.
\r
16 * @type {CKEDITOR.dialog}
\r
19 var onClick = function( evt )
\r
21 var target = evt.data.getTarget(),
\r
22 targetName = target.getName();
\r
24 if ( targetName == 'a' )
\r
25 target = target.getChild( 0 );
\r
26 else if ( targetName != 'img' )
\r
29 var src = target.getAttribute( 'cke_src' ),
\r
30 title = target.getAttribute( 'title' );
\r
32 var img = editor.document.createElement( 'img',
\r
37 'data-cke-saved-src' : src,
\r
40 width : target.$.width,
\r
41 height : target.$.height
\r
45 editor.insertElement( img );
\r
48 evt.data.preventDefault();
\r
51 var onKeydown = CKEDITOR.tools.addFunction( function( ev, element )
\r
53 ev = new CKEDITOR.dom.event( ev );
\r
54 element = new CKEDITOR.dom.element( element );
\r
55 var relative, nodeToMove;
\r
57 var keystroke = ev.getKeystroke(),
\r
58 rtl = editor.lang.dir == 'rtl';
\r
59 switch ( keystroke )
\r
64 if ( ( relative = element.getParent().getParent().getPrevious() ) )
\r
66 nodeToMove = relative.getChild( [element.getParent().getIndex(), 0] );
\r
69 ev.preventDefault();
\r
74 if ( ( relative = element.getParent().getParent().getNext() ) )
\r
76 nodeToMove = relative.getChild( [element.getParent().getIndex(), 0] );
\r
80 ev.preventDefault();
\r
85 onClick( { data: ev } );
\r
86 ev.preventDefault();
\r
90 case rtl ? 37 : 39 :
\r
94 if ( ( relative = element.getParent().getNext() ) )
\r
96 nodeToMove = relative.getChild( 0 );
\r
98 ev.preventDefault(true);
\r
101 else if ( ( relative = element.getParent().getParent().getNext() ) )
\r
103 nodeToMove = relative.getChild( [0, 0] );
\r
105 nodeToMove.focus();
\r
106 ev.preventDefault(true);
\r
111 case rtl ? 39 : 37 :
\r
113 case CKEDITOR.SHIFT + 9 :
\r
115 if ( ( relative = element.getParent().getPrevious() ) )
\r
117 nodeToMove = relative.getChild( 0 );
\r
118 nodeToMove.focus();
\r
119 ev.preventDefault(true);
\r
122 else if ( ( relative = element.getParent().getParent().getPrevious() ) )
\r
124 nodeToMove = relative.getLast().getChild( 0 );
\r
125 nodeToMove.focus();
\r
126 ev.preventDefault(true);
\r
130 // Do not stop not handled events.
\r
135 // Build the HTML for the smiley images table.
\r
136 var labelId = CKEDITOR.tools.getNextId() + '_smiley_emtions_label';
\r
140 '<span id="' + labelId + '" class="cke_voice_label">' + lang.options +'</span>',
\r
141 '<table role="listbox" aria-labelledby="' + labelId + '" style="width:100%;height:100%" cellspacing="2" cellpadding="2"',
\r
142 CKEDITOR.env.ie && CKEDITOR.env.quirks ? ' style="position:absolute;"' : '',
\r
146 var size = images.length;
\r
147 for ( i = 0 ; i < size ; i++ )
\r
149 if ( i % columns === 0 )
\r
150 html.push( '<tr>' );
\r
152 var smileyLabelId = 'cke_smile_label_' + i + '_' + CKEDITOR.tools.getNextNumber();
\r
154 '<td class="cke_dark_background cke_centered" style="vertical-align: middle;">' +
\r
155 '<a href="javascript:void(0)" role="option"',
\r
156 ' aria-posinset="' + ( i +1 ) + '"',
\r
157 ' aria-setsize="' + size + '"',
\r
158 ' aria-labelledby="' + smileyLabelId + '"',
\r
159 ' class="cke_smile cke_hand" tabindex="-1" onkeydown="CKEDITOR.tools.callFunction( ', onKeydown, ', event, this );">',
\r
160 '<img class="cke_hand" title="', config.smiley_descriptions[i], '"' +
\r
161 ' cke_src="', CKEDITOR.tools.htmlEncode( config.smiley_path + images[ i ] ), '" alt="', config.smiley_descriptions[i], '"',
\r
162 ' src="', CKEDITOR.tools.htmlEncode( config.smiley_path + images[ i ] ), '"',
\r
163 // IE BUG: Below is a workaround to an IE image loading bug to ensure the image sizes are correct.
\r
164 ( CKEDITOR.env.ie ? ' onload="this.setAttribute(\'width\', 2); this.removeAttribute(\'width\');" ' : '' ),
\r
166 '<span id="' + smileyLabelId + '" class="cke_voice_label">' +config.smiley_descriptions[ i ] + '</span>' +
\r
170 if ( i % columns == columns - 1 )
\r
171 html.push( '</tr>' );
\r
174 if ( i < columns - 1 )
\r
176 for ( ; i < columns - 1 ; i++ )
\r
177 html.push( '<td></td>' );
\r
178 html.push( '</tr>' );
\r
181 html.push( '</tbody></table></div>' );
\r
183 var smileySelector =
\r
186 html : html.join( '' ),
\r
187 onLoad : function( event )
\r
189 dialog = event.sender;
\r
194 // IE need a while to move the focus (#6539).
\r
195 setTimeout( function ()
\r
197 var firstSmile = self.getElement().getElementsByTag( 'a' ).getItem( 0 );
\r
198 firstSmile.focus();
\r
202 style : 'width: 100%; border-collapse: separate;'
\r
206 title : editor.lang.smiley.title,
\r
221 buttons : [ CKEDITOR.dialog.cancelButton ]
\r