NewPage.js.uncompressed.js 2.1 KB

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