##// END OF EJS Templates
once-displayed
Sylvain Corlay -
Show More
@@ -275,6 +275,9 define(["widgets/js/manager",
275 275 this.child_views = {};
276 276 this.model.views.push(this);
277 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 283 update: function(){
@@ -386,6 +389,16 define(["widgets/js/manager",
386 389 touch: function () {
387 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 define([
17 17 this.update_children(model.previous('children'), value);
18 18 }, this);
19 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 22 update_children: function(old_list, new_list) {
@@ -49,10 +37,8 define([
49 37 var view = this.create_child_view(model);
50 38 this.$el.append(view.$el);
51 39
52 // Trigger the displayed event if this model is displayed.
53 if (this.is_displayed) {
54 view.trigger('displayed');
55 }
40 // Trigger the displayed event once this model is displayed.
41 this.once_displayed(function() { view.trigger('displayed'); }, this);
56 42 },
57 43
58 44 update: function(){
@@ -179,17 +165,6 define([
179 165 this.update_children(model.previous('children'), value);
180 166 }, this);
181 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 170 hide: function() {
@@ -252,10 +227,10 define([
252 227 var view = this.create_child_view(model);
253 228 this.$body.append(view.$el);
254 229
255 // Trigger the displayed event if this model is displayed.
256 if (this.is_displayed) {
257 view.trigger('displayed');
258 }
230 // Trigger the displayed event once this model is displayed.
231 this.once_displayed(function() {
232 view.trigger('displayed');
233 }, this);
259 234 },
260 235
261 236 update: function(){
General Comments 0
You need to be logged in to leave comments. Login now