103
Collapsable.prototype._animate = function (callback)
105
if (this.anim) this.anim.stop();
107
this.anim = new Y.Anim(
109
node: this.container,
111
marginBottom: this.container.getStyle('marginBottom')
120
this.anim.on('end', this.animComplete, this, callback);
123
Collapsable.prototype._load_finished = function(tid, res, args)
125
var l = res.responseText.split('\n');
127
var newNode = Y.Node.create(l.join(''));
128
if (this.node_process)
129
this.node_process(newNode);
102
Collapsable.prototype._load_finished = function(tid, res)
104
var newNode = Y.Node.create(res.responseText.split('\n').splice(1).join(''));
105
this.source_target.ancestor().replaceChild(newNode, this.source_target);
106
this.source_target = null;
130
107
this.source = null;
131
newNode.setStyle('display', 'none');
132
this.loading.ancestor().insertBefore(newNode, this.loading);
133
var delta = this.loading.get('region').height - get_height(newNode);
134
newNode.setStyle('display', 'block');
135
this.container.setStyle('marginBottom', parseFloat(this.container.getStyle('marginBottom')) + delta);
136
this.loading.ancestor().removeChild(this.loading);
137
this._animate(args[0]);
108
this.loading.setStyle('display', 'none');
140
Collapsable.prototype._ensure_container = function(callback)
142
if (this.container == null) {
143
this.container = Y.Node.create('<div></div>');
144
if (this.closed_node) {
145
this.closed_node.ancestor().replaceChild(
146
this.container, this.closed_node);
147
this.container.appendChild(this.closed_node);
148
if (this.open_node) {
149
this.container.appendChild(this.open_node);
153
this.open_node.ancestor().replaceChild(
154
this.container, this.open_node);
155
this.container.appendChild(this.open_node);
157
var outer = Y.Node.create('<div style="overflow:hidden;"></div>');
158
this.container.ancestor().replaceChild(outer, this.container);
159
outer.appendChild(this.container);
163
/* What happens when you click open.
165
* 1. The arrow flips to the expanded position.
167
* 2. If necessary, the div which will be running the animation is
168
* created and the open/closed content stuffed into it (and has height
169
* set to the height of the closed content).
171
* 3. The open content is shown and the closed content is closed.
173
* 4. The animation to expose all of the open content is started.
175
* 5. If we have to do ajax to load content, start the request.
177
* 6. When the request completes, parse the content into a node, run
178
* the node_process callback over it and replace the spinner (assumed
179
* to be appropriately contained in the open node) with the new node.
181
* 7. If the animation showing the open content has not completed,
184
* 8. Start a new animation to show the rest of the new content.
187
Collapsable.prototype.open = function(callback)
189
this.expand_icon.set('src', expanded_icon_path);
191
this._ensure_container();
193
var open_height = get_height(this.open_node);
196
if (this.close_node) {
197
close_height = this.close_node.get('region').height;
203
this.container.setStyle('marginBottom', close_height - open_height);
204
if (this.close_node) {
205
this.close_node.setStyle('display', 'none');
207
this.open_node.setStyle('display', 'block');
209
this._animate(callback);
112
Collapsable.prototype.open = function()
211
114
if (this.source) {
115
this.loading.setStyle('display', 'block');
215
119
on: {complete: this._load_finished},
216
arguments: [callback],
125
var open_height = get_height(this.open_node);
128
if (this.close_node) {
129
close_height = this.close_node.get('region').height;
135
var container = this.open_node.ancestor('.container');
137
var anim = new Y.Anim(
141
marginBottom: close_height - open_height
149
anim.on('end', this.openComplete, this);
150
container.setStyle('marginBottom', close_height - open_height);
151
if (this.close_node) {
152
this.close_node.setStyle('display', 'none');
154
this.open_node.setStyle('display', 'block');
155
this.expand_icon.set('src', this.expand_icon.get('alt'));
224
Collapsable.prototype.animComplete = function(evt, callback)
159
Collapsable.prototype.openComplete = function()
227
if (this._loading) return;
228
if (callback) callback();
229
161
this.is_open = true;
232
164
Collapsable.prototype.close = function()
234
this._ensure_container();
166
var container = this.open_node.ancestor('.container');
236
168
var open_height = this.open_node.get('region').height;