diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-01-25 17:45:33 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-01-25 18:00:33 +0100 |
commit | 7adcb81e4f83f98c468889aaa5a85558ba88c770 (patch) | |
tree | 0d6ede733777b29060b48df4afaa2c64bfbae276 /sources/plugins/table/plugin.js | |
download | connexionswing-ckeditor-component-7adcb81e4f83f98c468889aaa5a85558ba88c770.tar.gz connexionswing-ckeditor-component-7adcb81e4f83f98c468889aaa5a85558ba88c770.tar.zst connexionswing-ckeditor-component-7adcb81e4f83f98c468889aaa5a85558ba88c770.zip |
Initial commit4.5.6
Diffstat (limited to 'sources/plugins/table/plugin.js')
-rw-r--r-- | sources/plugins/table/plugin.js | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/sources/plugins/table/plugin.js b/sources/plugins/table/plugin.js new file mode 100644 index 00000000..a013bc17 --- /dev/null +++ b/sources/plugins/table/plugin.js | |||
@@ -0,0 +1,109 @@ | |||
1 | /** | ||
2 | * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | ||
4 | */ | ||
5 | |||
6 | CKEDITOR.plugins.add( 'table', { | ||
7 | requires: 'dialog', | ||
8 | // jscs:disable maximumLineLength | ||
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% | ||
10 | // jscs:enable maximumLineLength | ||
11 | icons: 'table', // %REMOVE_LINE_CORE% | ||
12 | hidpi: true, // %REMOVE_LINE_CORE% | ||
13 | init: function( editor ) { | ||
14 | if ( editor.blockless ) | ||
15 | return; | ||
16 | |||
17 | var lang = editor.lang.table; | ||
18 | |||
19 | editor.addCommand( 'table', new CKEDITOR.dialogCommand( 'table', { | ||
20 | context: 'table', | ||
21 | allowedContent: 'table{width,height}[align,border,cellpadding,cellspacing,summary];' + | ||
22 | 'caption tbody thead tfoot;' + | ||
23 | 'th td tr[scope];' + | ||
24 | ( editor.plugins.dialogadvtab ? 'table' + editor.plugins.dialogadvtab.allowedContent() : '' ), | ||
25 | requiredContent: 'table', | ||
26 | contentTransformations: [ | ||
27 | [ 'table{width}: sizeToStyle', 'table[width]: sizeToAttribute' ] | ||
28 | ] | ||
29 | } ) ); | ||
30 | |||
31 | function createDef( def ) { | ||
32 | return CKEDITOR.tools.extend( def || {}, { | ||
33 | contextSensitive: 1, | ||
34 | refresh: function( editor, path ) { | ||
35 | this.setState( path.contains( 'table', 1 ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED ); | ||
36 | } | ||
37 | } ); | ||
38 | } | ||
39 | |||
40 | editor.addCommand( 'tableProperties', new CKEDITOR.dialogCommand( 'tableProperties', createDef() ) ); | ||
41 | editor.addCommand( 'tableDelete', createDef( { | ||
42 | exec: function( editor ) { | ||
43 | var path = editor.elementPath(), | ||
44 | table = path.contains( 'table', 1 ); | ||
45 | |||
46 | if ( !table ) | ||
47 | return; | ||
48 | |||
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) | ||
50 | var parent = table.getParent(), | ||
51 | editable = editor.editable(); | ||
52 | |||
53 | if ( parent.getChildCount() == 1 && !parent.is( 'td', 'th' ) && !parent.equals( editable ) ) | ||
54 | table = parent; | ||
55 | |||
56 | var range = editor.createRange(); | ||
57 | range.moveToPosition( table, CKEDITOR.POSITION_BEFORE_START ); | ||
58 | table.remove(); | ||
59 | range.select(); | ||
60 | } | ||
61 | } ) ); | ||
62 | |||
63 | editor.ui.addButton && editor.ui.addButton( 'Table', { | ||
64 | label: lang.toolbar, | ||
65 | command: 'table', | ||
66 | toolbar: 'insert,30' | ||
67 | } ); | ||
68 | |||
69 | CKEDITOR.dialog.add( 'table', this.path + 'dialogs/table.js' ); | ||
70 | CKEDITOR.dialog.add( 'tableProperties', this.path + 'dialogs/table.js' ); | ||
71 | |||
72 | // If the "menu" plugin is loaded, register the menu items. | ||
73 | if ( editor.addMenuItems ) { | ||
74 | editor.addMenuItems( { | ||
75 | table: { | ||
76 | label: lang.menu, | ||
77 | command: 'tableProperties', | ||
78 | group: 'table', | ||
79 | order: 5 | ||
80 | }, | ||
81 | |||
82 | tabledelete: { | ||
83 | label: lang.deleteTable, | ||
84 | command: 'tableDelete', | ||
85 | group: 'table', | ||
86 | order: 1 | ||
87 | } | ||
88 | } ); | ||
89 | } | ||
90 | |||
91 | editor.on( 'doubleclick', function( evt ) { | ||
92 | var element = evt.data.element; | ||
93 | |||
94 | if ( element.is( 'table' ) ) | ||
95 | evt.data.dialog = 'tableProperties'; | ||
96 | } ); | ||
97 | |||
98 | // If the "contextmenu" plugin is loaded, register the listeners. | ||
99 | if ( editor.contextMenu ) { | ||
100 | editor.contextMenu.addListener( function() { | ||
101 | // menu item state is resolved on commands. | ||
102 | return { | ||
103 | tabledelete: CKEDITOR.TRISTATE_OFF, | ||
104 | table: CKEDITOR.TRISTATE_OFF | ||
105 | }; | ||
106 | } ); | ||
107 | } | ||
108 | } | ||
109 | } ); | ||