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