1 /*
  2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5 
  6 CKEDITOR.plugins.add( 'table',
  7 {
  8 	requires : [ 'dialog' ],
  9 	init : function( editor )
 10 	{
 11 		var table = CKEDITOR.plugins.table,
 12 			lang = editor.lang.table;
 13 
 14 		editor.addCommand( 'table', new CKEDITOR.dialogCommand( 'table' ) );
 15 		editor.addCommand( 'tableProperties', new CKEDITOR.dialogCommand( 'tableProperties' ) );
 16 
 17 		editor.ui.addButton( 'Table',
 18 			{
 19 				label : lang.toolbar,
 20 				command : 'table'
 21 			});
 22 
 23 		CKEDITOR.dialog.add( 'table', this.path + 'dialogs/table.js' );
 24 		CKEDITOR.dialog.add( 'tableProperties', this.path + 'dialogs/table.js' );
 25 
 26 		// If the "menu" plugin is loaded, register the menu items.
 27 		if ( editor.addMenuItems )
 28 		{
 29 			editor.addMenuItems(
 30 				{
 31 					table :
 32 					{
 33 						label : lang.menu,
 34 						command : 'tableProperties',
 35 						group : 'table',
 36 						order : 5
 37 					},
 38 
 39 					tabledelete :
 40 					{
 41 						label : lang.deleteTable,
 42 						command : 'tableDelete',
 43 						group : 'table',
 44 						order : 1
 45 					}
 46 				} );
 47 		}
 48 
 49 		editor.on( 'doubleclick', function( evt )
 50 			{
 51 				var element = evt.data.element;
 52 
 53 				if ( element.is( 'table' ) )
 54 					evt.data.dialog = 'tableProperties';
 55 			});
 56 
 57 		// If the "contextmenu" plugin is loaded, register the listeners.
 58 		if ( editor.contextMenu )
 59 		{
 60 			editor.contextMenu.addListener( function( element, selection )
 61 				{
 62 					if ( !element || element.isReadOnly() )
 63 						return null;
 64 
 65 					var isTable = element.hasAscendant( 'table', 1 );
 66 
 67 					if ( isTable )
 68 					{
 69 						return {
 70 							tabledelete : CKEDITOR.TRISTATE_OFF,
 71 							table : CKEDITOR.TRISTATE_OFF
 72 						};
 73 					}
 74 
 75 					return null;
 76 				} );
 77 		}
 78 	}
 79 } );
 80