diff --git a/IPython/html/static/notebook/js/widgets/model_container.js b/IPython/html/static/notebook/js/widgets/model_container.js index a4f1325..b0a0cf7 100644 --- a/IPython/html/static/notebook/js/widgets/model_container.js +++ b/IPython/html/static/notebook/js/widgets/model_container.js @@ -1,17 +1,19 @@ -var ContainerModel = IPython.WidgetModel.extend({}); -IPython.notebook.widget_manager.register_widget_model('container_widget', ContainerModel); +require(["notebook/js/widget"], function () { + var ContainerModel = IPython.WidgetModel.extend({}); + IPython.notebook.widget_manager.register_widget_model('container_widget', ContainerModel); -var ContainerView = IPython.WidgetView.extend({ - - render : function(){ - this.$el.html(''); - this.$container = $('<div />') - .addClass('container') - .addClass(this.model.comm.comm_id); - this.$el.append(this.$container); - }, - - update : function(){}, -}); + var ContainerView = IPython.WidgetView.extend({ + + render : function(){ + this.$el.html(''); + this.$container = $('<div />') + .addClass('container') + .addClass(this.model.comm.comm_id); + this.$el.append(this.$container); + }, + + update : function(){}, + }); -IPython.notebook.widget_manager.register_widget_view('ContainerView', ContainerView); + IPython.notebook.widget_manager.register_widget_view('ContainerView', ContainerView); +}); \ No newline at end of file diff --git a/IPython/html/static/notebook/js/widgets/model_float_range.js b/IPython/html/static/notebook/js/widgets/model_float_range.js index 0fc5366..8992097 100644 --- a/IPython/html/static/notebook/js/widgets/model_float_range.js +++ b/IPython/html/static/notebook/js/widgets/model_float_range.js @@ -1,119 +1,121 @@ -var FloatRangeWidgetModel = IPython.WidgetModel.extend({}); -IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel); +require(["notebook/js/widget"], function () { + var FloatRangeWidgetModel = IPython.WidgetModel.extend({}); + IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel); -var FloatSliderView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.$slider = $('<div />') - .slider({}) - .addClass('slider'); + var FloatSliderView = IPython.WidgetView.extend({ - // Put the slider in a container - this.$slider_container = $('<div />') - .css('padding-top', '4px') - .css('padding-bottom', '4px') - .append(this.$slider); - this.$el.append(this.$slider_container); + // Called when view is rendered. + render : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.$slider = $('<div />') + .slider({}) + .addClass('slider'); + + // Put the slider in a container + this.$slider_container = $('<div />') + .css('padding-top', '4px') + .css('padding-bottom', '4px') + .append(this.$slider); + this.$el.append(this.$slider_container); + + // Set defaults. + this.update(); + }, - // Set defaults. - this.update(); - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - // Slider related keys. - var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation']; - for (var index in _keys) { - var key = _keys[index]; - if (this.model.get(key) != undefined) { - this.$slider.slider("option", key, this.model.get(key)); + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + // Slider related keys. + var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation']; + for (var index in _keys) { + var key = _keys[index]; + if (this.model.get(key) != undefined) { + this.$slider.slider("option", key, this.model.get(key)); + } } - } - }, - - // Handles: User input - events: { "slide" : "handleSliderChange" }, - handleSliderChange: function(e, ui) { - this.model.set('value', ui.value); - this.model.apply(this); - }, -}); + }, + + // Handles: User input + events: { "slide" : "handleSliderChange" }, + handleSliderChange: function(e, ui) { + this.model.set('value', ui.value); + this.model.apply(this); + }, + }); -IPython.notebook.widget_manager.register_widget_view('FloatSliderView', FloatSliderView); + IPython.notebook.widget_manager.register_widget_view('FloatSliderView', FloatSliderView); -var FloatTextView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.$textbox = $('<input type="text" />') - .addClass('input') - .appendTo(this.$el); - this.update(); // Set defaults. - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - var value = this.model.get('value'); - if (!this.changing && parseFloat(this.$textbox.val()) != value) { - this.$textbox.val(value); - } + var FloatTextView = IPython.WidgetView.extend({ - if (this.model.get('disabled')) { - this.$textbox.attr('disabled','disabled'); - } else { - this.$textbox.removeAttr('disabled'); - } - }, - - - events: {"keyup input" : "handleChanging", - "paste input" : "handleChanging", - "cut input" : "handleChanging", - "change input" : "handleChanged"}, // Fires only when control is validated or looses focus. - - // Handles and validates user input. - handleChanging: function(e) { + // Called when view is rendered. + render : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.$textbox = $('<input type="text" />') + .addClass('input') + .appendTo(this.$el); + this.update(); // Set defaults. + }, + + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + var value = this.model.get('value'); + if (!this.changing && parseFloat(this.$textbox.val()) != value) { + this.$textbox.val(value); + } + + if (this.model.get('disabled')) { + this.$textbox.attr('disabled','disabled'); + } else { + this.$textbox.removeAttr('disabled'); + } + }, - // Try to parse value as a float. - var numericalValue = 0.0; - if (e.target.value != '') { - numericalValue = parseFloat(e.target.value); - } - // If parse failed, reset value to value stored in model. - if (isNaN(numericalValue)) { - e.target.value = this.model.get('value'); - } else if (!isNaN(numericalValue)) { - numericalValue = Math.min(this.model.get('max'), numericalValue); - numericalValue = Math.max(this.model.get('min'), numericalValue); + events: {"keyup input" : "handleChanging", + "paste input" : "handleChanging", + "cut input" : "handleChanging", + "change input" : "handleChanged"}, // Fires only when control is validated or looses focus. + + // Handles and validates user input. + handleChanging: function(e) { - // Apply the value if it has changed. - if (numericalValue != this.model.get('value')) { - this.changing = true; - this.model.set('value', numericalValue); - this.model.apply(this); - this.changing = false; + // Try to parse value as a float. + var numericalValue = 0.0; + if (e.target.value != '') { + numericalValue = parseFloat(e.target.value); + } + + // If parse failed, reset value to value stored in model. + if (isNaN(numericalValue)) { + e.target.value = this.model.get('value'); + } else if (!isNaN(numericalValue)) { + numericalValue = Math.min(this.model.get('max'), numericalValue); + numericalValue = Math.max(this.model.get('min'), numericalValue); + + // Apply the value if it has changed. + if (numericalValue != this.model.get('value')) { + this.changing = true; + this.model.set('value', numericalValue); + this.model.apply(this); + this.changing = false; + } + } + }, + + // Applies validated input. + handleChanged: function(e) { + // Update the textbox + if (this.model.get('value') != e.target.value) { + e.target.value = this.model.get('value'); } } - }, - - // Applies validated input. - handleChanged: function(e) { - // Update the textbox - if (this.model.get('value') != e.target.value) { - e.target.value = this.model.get('value'); - } - } -}); + }); -IPython.notebook.widget_manager.register_widget_view('FloatTextView', FloatTextView); + IPython.notebook.widget_manager.register_widget_view('FloatTextView', FloatTextView); +}); \ No newline at end of file diff --git a/IPython/html/static/notebook/js/widgets/model_int_range.js b/IPython/html/static/notebook/js/widgets/model_int_range.js index 996aeec..bf71c6c 100644 --- a/IPython/html/static/notebook/js/widgets/model_int_range.js +++ b/IPython/html/static/notebook/js/widgets/model_int_range.js @@ -1,117 +1,119 @@ -var IntRangeWidgetModel = IPython.WidgetModel.extend({}); -IPython.notebook.widget_manager.register_widget_model('IntRangeWidgetModel', IntRangeWidgetModel); +require(["notebook/js/widget"], function () { + var IntRangeWidgetModel = IPython.WidgetModel.extend({}); + IPython.notebook.widget_manager.register_widget_model('IntRangeWidgetModel', IntRangeWidgetModel); -var IntSliderView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el.html(''); - this.$slider = $('<div />') - .slider({}) - .addClass('slider'); + var IntSliderView = IPython.WidgetView.extend({ - // Put the slider in a container - this.$slider_container = $('<div />') - .css('padding-top', '4px') - .css('padding-bottom', '4px') - .addClass(this.model.comm.comm_id) - .append(this.$slider); - this.$el.append(this.$slider_container); + // Called when view is rendered. + render : function(){ + this.$el.html(''); + this.$slider = $('<div />') + .slider({}) + .addClass('slider'); + + // Put the slider in a container + this.$slider_container = $('<div />') + .css('padding-top', '4px') + .css('padding-bottom', '4px') + .addClass(this.model.comm.comm_id) + .append(this.$slider); + this.$el.append(this.$slider_container); + + // Set defaults. + this.update(); + }, - // Set defaults. - this.update(); - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - // Slider related keys. - var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation']; - for (var index in _keys) { - var key = _keys[index]; - if (this.model.get(key) != undefined) { - this.$slider.slider("option", key, this.model.get(key)); + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + // Slider related keys. + var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation']; + for (var index in _keys) { + var key = _keys[index]; + if (this.model.get(key) != undefined) { + this.$slider.slider("option", key, this.model.get(key)); + } } - } - }, - - // Handles: User input - events: { "slide" : "handleSliderChange" }, - handleSliderChange: function(e, ui) { - this.model.set('value', ~~ui.value); // Double bit-wise not to truncate decimel - this.model.apply(this); - }, -}); + }, + + // Handles: User input + events: { "slide" : "handleSliderChange" }, + handleSliderChange: function(e, ui) { + this.model.set('value', ~~ui.value); // Double bit-wise not to truncate decimel + this.model.apply(this); + }, + }); -IPython.notebook.widget_manager.register_widget_view('IntSliderView', IntSliderView); + IPython.notebook.widget_manager.register_widget_view('IntSliderView', IntSliderView); -var IntTextView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.$textbox = $('<input type="text" />') - .addClass('input') - .appendTo(this.$el); - this.update(); // Set defaults. - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - var value = this.model.get('value'); - if (!this.changing && parseInt(this.$textbox.val()) != value) { - this.$textbox.val(value); - } + var IntTextView = IPython.WidgetView.extend({ - if (this.model.get('disabled')) { - this.$textbox.attr('disabled','disabled'); - } else { - this.$textbox.removeAttr('disabled'); - } - }, - - - events: {"keyup input" : "handleChanging", - "paste input" : "handleChanging", - "cut input" : "handleChanging", - "change input" : "handleChanged"}, // Fires only when control is validated or looses focus. - - // Handles and validates user input. - handleChanging: function(e) { + // Called when view is rendered. + render : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.$textbox = $('<input type="text" />') + .addClass('input') + .appendTo(this.$el); + this.update(); // Set defaults. + }, + + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + var value = this.model.get('value'); + if (!this.changing && parseInt(this.$textbox.val()) != value) { + this.$textbox.val(value); + } + + if (this.model.get('disabled')) { + this.$textbox.attr('disabled','disabled'); + } else { + this.$textbox.removeAttr('disabled'); + } + }, - // Try to parse value as a float. - var numericalValue = 0; - if (e.target.value != '') { - numericalValue = parseInt(e.target.value); - } - // If parse failed, reset value to value stored in model. - if (isNaN(numericalValue)) { - e.target.value = this.model.get('value'); - } else if (!isNaN(numericalValue)) { - numericalValue = Math.min(this.model.get('max'), numericalValue); - numericalValue = Math.max(this.model.get('min'), numericalValue); + events: {"keyup input" : "handleChanging", + "paste input" : "handleChanging", + "cut input" : "handleChanging", + "change input" : "handleChanged"}, // Fires only when control is validated or looses focus. + + // Handles and validates user input. + handleChanging: function(e) { - // Apply the value if it has changed. - if (numericalValue != this.model.get('value')) { - this.changing = true; - this.model.set('value', numericalValue); - this.model.apply(this); - this.changing = false; + // Try to parse value as a float. + var numericalValue = 0; + if (e.target.value != '') { + numericalValue = parseInt(e.target.value); + } + + // If parse failed, reset value to value stored in model. + if (isNaN(numericalValue)) { + e.target.value = this.model.get('value'); + } else if (!isNaN(numericalValue)) { + numericalValue = Math.min(this.model.get('max'), numericalValue); + numericalValue = Math.max(this.model.get('min'), numericalValue); + + // Apply the value if it has changed. + if (numericalValue != this.model.get('value')) { + this.changing = true; + this.model.set('value', numericalValue); + this.model.apply(this); + this.changing = false; + } + } + }, + + // Applies validated input. + handleChanged: function(e) { + // Update the textbox + if (this.model.get('value') != e.target.value) { + e.target.value = this.model.get('value'); } } - }, - - // Applies validated input. - handleChanged: function(e) { - // Update the textbox - if (this.model.get('value') != e.target.value) { - e.target.value = this.model.get('value'); - } - } -}); + }); -IPython.notebook.widget_manager.register_widget_view('IntTextView', IntTextView); + IPython.notebook.widget_manager.register_widget_view('IntTextView', IntTextView); +}); \ No newline at end of file diff --git a/IPython/html/static/notebook/js/widgets/model_selection.js b/IPython/html/static/notebook/js/widgets/model_selection.js index e4eedb5..a7b0a97 100644 --- a/IPython/html/static/notebook/js/widgets/model_selection.js +++ b/IPython/html/static/notebook/js/widgets/model_selection.js @@ -1,128 +1,130 @@ -var SelectionWidgetModel = IPython.WidgetModel.extend({}); -IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel); +require(["notebook/js/widget"], function () { + var SelectionWidgetModel = IPython.WidgetModel.extend({}); + IPython.notebook.widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel); -var DropdownView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ + var DropdownView = IPython.WidgetView.extend({ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.$buttongroup = $('<div />') - .addClass('btn-group') - .appendTo(this.$el); - this.$droplabel = $('<button />') - .addClass('btn') - .appendTo(this.$buttongroup); - this.$dropbutton = $('<button />') - .addClass('btn') - .addClass('dropdown-toggle') - .attr('data-toggle', 'dropdown') - .html('<span class="caret"></span>') - .appendTo(this.$buttongroup); - this.$droplist = $('<ul />') - .addClass('dropdown-menu') - .appendTo(this.$buttongroup); - - // Set defaults. - this.update(); - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - this.$droplabel.html(this.model.get('value')); - - var items = this.model.get('values'); - this.$droplist.html(''); - for (var index in items) { - var that = this; - var item_button = $('<a href="#"/>') - .html(items[index]) - .on('click', function(e){ - that.model.set('value', $(e.target).html(), this ); - }) + // Called when view is rendered. + render : function(){ - this.$droplist.append($('<li />').append(item_button)) - } - - if (this.model.get('disabled')) { - this.$buttongroup.attr('disabled','disabled'); - this.$droplabel.attr('disabled','disabled'); - this.$dropbutton.attr('disabled','disabled'); - this.$droplist.attr('disabled','disabled'); - } else { - this.$buttongroup.removeAttr('disabled'); - this.$droplabel.removeAttr('disabled'); - this.$dropbutton.removeAttr('disabled'); - this.$droplist.removeAttr('disabled'); - } - }, - -}); - -IPython.notebook.widget_manager.register_widget_view('DropdownView', DropdownView); -var RadioButtonView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.update(); - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.$buttongroup = $('<div />') + .addClass('btn-group') + .appendTo(this.$el); + this.$droplabel = $('<button />') + .addClass('btn') + .appendTo(this.$buttongroup); + this.$dropbutton = $('<button />') + .addClass('btn') + .addClass('dropdown-toggle') + .attr('data-toggle', 'dropdown') + .html('<span class="caret"></span>') + .appendTo(this.$buttongroup); + this.$droplist = $('<ul />') + .addClass('dropdown-menu') + .appendTo(this.$buttongroup); + + // Set defaults. + this.update(); + }, - // Add missing items to the DOM. - var items = this.model.get('values'); - for (var index in items) { - var item_query = ' :input[value="' + items[index] + '"]'; - if (this.$el.find(item_query).length == 0) { - var $label = $('<label />') - .addClass('radio') - .html(items[index]) - .appendTo(this.$el); - + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + this.$droplabel.html(this.model.get('value')); + + var items = this.model.get('values'); + this.$droplist.html(''); + for (var index in items) { var that = this; - $('<input />') - .attr('type', 'radio') - .addClass(this.model) - .val(items[index]) - .prependTo($label) + var item_button = $('<a href="#"/>') + .html(items[index]) .on('click', function(e){ - that.model.set('value', $(e.target).val(), this); - that.model.apply(); - }); + that.model.set('value', $(e.target).html(), this ); + }) + + this.$droplist.append($('<li />').append(item_button)) } - if (this.model.get('value') == items[index]) { - this.$el.find(item_query).prop('checked', true); + if (this.model.get('disabled')) { + this.$buttongroup.attr('disabled','disabled'); + this.$droplabel.attr('disabled','disabled'); + this.$dropbutton.attr('disabled','disabled'); + this.$droplist.attr('disabled','disabled'); } else { - this.$el.find(item_query).prop('checked', false); + this.$buttongroup.removeAttr('disabled'); + this.$droplabel.removeAttr('disabled'); + this.$dropbutton.removeAttr('disabled'); + this.$droplist.removeAttr('disabled'); } - } + }, - // Remove items that no longer exist. - this.$el.find('input').each(function(i, obj) { - var value = $(obj).val(); - var found = false; + }); + + IPython.notebook.widget_manager.register_widget_view('DropdownView', DropdownView); + var RadioButtonView = IPython.WidgetView.extend({ + + // Called when view is rendered. + render : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.update(); + }, + + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + + // Add missing items to the DOM. + var items = this.model.get('values'); for (var index in items) { - if (items[index] == value) { - found = true; - break; + var item_query = ' :input[value="' + items[index] + '"]'; + if (this.$el.find(item_query).length == 0) { + var $label = $('<label />') + .addClass('radio') + .html(items[index]) + .appendTo(this.$el); + + var that = this; + $('<input />') + .attr('type', 'radio') + .addClass(this.model) + .val(items[index]) + .prependTo($label) + .on('click', function(e){ + that.model.set('value', $(e.target).val(), this); + that.model.apply(); + }); + } + + if (this.model.get('value') == items[index]) { + this.$el.find(item_query).prop('checked', true); + } else { + this.$el.find(item_query).prop('checked', false); } } - if (!found) { - $(obj).parent().remove(); - } - }); - }, - -}); + // Remove items that no longer exist. + this.$el.find('input').each(function(i, obj) { + var value = $(obj).val(); + var found = false; + for (var index in items) { + if (items[index] == value) { + found = true; + break; + } + } + + if (!found) { + $(obj).parent().remove(); + } + }); + }, + + }); -IPython.notebook.widget_manager.register_widget_view('RadioButtonView', RadioButtonView); + IPython.notebook.widget_manager.register_widget_view('RadioButtonView', RadioButtonView); +}); \ No newline at end of file diff --git a/IPython/html/static/notebook/js/widgets/model_string.js b/IPython/html/static/notebook/js/widgets/model_string.js index cc7c930..df345ac 100644 --- a/IPython/html/static/notebook/js/widgets/model_string.js +++ b/IPython/html/static/notebook/js/widgets/model_string.js @@ -1,74 +1,77 @@ -var StringWidgetModel = IPython.WidgetModel.extend({}); -IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel); +require(["notebook/js/widget"], function () { + var StringWidgetModel = IPython.WidgetModel.extend({}); + IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel); -var TextareaView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.$textbox = $('<textarea />') - .attr('rows', 5) - .appendTo(this.$el); - this.update(); // Set defaults. - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - if (!this.user_invoked_update) { - this.$textbox.val(this.model.get('value')); - } - }, - - events: {"keyup textarea" : "handleChanging", - "paste textarea" : "handleChanging", - "cut textarea" : "handleChanging"}, - - // Handles and validates user input. - handleChanging: function(e) { - this.user_invoked_update = true; - this.model.set('value', e.target.value); - this.model.apply(this); - this.user_invoked_update = false; - }, -}); + var TextareaView = IPython.WidgetView.extend({ + + // Called when view is rendered. + render : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.$textbox = $('<textarea />') + .attr('rows', 5) + .appendTo(this.$el); + this.update(); // Set defaults. + }, + + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + if (!this.user_invoked_update) { + this.$textbox.val(this.model.get('value')); + } + }, + + events: {"keyup textarea" : "handleChanging", + "paste textarea" : "handleChanging", + "cut textarea" : "handleChanging"}, + + // Handles and validates user input. + handleChanging: function(e) { + this.user_invoked_update = true; + this.model.set('value', e.target.value); + this.model.apply(this); + this.user_invoked_update = false; + }, + }); -IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView); + IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView); -var TextboxView = IPython.WidgetView.extend({ - - // Called when view is rendered. - render : function(){ - this.$el - .html('') - .addClass(this.model.comm.comm_id); - this.$textbox = $('<input type="text" />') - .addClass('input') - .appendTo(this.$el); - this.update(); // Set defaults. - }, - - // Handles: Backend -> Frontend Sync - // Frontent -> Frontend Sync - update : function(){ - if (!this.user_invoked_update) { - this.$textbox.val(this.model.get('value')); - } - }, - - events: {"keyup input" : "handleChanging", - "paste input" : "handleChanging", - "cut input" : "handleChanging"}, - - // Handles and validates user input. - handleChanging: function(e) { - this.user_invoked_update = true; - this.model.set('value', e.target.value); - this.model.apply(this); - this.user_invoked_update = false; - }, -}); + var TextboxView = IPython.WidgetView.extend({ + + // Called when view is rendered. + render : function(){ + this.$el + .html('') + .addClass(this.model.comm.comm_id); + this.$textbox = $('<input type="text" />') + .addClass('input') + .appendTo(this.$el); + this.update(); // Set defaults. + }, + + // Handles: Backend -> Frontend Sync + // Frontent -> Frontend Sync + update : function(){ + if (!this.user_invoked_update) { + this.$textbox.val(this.model.get('value')); + } + }, + + events: {"keyup input" : "handleChanging", + "paste input" : "handleChanging", + "cut input" : "handleChanging"}, + + // Handles and validates user input. + handleChanging: function(e) { + this.user_invoked_update = true; + this.model.set('value', e.target.value); + this.model.apply(this); + this.user_invoked_update = false; + }, + }); -IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView); + IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView); + +}); \ No newline at end of file