1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
if(!dojo._hasResource["dojox.layout.ToggleSplitter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.layout.ToggleSplitter"] = true;
dojo.provide("dojox.layout.ToggleSplitter");
dojo.experimental("dojox.layout.ToggleSplitter");
dojo.require("dijit.layout.BorderContainer");
dojo.declare("dojox.layout.ToggleSplitter", [ dijit.layout._Splitter ],
{
// summary:
// A draggable and toggle-to-close/open spacer between two items in a BorderContainer
//
// description:
// Extends the dijit.layout._Splitter to add a toggling behavior
// on double-click
//
/*=====
container: null,
child: null,
region: null,
=====*/
// open: Boolean
// the initial and current state of the splitter (and its attached pane)
open: true,
// closedThreshold: Integer
// how small the attached pane can be before its considered closed
closedThreshold: 5,
// openSize: String
// the css height/width value to apply by default when the attached pane is open
openSize: "",
// _closedSize: String
// the css height/width value to apply by default when the attached pane is closed
_closedSize: "0",
templateString: '<div class="dijitSplitter dojoxToggleSplitter" dojoAttachEvent="onkeypress:_onKeyPress,onmousedown:_onMouseDown" tabIndex="0" role="separator"><div dojoAttachPoint="toggleNode" class="dijitSplitterThumb dojoxToggleSplitterIcon"></div></div>',
postCreate: function(){
this._started = false;
this.inherited(arguments);
// add a region css hook
var region = this.region;
dojo.addClass(this.domNode, "dojoxToggleSplitter"+region.charAt(0).toUpperCase() + region.substring(1));
// hook up double-clicks to toggle the splitter -
this.connect(this, "onDblClick", "_toggleMe");
},
startup: function(){
this.inherited(arguments);
// we have to wait until startup to be sure the child exists in the dom
// and has non-zero size (if its supposed to be showing)
var paneNode = this.child.domNode,
intPaneSize = dojo.style(paneNode, (this.horizontal ? "height" : "width"));
// creation of splitters is an opaque process in BorderContainer,
// so if we want to get init params, we have to retrieve them from the attached BC child
// NOTE: for this to work we have to extend the prototype of dijit._Widget (some more)
dojo.forEach(["toggleSplitterOpen", "toggleSplitterClosedThreshold", "toggleSplitterOpenSize"], function(name){
var pname = name.substring("toggleSplitter".length);
pname = pname.charAt(0).toLowerCase() + pname.substring(1);
if(name in this.child){
this[pname] = this.child[name];
}
}, this);
if(!this.openSize){
// store the current size as the openSize if none was provided
// dojo.style always returns a integer (pixel) value for height/width
// use an arbirary default if a pane was initalized closed and no openSize provided
this.openSize = (this.open) ? intPaneSize + "px" : "75px";
}
this._openStyleProps = this._getStyleProps(paneNode, true);
// update state
this._started = true;
this.set("open", this.open);
return this;
},
_onMouseUp: function(evt){
dojo.disconnect(this._onMoveHandle);
dojo.disconnect(this._onUpHandle);
delete this._onMoveHandle;
delete this._onUpHandle;
delete this._startPosn;
},
_onPrelimMouseMove: function(evt){
// only start dragging when a mouse down AND a significant mousemove occurs
var startPosn = this._startPosn || 0;
// allow a little fudging in a click before we consider a drag started
var dragThreshold = 3;
var offset = Math.abs( startPosn - (this.horizontal ? evt.clientY : evt.clientX) );
if(offset >= dragThreshold){
// treat as a drag and dismantle this preliminary handlers
dojo.disconnect(this._onMoveHandle);
this._startDrag(evt);
}
},
_onMouseDown: function(evt){
// summary:
// handle mousedown events from the domNode
if(!this.open){
// ignore mousedown while closed
// - this has the effect of preventing dragging while closed, which is the prefered behavior (for now)
return;
}
// Mousedown can fire more than once (!)
// ..so check before connecting
if(!this._onUpHandle){
this._onUpHandle = dojo.connect(dojo.body(), "onmouseup", this, "_onMouseUp");
}
if(!this._onMoveHandle){
this._startPosn = this.horizontal ? evt.clientY : evt.clientX;
// start listening for mousemove
this._onMoveHandle = dojo.connect(dojo.body(), "onmousemove", this, "_onPrelimMouseMove");
}
},
_handleOnChange: function(){
// summary
// effect the state change with the new value of this.open
// TODO: animate the open/close
var paneNode = this.child.domNode,
openProps,
dim = this.horizontal ? "height" : "width";
if(this.open){
// change to open state
var styleProps = dojo.mixin({
display: "block",
overflow: "auto",
visibility: "visible"
}, this._openStyleProps);
styleProps[dim] = (this._openStyleProps && this._openStyleProps[dim]) ? this._openStyleProps[dim] : this.openSize;
dojo.style(paneNode, styleProps);
// and re-hook up the mouse event handler
this.connect(this.domNode, "onmousedown", "_onMouseDown");
} else {
// change to closed state
// FIXME: this wont work in a drag-to-closed scenario
var paneStyle = dojo.getComputedStyle(paneNode);
openProps = this._getStyleProps(paneNode, true, paneStyle);
var closedProps = this._getStyleProps(paneNode, false, paneStyle);
this._openStyleProps = openProps;
dojo.style(paneNode, closedProps);
}
this._setStateClass();
if(this.container._started){
this.container._layoutChildren(this.region);
}
},
_getStyleProps: function(paneNode, open, paneStyle){
// summary:
// create an object with the style property name: values
// that will need to be applied to the child pane render the given state
if(!paneStyle){
paneStyle = dojo.getComputedStyle(paneNode);
}
var styleProps = {},
dim = this.horizontal ? "height" : "width";
styleProps["overflow"] = (open) ? paneStyle["overflow"] : "hidden";
styleProps["visibility"] = (open) ? paneStyle["visibility"] : "hidden";
// use the inline width/height style value, in preference to the computedStyle
// for the open width/height
styleProps[dim] = (open) ? paneNode.style[dim] || paneStyle[dim] : this._closedSize;
// We include the padding,border,margin width values for restoring on open
var edgeNames = ["Top", "Right", "Bottom", "Left"];
dojo.forEach(["padding","margin","border"], function(pname){
for(var i=0; i<edgeNames.length; i++){
var fullname = pname+edgeNames[i];
if(pname=="border"){
pname+="Width";
}
if(undefined !== paneStyle[fullname]){
styleProps[fullname] = (open) ?
paneStyle[fullname] : 0;
}
}
});
return styleProps;
},
_setStateClass: function(){
// sumamry:
// apply the appropriate classes for the current open state
if(this.open){
dojo.removeClass(this.domNode, "dojoxToggleSplitterClosed");
dojo.addClass(this.domNode, "dojoxToggleSplitterOpen");
dojo.removeClass(this.toggleNode, "dojoxToggleSplitterIconClosed");
dojo.addClass(this.toggleNode, "dojoxToggleSplitterIconOpen");
} else {
dojo.addClass(this.domNode, "dojoxToggleSplitterClosed");
dojo.removeClass(this.domNode, "dojoxToggleSplitterOpen");
dojo.addClass(this.toggleNode, "dojoxToggleSplitterIconClosed");
dojo.removeClass(this.toggleNode, "dojoxToggleSplitterIconOpen");
}
},
_setOpenAttr: function(/*Boolean*/ value){
// summary:
// setter for the open property
if(!this._started) {
return;
}
this.open = value;
this._handleOnChange(value, true);
var evt = this.open ? "onOpen" : "onClose";
this[evt](this.child);
},
onOpen: function(){
// stub
},
onClose: function(){
// stub
},
_toggleMe: function(evt){
// summary:
// event handle, toggle the open state
if(evt){
dojo.stopEvent(evt);
}
this.set("open", !this.open);
},
_onKeyPress: function(/*Event*/ e){
this.inherited(arguments);
// TODO: add support for space, enter to cause toggle
}
});
// As BC places no constraints on what kind of widgets can be children
// we have to extend the base class to ensure the properties we need can be set (both in markup and programatically)
dojo.extend(dijit._Widget, {
// toggleSplitterOpen: Boolean
toggleSplitterOpen: true,
// toggleSplitterClosedThreshold: Integer
toggleSplitterClosedThreshold: 5,
// toggleSplitterClosedThreshold: String
// a css size value (e.g. "100px")
toggleSplitterOpenSize: ""
});
}
|