##// END OF EJS Templates
Made scroll to bottom use msgs...
Jonathan Frederic -
Show More
@@ -36,6 +36,7 b' define(["components/underscore/underscore-min",'
36 36 this.msg_throttle = 3;
37 37 this.msg_buffer = null;
38 38 this.views = {};
39 this._custom_msg_callbacks = [];
39 40
40 41 // Remember comm associated with the model.
41 42 this.comm = comm;
@@ -64,15 +65,17 b' define(["components/underscore/underscore-min",'
64 65 }
65 66 },
66 67
67 send: function(content) {
68
69 send: function(content, cell) {
68 70
69 71 // Used the last modified view as the sender of the message. This
70 72 // will insure that any python code triggered by the sent message
71 73 // can create and display widgets and output.
72 var cell = null;
73 if (this.last_modified_view != undefined &&
74 this.last_modified_view.cell != undefined) {
75 cell = this.last_modified_view.cell;
74 if (cell === undefined) {
75 if (this.last_modified_view != undefined &&
76 this.last_modified_view.cell != undefined) {
77 cell = this.last_modified_view.cell;
78 }
76 79 }
77 80 var callbacks = this._make_callbacks(cell);
78 81 var data = {'custom_content': content};
@@ -90,15 +93,29 b' define(["components/underscore/underscore-min",'
90 93 },
91 94
92 95
93 on_msg: function (callback) {
94 this._msg_callback = callback;
96 on_msg: function (callback, remove) {
97 if (remove) {
98 var found_index = -1;
99 for (var index in this._custom_msg_callbacks) {
100 if (callback === this._custom_msg_callbacks[index]) {
101 found_index = index;
102 break;
103 }
104 }
105
106 if (found_index >= 0) {
107 this._custom_msg_callbacks.splice(found_index, 1);
108 }
109 } else {
110 this._custom_msg_callbacks.push(callback)
111 }
95 112 },
96 113
97 114
98 115 _handle_custom_msg: function (content) {
99 if (this._msg_callback) {
116 for (var index in this._custom_msg_callbacks) {
100 117 try {
101 this._msg_callback(content);
118 this._custom_msg_callbacks[index](content);
102 119 } catch (e) {
103 120 console.log("Exception in widget model msg callback", e, content);
104 121 }
@@ -465,6 +482,11 b' define(["components/underscore/underscore-min",'
465 482 elements.removeClass(class_list);
466 483 }
467 484 },
485
486
487 send: function(content) {
488 this.model.send({event: 'click'}, this.cell);
489 },
468 490
469 491 update: function() {
470 492 if (this.model.get('visible') != undefined) {
@@ -50,8 +50,7 b' define(["notebook/js/widget"], function(widget_manager){'
50 50 },
51 51
52 52 _handle_click: function(){
53 this.model.last_modified_view = this; // For callbacks.
54 this.model.send({event: 'click'});
53 this.send({event: 'click'});
55 54 },
56 55 });
57 56
@@ -39,7 +39,7 b' define(["notebook/js/widget"], function(widget_manager){'
39 39 var TextAreaView = IPython.WidgetView.extend({
40 40
41 41 // Called when view is rendered.
42 render : function(){
42 render: function(){
43 43 this.$el
44 44 .addClass('widget-hbox')
45 45 .html('');
@@ -53,23 +53,30 b' define(["notebook/js/widget"], function(widget_manager){'
53 53 .appendTo(this.$el);
54 54 this.$el_to_style = this.$textbox; // Set default element to style
55 55 this.update(); // Set defaults.
56
57 this.on_msg();
58 },
59
60
61 _handle_textarea_msg: function (content){
62 if (content.method == "scroll_to_bottom") {
63 this.scroll_to_bottom();
64 }
65 },
66
67
68 scroll_to_bottom: function (){
69 this.$textbox.scrollTop(this.$textbox[0].scrollHeight);
56 70 },
71
57 72
58 73 // Handles: Backend -> Frontend Sync
59 74 // Frontent -> Frontend Sync
60 update : function(){
75 update: function(){
61 76 if (!this.user_invoked_update) {
62 77 this.$textbox.val(this.model.get('value'));
63 78 }
64 79
65 if (this.last_scroll_to_bottom == undefined) {
66 this.last_scroll_to_bottom = 0;
67 }
68 if (this.last_scroll_to_bottom < this.model.get('scroll_to_bottoms')) {
69 this.last_scroll_to_bottom < this.model.get('scroll_to_bottoms');
70 this.$textbox.scrollTop(this.$textbox[0].scrollHeight);
71 }
72
73 80 var disabled = this.model.get('disabled');
74 81 this.$textbox.prop('disabled', disabled);
75 82
@@ -83,9 +90,9 b' define(["notebook/js/widget"], function(widget_manager){'
83 90 return IPython.WidgetView.prototype.update.call(this);
84 91 },
85 92
86 events: {"keyup textarea" : "handleChanging",
87 "paste textarea" : "handleChanging",
88 "cut textarea" : "handleChanging"},
93 events: {"keyup textarea": "handleChanging",
94 "paste textarea": "handleChanging",
95 "cut textarea": "handleChanging"},
89 96
90 97 // Handles and validates user input.
91 98 handleChanging: function(e) {
@@ -101,7 +108,7 b' define(["notebook/js/widget"], function(widget_manager){'
101 108 var TextBoxView = IPython.WidgetView.extend({
102 109
103 110 // Called when view is rendered.
104 render : function(){
111 render: function(){
105 112 this.$el
106 113 .addClass('widget-hbox-single')
107 114 .html('');
@@ -119,7 +126,7 b' define(["notebook/js/widget"], function(widget_manager){'
119 126
120 127 // Handles: Backend -> Frontend Sync
121 128 // Frontent -> Frontend Sync
122 update : function(){
129 update: function(){
123 130 if (this.$textbox.val() != this.model.get('value')) {
124 131 this.$textbox.val(this.model.get('value'));
125 132 }
@@ -137,10 +144,10 b' define(["notebook/js/widget"], function(widget_manager){'
137 144 return IPython.WidgetView.prototype.update.call(this);
138 145 },
139 146
140 events: {"keyup input" : "handleChanging",
141 "paste input" : "handleChanging",
142 "cut input" : "handleChanging",
143 "keypress input" : "handleKeypress"},
147 events: {"keyup input": "handleChanging",
148 "paste input": "handleChanging",
149 "cut input": "handleChanging",
150 "keypress input": "handleKeypress"},
144 151
145 152 // Handles and validates user input.
146 153 handleChanging: function(e) {
@@ -151,8 +158,7 b' define(["notebook/js/widget"], function(widget_manager){'
151 158 // Handles text submition
152 159 handleKeypress: function(e) {
153 160 if (e.keyCode == 13) { // Return key
154 this.model.last_modified_view = this; // For callbacks.
155 this.model.send({event: 'submit'});
161 this.send({event: 'submit'});
156 162 }
157 163 },
158 164 });
@@ -27,11 +27,10 b' class StringWidget(Widget):'
27 27 default_view_name = Unicode('TextBoxView')
28 28
29 29 # Keys
30 _keys = ['value', 'disabled', 'description', 'scroll_to_bottoms']
30 _keys = ['value', 'disabled', 'description']
31 31 value = Unicode(help="String value")
32 32 disabled = Bool(False, help="Enable or disable user changes")
33 33 description = Unicode(help="Description of the value this widget represents")
34 scroll_to_bottoms = Int(0, help="Used to scroll a TextAreaView to the bottom")
35 34
36 35
37 36 def __init__(self, **kwargs):
@@ -41,7 +40,7 b' class StringWidget(Widget):'
41 40
42 41
43 42 def scroll_to_bottom(self):
44 self.scroll_to_bottoms += 1
43 self._comm.send({"method": "scroll_to_bottom"})
45 44
46 45
47 46 def on_click(self, callback, remove=False):
General Comments 0
You need to be logged in to leave comments. Login now