Debian Codegraph @

dojox/editor/plugins/CollapsibleToolbar.js

raw symbols SCIP
1 define([
2 "dojo",
3 "dijit",
4 "dojox",
5 "dijit/_Widget",
6 "dijit/_TemplatedMixin",
7 "dijit/_editor/_Plugin",
8 "dijit/form/Button",
9 "dijit/focus",
10 "dojo/_base/connect",
11 "dojo/_base/declare",
12 "dojo/i18n",
13 "dojo/i18n!dojox/editor/plugins/nls/CollapsibleToolbar"
14 ], function(dojo, dijit, dojox, _Widget, _TemplatedMixin, _Plugin) {
15
16 var CollapsibleToolbarButton = dojo.declare("dojox.editor.plugins._CollapsibleToolbarButton", [_Widget, _TemplatedMixin], {
17 // summary:
18 // Simple internal widget for representing a clickable button for expand/collapse
19 // with A11Y support.
20 // tags:
21 // private
22 templateString: "<div tabindex='0' role='button' title='${title}' class='${buttonClass}' " +
23 "dojoAttachEvent='ondijitclick: onClick'><span class='${textClass}'>${text}</span></div>",
24
25
26 // title [public] String
27 // The text to read by a screen reader that gets button focus.
28 title: "",
29
30 // buttonClass [public] String
31 // The classname to apply to the expand/collapse button.
32 buttonClass: "",
33
34 // text [public] String
35 // The text to use as expand/collapse in A11Y mode.
36 text: "",
37
38 // textClass [public] String
39 // The classname to apply to the expand/collapse text.
40 textClass: "",
41
42 onClick: function(e){
43 // summary:
44 // Simple synthetic event to listen for dijit click events (mouse or keyboard)
45 }
46 });
47
48 var CollapsibleToolbar = dojo.declare("dojox.editor.plugins.CollapsibleToolbar", _Plugin, {
49 // summary:
50 // This plugin provides a weappable toolbar container to allow expand/collapse
51 // of the editor toolbars. This plugin should be registered first in most cases to
52 // avoid conflicts in toolbar construction.
53
54 // _myWidgets: [private] Array
55 // Container for widgets I allocate that will need to be destroyed.
56 _myWidgets: null,
57
58 setEditor: function(editor){
59 // summary:
60 // Over-ride for the setting of the editor.
61 // editor: Object
62 // The editor to configure for this plugin to use.
63 this.editor = editor;
64 this._constructContainer();
65 },
66
67 _constructContainer: function(){
68 // summary:
69 // Internal function to construct a wrapper for the toolbar/header that allows
70 // it to expand and collapse. It effectively builds a containing table,
71 // which handles the layout nicely and gets BIDI support by default.
72 // tags:
73 // private
74 var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "CollapsibleToolbar");
75 this._myWidgets = [];
76
77 // Build the containers.
78 var container = dojo.create("table", {style: { width: "100%" }, tabindex: -1, "class": "dojoxCollapsibleToolbarContainer"});
79 var tbody = dojo.create("tbody", {tabindex: -1}, container);
80 var row = dojo.create("tr", {tabindex: -1}, tbody);
81 var openTd = dojo.create("td", {"class": "dojoxCollapsibleToolbarControl", tabindex: -1}, row);
82 var closeTd = dojo.create("td", {"class": "dojoxCollapsibleToolbarControl", tabindex: -1}, row);
83 var menuTd = dojo.create("td", {style: { width: "100%" }, tabindex: -1}, row);
84 var m = dojo.create("span", {style: { width: "100%" }, tabindex: -1}, menuTd);
85
86 var collapseButton = new CollapsibleToolbarButton({
87 buttonClass: "dojoxCollapsibleToolbarCollapse",
88 title: strings.collapse,
89 text: "-",
90 textClass: "dojoxCollapsibleToolbarCollapseText"
91 });
92 dojo.place(collapseButton.domNode, openTd);
93 var expandButton = new CollapsibleToolbarButton({
94 buttonClass: "dojoxCollapsibleToolbarExpand",
95 title: strings.expand,
96 text: "+",
97 textClass: "dojoxCollapsibleToolbarExpandText"
98 });
99 dojo.place(expandButton.domNode, closeTd);
100
101 this._myWidgets.push(collapseButton);
102 this._myWidgets.push(expandButton);
103
104 // Attach everything in now.
105 dojo.style(closeTd, "display", "none");
106 dojo.place(container, this.editor.toolbar.domNode, "after");
107 dojo.place(this.editor.toolbar.domNode, m);
108
109 this.openTd = openTd;
110 this.closeTd = closeTd;
111 this.menu = m;
112
113 // Establish the events to handle open/close.
114 this.connect(collapseButton, "onClick", "_onClose");
115 this.connect(expandButton, "onClick", "_onOpen");
116 },
117
118 _onClose: function(e){
119 // summary:
120 // Internal function for handling a click event that will close the toolbar.
121 // e:
122 // The click event.
123 // tags:
124 // private
125 if(e){ dojo.stopEvent(e); }
126 var size = dojo.marginBox(this.editor.domNode);
127 dojo.style(this.openTd, "display", "none");
128 dojo.style(this.closeTd, "display", "");
129 dojo.style(this.menu, "display", "none");
130 this.editor.resize({h: size.h});
131 // work around IE rendering glitch in a11y mode.
132 if(dojo.isIE){
133 this.editor.header.className = this.editor.header.className;
134 this.editor.footer.className = this.editor.footer.className;
135 }
136 dijit.focus(this.closeTd.firstChild);
137 },
138
139 _onOpen: function(e) {
140 // summary:
141 // Internal function for handling a click event that will open the toolbar.
142 // e:
143 // The click event.
144 // tags:
145 // private
146 if(e){ dojo.stopEvent(e); }
147 var size = dojo.marginBox(this.editor.domNode);
148 dojo.style(this.closeTd, "display", "none");
149 dojo.style(this.openTd, "display", "");
150 dojo.style(this.menu, "display", "");
151 this.editor.resize({h: size.h});
152 // work around IE rendering glitch in a11y mode.
153 if(dojo.isIE){
154 this.editor.header.className = this.editor.header.className;
155 this.editor.footer.className = this.editor.footer.className;
156 }
157 dijit.focus(this.openTd.firstChild);
158 },
159
160 destroy: function(){
161 // summary:
162 // Over-ride of destroy method for cleanup.
163 this.inherited(arguments);
164 if(this._myWidgets){
165 while(this._myWidgets.length){
166 this._myWidgets.pop().destroy();
167 }
168 delete this._myWidgets;
169 }
170 }
171 });
172
173 // For monkey patching
174 CollapsibleToolbar._CollapsibleToolbarButton = CollapsibleToolbarButton;
175
176 // Register this plugin.
177 dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
178 if(o.plugin){ return; }
179 var name = o.args.name.toLowerCase();
180 if(name === "collapsibletoolbar"){
181 o.plugin = new CollapsibleToolbar({});
182 }
183 });
184
185 return CollapsibleToolbar;
186
187 });