1 | define([ |
---|
2 | "dojo", |
---|
3 | "dijit", |
---|
4 | "dojox", |
---|
5 | "dijit/_Widget", |
---|
6 | "dijit/_TemplatedMixin", |
---|
7 | "dijit/_editor/_Plugin", |
---|
8 | "dojo/_base/connect", |
---|
9 | "dojo/_base/declare", |
---|
10 | "dojox/layout/ResizeHandle" |
---|
11 | ], function(dojo, dijit, dojox, _Widget, _TemplatedMixin, _Plugin) { |
---|
12 | |
---|
13 | dojo.experimental("dojox.editor.plugins.StatusBar"); |
---|
14 | |
---|
15 | var _StatusBar = dojo.declare("dojox.editor.plugins._StatusBar", [_Widget, _TemplatedMixin],{ |
---|
16 | // templateString: String |
---|
17 | // Template for the widget. Currently using table to get the alignment behavior and |
---|
18 | // bordering I wanted. Would prefer not to use table, though. |
---|
19 | templateString: '<div class="dojoxEditorStatusBar">' + |
---|
20 | '<table><tbody><tr>'+ |
---|
21 | '<td class="dojoxEditorStatusBarText" tabindex="-1" aria-role="presentation" aria-live="aggressive"><span dojoAttachPoint="barContent"> </span></td>' + |
---|
22 | '<td><span dojoAttachPoint="handle"></span></td>' + |
---|
23 | '</tr></tbody><table>'+ |
---|
24 | '</div>', |
---|
25 | |
---|
26 | _getValueAttr: function(){ |
---|
27 | // summary: |
---|
28 | // Over-ride to get the value of the status bar from the widget. |
---|
29 | // tags: |
---|
30 | // Protected |
---|
31 | return this.barContent.innerHTML; |
---|
32 | }, |
---|
33 | |
---|
34 | _setValueAttr: function(str){ |
---|
35 | // summary: |
---|
36 | // Over-ride to set the value of the status bar from the widget. |
---|
37 | // If no value is set, it is replaced with a non-blocking space. |
---|
38 | // str: String |
---|
39 | // The string to set as the status bar content. |
---|
40 | // tags: |
---|
41 | // protected |
---|
42 | if(str){ |
---|
43 | str = dojo.trim(str); |
---|
44 | if(!str){ |
---|
45 | str = " "; |
---|
46 | } |
---|
47 | }else{ |
---|
48 | str = " "; |
---|
49 | } |
---|
50 | this.barContent.innerHTML = str; |
---|
51 | } |
---|
52 | }); |
---|
53 | |
---|
54 | var StatusBar = dojo.declare("dojox.editor.plugins.StatusBar", _Plugin, { |
---|
55 | // summary: |
---|
56 | // This plugin provides StatusBar capability to the editor. |
---|
57 | // Basically a footer bar where status can be published. It also |
---|
58 | // puts a resize handle on the status bar, allowing you to resize the |
---|
59 | // editor via mouse. |
---|
60 | |
---|
61 | // statusBar: [protected] |
---|
62 | // The status bar and resizer. |
---|
63 | statusBar: null, |
---|
64 | |
---|
65 | // resizer: [public] Boolean |
---|
66 | // Flag indicating that a resizer should be shown or not. Default is true. |
---|
67 | // There are cases (such as using center pane border container to autoresize the editor |
---|
68 | // That a resizer is not valued. |
---|
69 | resizer: true, |
---|
70 | |
---|
71 | setEditor: function(editor){ |
---|
72 | // summary: |
---|
73 | // Over-ride for the setting of the editor. |
---|
74 | // editor: Object |
---|
75 | // The editor to configure for this plugin to use. |
---|
76 | this.editor = editor; |
---|
77 | this.statusBar = new _StatusBar(); |
---|
78 | if(this.resizer){ |
---|
79 | this.resizeHandle = new dojox.layout.ResizeHandle({targetId: this.editor, activeResize: true}, this.statusBar.handle); |
---|
80 | this.resizeHandle.startup(); |
---|
81 | }else{ |
---|
82 | dojo.style(this.statusBar.handle.parentNode, "display", "none"); |
---|
83 | } |
---|
84 | var pos = null; |
---|
85 | if(editor.footer.lastChild){ |
---|
86 | pos = "after"; |
---|
87 | } |
---|
88 | dojo.place(this.statusBar.domNode, editor.footer.lastChild || editor.footer, pos); |
---|
89 | this.statusBar.startup(); |
---|
90 | this.editor.statusBar = this; |
---|
91 | |
---|
92 | // Register a pub-sub event to listen for status bar messages, in addition to being available off |
---|
93 | // the editor as a property 'statusBar' |
---|
94 | this._msgListener = dojo.subscribe(this.editor.id + "_statusBar", dojo.hitch(this, this._setValueAttr)); |
---|
95 | }, |
---|
96 | |
---|
97 | _getValueAttr: function(){ |
---|
98 | // summary: |
---|
99 | // Over-ride to get the value of the status bar from the widget. |
---|
100 | // tags: |
---|
101 | // protected |
---|
102 | return this.statusBar.get("value"); |
---|
103 | }, |
---|
104 | |
---|
105 | _setValueAttr: function(str){ |
---|
106 | // summary: |
---|
107 | // Over-ride to set the value of the status bar from the widget. |
---|
108 | // If no value is set, it is replaced with a non-blocking space. |
---|
109 | // str: String |
---|
110 | // The String value to set in the bar. |
---|
111 | // tags: |
---|
112 | // protected |
---|
113 | this.statusBar.set("value", str); |
---|
114 | }, |
---|
115 | |
---|
116 | set: function(attr, val){ |
---|
117 | // summary: |
---|
118 | // Quick and dirty implementation of 'set' pattern |
---|
119 | // attr: |
---|
120 | // The attribute to set. |
---|
121 | // val: |
---|
122 | // The value to set it to. |
---|
123 | if(attr){ |
---|
124 | var fName = "_set" + attr.charAt(0).toUpperCase() + attr.substring(1, attr.length) + "Attr"; |
---|
125 | if(dojo.isFunction(this[fName])){ |
---|
126 | this[fName](val); |
---|
127 | }else{ |
---|
128 | this[attr] = val; |
---|
129 | } |
---|
130 | } |
---|
131 | }, |
---|
132 | |
---|
133 | get: function(attr){ |
---|
134 | // summary: |
---|
135 | // Quick and dirty implementation of 'get' pattern |
---|
136 | // attr: |
---|
137 | // The attribute to get. |
---|
138 | if(attr){ |
---|
139 | var fName = "_get" + attr.charAt(0).toUpperCase() + attr.substring(1, attr.length) + "Attr"; |
---|
140 | var f = this[fName]; |
---|
141 | if(dojo.isFunction(f)){ |
---|
142 | return this[fName](); |
---|
143 | }else{ |
---|
144 | return this[attr]; |
---|
145 | } |
---|
146 | } |
---|
147 | return null; |
---|
148 | }, |
---|
149 | |
---|
150 | destroy: function(){ |
---|
151 | // summary: |
---|
152 | // Over-ride to clean up the breadcrumb toolbar. |
---|
153 | if(this.statusBar){ |
---|
154 | this.statusBar.destroy(); |
---|
155 | delete this.statusBar; |
---|
156 | } |
---|
157 | if(this.resizeHandle){ |
---|
158 | this.resizeHandle.destroy(); |
---|
159 | delete this.resizeHandle; |
---|
160 | } |
---|
161 | if(this._msgListener){ |
---|
162 | dojo.unsubscribe(this._msgListener); |
---|
163 | delete this._msgListener; |
---|
164 | } |
---|
165 | delete this.editor.statusBar; |
---|
166 | } |
---|
167 | }); |
---|
168 | |
---|
169 | // For monkey patching |
---|
170 | StatusBar._StatusBar = _StatusBar; |
---|
171 | |
---|
172 | // Register this plugin. |
---|
173 | dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){ |
---|
174 | if(o.plugin){ return; } |
---|
175 | var name = o.args.name.toLowerCase(); |
---|
176 | if(name === "statusbar"){ |
---|
177 | var resizer = ("resizer" in o.args)?o.args.resizer:true; |
---|
178 | o.plugin = new StatusBar({resizer: resizer}); |
---|
179 | } |
---|
180 | }); |
---|
181 | |
---|
182 | return StatusBar; |
---|
183 | |
---|
184 | }); |
---|