TabIndent.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dijit._editor.plugins.TabIndent"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit._editor.plugins.TabIndent"] = true;
  8. dojo.provide("dijit._editor.plugins.TabIndent");
  9. dojo.require("dijit._editor._Plugin");
  10. dojo.require("dijit.form.ToggleButton");
  11. dojo.experimental("dijit._editor.plugins.TabIndent");
  12. dojo.declare("dijit._editor.plugins.TabIndent",
  13. dijit._editor._Plugin,
  14. {
  15. // summary:
  16. // This plugin is used to allow the use of the tab and shift-tab keys
  17. // to indent/outdent list items. This overrides the default behavior
  18. // of moving focus from/to the toolbar
  19. // Override _Plugin.useDefaultCommand... processing is handled by this plugin, not by dijit.Editor.
  20. useDefaultCommand: false,
  21. // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
  22. buttonClass: dijit.form.ToggleButton,
  23. command: "tabIndent",
  24. _initButton: function(){
  25. // Override _Plugin._initButton() to setup listener on button click
  26. this.inherited(arguments);
  27. var e = this.editor;
  28. this.connect(this.button, "onChange", function(val){
  29. e.set("isTabIndent", val);
  30. });
  31. // Set initial checked state of button based on Editor.isTabIndent
  32. this.updateState();
  33. },
  34. updateState: function(){
  35. // Overrides _Plugin.updateState().
  36. // Ctrl-m in the editor will switch tabIndent mode on/off, so we need to react to that.
  37. var disabled = this.get("disabled");
  38. this.button.set("disabled", disabled);
  39. if(disabled){
  40. return;
  41. }
  42. this.button.set('checked', this.editor.isTabIndent, false);
  43. }
  44. }
  45. );
  46. // Register this plugin.
  47. dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
  48. if(o.plugin){ return; }
  49. switch(o.args.name){
  50. case "tabIndent":
  51. o.plugin = new dijit._editor.plugins.TabIndent({command: o.args.name});
  52. }
  53. });
  54. }