##// END OF EJS Templates
Fix whitespace
Jason Grout -
Show More
@@ -1,87 +1,86 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 define([
4 define([
5 "widgets/js/widget",
5 "widgets/js/widget",
6 "jquery",
6 "jquery",
7 ], function(widget, $){
7 ], function(widget, $){
8 var LinkModel = widget.WidgetModel.extend({
8 var LinkModel = widget.WidgetModel.extend({
9 initialize: function() {
9 initialize: function() {
10 this.on("change:widgets", function(model, value, options) {
10 this.on("change:widgets", function(model, value, options) {
11 this.update_bindings(model.previous("widgets") || [], value);
11 this.update_bindings(model.previous("widgets") || [], value);
12 this.update_value(this.get("widgets")[0]);
12 this.update_value(this.get("widgets")[0]);
13 }, this);
13 }, this);
14 this.on("destroy", function(model, collection, options) {
14 this.on("destroy", function(model, collection, options) {
15 this.update_bindings(this.get("widgets"), []);
15 this.update_bindings(this.get("widgets"), []);
16 }, this);
16 }, this);
17 },
17 },
18 update_bindings: function(oldlist, newlist) {
18 update_bindings: function(oldlist, newlist) {
19 var that = this;
19 var that = this;
20 _.each(oldlist, function(elt) {elt[0].off("change:" + elt[1], null, that);});
20 _.each(oldlist, function(elt) {elt[0].off("change:" + elt[1], null, that);});
21 _.each(newlist, function(elt) {elt[0].on("change:" + elt[1],
21 _.each(newlist, function(elt) {elt[0].on("change:" + elt[1],
22 function(model, value, options) {
22 function(model, value, options) {
23 that.update_value(elt);
23 that.update_value(elt);
24 }, that);
24 }, that);
25 // TODO: register for any destruction handlers
25 // TODO: register for any destruction handlers
26 // to take an item out of the list
26 // to take an item out of the list
27 });
27 });
28 },
28 },
29 update_value: function(elt) {
29 update_value: function(elt) {
30 if (this.updating) {return;}
30 if (this.updating) {return;}
31 var model = elt[0];
31 var model = elt[0];
32 var attr = elt[1];
32 var attr = elt[1];
33 var new_value = model.get(attr);
33 var new_value = model.get(attr);
34 this.updating = true;
34 this.updating = true;
35 _.each(_.without(this.get("widgets"), elt),
35 _.each(_.without(this.get("widgets"), elt),
36 function(element, index, list) {
36 function(element, index, list) {
37 if (element[0]) {
37 if (element[0]) {
38 element[0].set(element[1], new_value);
38 element[0].set(element[1], new_value);
39 element[0].save_changes();
39 element[0].save_changes();
40 }
40 }
41 }, this);
41 }, this);
42 this.updating = false;
42 this.updating = false;
43 },
43 },
44 });
44 });
45
45
46 var DirectionalLinkModel = widget.WidgetModel.extend({
46 var DirectionalLinkModel = widget.WidgetModel.extend({
47 initialize: function() {
47 initialize: function() {
48 this.on("change", this.update_bindings, this);
48 this.on("change", this.update_bindings, this);
49 this.on("destroy", function() {
49 this.on("destroy", function() {
50 if (this.source) {
50 if (this.source) {
51 this.source[0].off("change:" + this.source[1], null, this);
51 this.source[0].off("change:" + this.source[1], null, this);
52 }
52 }
53 }, this);
53 }, this);
54 },
54 },
55 update_bindings: function() {
55 update_bindings: function() {
56 if (this.source) {
56 if (this.source) {
57 this.source[0].off("change:" + this.source[1], null, this);
57 this.source[0].off("change:" + this.source[1], null, this);
58 }
58 }
59 this.source = this.get("source");
59 this.source = this.get("source");
60 if (this.source) {
60 if (this.source) {
61 this.source[0].on("change:" + this.source[1], function() { this.update_value(this.source); }, this);
61 this.source[0].on("change:" + this.source[1], function() { this.update_value(this.source); }, this);
62 this.update_value(this.source);
62 this.update_value(this.source);
63 }
63 }
64 },
64 },
65 update_value: function(elt) {
65 update_value: function(elt) {
66 if (this.updating) {return;}
66 if (this.updating) {return;}
67 var model = elt[0];
67 var model = elt[0];
68 var attr = elt[1];
68 var attr = elt[1];
69 var new_value = model.get(attr);
69 var new_value = model.get(attr);
70 this.updating = true;
70 this.updating = true;
71 _.each(this.get("targets"),
71 _.each(this.get("targets"),
72 function(element, index, list) {
72 function(element, index, list) {
73 if (element[0]) {
73 if (element[0]) {
74 element[0].set(element[1], new_value);
74 element[0].set(element[1], new_value);
75 element[0].save_changes();
75 element[0].save_changes();
76 }
76 }
77 }, this);
77 }, this);
78 this.updating = false;
78 this.updating = false;
79 },
79 },
80 });
80 });
81
81
82
83 return {
82 return {
84 "LinkModel": LinkModel,
83 "LinkModel": LinkModel,
85 "DirectionalLinkModel": DirectionalLinkModel,
84 "DirectionalLinkModel": DirectionalLinkModel,
86 }
85 }
87 });
86 });
General Comments 0
You need to be logged in to leave comments. Login now