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