1 /*
  2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5
  6 CKEDITOR.dialog.add( 'smiley', function( editor )
  7 {
  8 	var config = editor.config,
  9 		images = config.smiley_images,
 10 		columns = config.smiley_columns,
 11 		i;
 12
 13 	// Build the HTML for the smiley images table.
 14 	var html = [ '<table cellspacing="2" cellpadding="2"><tbody>' ];
 15
 16 	for ( i = 0 ; i < images.length ; i++ )
 17 	{
 18 		if ( i % columns === 0 )
 19 			html.push( '<tr>' );
 20
 21 		html.push(
 22 			'<td class="dark_background hand centered" style="vertical-align: middle;">' +
 23 				'<img border="0" class="hand" title="', config.smiley_descriptions[i], '"' +
 24 					' src="', CKEDITOR.tools.htmlEncode( config.smiley_path + images[ i ] ), '"',
 25 					// IE BUG: Below is a workaround to an IE image loading bug to ensure the image sizes are correct.
 26 					( CKEDITOR.env.ie ? ' onload="this.setAttribute(\'width\', 2); this.removeAttribute(\'width\');" ' : '' ),
 27 				'>' +
 28 			'</td>' );
 29
 30 		if ( i % columns == columns - 1 )
 31 			html.push( '</tr>' );
 32 	}
 33
 34 	if ( i < columns - 1 )
 35 	{
 36 		for ( ; i < columns - 1 ; i++ )
 37 			html.push( '<td></td>' );
 38 		html.push( '</tr>' );
 39 	}
 40
 41 	html.push( '</tbody></table>' );
 42
 43 	var smileySelector =
 44 	{
 45 		type : 'html',
 46 		html : html.join( '' ),
 47 		onClick : function( evt )
 48 		{
 49 			var target = evt.data.getTarget(),
 50 				targetName = target.getName();
 51
 52 			if ( targetName == 'td' )
 53 				target = target.getChild(0);
 54 			else if ( targetName != 'img' )
 55 				return;
 56
 57 			this.getDialog().restoreSelection();
 58
 59 			var src = target.getAttribute( 'src' ),
 60 				title = target.getAttribute( 'title' );
 61
 62 			var img = editor.document.createElement( 'img',
 63 				{
 64 					attributes :
 65 					{
 66 						src : src,
 67 						_cke_saved_src : src,
 68 						title : title,
 69 						alt : title
 70 					}
 71 				});
 72
 73 			editor.insertElement( img );
 74
 75 			this.getDialog().hide();
 76 		},
 77 		style : 'width: 100%; height: 100%; border-collapse: separate;'
 78 	};
 79
 80 	return {
 81 		title : editor.lang.smiley.title,
 82 		minWidth : 320,
 83 		minHeight : 210,
 84 		contents : [
 85 			{
 86 				id : 'tab1',
 87 				label : '',
 88 				title : '',
 89 				expand : true,
 90 				elements : [
 91 						smileySelector
 92 					]
 93 			}
 94 		],
 95 		buttons : [ CKEDITOR.dialog.cancelButton ]
 96 	};
 97 } );
 98