Show More
@@ -1,2 +1,17 b'' | |||||
1 | var ContainerModel = IPython.WidgetModel.extend({}); |
|
1 | var ContainerModel = IPython.WidgetModel.extend({}); | |
2 | IPython.notebook.widget_manager.register_widget_model('container_widget', ContainerModel); |
|
2 | IPython.notebook.widget_manager.register_widget_model('container_widget', ContainerModel); | |
|
3 | ||||
|
4 | var ContainerView = IPython.WidgetView.extend({ | |||
|
5 | ||||
|
6 | render : function(){ | |||
|
7 | this.$el.html(''); | |||
|
8 | this.$container = $('<div />') | |||
|
9 | .addClass('container') | |||
|
10 | .addClass(this.model.comm.comm_id); | |||
|
11 | this.$el.append(this.$container); | |||
|
12 | }, | |||
|
13 | ||||
|
14 | update : function(){}, | |||
|
15 | }); | |||
|
16 | ||||
|
17 | IPython.notebook.widget_manager.register_widget_view('ContainerView', ContainerView); |
@@ -1,2 +1,119 b'' | |||||
1 | var FloatRangeWidgetModel = IPython.WidgetModel.extend({}); |
|
1 | var FloatRangeWidgetModel = IPython.WidgetModel.extend({}); | |
2 | IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel); |
|
2 | IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel); | |
|
3 | ||||
|
4 | var FloatSliderView = IPython.WidgetView.extend({ | |||
|
5 | ||||
|
6 | // Called when view is rendered. | |||
|
7 | render : function(){ | |||
|
8 | this.$el | |||
|
9 | .html('') | |||
|
10 | .addClass(this.model.comm.comm_id); | |||
|
11 | this.$slider = $('<div />') | |||
|
12 | .slider({}) | |||
|
13 | .addClass('slider'); | |||
|
14 | ||||
|
15 | // Put the slider in a container | |||
|
16 | this.$slider_container = $('<div />') | |||
|
17 | .css('padding-top', '4px') | |||
|
18 | .css('padding-bottom', '4px') | |||
|
19 | .append(this.$slider); | |||
|
20 | this.$el.append(this.$slider_container); | |||
|
21 | ||||
|
22 | // Set defaults. | |||
|
23 | this.update(); | |||
|
24 | }, | |||
|
25 | ||||
|
26 | // Handles: Backend -> Frontend Sync | |||
|
27 | // Frontent -> Frontend Sync | |||
|
28 | update : function(){ | |||
|
29 | // Slider related keys. | |||
|
30 | var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation']; | |||
|
31 | for (var index in _keys) { | |||
|
32 | var key = _keys[index]; | |||
|
33 | if (this.model.get(key) != undefined) { | |||
|
34 | this.$slider.slider("option", key, this.model.get(key)); | |||
|
35 | } | |||
|
36 | } | |||
|
37 | }, | |||
|
38 | ||||
|
39 | // Handles: User input | |||
|
40 | events: { "slide" : "handleSliderChange" }, | |||
|
41 | handleSliderChange: function(e, ui) { | |||
|
42 | this.model.set('value', ui.value); | |||
|
43 | this.model.apply(this); | |||
|
44 | }, | |||
|
45 | }); | |||
|
46 | ||||
|
47 | IPython.notebook.widget_manager.register_widget_view('FloatSliderView', FloatSliderView); | |||
|
48 | ||||
|
49 | ||||
|
50 | var FloatTextView = IPython.WidgetView.extend({ | |||
|
51 | ||||
|
52 | // Called when view is rendered. | |||
|
53 | render : function(){ | |||
|
54 | this.$el | |||
|
55 | .html('') | |||
|
56 | .addClass(this.model.comm.comm_id); | |||
|
57 | this.$textbox = $('<input type="text" />') | |||
|
58 | .addClass('input') | |||
|
59 | .appendTo(this.$el); | |||
|
60 | this.update(); // Set defaults. | |||
|
61 | }, | |||
|
62 | ||||
|
63 | // Handles: Backend -> Frontend Sync | |||
|
64 | // Frontent -> Frontend Sync | |||
|
65 | update : function(){ | |||
|
66 | var value = this.model.get('value'); | |||
|
67 | if (!this.changing && parseFloat(this.$textbox.val()) != value) { | |||
|
68 | this.$textbox.val(value); | |||
|
69 | } | |||
|
70 | ||||
|
71 | if (this.model.get('disabled')) { | |||
|
72 | this.$textbox.attr('disabled','disabled'); | |||
|
73 | } else { | |||
|
74 | this.$textbox.removeAttr('disabled'); | |||
|
75 | } | |||
|
76 | }, | |||
|
77 | ||||
|
78 | ||||
|
79 | events: {"keyup input" : "handleChanging", | |||
|
80 | "paste input" : "handleChanging", | |||
|
81 | "cut input" : "handleChanging", | |||
|
82 | "change input" : "handleChanged"}, // Fires only when control is validated or looses focus. | |||
|
83 | ||||
|
84 | // Handles and validates user input. | |||
|
85 | handleChanging: function(e) { | |||
|
86 | ||||
|
87 | // Try to parse value as a float. | |||
|
88 | var numericalValue = 0.0; | |||
|
89 | if (e.target.value != '') { | |||
|
90 | numericalValue = parseFloat(e.target.value); | |||
|
91 | } | |||
|
92 | ||||
|
93 | // If parse failed, reset value to value stored in model. | |||
|
94 | if (isNaN(numericalValue)) { | |||
|
95 | e.target.value = this.model.get('value'); | |||
|
96 | } else if (!isNaN(numericalValue)) { | |||
|
97 | numericalValue = Math.min(this.model.get('max'), numericalValue); | |||
|
98 | numericalValue = Math.max(this.model.get('min'), numericalValue); | |||
|
99 | ||||
|
100 | // Apply the value if it has changed. | |||
|
101 | if (numericalValue != this.model.get('value')) { | |||
|
102 | this.changing = true; | |||
|
103 | this.model.set('value', numericalValue); | |||
|
104 | this.model.apply(this); | |||
|
105 | this.changing = false; | |||
|
106 | } | |||
|
107 | } | |||
|
108 | }, | |||
|
109 | ||||
|
110 | // Applies validated input. | |||
|
111 | handleChanged: function(e) { | |||
|
112 | // Update the textbox | |||
|
113 | if (this.model.get('value') != e.target.value) { | |||
|
114 | e.target.value = this.model.get('value'); | |||
|
115 | } | |||
|
116 | } | |||
|
117 | }); | |||
|
118 | ||||
|
119 | IPython.notebook.widget_manager.register_widget_view('FloatTextView', FloatTextView); |
@@ -1,2 +1,117 b'' | |||||
1 | var IntRangeWidgetModel = IPython.WidgetModel.extend({}); |
|
1 | var IntRangeWidgetModel = IPython.WidgetModel.extend({}); | |
2 | IPython.notebook.widget_manager.register_widget_model('IntRangeWidgetModel', IntRangeWidgetModel); |
|
2 | IPython.notebook.widget_manager.register_widget_model('IntRangeWidgetModel', IntRangeWidgetModel); | |
|
3 | ||||
|
4 | var IntSliderView = IPython.WidgetView.extend({ | |||
|
5 | ||||
|
6 | // Called when view is rendered. | |||
|
7 | render : function(){ | |||
|
8 | this.$el.html(''); | |||
|
9 | this.$slider = $('<div />') | |||
|
10 | .slider({}) | |||
|
11 | .addClass('slider'); | |||
|
12 | ||||
|
13 | // Put the slider in a container | |||
|
14 | this.$slider_container = $('<div />') | |||
|
15 | .css('padding-top', '4px') | |||
|
16 | .css('padding-bottom', '4px') | |||
|
17 | .addClass(this.model.comm.comm_id) | |||
|
18 | .append(this.$slider); | |||
|
19 | this.$el.append(this.$slider_container); | |||
|
20 | ||||
|
21 | // Set defaults. | |||
|
22 | this.update(); | |||
|
23 | }, | |||
|
24 | ||||
|
25 | // Handles: Backend -> Frontend Sync | |||
|
26 | // Frontent -> Frontend Sync | |||
|
27 | update : function(){ | |||
|
28 | // Slider related keys. | |||
|
29 | var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation']; | |||
|
30 | for (var index in _keys) { | |||
|
31 | var key = _keys[index]; | |||
|
32 | if (this.model.get(key) != undefined) { | |||
|
33 | this.$slider.slider("option", key, this.model.get(key)); | |||
|
34 | } | |||
|
35 | } | |||
|
36 | }, | |||
|
37 | ||||
|
38 | // Handles: User input | |||
|
39 | events: { "slide" : "handleSliderChange" }, | |||
|
40 | handleSliderChange: function(e, ui) { | |||
|
41 | this.model.set('value', ~~ui.value); // Double bit-wise not to truncate decimel | |||
|
42 | this.model.apply(this); | |||
|
43 | }, | |||
|
44 | }); | |||
|
45 | ||||
|
46 | IPython.notebook.widget_manager.register_widget_view('IntSliderView', IntSliderView); | |||
|
47 | ||||
|
48 | var IntTextView = IPython.WidgetView.extend({ | |||
|
49 | ||||
|
50 | // Called when view is rendered. | |||
|
51 | render : function(){ | |||
|
52 | this.$el | |||
|
53 | .html('') | |||
|
54 | .addClass(this.model.comm.comm_id); | |||
|
55 | this.$textbox = $('<input type="text" />') | |||
|
56 | .addClass('input') | |||
|
57 | .appendTo(this.$el); | |||
|
58 | this.update(); // Set defaults. | |||
|
59 | }, | |||
|
60 | ||||
|
61 | // Handles: Backend -> Frontend Sync | |||
|
62 | // Frontent -> Frontend Sync | |||
|
63 | update : function(){ | |||
|
64 | var value = this.model.get('value'); | |||
|
65 | if (!this.changing && parseInt(this.$textbox.val()) != value) { | |||
|
66 | this.$textbox.val(value); | |||
|
67 | } | |||
|
68 | ||||
|
69 | if (this.model.get('disabled')) { | |||
|
70 | this.$textbox.attr('disabled','disabled'); | |||
|
71 | } else { | |||
|
72 | this.$textbox.removeAttr('disabled'); | |||
|
73 | } | |||
|
74 | }, | |||
|
75 | ||||
|
76 | ||||
|
77 | events: {"keyup input" : "handleChanging", | |||
|
78 | "paste input" : "handleChanging", | |||
|
79 | "cut input" : "handleChanging", | |||
|
80 | "change input" : "handleChanged"}, // Fires only when control is validated or looses focus. | |||
|
81 | ||||
|
82 | // Handles and validates user input. | |||
|
83 | handleChanging: function(e) { | |||
|
84 | ||||
|
85 | // Try to parse value as a float. | |||
|
86 | var numericalValue = 0; | |||
|
87 | if (e.target.value != '') { | |||
|
88 | numericalValue = parseInt(e.target.value); | |||
|
89 | } | |||
|
90 | ||||
|
91 | // If parse failed, reset value to value stored in model. | |||
|
92 | if (isNaN(numericalValue)) { | |||
|
93 | e.target.value = this.model.get('value'); | |||
|
94 | } else if (!isNaN(numericalValue)) { | |||
|
95 | numericalValue = Math.min(this.model.get('max'), numericalValue); | |||
|
96 | numericalValue = Math.max(this.model.get('min'), numericalValue); | |||
|
97 | ||||
|
98 | // Apply the value if it has changed. | |||
|
99 | if (numericalValue != this.model.get('value')) { | |||
|
100 | this.changing = true; | |||
|
101 | this.model.set('value', numericalValue); | |||
|
102 | this.model.apply(this); | |||
|
103 | this.changing = false; | |||
|
104 | } | |||
|
105 | } | |||
|
106 | }, | |||
|
107 | ||||
|
108 | // Applies validated input. | |||
|
109 | handleChanged: function(e) { | |||
|
110 | // Update the textbox | |||
|
111 | if (this.model.get('value') != e.target.value) { | |||
|
112 | e.target.value = this.model.get('value'); | |||
|
113 | } | |||
|
114 | } | |||
|
115 | }); | |||
|
116 | ||||
|
117 | IPython.notebook.widget_manager.register_widget_view('IntTextView', IntTextView); |
@@ -1,2 +1,128 b'' | |||||
1 | var SelectionWidgetModel = IPython.WidgetModel.extend({}); |
|
1 | var SelectionWidgetModel = IPython.WidgetModel.extend({}); | |
2 | IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel); |
|
2 | IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel); | |
|
3 | ||||
|
4 | var DropdownView = IPython.WidgetView.extend({ | |||
|
5 | ||||
|
6 | // Called when view is rendered. | |||
|
7 | render : function(){ | |||
|
8 | ||||
|
9 | this.$el | |||
|
10 | .html('') | |||
|
11 | .addClass(this.model.comm.comm_id); | |||
|
12 | this.$buttongroup = $('<div />') | |||
|
13 | .addClass('btn-group') | |||
|
14 | .appendTo(this.$el); | |||
|
15 | this.$droplabel = $('<button />') | |||
|
16 | .addClass('btn') | |||
|
17 | .appendTo(this.$buttongroup); | |||
|
18 | this.$dropbutton = $('<button />') | |||
|
19 | .addClass('btn') | |||
|
20 | .addClass('dropdown-toggle') | |||
|
21 | .attr('data-toggle', 'dropdown') | |||
|
22 | .html('<span class="caret"></span>') | |||
|
23 | .appendTo(this.$buttongroup); | |||
|
24 | this.$droplist = $('<ul />') | |||
|
25 | .addClass('dropdown-menu') | |||
|
26 | .appendTo(this.$buttongroup); | |||
|
27 | ||||
|
28 | // Set defaults. | |||
|
29 | this.update(); | |||
|
30 | }, | |||
|
31 | ||||
|
32 | // Handles: Backend -> Frontend Sync | |||
|
33 | // Frontent -> Frontend Sync | |||
|
34 | update : function(){ | |||
|
35 | this.$droplabel.html(this.model.get('value')); | |||
|
36 | ||||
|
37 | var items = this.model.get('values'); | |||
|
38 | this.$droplist.html(''); | |||
|
39 | for (var index in items) { | |||
|
40 | var that = this; | |||
|
41 | var item_button = $('<a href="#"/>') | |||
|
42 | .html(items[index]) | |||
|
43 | .on('click', function(e){ | |||
|
44 | that.model.set('value', $(e.target).html(), this ); | |||
|
45 | }) | |||
|
46 | ||||
|
47 | this.$droplist.append($('<li />').append(item_button)) | |||
|
48 | } | |||
|
49 | ||||
|
50 | if (this.model.get('disabled')) { | |||
|
51 | this.$buttongroup.attr('disabled','disabled'); | |||
|
52 | this.$droplabel.attr('disabled','disabled'); | |||
|
53 | this.$dropbutton.attr('disabled','disabled'); | |||
|
54 | this.$droplist.attr('disabled','disabled'); | |||
|
55 | } else { | |||
|
56 | this.$buttongroup.removeAttr('disabled'); | |||
|
57 | this.$droplabel.removeAttr('disabled'); | |||
|
58 | this.$dropbutton.removeAttr('disabled'); | |||
|
59 | this.$droplist.removeAttr('disabled'); | |||
|
60 | } | |||
|
61 | }, | |||
|
62 | ||||
|
63 | }); | |||
|
64 | ||||
|
65 | IPython.notebook.widget_manager.register_widget_view('DropdownView', DropdownView); | |||
|
66 | var RadioButtonView = IPython.WidgetView.extend({ | |||
|
67 | ||||
|
68 | // Called when view is rendered. | |||
|
69 | render : function(){ | |||
|
70 | this.$el | |||
|
71 | .html('') | |||
|
72 | .addClass(this.model.comm.comm_id); | |||
|
73 | this.update(); | |||
|
74 | }, | |||
|
75 | ||||
|
76 | // Handles: Backend -> Frontend Sync | |||
|
77 | // Frontent -> Frontend Sync | |||
|
78 | update : function(){ | |||
|
79 | ||||
|
80 | // Add missing items to the DOM. | |||
|
81 | var items = this.model.get('values'); | |||
|
82 | for (var index in items) { | |||
|
83 | var item_query = ' :input[value="' + items[index] + '"]'; | |||
|
84 | if (this.$el.find(item_query).length == 0) { | |||
|
85 | var $label = $('<label />') | |||
|
86 | .addClass('radio') | |||
|
87 | .html(items[index]) | |||
|
88 | .appendTo(this.$el); | |||
|
89 | ||||
|
90 | var that = this; | |||
|
91 | $('<input />') | |||
|
92 | .attr('type', 'radio') | |||
|
93 | .addClass(this.model) | |||
|
94 | .val(items[index]) | |||
|
95 | .prependTo($label) | |||
|
96 | .on('click', function(e){ | |||
|
97 | that.model.set('value', $(e.target).val(), this); | |||
|
98 | that.model.apply(); | |||
|
99 | }); | |||
|
100 | } | |||
|
101 | ||||
|
102 | if (this.model.get('value') == items[index]) { | |||
|
103 | this.$el.find(item_query).prop('checked', true); | |||
|
104 | } else { | |||
|
105 | this.$el.find(item_query).prop('checked', false); | |||
|
106 | } | |||
|
107 | } | |||
|
108 | ||||
|
109 | // Remove items that no longer exist. | |||
|
110 | this.$el.find('input').each(function(i, obj) { | |||
|
111 | var value = $(obj).val(); | |||
|
112 | var found = false; | |||
|
113 | for (var index in items) { | |||
|
114 | if (items[index] == value) { | |||
|
115 | found = true; | |||
|
116 | break; | |||
|
117 | } | |||
|
118 | } | |||
|
119 | ||||
|
120 | if (!found) { | |||
|
121 | $(obj).parent().remove(); | |||
|
122 | } | |||
|
123 | }); | |||
|
124 | }, | |||
|
125 | ||||
|
126 | }); | |||
|
127 | ||||
|
128 | IPython.notebook.widget_manager.register_widget_view('RadioButtonView', RadioButtonView); |
@@ -1,2 +1,74 b'' | |||||
1 | var StringWidgetModel = IPython.WidgetModel.extend({}); |
|
1 | var StringWidgetModel = IPython.WidgetModel.extend({}); | |
2 | IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel); |
|
2 | IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel); | |
|
3 | ||||
|
4 | var TextareaView = IPython.WidgetView.extend({ | |||
|
5 | ||||
|
6 | // Called when view is rendered. | |||
|
7 | render : function(){ | |||
|
8 | this.$el | |||
|
9 | .html('') | |||
|
10 | .addClass(this.model.comm.comm_id); | |||
|
11 | this.$textbox = $('<textarea />') | |||
|
12 | .attr('rows', 5) | |||
|
13 | .appendTo(this.$el); | |||
|
14 | this.update(); // Set defaults. | |||
|
15 | }, | |||
|
16 | ||||
|
17 | // Handles: Backend -> Frontend Sync | |||
|
18 | // Frontent -> Frontend Sync | |||
|
19 | update : function(){ | |||
|
20 | if (!this.user_invoked_update) { | |||
|
21 | this.$textbox.val(this.model.get('value')); | |||
|
22 | } | |||
|
23 | }, | |||
|
24 | ||||
|
25 | events: {"keyup textarea" : "handleChanging", | |||
|
26 | "paste textarea" : "handleChanging", | |||
|
27 | "cut textarea" : "handleChanging"}, | |||
|
28 | ||||
|
29 | // Handles and validates user input. | |||
|
30 | handleChanging: function(e) { | |||
|
31 | this.user_invoked_update = true; | |||
|
32 | this.model.set('value', e.target.value); | |||
|
33 | this.model.apply(this); | |||
|
34 | this.user_invoked_update = false; | |||
|
35 | }, | |||
|
36 | }); | |||
|
37 | ||||
|
38 | IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView); | |||
|
39 | ||||
|
40 | var TextboxView = IPython.WidgetView.extend({ | |||
|
41 | ||||
|
42 | // Called when view is rendered. | |||
|
43 | render : function(){ | |||
|
44 | this.$el | |||
|
45 | .html('') | |||
|
46 | .addClass(this.model.comm.comm_id); | |||
|
47 | this.$textbox = $('<input type="text" />') | |||
|
48 | .addClass('input') | |||
|
49 | .appendTo(this.$el); | |||
|
50 | this.update(); // Set defaults. | |||
|
51 | }, | |||
|
52 | ||||
|
53 | // Handles: Backend -> Frontend Sync | |||
|
54 | // Frontent -> Frontend Sync | |||
|
55 | update : function(){ | |||
|
56 | if (!this.user_invoked_update) { | |||
|
57 | this.$textbox.val(this.model.get('value')); | |||
|
58 | } | |||
|
59 | }, | |||
|
60 | ||||
|
61 | events: {"keyup input" : "handleChanging", | |||
|
62 | "paste input" : "handleChanging", | |||
|
63 | "cut input" : "handleChanging"}, | |||
|
64 | ||||
|
65 | // Handles and validates user input. | |||
|
66 | handleChanging: function(e) { | |||
|
67 | this.user_invoked_update = true; | |||
|
68 | this.model.set('value', e.target.value); | |||
|
69 | this.model.apply(this); | |||
|
70 | this.user_invoked_update = false; | |||
|
71 | }, | |||
|
72 | }); | |||
|
73 | ||||
|
74 | IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView); |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now