##// END OF EJS Templates
once-displayed
Sylvain Corlay -
Show More
@@ -275,6 +275,9 b' define(["widgets/js/manager",'
275 this.child_views = {};
275 this.child_views = {};
276 this.model.views.push(this);
276 this.model.views.push(this);
277 this.id = this.id || IPython.utils.uuid();
277 this.id = this.id || IPython.utils.uuid();
278 this.on('displayed', function() {
279 this.is_displayed = true;
280 }, this);
278 },
281 },
279
282
280 update: function(){
283 update: function(){
@@ -386,6 +389,16 b' define(["widgets/js/manager",'
386 touch: function () {
389 touch: function () {
387 this.model.save_changes(this.callbacks());
390 this.model.save_changes(this.callbacks());
388 },
391 },
392
393 once_displayed: function (callback, context) {
394 // Calls the callback right away is the view is already displayed
395 // otherwise, register the callback to the 'displayed' event.
396 if (this.is_displayed) {
397 callback.apply(context);
398 } else {
399 this.on('displayed', callback, context);
400 }
401 },
389 });
402 });
390
403
391
404
@@ -17,18 +17,6 b' define(['
17 this.update_children(model.previous('children'), value);
17 this.update_children(model.previous('children'), value);
18 }, this);
18 }, this);
19 this.update();
19 this.update();
20
21 // Trigger model displayed events for any models that are child to
22 // this model when this model is displayed.
23 var that = this;
24 this.on('displayed', function(){
25 that.is_displayed = true;
26 for (var property in that.child_views) {
27 if (that.child_views.hasOwnProperty(property)) {
28 that.child_views[property].trigger('displayed');
29 }
30 }
31 });
32 },
20 },
33
21
34 update_children: function(old_list, new_list) {
22 update_children: function(old_list, new_list) {
@@ -49,10 +37,8 b' define(['
49 var view = this.create_child_view(model);
37 var view = this.create_child_view(model);
50 this.$el.append(view.$el);
38 this.$el.append(view.$el);
51
39
52 // Trigger the displayed event if this model is displayed.
40 // Trigger the displayed event once this model is displayed.
53 if (this.is_displayed) {
41 this.once_displayed(function() { view.trigger('displayed'); }, this);
54 view.trigger('displayed');
55 }
56 },
42 },
57
43
58 update: function(){
44 update: function(){
@@ -179,17 +165,6 b' define(['
179 this.update_children(model.previous('children'), value);
165 this.update_children(model.previous('children'), value);
180 }, this);
166 }, this);
181 this.update();
167 this.update();
182
183 // Trigger model displayed events for any models that are child to
184 // this model when this model is displayed.
185 this.on('displayed', function(){
186 that.is_displayed = true;
187 for (var property in that.child_views) {
188 if (that.child_views.hasOwnProperty(property)) {
189 that.child_views[property].trigger('displayed');
190 }
191 }
192 });
193 },
168 },
194
169
195 hide: function() {
170 hide: function() {
@@ -252,10 +227,10 b' define(['
252 var view = this.create_child_view(model);
227 var view = this.create_child_view(model);
253 this.$body.append(view.$el);
228 this.$body.append(view.$el);
254
229
255 // Trigger the displayed event if this model is displayed.
230 // Trigger the displayed event once this model is displayed.
256 if (this.is_displayed) {
231 this.once_displayed(function() {
257 view.trigger('displayed');
232 view.trigger('displayed');
258 }
233 }, this);
259 },
234 },
260
235
261 update: function(){
236 update: function(){
General Comments 0
You need to be logged in to leave comments. Login now