commanddefinition.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * @fileOverview Defines the "virtual" {@link CKEDITOR.commandDefinition} class,
  7. * which contains the defintion of a command. This file is for
  8. * documentation purposes only.
  9. */
  10. /**
  11. * Virtual class that illustrates the features of command objects to be
  12. * passed to the {@link CKEDITOR.editor#addCommand} function.
  13. *
  14. * @class CKEDITOR.commandDefinition
  15. * @abstract
  16. */
  17. /**
  18. * The function to be fired when the commend is executed.
  19. *
  20. * editorInstance.addCommand( 'sample', {
  21. * exec: function( editor ) {
  22. * alert( 'Executing a command for the editor name "' + editor.name + '"!' );
  23. * }
  24. * } );
  25. *
  26. * @method exec
  27. * @param {CKEDITOR.editor} editor The editor within which run the command.
  28. * @param {Object} [data] Additional data to be used to execute the command.
  29. * @returns {Boolean} Whether the command has been successfully executed.
  30. * Defaults to `true`, if nothing is returned.
  31. */
  32. /**
  33. * Whether the command need to be hooked into the redo/undo system.
  34. *
  35. * editorInstance.addCommand( 'alertName', {
  36. * exec: function( editor ) {
  37. * alert( editor.name );
  38. * },
  39. * canUndo: false // No support for undo/redo.
  40. * } );
  41. *
  42. * @property {Boolean} [canUndo=true]
  43. */
  44. /**
  45. * Whether the command is asynchronous, which means that the
  46. * {@link CKEDITOR.editor#event-afterCommandExec} event will be fired by the
  47. * command itself manually, and that the return value of this command is not to
  48. * be returned by the {@link #exec} function.
  49. *
  50. * editorInstance.addCommand( 'loadOptions', {
  51. * exec: function( editor ) {
  52. * // Asynchronous operation below.
  53. * CKEDITOR.ajax.loadXml( 'data.xml', function() {
  54. * editor.fire( 'afterCommandExec' );
  55. * } );
  56. * },
  57. * async: true // The command need some time to complete after exec function returns.
  58. * } );
  59. *
  60. * @property {Boolean} [async=false]
  61. */
  62. /**
  63. * Whether the command should give focus to the editor before execution.
  64. *
  65. * editorInstance.addCommand( 'maximize', {
  66. * exec: function( editor ) {
  67. * // ...
  68. * },
  69. * editorFocus: false // The command doesn't require focusing the editing document.
  70. * } );
  71. *
  72. * @property {Boolean} [editorFocus=true]
  73. * @see CKEDITOR.command#editorFocus
  74. */
  75. /**
  76. * Whether the command state should be set to {@link CKEDITOR#TRISTATE_DISABLED} on startup.
  77. *
  78. * editorInstance.addCommand( 'unlink', {
  79. * exec: function( editor ) {
  80. * // ...
  81. * },
  82. * startDisabled: true // Command is unavailable until selection is inside a link.
  83. * } );
  84. *
  85. * @property {Boolean} [startDisabled=false]
  86. */
  87. /**
  88. * Indicates that this command is sensible to the selection context.
  89. * If `true`, the {@link CKEDITOR.command#method-refresh} method will be
  90. * called for this command on selection changes, with a single parameter
  91. * representing the current elements path.
  92. *
  93. * @property {Boolean} [contextSensitive=true]
  94. */
  95. /**
  96. * Defined by command definition a function to determinate the command state, it will be invoked
  97. * when editor has it's `states` or `selection` changed.
  98. *
  99. * **Note:** The function provided must be calling {@link CKEDITOR.command#setState} in all circumstance,
  100. * if it is intended to update the command state.
  101. *
  102. * @method refresh
  103. * @param {CKEDITOR.editor} editor
  104. * @param {CKEDITOR.dom.elementPath} path
  105. */
  106. /**
  107. * Sets the element name used to reflect the command state on selection changes.
  108. * If the selection is in a place where the element is not allowed, the command
  109. * will be disabled.
  110. * Setting this property overrides {@link #contextSensitive} to `true`.
  111. *
  112. * @property {Boolean} [context=true]
  113. */
  114. /**
  115. * The editor modes within which the command can be executed. The execution
  116. * will have no action if the current mode is not listed in this property.
  117. *
  118. * editorInstance.addCommand( 'link', {
  119. * exec: function( editor ) {
  120. * // ...
  121. * },
  122. * modes: { wysiwyg:1 } // Command is available in wysiwyg mode only.
  123. * } );
  124. *
  125. * @property {Object} [modes={ wysiwyg:1 }]
  126. * @see CKEDITOR.command#modes
  127. */