##// END OF EJS Templates
Removed widget_item class
Jonathan Frederic -
Show More
@@ -1,94 +1,92 b''
1
1
2 require(["notebook/js/widget"], function(){
2 require(["notebook/js/widget"], function(){
3
3
4 var BoolWidgetModel = IPython.WidgetModel.extend({});
4 var BoolWidgetModel = IPython.WidgetModel.extend({});
5 IPython.notebook.widget_manager.register_widget_model('BoolWidgetModel', BoolWidgetModel);
5 IPython.notebook.widget_manager.register_widget_model('BoolWidgetModel', BoolWidgetModel);
6
6
7 var CheckboxView = IPython.WidgetView.extend({
7 var CheckboxView = IPython.WidgetView.extend({
8
8
9 // Called when view is rendered.
9 // Called when view is rendered.
10 render : function(){
10 render : function(){
11 this.$el
11 this.$el
12 .html('')
12 .html('')
13 .addClass('widget_item')
14 .addClass(this.model.comm.comm_id);
13 .addClass(this.model.comm.comm_id);
15
14
16 var $label = $('<label />')
15 var $label = $('<label />')
17 .addClass('checkbox')
16 .addClass('checkbox')
18 .appendTo(this.$el);
17 .appendTo(this.$el);
19 this.$checkbox = $('<input />')
18 this.$checkbox = $('<input />')
20 .attr('type', 'checkbox')
19 .attr('type', 'checkbox')
21 .appendTo($label);
20 .appendTo($label);
22 this.$checkbox_label = $('<div />')
21 this.$checkbox_label = $('<div />')
23 .addClass('widget_item')
24 .appendTo($label);
22 .appendTo($label);
25
23
26 this.update(); // Set defaults.
24 this.update(); // Set defaults.
27 },
25 },
28
26
29 // Handles: Backend -> Frontend Sync
27 // Handles: Backend -> Frontend Sync
30 // Frontent -> Frontend Sync
28 // Frontent -> Frontend Sync
31 update : function(){
29 update : function(){
32 if (!this.user_invoked_update) {
30 if (!this.user_invoked_update) {
33 this.$checkbox.prop('checked', this.model.get('value'));
31 this.$checkbox.prop('checked', this.model.get('value'));
34 this.$checkbox_label.html(this.model.get('description'));
32 this.$checkbox_label.html(this.model.get('description'));
35 }
33 }
36 },
34 },
37
35
38 events: {"change input" : "handleChanged"},
36 events: {"change input" : "handleChanged"},
39
37
40 // Handles and validates user input.
38 // Handles and validates user input.
41 handleChanged: function(e) {
39 handleChanged: function(e) {
42 this.user_invoked_update = true;
40 this.user_invoked_update = true;
43 this.model.set('value', $(e.target).prop('checked'));
41 this.model.set('value', $(e.target).prop('checked'));
44 this.model.apply(this);
42 this.model.apply(this);
45 this.user_invoked_update = false;
43 this.user_invoked_update = false;
46 },
44 },
47 });
45 });
48
46
49 IPython.notebook.widget_manager.register_widget_view('CheckboxView', CheckboxView);
47 IPython.notebook.widget_manager.register_widget_view('CheckboxView', CheckboxView);
50
48
51 var ToggleButtonView = IPython.WidgetView.extend({
49 var ToggleButtonView = IPython.WidgetView.extend({
52
50
53 // Called when view is rendered.
51 // Called when view is rendered.
54 render : function(){
52 render : function(){
55 this.$el
53 this.$el
56 .html('')
54 .html('')
57 .addClass(this.model.comm.comm_id);
55 .addClass(this.model.comm.comm_id);
58
56
59 this.$button = $('<button />')
57 this.$button = $('<button />')
60 .addClass('btn')
58 .addClass('btn')
61 .attr('type', 'button')
59 .attr('type', 'button')
62 .attr('data-toggle', 'button')
60 .attr('data-toggle', 'button')
63 .appendTo(this.$el);
61 .appendTo(this.$el);
64
62
65 this.update(); // Set defaults.
63 this.update(); // Set defaults.
66 },
64 },
67
65
68 // Handles: Backend -> Frontend Sync
66 // Handles: Backend -> Frontend Sync
69 // Frontent -> Frontend Sync
67 // Frontent -> Frontend Sync
70 update : function(){
68 update : function(){
71 if (!this.user_invoked_update) {
69 if (!this.user_invoked_update) {
72 if (this.model.get('value')) {
70 if (this.model.get('value')) {
73 this.$button.addClass('active');
71 this.$button.addClass('active');
74 } else {
72 } else {
75 this.$button.removeClass('active');
73 this.$button.removeClass('active');
76 }
74 }
77 this.$button.html(this.model.get('description'));
75 this.$button.html(this.model.get('description'));
78 }
76 }
79 },
77 },
80
78
81 events: {"click button" : "handleClick"},
79 events: {"click button" : "handleClick"},
82
80
83 // Handles and validates user input.
81 // Handles and validates user input.
84 handleClick: function(e) {
82 handleClick: function(e) {
85 this.user_invoked_update = true;
83 this.user_invoked_update = true;
86 this.model.set('value', ! $(e.target).hasClass('active'));
84 this.model.set('value', ! $(e.target).hasClass('active'));
87 this.model.apply(this);
85 this.model.apply(this);
88 this.user_invoked_update = false;
86 this.user_invoked_update = false;
89 },
87 },
90 });
88 });
91
89
92 IPython.notebook.widget_manager.register_widget_view('ToggleButtonView', ToggleButtonView);
90 IPython.notebook.widget_manager.register_widget_view('ToggleButtonView', ToggleButtonView);
93
91
94 });
92 });
@@ -1,126 +1,125 b''
1 require(["notebook/js/widget"], function(){
1 require(["notebook/js/widget"], function(){
2 var FloatRangeWidgetModel = IPython.WidgetModel.extend({});
2 var FloatRangeWidgetModel = IPython.WidgetModel.extend({});
3 IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel);
3 IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel);
4
4
5 var FloatSliderView = IPython.WidgetView.extend({
5 var FloatSliderView = IPython.WidgetView.extend({
6
6
7 // Called when view is rendered.
7 // Called when view is rendered.
8 render : function(){
8 render : function(){
9 this.$el
9 this.$el
10 .html('')
10 .html('')
11 .addClass(this.model.comm.comm_id);
11 .addClass(this.model.comm.comm_id);
12 this.$slider = $('<div />')
12 this.$slider = $('<div />')
13 .slider({})
13 .slider({})
14 .addClass('slider');
14 .addClass('slider');
15
15
16 // Put the slider in a container
16 // Put the slider in a container
17 this.$slider_container = $('<div />')
17 this.$slider_container = $('<div />')
18 .css('padding-top', '4px')
18 .css('padding-top', '4px')
19 .css('padding-bottom', '4px')
19 .css('padding-bottom', '4px')
20 .append(this.$slider);
20 .append(this.$slider);
21 this.$el.append(this.$slider_container);
21 this.$el.append(this.$slider_container);
22
22
23 // Set defaults.
23 // Set defaults.
24 this.update();
24 this.update();
25 },
25 },
26
26
27 // Handles: Backend -> Frontend Sync
27 // Handles: Backend -> Frontend Sync
28 // Frontent -> Frontend Sync
28 // Frontent -> Frontend Sync
29 update : function(){
29 update : function(){
30 // Slider related keys.
30 // Slider related keys.
31 var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'];
31 var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'];
32 for (var index in _keys) {
32 for (var index in _keys) {
33 var key = _keys[index];
33 var key = _keys[index];
34 if (this.model.get(key) != undefined) {
34 if (this.model.get(key) != undefined) {
35 this.$slider.slider("option", key, this.model.get(key));
35 this.$slider.slider("option", key, this.model.get(key));
36 }
36 }
37 }
37 }
38 },
38 },
39
39
40 // Handles: User input
40 // Handles: User input
41 events: { "slide" : "handleSliderChange" },
41 events: { "slide" : "handleSliderChange" },
42 handleSliderChange: function(e, ui) {
42 handleSliderChange: function(e, ui) {
43 this.model.set('value', ui.value);
43 this.model.set('value', ui.value);
44 this.model.apply(this);
44 this.model.apply(this);
45 },
45 },
46 });
46 });
47
47
48 IPython.notebook.widget_manager.register_widget_view('FloatSliderView', FloatSliderView);
48 IPython.notebook.widget_manager.register_widget_view('FloatSliderView', FloatSliderView);
49
49
50
50
51 var FloatTextView = IPython.WidgetView.extend({
51 var FloatTextView = IPython.WidgetView.extend({
52
52
53 // Called when view is rendered.
53 // Called when view is rendered.
54 render : function(){
54 render : function(){
55 this.$el
55 this.$el
56 .html('')
56 .html('')
57 .addClass('widget_item')
58 .addClass(this.model.comm.comm_id);
57 .addClass(this.model.comm.comm_id);
59 this.$textbox = $('<input type="text" />')
58 this.$textbox = $('<input type="text" />')
60 .addClass('input')
59 .addClass('input')
61 .appendTo(this.$el);
60 .appendTo(this.$el);
62 this.update(); // Set defaults.
61 this.update(); // Set defaults.
63 },
62 },
64
63
65 // Handles: Backend -> Frontend Sync
64 // Handles: Backend -> Frontend Sync
66 // Frontent -> Frontend Sync
65 // Frontent -> Frontend Sync
67 update : function(){
66 update : function(){
68 var value = this.model.get('value');
67 var value = this.model.get('value');
69 if (!this.changing && parseFloat(this.$textbox.val()) != value) {
68 if (!this.changing && parseFloat(this.$textbox.val()) != value) {
70 this.$textbox.val(value);
69 this.$textbox.val(value);
71 }
70 }
72
71
73 if (this.model.get('disabled')) {
72 if (this.model.get('disabled')) {
74 this.$textbox.attr('disabled','disabled');
73 this.$textbox.attr('disabled','disabled');
75 } else {
74 } else {
76 this.$textbox.removeAttr('disabled');
75 this.$textbox.removeAttr('disabled');
77 }
76 }
78 },
77 },
79
78
80
79
81 events: {"keyup input" : "handleChanging",
80 events: {"keyup input" : "handleChanging",
82 "paste input" : "handleChanging",
81 "paste input" : "handleChanging",
83 "cut input" : "handleChanging",
82 "cut input" : "handleChanging",
84 "change input" : "handleChanged"}, // Fires only when control is validated or looses focus.
83 "change input" : "handleChanged"}, // Fires only when control is validated or looses focus.
85
84
86 // Handles and validates user input.
85 // Handles and validates user input.
87 handleChanging: function(e) {
86 handleChanging: function(e) {
88
87
89 // Try to parse value as a float.
88 // Try to parse value as a float.
90 var numericalValue = 0.0;
89 var numericalValue = 0.0;
91 if (e.target.value != '') {
90 if (e.target.value != '') {
92 numericalValue = parseFloat(e.target.value);
91 numericalValue = parseFloat(e.target.value);
93 }
92 }
94
93
95 // If parse failed, reset value to value stored in model.
94 // If parse failed, reset value to value stored in model.
96 if (isNaN(numericalValue)) {
95 if (isNaN(numericalValue)) {
97 e.target.value = this.model.get('value');
96 e.target.value = this.model.get('value');
98 } else if (!isNaN(numericalValue)) {
97 } else if (!isNaN(numericalValue)) {
99 if (this.model.get('max') != undefined) {
98 if (this.model.get('max') != undefined) {
100 numericalValue = Math.min(this.model.get('max'), numericalValue);
99 numericalValue = Math.min(this.model.get('max'), numericalValue);
101 }
100 }
102 if (this.model.get('min') != undefined) {
101 if (this.model.get('min') != undefined) {
103 numericalValue = Math.max(this.model.get('min'), numericalValue);
102 numericalValue = Math.max(this.model.get('min'), numericalValue);
104 }
103 }
105
104
106 // Apply the value if it has changed.
105 // Apply the value if it has changed.
107 if (numericalValue != this.model.get('value')) {
106 if (numericalValue != this.model.get('value')) {
108 this.changing = true;
107 this.changing = true;
109 this.model.set('value', numericalValue);
108 this.model.set('value', numericalValue);
110 this.model.apply(this);
109 this.model.apply(this);
111 this.changing = false;
110 this.changing = false;
112 }
111 }
113 }
112 }
114 },
113 },
115
114
116 // Applies validated input.
115 // Applies validated input.
117 handleChanged: function(e) {
116 handleChanged: function(e) {
118 // Update the textbox
117 // Update the textbox
119 if (this.model.get('value') != e.target.value) {
118 if (this.model.get('value') != e.target.value) {
120 e.target.value = this.model.get('value');
119 e.target.value = this.model.get('value');
121 }
120 }
122 }
121 }
123 });
122 });
124
123
125 IPython.notebook.widget_manager.register_widget_view('FloatTextView', FloatTextView);
124 IPython.notebook.widget_manager.register_widget_view('FloatTextView', FloatTextView);
126 });
125 });
@@ -1,125 +1,124 b''
1 require(["notebook/js/widget"], function(){
1 require(["notebook/js/widget"], function(){
2 var IntRangeWidgetModel = IPython.WidgetModel.extend({});
2 var IntRangeWidgetModel = IPython.WidgetModel.extend({});
3 IPython.notebook.widget_manager.register_widget_model('IntRangeWidgetModel', IntRangeWidgetModel);
3 IPython.notebook.widget_manager.register_widget_model('IntRangeWidgetModel', IntRangeWidgetModel);
4
4
5 var IntSliderView = IPython.WidgetView.extend({
5 var IntSliderView = IPython.WidgetView.extend({
6
6
7 // Called when view is rendered.
7 // Called when view is rendered.
8 render : function(){
8 render : function(){
9 this.$el
9 this.$el
10 .html('')
10 .html('')
11 this.$slider = $('<div />')
11 this.$slider = $('<div />')
12 .slider({})
12 .slider({})
13 .addClass('slider');
13 .addClass('slider');
14
14
15 // Put the slider in a container
15 // Put the slider in a container
16 this.$slider_container = $('<div />')
16 this.$slider_container = $('<div />')
17 .css('padding-top', '4px')
17 .css('padding-top', '4px')
18 .css('padding-bottom', '4px')
18 .css('padding-bottom', '4px')
19 .addClass(this.model.comm.comm_id)
19 .addClass(this.model.comm.comm_id)
20 .append(this.$slider);
20 .append(this.$slider);
21 this.$el.append(this.$slider_container);
21 this.$el.append(this.$slider_container);
22
22
23 // Set defaults.
23 // Set defaults.
24 this.update();
24 this.update();
25 },
25 },
26
26
27 // Handles: Backend -> Frontend Sync
27 // Handles: Backend -> Frontend Sync
28 // Frontent -> Frontend Sync
28 // Frontent -> Frontend Sync
29 update : function(){
29 update : function(){
30 // Slider related keys.
30 // Slider related keys.
31 var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'];
31 var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'];
32 for (var index in _keys) {
32 for (var index in _keys) {
33 var key = _keys[index];
33 var key = _keys[index];
34 if (this.model.get(key) != undefined) {
34 if (this.model.get(key) != undefined) {
35 this.$slider.slider("option", key, this.model.get(key));
35 this.$slider.slider("option", key, this.model.get(key));
36 }
36 }
37 }
37 }
38 },
38 },
39
39
40 // Handles: User input
40 // Handles: User input
41 events: { "slide" : "handleSliderChange" },
41 events: { "slide" : "handleSliderChange" },
42 handleSliderChange: function(e, ui) {
42 handleSliderChange: function(e, ui) {
43 this.model.set('value', ~~ui.value); // Double bit-wise not to truncate decimel
43 this.model.set('value', ~~ui.value); // Double bit-wise not to truncate decimel
44 this.model.apply(this);
44 this.model.apply(this);
45 },
45 },
46 });
46 });
47
47
48 IPython.notebook.widget_manager.register_widget_view('IntSliderView', IntSliderView);
48 IPython.notebook.widget_manager.register_widget_view('IntSliderView', IntSliderView);
49
49
50 var IntTextView = IPython.WidgetView.extend({
50 var IntTextView = IPython.WidgetView.extend({
51
51
52 // Called when view is rendered.
52 // Called when view is rendered.
53 render : function(){
53 render : function(){
54 this.$el
54 this.$el
55 .html('')
55 .html('')
56 .addClass('widget_item')
57 .addClass(this.model.comm.comm_id);
56 .addClass(this.model.comm.comm_id);
58 this.$textbox = $('<input type="text" />')
57 this.$textbox = $('<input type="text" />')
59 .addClass('input')
58 .addClass('input')
60 .appendTo(this.$el);
59 .appendTo(this.$el);
61 this.update(); // Set defaults.
60 this.update(); // Set defaults.
62 },
61 },
63
62
64 // Handles: Backend -> Frontend Sync
63 // Handles: Backend -> Frontend Sync
65 // Frontent -> Frontend Sync
64 // Frontent -> Frontend Sync
66 update : function(){
65 update : function(){
67 var value = this.model.get('value');
66 var value = this.model.get('value');
68 if (!this.changing && parseInt(this.$textbox.val()) != value) {
67 if (!this.changing && parseInt(this.$textbox.val()) != value) {
69 this.$textbox.val(value);
68 this.$textbox.val(value);
70 }
69 }
71
70
72 if (this.model.get('disabled')) {
71 if (this.model.get('disabled')) {
73 this.$textbox.attr('disabled','disabled');
72 this.$textbox.attr('disabled','disabled');
74 } else {
73 } else {
75 this.$textbox.removeAttr('disabled');
74 this.$textbox.removeAttr('disabled');
76 }
75 }
77 },
76 },
78
77
79
78
80 events: {"keyup input" : "handleChanging",
79 events: {"keyup input" : "handleChanging",
81 "paste input" : "handleChanging",
80 "paste input" : "handleChanging",
82 "cut input" : "handleChanging",
81 "cut input" : "handleChanging",
83 "change input" : "handleChanged"}, // Fires only when control is validated or looses focus.
82 "change input" : "handleChanged"}, // Fires only when control is validated or looses focus.
84
83
85 // Handles and validates user input.
84 // Handles and validates user input.
86 handleChanging: function(e) {
85 handleChanging: function(e) {
87
86
88 // Try to parse value as a float.
87 // Try to parse value as a float.
89 var numericalValue = 0;
88 var numericalValue = 0;
90 if (e.target.value != '') {
89 if (e.target.value != '') {
91 numericalValue = parseInt(e.target.value);
90 numericalValue = parseInt(e.target.value);
92 }
91 }
93
92
94 // If parse failed, reset value to value stored in model.
93 // If parse failed, reset value to value stored in model.
95 if (isNaN(numericalValue)) {
94 if (isNaN(numericalValue)) {
96 e.target.value = this.model.get('value');
95 e.target.value = this.model.get('value');
97 } else if (!isNaN(numericalValue)) {
96 } else if (!isNaN(numericalValue)) {
98 if (this.model.get('max') != undefined) {
97 if (this.model.get('max') != undefined) {
99 numericalValue = Math.min(this.model.get('max'), numericalValue);
98 numericalValue = Math.min(this.model.get('max'), numericalValue);
100 }
99 }
101 if (this.model.get('min') != undefined) {
100 if (this.model.get('min') != undefined) {
102 numericalValue = Math.max(this.model.get('min'), numericalValue);
101 numericalValue = Math.max(this.model.get('min'), numericalValue);
103 }
102 }
104
103
105 // Apply the value if it has changed.
104 // Apply the value if it has changed.
106 if (numericalValue != this.model.get('value')) {
105 if (numericalValue != this.model.get('value')) {
107 this.changing = true;
106 this.changing = true;
108 this.model.set('value', numericalValue);
107 this.model.set('value', numericalValue);
109 this.model.apply(this);
108 this.model.apply(this);
110 this.changing = false;
109 this.changing = false;
111 }
110 }
112 }
111 }
113 },
112 },
114
113
115 // Applies validated input.
114 // Applies validated input.
116 handleChanged: function(e) {
115 handleChanged: function(e) {
117 // Update the textbox
116 // Update the textbox
118 if (this.model.get('value') != e.target.value) {
117 if (this.model.get('value') != e.target.value) {
119 e.target.value = this.model.get('value');
118 e.target.value = this.model.get('value');
120 }
119 }
121 }
120 }
122 });
121 });
123
122
124 IPython.notebook.widget_manager.register_widget_view('IntTextView', IntTextView);
123 IPython.notebook.widget_manager.register_widget_view('IntTextView', IntTextView);
125 });
124 });
@@ -1,202 +1,198 b''
1 require(["notebook/js/widget"], function(){
1 require(["notebook/js/widget"], function(){
2 var SelectionWidgetModel = IPython.WidgetModel.extend({});
2 var SelectionWidgetModel = IPython.WidgetModel.extend({});
3 IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel);
3 IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel);
4
4
5 var DropdownView = IPython.WidgetView.extend({
5 var DropdownView = IPython.WidgetView.extend({
6
6
7 // Called when view is rendered.
7 // Called when view is rendered.
8 render : function(){
8 render : function(){
9
9
10 this.$el
10 this.$el
11 .html('')
11 .html('')
12 .addClass('widget_item')
13 .addClass(this.model.comm.comm_id);
12 .addClass(this.model.comm.comm_id);
14 this.$buttongroup = $('<div />')
13 this.$buttongroup = $('<div />')
15 .addClass('widget_item')
14 .addClass('widget_item')
16 .addClass('btn-group')
15 .addClass('btn-group')
17 .appendTo(this.$el);
16 .appendTo(this.$el);
18 this.$droplabel = $('<button />')
17 this.$droplabel = $('<button />')
19 .addClass('btn')
18 .addClass('btn')
20 .appendTo(this.$buttongroup);
19 .appendTo(this.$buttongroup);
21 this.$dropbutton = $('<button />')
20 this.$dropbutton = $('<button />')
22 .addClass('btn')
21 .addClass('btn')
23 .addClass('dropdown-toggle')
22 .addClass('dropdown-toggle')
24 .attr('data-toggle', 'dropdown')
23 .attr('data-toggle', 'dropdown')
25 .html('<span class="caret"></span>')
24 .html('<span class="caret"></span>')
26 .appendTo(this.$buttongroup);
25 .appendTo(this.$buttongroup);
27 this.$droplist = $('<ul />')
26 this.$droplist = $('<ul />')
28 .addClass('dropdown-menu')
27 .addClass('dropdown-menu')
29 .appendTo(this.$buttongroup);
28 .appendTo(this.$buttongroup);
30
29
31 // Set defaults.
30 // Set defaults.
32 this.update();
31 this.update();
33 },
32 },
34
33
35 // Handles: Backend -> Frontend Sync
34 // Handles: Backend -> Frontend Sync
36 // Frontent -> Frontend Sync
35 // Frontent -> Frontend Sync
37 update : function(){
36 update : function(){
38 this.$droplabel.html(this.model.get('value'));
37 this.$droplabel.html(this.model.get('value'));
39
38
40 var items = this.model.get('values');
39 var items = this.model.get('values');
41 this.$droplist.html('');
40 this.$droplist.html('');
42 for (var index in items) {
41 for (var index in items) {
43 var that = this;
42 var that = this;
44 var item_button = $('<a href="#"/>')
43 var item_button = $('<a href="#"/>')
45 .html(items[index])
44 .html(items[index])
46 .on('click', function(e){
45 .on('click', function(e){
47 that.model.set('value', $(e.target).html(), this );
46 that.model.set('value', $(e.target).html(), this );
48 that.model.apply(that);
47 that.model.apply(that);
49 })
48 })
50
49
51 this.$droplist.append($('<li />').append(item_button))
50 this.$droplist.append($('<li />').append(item_button))
52 }
51 }
53
52
54 if (this.model.get('disabled')) {
53 if (this.model.get('disabled')) {
55 this.$buttongroup.attr('disabled','disabled');
54 this.$buttongroup.attr('disabled','disabled');
56 this.$droplabel.attr('disabled','disabled');
55 this.$droplabel.attr('disabled','disabled');
57 this.$dropbutton.attr('disabled','disabled');
56 this.$dropbutton.attr('disabled','disabled');
58 this.$droplist.attr('disabled','disabled');
57 this.$droplist.attr('disabled','disabled');
59 } else {
58 } else {
60 this.$buttongroup.removeAttr('disabled');
59 this.$buttongroup.removeAttr('disabled');
61 this.$droplabel.removeAttr('disabled');
60 this.$droplabel.removeAttr('disabled');
62 this.$dropbutton.removeAttr('disabled');
61 this.$dropbutton.removeAttr('disabled');
63 this.$droplist.removeAttr('disabled');
62 this.$droplist.removeAttr('disabled');
64 }
63 }
65 },
64 },
66
65
67 });
66 });
68
67
69 IPython.notebook.widget_manager.register_widget_view('DropdownView', DropdownView);
68 IPython.notebook.widget_manager.register_widget_view('DropdownView', DropdownView);
70
69
71 var RadioButtonsView = IPython.WidgetView.extend({
70 var RadioButtonsView = IPython.WidgetView.extend({
72
71
73 // Called when view is rendered.
72 // Called when view is rendered.
74 render : function(){
73 render : function(){
75 this.$el
74 this.$el
76 .html('')
75 .html('')
77 .addClass('widget_item')
78 .addClass(this.model.comm.comm_id);
76 .addClass(this.model.comm.comm_id);
79 this.update();
77 this.update();
80 },
78 },
81
79
82 // Handles: Backend -> Frontend Sync
80 // Handles: Backend -> Frontend Sync
83 // Frontent -> Frontend Sync
81 // Frontent -> Frontend Sync
84 update : function(){
82 update : function(){
85
83
86 // Add missing items to the DOM.
84 // Add missing items to the DOM.
87 var items = this.model.get('values');
85 var items = this.model.get('values');
88 for (var index in items) {
86 for (var index in items) {
89 var item_query = ' :input[value="' + items[index] + '"]';
87 var item_query = ' :input[value="' + items[index] + '"]';
90 if (this.$el.find(item_query).length == 0) {
88 if (this.$el.find(item_query).length == 0) {
91 var $label = $('<label />')
89 var $label = $('<label />')
92 .addClass('radio')
90 .addClass('radio')
93 .html(items[index])
91 .html(items[index])
94 .appendTo(this.$el);
92 .appendTo(this.$el);
95
93
96 var that = this;
94 var that = this;
97 $('<input />')
95 $('<input />')
98 .attr('type', 'radio')
96 .attr('type', 'radio')
99 .addClass(this.model)
97 .addClass(this.model)
100 .val(items[index])
98 .val(items[index])
101 .prependTo($label)
99 .prependTo($label)
102 .on('click', function(e){
100 .on('click', function(e){
103 that.model.set('value', $(e.target).val(), this);
101 that.model.set('value', $(e.target).val(), this);
104 that.model.apply();
102 that.model.apply();
105 });
103 });
106 }
104 }
107
105
108 if (this.model.get('value') == items[index]) {
106 if (this.model.get('value') == items[index]) {
109 this.$el.find(item_query).prop('checked', true);
107 this.$el.find(item_query).prop('checked', true);
110 } else {
108 } else {
111 this.$el.find(item_query).prop('checked', false);
109 this.$el.find(item_query).prop('checked', false);
112 }
110 }
113 }
111 }
114
112
115 // Remove items that no longer exist.
113 // Remove items that no longer exist.
116 this.$el.find('input').each(function(i, obj) {
114 this.$el.find('input').each(function(i, obj) {
117 var value = $(obj).val();
115 var value = $(obj).val();
118 var found = false;
116 var found = false;
119 for (var index in items) {
117 for (var index in items) {
120 if (items[index] == value) {
118 if (items[index] == value) {
121 found = true;
119 found = true;
122 break;
120 break;
123 }
121 }
124 }
122 }
125
123
126 if (!found) {
124 if (!found) {
127 $(obj).parent().remove();
125 $(obj).parent().remove();
128 }
126 }
129 });
127 });
130 },
128 },
131
129
132 });
130 });
133
131
134 IPython.notebook.widget_manager.register_widget_view('RadioButtonsView', RadioButtonsView);
132 IPython.notebook.widget_manager.register_widget_view('RadioButtonsView', RadioButtonsView);
135
133
136
134
137 var ToggleButtonsView = IPython.WidgetView.extend({
135 var ToggleButtonsView = IPython.WidgetView.extend({
138
136
139 // Called when view is rendered.
137 // Called when view is rendered.
140 render : function(){
138 render : function(){
141 this.$el
139 this.$el
142 .html('')
140 .html('')
143 .addClass('widget_item')
144 .addClass(this.model.comm.comm_id);
141 .addClass(this.model.comm.comm_id);
145 this.$buttongroup = $('<div />')
142 this.$buttongroup = $('<div />')
146 .addClass('widget_item')
147 .addClass('btn-group')
143 .addClass('btn-group')
148 .attr('data-toggle', 'buttons-radio')
144 .attr('data-toggle', 'buttons-radio')
149 .appendTo(this.$el);
145 .appendTo(this.$el);
150 this.update();
146 this.update();
151 },
147 },
152
148
153 // Handles: Backend -> Frontend Sync
149 // Handles: Backend -> Frontend Sync
154 // Frontent -> Frontend Sync
150 // Frontent -> Frontend Sync
155 update : function(){
151 update : function(){
156
152
157 // Add missing items to the DOM.
153 // Add missing items to the DOM.
158 var items = this.model.get('values');
154 var items = this.model.get('values');
159 for (var index in items) {
155 for (var index in items) {
160 var item_query = ' :contains("' + items[index] + '")';
156 var item_query = ' :contains("' + items[index] + '")';
161 if (this.$buttongroup.find(item_query).length == 0) {
157 if (this.$buttongroup.find(item_query).length == 0) {
162
158
163 var that = this;
159 var that = this;
164 $('<button />')
160 $('<button />')
165 .attr('type', 'button')
161 .attr('type', 'button')
166 .addClass('btn')
162 .addClass('btn')
167 .html(items[index])
163 .html(items[index])
168 .appendTo(this.$buttongroup)
164 .appendTo(this.$buttongroup)
169 .on('click', function(e){
165 .on('click', function(e){
170 that.model.set('value', $(e.target).html(), this);
166 that.model.set('value', $(e.target).html(), this);
171 that.model.apply();
167 that.model.apply();
172 });
168 });
173 }
169 }
174
170
175 if (this.model.get('value') == items[index]) {
171 if (this.model.get('value') == items[index]) {
176 this.$buttongroup.find(item_query).addClass('active');
172 this.$buttongroup.find(item_query).addClass('active');
177 } else {
173 } else {
178 this.$buttongroup.find(item_query).removeClass('active');
174 this.$buttongroup.find(item_query).removeClass('active');
179 }
175 }
180 }
176 }
181
177
182 // Remove items that no longer exist.
178 // Remove items that no longer exist.
183 this.$buttongroup.find('button').each(function(i, obj) {
179 this.$buttongroup.find('button').each(function(i, obj) {
184 var value = $(obj).html();
180 var value = $(obj).html();
185 var found = false;
181 var found = false;
186 for (var index in items) {
182 for (var index in items) {
187 if (items[index] == value) {
183 if (items[index] == value) {
188 found = true;
184 found = true;
189 break;
185 break;
190 }
186 }
191 }
187 }
192
188
193 if (!found) {
189 if (!found) {
194 $(obj).remove();
190 $(obj).remove();
195 }
191 }
196 });
192 });
197 },
193 },
198
194
199 });
195 });
200
196
201 IPython.notebook.widget_manager.register_widget_view('ToggleButtonsView', ToggleButtonsView);
197 IPython.notebook.widget_manager.register_widget_view('ToggleButtonsView', ToggleButtonsView);
202 });
198 });
@@ -1,98 +1,95 b''
1 require(["notebook/js/widget"], function(){
1 require(["notebook/js/widget"], function(){
2 var StringWidgetModel = IPython.WidgetModel.extend({});
2 var StringWidgetModel = IPython.WidgetModel.extend({});
3 IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel);
3 IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel);
4
4
5 var LabelView = IPython.WidgetView.extend({
5 var LabelView = IPython.WidgetView.extend({
6
6
7 // Called when view is rendered.
7 // Called when view is rendered.
8 render : function(){
8 render : function(){
9 this.$el = $('<div />')
9 this.$el = $('<div />')
10 .addClass('widget_item')
11 .addClass(this.model.comm.comm_id);
10 .addClass(this.model.comm.comm_id);
12 this.update(); // Set defaults.
11 this.update(); // Set defaults.
13 },
12 },
14
13
15 // Handles: Backend -> Frontend Sync
14 // Handles: Backend -> Frontend Sync
16 // Frontent -> Frontend Sync
15 // Frontent -> Frontend Sync
17 update : function(){
16 update : function(){
18 this.$el.html(this.model.get('value'));
17 this.$el.html(this.model.get('value'));
19 },
18 },
20
19
21 });
20 });
22
21
23 IPython.notebook.widget_manager.register_widget_view('LabelView', LabelView);
22 IPython.notebook.widget_manager.register_widget_view('LabelView', LabelView);
24
23
25 var TextareaView = IPython.WidgetView.extend({
24 var TextareaView = IPython.WidgetView.extend({
26
25
27 // Called when view is rendered.
26 // Called when view is rendered.
28 render : function(){
27 render : function(){
29 this.$el
28 this.$el
30 .html('')
29 .html('')
31 .addClass('widget_item')
32 .addClass(this.model.comm.comm_id);
30 .addClass(this.model.comm.comm_id);
33 this.$textbox = $('<textarea />')
31 this.$textbox = $('<textarea />')
34 .attr('rows', 5)
32 .attr('rows', 5)
35 .appendTo(this.$el);
33 .appendTo(this.$el);
36 this.update(); // Set defaults.
34 this.update(); // Set defaults.
37 },
35 },
38
36
39 // Handles: Backend -> Frontend Sync
37 // Handles: Backend -> Frontend Sync
40 // Frontent -> Frontend Sync
38 // Frontent -> Frontend Sync
41 update : function(){
39 update : function(){
42 if (!this.user_invoked_update) {
40 if (!this.user_invoked_update) {
43 this.$textbox.val(this.model.get('value'));
41 this.$textbox.val(this.model.get('value'));
44 }
42 }
45 },
43 },
46
44
47 events: {"keyup textarea" : "handleChanging",
45 events: {"keyup textarea" : "handleChanging",
48 "paste textarea" : "handleChanging",
46 "paste textarea" : "handleChanging",
49 "cut textarea" : "handleChanging"},
47 "cut textarea" : "handleChanging"},
50
48
51 // Handles and validates user input.
49 // Handles and validates user input.
52 handleChanging: function(e) {
50 handleChanging: function(e) {
53 this.user_invoked_update = true;
51 this.user_invoked_update = true;
54 this.model.set('value', e.target.value);
52 this.model.set('value', e.target.value);
55 this.model.apply(this);
53 this.model.apply(this);
56 this.user_invoked_update = false;
54 this.user_invoked_update = false;
57 },
55 },
58 });
56 });
59
57
60 IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView);
58 IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView);
61
59
62 var TextboxView = IPython.WidgetView.extend({
60 var TextboxView = IPython.WidgetView.extend({
63
61
64 // Called when view is rendered.
62 // Called when view is rendered.
65 render : function(){
63 render : function(){
66 this.$el
64 this.$el
67 .html('')
65 .html('')
68 .addClass('widget_item')
69 .addClass(this.model.comm.comm_id);
66 .addClass(this.model.comm.comm_id);
70 this.$textbox = $('<input type="text" />')
67 this.$textbox = $('<input type="text" />')
71 .addClass('input')
68 .addClass('input')
72 .appendTo(this.$el);
69 .appendTo(this.$el);
73 this.update(); // Set defaults.
70 this.update(); // Set defaults.
74 },
71 },
75
72
76 // Handles: Backend -> Frontend Sync
73 // Handles: Backend -> Frontend Sync
77 // Frontent -> Frontend Sync
74 // Frontent -> Frontend Sync
78 update : function(){
75 update : function(){
79 if (!this.user_invoked_update) {
76 if (!this.user_invoked_update) {
80 this.$textbox.val(this.model.get('value'));
77 this.$textbox.val(this.model.get('value'));
81 }
78 }
82 },
79 },
83
80
84 events: {"keyup input" : "handleChanging",
81 events: {"keyup input" : "handleChanging",
85 "paste input" : "handleChanging",
82 "paste input" : "handleChanging",
86 "cut input" : "handleChanging"},
83 "cut input" : "handleChanging"},
87
84
88 // Handles and validates user input.
85 // Handles and validates user input.
89 handleChanging: function(e) {
86 handleChanging: function(e) {
90 this.user_invoked_update = true;
87 this.user_invoked_update = true;
91 this.model.set('value', e.target.value);
88 this.model.set('value', e.target.value);
92 this.model.apply(this);
89 this.model.apply(this);
93 this.user_invoked_update = false;
90 this.user_invoked_update = false;
94 },
91 },
95 });
92 });
96
93
97 IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView);
94 IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView);
98 });
95 });
General Comments 0
You need to be logged in to leave comments. Login now