]> git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blame - sources/plugins/table/plugin.js
Initial commit
[perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git] / sources / plugins / table / plugin.js
CommitLineData
7adcb81e
IB
1/**\r
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.\r
3 * For licensing, see LICENSE.md or http://ckeditor.com/license\r
4 */\r
5\r
6CKEDITOR.plugins.add( 'table', {\r
7 requires: 'dialog',\r
8 // jscs:disable maximumLineLength\r
9 lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%\r
10 // jscs:enable maximumLineLength\r
11 icons: 'table', // %REMOVE_LINE_CORE%\r
12 hidpi: true, // %REMOVE_LINE_CORE%\r
13 init: function( editor ) {\r
14 if ( editor.blockless )\r
15 return;\r
16\r
17 var lang = editor.lang.table;\r
18\r
19 editor.addCommand( 'table', new CKEDITOR.dialogCommand( 'table', {\r
20 context: 'table',\r
21 allowedContent: 'table{width,height}[align,border,cellpadding,cellspacing,summary];' +\r
22 'caption tbody thead tfoot;' +\r
23 'th td tr[scope];' +\r
24 ( editor.plugins.dialogadvtab ? 'table' + editor.plugins.dialogadvtab.allowedContent() : '' ),\r
25 requiredContent: 'table',\r
26 contentTransformations: [\r
27 [ 'table{width}: sizeToStyle', 'table[width]: sizeToAttribute' ]\r
28 ]\r
29 } ) );\r
30\r
31 function createDef( def ) {\r
32 return CKEDITOR.tools.extend( def || {}, {\r
33 contextSensitive: 1,\r
34 refresh: function( editor, path ) {\r
35 this.setState( path.contains( 'table', 1 ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );\r
36 }\r
37 } );\r
38 }\r
39\r
40 editor.addCommand( 'tableProperties', new CKEDITOR.dialogCommand( 'tableProperties', createDef() ) );\r
41 editor.addCommand( 'tableDelete', createDef( {\r
42 exec: function( editor ) {\r
43 var path = editor.elementPath(),\r
44 table = path.contains( 'table', 1 );\r
45\r
46 if ( !table )\r
47 return;\r
48\r
49 // If the table's parent has only one child remove it as well (unless it's a table cell, or the editable element) (#5416, #6289, #12110)\r
50 var parent = table.getParent(),\r
51 editable = editor.editable();\r
52\r
53 if ( parent.getChildCount() == 1 && !parent.is( 'td', 'th' ) && !parent.equals( editable ) )\r
54 table = parent;\r
55\r
56 var range = editor.createRange();\r
57 range.moveToPosition( table, CKEDITOR.POSITION_BEFORE_START );\r
58 table.remove();\r
59 range.select();\r
60 }\r
61 } ) );\r
62\r
63 editor.ui.addButton && editor.ui.addButton( 'Table', {\r
64 label: lang.toolbar,\r
65 command: 'table',\r
66 toolbar: 'insert,30'\r
67 } );\r
68\r
69 CKEDITOR.dialog.add( 'table', this.path + 'dialogs/table.js' );\r
70 CKEDITOR.dialog.add( 'tableProperties', this.path + 'dialogs/table.js' );\r
71\r
72 // If the "menu" plugin is loaded, register the menu items.\r
73 if ( editor.addMenuItems ) {\r
74 editor.addMenuItems( {\r
75 table: {\r
76 label: lang.menu,\r
77 command: 'tableProperties',\r
78 group: 'table',\r
79 order: 5\r
80 },\r
81\r
82 tabledelete: {\r
83 label: lang.deleteTable,\r
84 command: 'tableDelete',\r
85 group: 'table',\r
86 order: 1\r
87 }\r
88 } );\r
89 }\r
90\r
91 editor.on( 'doubleclick', function( evt ) {\r
92 var element = evt.data.element;\r
93\r
94 if ( element.is( 'table' ) )\r
95 evt.data.dialog = 'tableProperties';\r
96 } );\r
97\r
98 // If the "contextmenu" plugin is loaded, register the listeners.\r
99 if ( editor.contextMenu ) {\r
100 editor.contextMenu.addListener( function() {\r
101 // menu item state is resolved on commands.\r
102 return {\r
103 tabledelete: CKEDITOR.TRISTATE_OFF,\r
104 table: CKEDITOR.TRISTATE_OFF\r
105 };\r
106 } );\r
107 }\r
108 }\r
109} );\r