2 Copyright (c) 2003-2012, 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
92 if ( ( relative = element.getParent().getNext() ) )
\r
94 nodeToMove = relative.getChild( 0 );
\r
96 ev.preventDefault(true);
\r
99 else if ( ( relative = element.getParent().getParent().getNext() ) )
\r
101 nodeToMove = relative.getChild( [0, 0] );
\r
103 nodeToMove.focus();
\r
104 ev.preventDefault(true);
\r
109 case rtl ? 39 : 37 :
\r
111 if ( ( relative = element.getParent().getPrevious() ) )
\r
113 nodeToMove = relative.getChild( 0 );
\r
114 nodeToMove.focus();
\r
115 ev.preventDefault(true);
\r
118 else if ( ( relative = element.getParent().getParent().getPrevious() ) )
\r
120 nodeToMove = relative.getLast().getChild( 0 );
\r
121 nodeToMove.focus();
\r
122 ev.preventDefault(true);
\r
126 // Do not stop not handled events.
\r
131 // Build the HTML for the smiley images table.
\r
132 var labelId = CKEDITOR.tools.getNextId() + '_smiley_emtions_label';
\r
136 '<span id="' + labelId + '" class="cke_voice_label">' + lang.options +'</span>',
\r
137 '<table role="listbox" aria-labelledby="' + labelId + '" style="width:100%;height:100%" cellspacing="2" cellpadding="2"',
\r
138 CKEDITOR.env.ie && CKEDITOR.env.quirks ? ' style="position:absolute;"' : '',
\r
142 var size = images.length;
\r
143 for ( i = 0 ; i < size ; i++ )
\r
145 if ( i % columns === 0 )
\r
146 html.push( '<tr role="presentation">' );
\r
148 var smileyLabelId = 'cke_smile_label_' + i + '_' + CKEDITOR.tools.getNextNumber();
\r
150 '<td class="cke_dark_background cke_centered" style="vertical-align: middle;" role="presentation">' +
\r
151 '<a href="javascript:void(0)" role="option"',
\r
152 ' aria-posinset="' + ( i +1 ) + '"',
\r
153 ' aria-setsize="' + size + '"',
\r
154 ' aria-labelledby="' + smileyLabelId + '"',
\r
155 ' class="cke_smile cke_hand" tabindex="-1" onkeydown="CKEDITOR.tools.callFunction( ', onKeydown, ', event, this );">',
\r
156 '<img class="cke_hand" title="', config.smiley_descriptions[i], '"' +
\r
157 ' cke_src="', CKEDITOR.tools.htmlEncode( config.smiley_path + images[ i ] ), '" alt="', config.smiley_descriptions[i], '"',
\r
158 ' src="', CKEDITOR.tools.htmlEncode( config.smiley_path + images[ i ] ), '"',
\r
159 // IE BUG: Below is a workaround to an IE image loading bug to ensure the image sizes are correct.
\r
160 ( CKEDITOR.env.ie ? ' onload="this.setAttribute(\'width\', 2); this.removeAttribute(\'width\');" ' : '' ),
\r
162 '<span id="' + smileyLabelId + '" class="cke_voice_label">' +config.smiley_descriptions[ i ] + '</span>' +
\r
166 if ( i % columns == columns - 1 )
\r
167 html.push( '</tr>' );
\r
170 if ( i < columns - 1 )
\r
172 for ( ; i < columns - 1 ; i++ )
\r
173 html.push( '<td></td>' );
\r
174 html.push( '</tr>' );
\r
177 html.push( '</tbody></table></div>' );
\r
179 var smileySelector =
\r
182 id : 'smileySelector',
\r
183 html : html.join( '' ),
\r
184 onLoad : function( event )
\r
186 dialog = event.sender;
\r
191 // IE need a while to move the focus (#6539).
\r
192 setTimeout( function ()
\r
194 var firstSmile = self.getElement().getElementsByTag( 'a' ).getItem( 0 );
\r
195 firstSmile.focus();
\r
199 style : 'width: 100%; border-collapse: separate;'
\r
203 title : editor.lang.smiley.title,
\r
218 buttons : [ CKEDITOR.dialog.cancelButton ]
\r