Show More
string.js
95 lines
| 3.2 KiB
| application/javascript
|
JavascriptLexer
|
r14278 | require(["../static/notebook/js/widget"], function(){ | ||
|
r14263 | var StringWidgetModel = IPython.WidgetModel.extend({}); | ||
IPython.notebook.widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel); | ||||
|
r14252 | |||
|
r14263 | var LabelView = IPython.WidgetView.extend({ | ||
// Called when view is rendered. | ||||
render : function(){ | ||||
|
r14278 | this.$el = $('<div />'); | ||
|
r14263 | this.update(); // Set defaults. | ||
}, | ||||
// Handles: Backend -> Frontend Sync | ||||
// Frontent -> Frontend Sync | ||||
update : function(){ | ||||
|
r14268 | this.$el.html(this.model.get('value')); | ||
|
r14279 | return IPython.WidgetView.prototype.update.call(this); | ||
|
r14263 | }, | ||
}); | ||||
|
r14252 | |||
|
r14263 | IPython.notebook.widget_manager.register_widget_view('LabelView', LabelView); | ||
|
r14252 | |||
|
r14263 | var TextareaView = IPython.WidgetView.extend({ | ||
// Called when view is rendered. | ||||
render : function(){ | ||||
this.$el | ||||
|
r14278 | .html(''); | ||
|
r14263 | 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')); | ||||
} | ||||
|
r14279 | return IPython.WidgetView.prototype.update.call(this); | ||
|
r14263 | }, | ||
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); | ||||
|
r14278 | this.model.update_other_views(this); | ||
|
r14263 | this.user_invoked_update = false; | ||
}, | ||||
}); | ||||
IPython.notebook.widget_manager.register_widget_view('TextareaView', TextareaView); | ||||
|
r14252 | |||
|
r14263 | var TextboxView = IPython.WidgetView.extend({ | ||
// Called when view is rendered. | ||||
render : function(){ | ||||
this.$el | ||||
|
r14278 | .html(''); | ||
|
r14263 | 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')); | ||||
} | ||||
|
r14279 | return IPython.WidgetView.prototype.update.call(this); | ||
|
r14263 | }, | ||
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); | ||||
|
r14278 | this.model.update_other_views(this); | ||
|
r14263 | this.user_invoked_update = false; | ||
}, | ||||
}); | ||||
IPython.notebook.widget_manager.register_widget_view('TextboxView', TextboxView); | ||||
}); | ||||