plugin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. CKEDITOR.plugins.add( 'table', {
  6. requires: 'dialog',
  7. // jscs:disable maximumLineLength
  8. 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%
  9. // jscs:enable maximumLineLength
  10. icons: 'table', // %REMOVE_LINE_CORE%
  11. hidpi: true, // %REMOVE_LINE_CORE%
  12. init: function( editor ) {
  13. if ( editor.blockless )
  14. return;
  15. var lang = editor.lang.table;
  16. editor.addCommand( 'table', new CKEDITOR.dialogCommand( 'table', {
  17. context: 'table',
  18. allowedContent: 'table{width,height}[align,border,cellpadding,cellspacing,summary];' +
  19. 'caption tbody thead tfoot;' +
  20. 'th td tr[scope];' +
  21. ( editor.plugins.dialogadvtab ? 'table' + editor.plugins.dialogadvtab.allowedContent() : '' ),
  22. requiredContent: 'table',
  23. contentTransformations: [
  24. [ 'table{width}: sizeToStyle', 'table[width]: sizeToAttribute' ]
  25. ]
  26. } ) );
  27. function createDef( def ) {
  28. return CKEDITOR.tools.extend( def || {}, {
  29. contextSensitive: 1,
  30. refresh: function( editor, path ) {
  31. this.setState( path.contains( 'table', 1 ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
  32. }
  33. } );
  34. }
  35. editor.addCommand( 'tableProperties', new CKEDITOR.dialogCommand( 'tableProperties', createDef() ) );
  36. editor.addCommand( 'tableDelete', createDef( {
  37. exec: function( editor ) {
  38. var path = editor.elementPath(),
  39. table = path.contains( 'table', 1 );
  40. if ( !table )
  41. return;
  42. // 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)
  43. var parent = table.getParent(),
  44. editable = editor.editable();
  45. if ( parent.getChildCount() == 1 && !parent.is( 'td', 'th' ) && !parent.equals( editable ) )
  46. table = parent;
  47. var range = editor.createRange();
  48. range.moveToPosition( table, CKEDITOR.POSITION_BEFORE_START );
  49. table.remove();
  50. range.select();
  51. }
  52. } ) );
  53. editor.ui.addButton && editor.ui.addButton( 'Table', {
  54. label: lang.toolbar,
  55. command: 'table',
  56. toolbar: 'insert,10'
  57. } );
  58. CKEDITOR.dialog.add( 'table', this.path + 'dialogs/table.js' );
  59. CKEDITOR.dialog.add( 'tableProperties', this.path + 'dialogs/table.js' );
  60. // If the "menu" plugin is loaded, register the menu items.
  61. if ( editor.addMenuItems ) {
  62. editor.addMenuItems( {
  63. table: {
  64. label: lang.menu,
  65. command: 'tableProperties',
  66. group: 'table',
  67. order: 5
  68. },
  69. tabledelete: {
  70. label: lang.deleteTable,
  71. command: 'tableDelete',
  72. group: 'table',
  73. order: 1
  74. }
  75. } );
  76. }
  77. editor.on( 'doubleclick', function( evt ) {
  78. var element = evt.data.element;
  79. if ( element.is( 'table' ) )
  80. evt.data.dialog = 'tableProperties';
  81. } );
  82. // If the "contextmenu" plugin is loaded, register the listeners.
  83. if ( editor.contextMenu ) {
  84. editor.contextMenu.addListener( function() {
  85. // menu item state is resolved on commands.
  86. return {
  87. tabledelete: CKEDITOR.TRISTATE_OFF,
  88. table: CKEDITOR.TRISTATE_OFF
  89. };
  90. } );
  91. }
  92. }
  93. } );