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