##// END OF EJS Templates
Add string widget
Jonathan Frederic -
Show More
@@ -0,0 +1,1 b''
1 from widget import StringWidget No newline at end of file
@@ -0,0 +1,2 b''
1 var StringWidgetModel = IPython.WidgetModel.extend({});
2 IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel);
@@ -0,0 +1,35 b''
1 var TextareaView = IPython.WidgetView.extend({
2
3 // Called when view is rendered.
4 render : function(){
5 this.$el
6 .html('')
7 .addClass(this.model.comm.comm_id);
8 this.$textbox = $('<textarea />')
9 .attr('rows', 5)
10 .appendTo(this.$el);
11 this.update(); // Set defaults.
12 },
13
14 // Handles: Backend -> Frontend Sync
15 // Frontent -> Frontend Sync
16 update : function(){
17 if (!this.user_invoked_update) {
18 this.$textbox.val(this.model.get('value'));
19 }
20 },
21
22 events: {"keyup textarea" : "handleChanging",
23 "paste textarea" : "handleChanging",
24 "cut textarea" : "handleChanging"},
25
26 // Handles and validates user input.
27 handleChanging: function(e) {
28 this.user_invoked_update = true;
29 this.model.set('value', e.target.value);
30 this.model.apply(this);
31 this.user_invoked_update = false;
32 },
33 });
34
35 IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView);
@@ -0,0 +1,35 b''
1 var TextboxView = IPython.WidgetView.extend({
2
3 // Called when view is rendered.
4 render : function(){
5 this.$el
6 .html('')
7 .addClass(this.model.comm.comm_id);
8 this.$textbox = $('<input type="text" />')
9 .addClass('input')
10 .appendTo(this.$el);
11 this.update(); // Set defaults.
12 },
13
14 // Handles: Backend -> Frontend Sync
15 // Frontent -> Frontend Sync
16 update : function(){
17 if (!this.user_invoked_update) {
18 this.$textbox.val(this.model.get('value'));
19 }
20 },
21
22 events: {"keyup input" : "handleChanging",
23 "paste input" : "handleChanging",
24 "cut input" : "handleChanging"},
25
26 // Handles and validates user input.
27 handleChanging: function(e) {
28 this.user_invoked_update = true;
29 this.model.set('value', e.target.value);
30 this.model.apply(this);
31 this.user_invoked_update = false;
32 },
33 });
34
35 IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView);
@@ -0,0 +1,14 b''
1 import os
2
3 from ..widget import Widget
4 from IPython.utils.traitlets import Unicode, Bool
5 from IPython.utils.javascript import display_all_js
6
7 class StringWidget(Widget):
8 target_name = Unicode('StringWidgetModel')
9 default_view_name = Unicode('TextboxView')
10 _keys = ['value', 'row_count', 'disabled']
11
12 value = Unicode()
13 disabled = Bool(False) # Enable or disable user changes
14 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now