NewPage.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. define("dijit/_editor/plugins/NewPage", [
  2. "dojo/_base/declare", // declare
  3. "dojo/i18n", // i18n.getLocalization
  4. "dojo/_base/lang", // lang.hitch
  5. "../_Plugin",
  6. "../../form/Button",
  7. "dojo/i18n!../nls/commands"
  8. ], function(declare, i18n, lang, _Plugin, Button){
  9. /*=====
  10. var _Plugin = dijit._editor._Plugin;
  11. =====*/
  12. // module:
  13. // dijit/_editor/plugins/NewPage
  14. // summary:
  15. // This plugin provides a simple 'new page' capability. In other
  16. // words, set content to some default user defined string.
  17. var NewPage = declare("dijit._editor.plugins.NewPage",_Plugin,{
  18. // summary:
  19. // This plugin provides a simple 'new page' capability. In other
  20. // words, set content to some default user defined string.
  21. // content: [public] String
  22. // The default content to insert into the editor as the new page.
  23. // The default is the <br> tag, a single blank line.
  24. content: "<br>",
  25. _initButton: function(){
  26. // summary:
  27. // Over-ride for creation of the Print button.
  28. var strings = i18n.getLocalization("dijit._editor", "commands"),
  29. editor = this.editor;
  30. this.button = new Button({
  31. label: strings["newPage"],
  32. dir: editor.dir,
  33. lang: editor.lang,
  34. showLabel: false,
  35. iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "NewPage",
  36. tabIndex: "-1",
  37. onClick: lang.hitch(this, "_newPage")
  38. });
  39. },
  40. setEditor: function(/*dijit.Editor*/ editor){
  41. // summary:
  42. // Tell the plugin which Editor it is associated with.
  43. // editor: Object
  44. // The editor object to attach the newPage capability to.
  45. this.editor = editor;
  46. this._initButton();
  47. },
  48. updateState: function(){
  49. // summary:
  50. // Over-ride for button state control for disabled to work.
  51. this.button.set("disabled", this.get("disabled"));
  52. },
  53. _newPage: function(){
  54. // summary:
  55. // Function to set the content to blank.
  56. // tags:
  57. // private
  58. this.editor.beginEditing();
  59. this.editor.set("value", this.content);
  60. this.editor.endEditing();
  61. this.editor.focus();
  62. }
  63. });
  64. // Register this plugin.
  65. // For back-compat accept "newpage" (all lowercase) too, remove in 2.0
  66. _Plugin.registry["newPage"] = _Plugin.registry["newpage"] = function(args){
  67. return new NewPage({
  68. content: ("content" in args)?args.content:"<br>"
  69. });
  70. };
  71. return NewPage;
  72. });