TabIndent.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. define("dijit/_editor/plugins/TabIndent", [
  2. "dojo/_base/declare", // declare
  3. "dojo/_base/kernel", // kernel.experimental
  4. "../_Plugin",
  5. "../../form/ToggleButton"
  6. ], function(declare, kernel, _Plugin, ToggleButton){
  7. /*=====
  8. var _Plugin = dijit._editor._Plugin;
  9. =====*/
  10. // module:
  11. // dijit/_editor/plugins/TabIndent
  12. // summary:
  13. // This plugin is used to allow the use of the tab and shift-tab keys
  14. // to indent/outdent list items. This overrides the default behavior
  15. // of moving focus from/to the toolbar
  16. kernel.experimental("dijit._editor.plugins.TabIndent");
  17. var TabIndent = declare("dijit._editor.plugins.TabIndent", _Plugin, {
  18. // summary:
  19. // This plugin is used to allow the use of the tab and shift-tab keys
  20. // to indent/outdent list items. This overrides the default behavior
  21. // of moving focus from/to the toolbar
  22. // Override _Plugin.useDefaultCommand... processing is handled by this plugin, not by dijit.Editor.
  23. useDefaultCommand: false,
  24. // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
  25. buttonClass: ToggleButton,
  26. command: "tabIndent",
  27. _initButton: function(){
  28. // Override _Plugin._initButton() to setup listener on button click
  29. this.inherited(arguments);
  30. var e = this.editor;
  31. this.connect(this.button, "onChange", function(val){
  32. e.set("isTabIndent", val);
  33. });
  34. // Set initial checked state of button based on Editor.isTabIndent
  35. this.updateState();
  36. },
  37. updateState: function(){
  38. // Overrides _Plugin.updateState().
  39. // Ctrl-m in the editor will switch tabIndent mode on/off, so we need to react to that.
  40. var disabled = this.get("disabled");
  41. this.button.set("disabled", disabled);
  42. if(disabled){
  43. return;
  44. }
  45. this.button.set('checked', this.editor.isTabIndent, false);
  46. }
  47. });
  48. // Register this plugin.
  49. _Plugin.registry["tabIndent"] = function(){
  50. return new TabIndent({command: "tabIndent"});
  51. };
  52. return TabIndent;
  53. });