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.plugins.add( 'format',
  7 {
  8 	requires : [ 'richcombo', 'styles' ],
  9
 10 	init : function( editor )
 11 	{
 12 		var config = editor.config,
 13 			lang = editor.lang.format;
 14
 15 		// Gets the list of tags from the settings.
 16 		var tags = config.format_tags.split( ';' );
 17
 18 		// Create style objects for all defined styles.
 19 		var styles = {};
 20 		for ( var i = 0 ; i < tags.length ; i++ )
 21 		{
 22 			var tag = tags[ i ];
 23 			styles[ tag ] = new CKEDITOR.style( config[ 'format_' + tag ] );
 24 		}
 25
 26 		editor.ui.addRichCombo( 'Format',
 27 			{
 28 				label : lang.label,
 29 				title : lang.panelTitle,
 30 				voiceLabel : lang.voiceLabel,
 31 				className : 'cke_format',
 32 				multiSelect : false,
 33
 34 				panel :
 35 				{
 36 					css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
 37 					voiceLabel : lang.panelVoiceLabel
 38 				},
 39
 40 				init : function()
 41 				{
 42 					this.startGroup( lang.panelTitle );
 43
 44 					for ( var tag in styles )
 45 					{
 46 						var label = lang[ 'tag_' + tag ];
 47
 48 						// Add the tag entry to the panel list.
 49 						this.add( tag, '<' + tag + '>' + label + '</' + tag + '>', label );
 50 					}
 51 				},
 52
 53 				onClick : function( value )
 54 				{
 55 					editor.focus();
 56 					editor.fire( 'saveSnapshot' );
 57
 58 					styles[ value ].apply( editor.document );
 59
 60 					editor.fire( 'saveSnapshot' );
 61 				},
 62
 63 				onRender : function()
 64 				{
 65 					editor.on( 'selectionChange', function( ev )
 66 						{
 67 							var currentTag = this.getValue();
 68
 69 							var elementPath = ev.data.path;
 70
 71 							for ( var tag in styles )
 72 							{
 73 								if ( styles[ tag ].checkActive( elementPath ) )
 74 								{
 75 									if ( tag != currentTag )
 76 										this.setValue( tag, editor.lang.format[ 'tag_' + tag ] );
 77 									return;
 78 								}
 79 							}
 80
 81 							// If no styles match, just empty it.
 82 							this.setValue( '' );
 83 						},
 84 						this);
 85 				}
 86 			});
 87 	}
 88 });
 89
 90 CKEDITOR.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div';
 91
 92 CKEDITOR.config.format_p		= { element : 'p' };
 93 CKEDITOR.config.format_div		= { element : 'div' };
 94 CKEDITOR.config.format_pre		= { element : 'pre' };
 95 CKEDITOR.config.format_address	= { element : 'address' };
 96 CKEDITOR.config.format_h1		= { element : 'h1' };
 97 CKEDITOR.config.format_h2		= { element : 'h2' };
 98 CKEDITOR.config.format_h3		= { element : 'h3' };
 99 CKEDITOR.config.format_h4		= { element : 'h4' };
100 CKEDITOR.config.format_h5		= { element : 'h5' };
101 CKEDITOR.config.format_h6		= { element : 'h6' };
102