NewPage.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.NewPage"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit._editor.plugins.NewPage"] = true;
  8. dojo.provide("dijit._editor.plugins.NewPage");
  9. dojo.require("dijit._editor._Plugin");
  10. dojo.require("dijit.form.Button");
  11. dojo.require("dojo.i18n");
  12. dojo.requireLocalization("dijit._editor", "commands", null, "ROOT,ar,az,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
  13. dojo.declare("dijit._editor.plugins.NewPage",dijit._editor._Plugin,{
  14. // summary:
  15. // This plugin provides a simple 'new page' calability. In other
  16. // words, set content to some default user defined string.
  17. // content: [public] String
  18. // The default content to insert into the editor as the new page.
  19. // The default is the <br> tag, a single blank line.
  20. content: "<br>",
  21. _initButton: function(){
  22. // summary:
  23. // Over-ride for creation of the Print button.
  24. var strings = dojo.i18n.getLocalization("dijit._editor", "commands"),
  25. editor = this.editor;
  26. this.button = new dijit.form.Button({
  27. label: strings["newPage"],
  28. dir: editor.dir,
  29. lang: editor.lang,
  30. showLabel: false,
  31. iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "NewPage",
  32. tabIndex: "-1",
  33. onClick: dojo.hitch(this, "_newPage")
  34. });
  35. },
  36. setEditor: function(/*dijit.Editor*/ editor){
  37. // summary:
  38. // Tell the plugin which Editor it is associated with.
  39. // editor: Object
  40. // The editor object to attach the newPage capability to.
  41. this.editor = editor;
  42. this._initButton();
  43. },
  44. updateState: function(){
  45. // summary:
  46. // Over-ride for button state control for disabled to work.
  47. this.button.set("disabled", this.get("disabled"));
  48. },
  49. _newPage: function(){
  50. // summary:
  51. // Function to set the content to blank.
  52. // tags:
  53. // private
  54. this.editor.beginEditing();
  55. this.editor.set("value", this.content);
  56. this.editor.endEditing();
  57. this.editor.focus();
  58. }
  59. });
  60. // Register this plugin.
  61. dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
  62. if(o.plugin){ return; }
  63. var name = o.args.name.toLowerCase();
  64. if(name === "newpage"){
  65. o.plugin = new dijit._editor.plugins.NewPage({
  66. content: ("content" in o.args)?o.args.content:"<br>"
  67. });
  68. }
  69. });
  70. }