##// END OF EJS Templates
Made scroll to bottom use msgs...
Made scroll to bottom use msgs allow multiple msg handlers added send to view to automatically hookup callbacks changed send signature to optionally accept a cell to connect callbacks

File last commit:

r14403:3dd14b75
r14403:3dd14b75
Show More
string.js
167 lines | 5.5 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366 //----------------------------------------------------------------------------
// Copyright (C) 2013 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// StringWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 define(["notebook/js/widget"], function(widget_manager){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var StringWidgetModel = IPython.WidgetModel.extend({});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var LabelView = IPython.WidgetView.extend({
// Called when view is rendered.
render : function(){
this.update(); // Set defaults.
},
// Handles: Backend -> Frontend Sync
// Frontent -> Frontend Sync
update : function(){
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268 this.$el.html(this.model.get('value'));
Jonathan Frederic
Fixes that allow last commit to work.
r14279 return IPython.WidgetView.prototype.update.call(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
});
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('LabelView', LabelView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
s/TextareaView/TextAreaView & s/TextboxView/TextBoxView
r14291 var TextAreaView = IPython.WidgetView.extend({
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Called when view is rendered.
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 render: function(){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el
Jonathan Frederic
MAJOR CSS FIXES...
r14295 .addClass('widget-hbox')
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 .html('');
Jonathan Frederic
Added labels to basic widgets
r14292 this.$label = $('<div />')
.appendTo(this.$el)
Jonathan Frederic
Fixed vertical widget labels
r14297 .addClass('widget-hlabel')
Jonathan Frederic
Added labels to basic widgets
r14292 .hide();
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$textbox = $('<textarea />')
.attr('rows', 5)
Jonathan Frederic
MAJOR CSS FIXES...
r14295 .addClass('widget-text')
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 .appendTo(this.$el);
Jonathan Frederic
Set default element to be styled in built-in views
r14314 this.$el_to_style = this.$textbox; // Set default element to style
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.update(); // Set defaults.
Jonathan Frederic
Made scroll to bottom use msgs...
r14403
this.on_msg();
},
_handle_textarea_msg: function (content){
if (content.method == "scroll_to_bottom") {
this.scroll_to_bottom();
}
},
scroll_to_bottom: function (){
this.$textbox.scrollTop(this.$textbox[0].scrollHeight);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Made scroll to bottom use msgs...
r14403
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Handles: Backend -> Frontend Sync
// Frontent -> Frontend Sync
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 update: function(){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 if (!this.user_invoked_update) {
this.$textbox.val(this.model.get('value'));
}
Jonathan Frederic
Added labels to basic widgets
r14292
Jonathan Frederic
Made TextArea and TextBox views compatable with disabled property
r14302 var disabled = this.model.get('disabled');
this.$textbox.prop('disabled', disabled);
Jonathan Frederic
Added labels to basic widgets
r14292 var description = this.model.get('description');
if (description.length == 0) {
this.$label.hide();
} else {
this.$label.html(description);
this.$label.show();
}
Jonathan Frederic
Fixes that allow last commit to work.
r14279 return IPython.WidgetView.prototype.update.call(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 events: {"keyup textarea": "handleChanging",
"paste textarea": "handleChanging",
"cut textarea": "handleChanging"},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Handles and validates user input.
handleChanging: function(e) {
this.user_invoked_update = true;
this.model.set('value', e.target.value);
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 this.model.update_other_views(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.user_invoked_update = false;
},
});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('TextAreaView', TextAreaView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
s/TextareaView/TextAreaView & s/TextboxView/TextBoxView
r14291 var TextBoxView = IPython.WidgetView.extend({
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Called when view is rendered.
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 render: function(){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el
Jonathan Frederic
MAJOR CSS FIXES...
r14295 .addClass('widget-hbox-single')
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 .html('');
Jonathan Frederic
Added labels to basic widgets
r14292 this.$label = $('<div />')
Jonathan Frederic
Fixed vertical widget labels
r14297 .addClass('widget-hlabel')
Jonathan Frederic
Added labels to basic widgets
r14292 .appendTo(this.$el)
.hide();
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$textbox = $('<input type="text" />')
.addClass('input')
Jonathan Frederic
MAJOR CSS FIXES...
r14295 .addClass('widget-text')
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 .appendTo(this.$el);
Jonathan Frederic
Set default element to be styled in built-in views
r14314 this.$el_to_style = this.$textbox; // Set default element to style
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.update(); // Set defaults.
},
// Handles: Backend -> Frontend Sync
// Frontent -> Frontend Sync
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 update: function(){
Jonathan Frederic
Fixed a bug that didn't allow callbacks to set a property...
r14392 if (this.$textbox.val() != this.model.get('value')) {
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$textbox.val(this.model.get('value'));
}
Jonathan Frederic
Added labels to basic widgets
r14292
Jonathan Frederic
Made TextArea and TextBox views compatable with disabled property
r14302 var disabled = this.model.get('disabled');
this.$textbox.prop('disabled', disabled);
Jonathan Frederic
Added labels to basic widgets
r14292 var description = this.model.get('description');
if (description.length == 0) {
this.$label.hide();
} else {
this.$label.html(description);
this.$label.show();
}
Jonathan Frederic
Fixes that allow last commit to work.
r14279 return IPython.WidgetView.prototype.update.call(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 events: {"keyup input": "handleChanging",
"paste input": "handleChanging",
"cut input": "handleChanging",
"keypress input": "handleKeypress"},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Handles and validates user input.
handleChanging: function(e) {
this.model.set('value', e.target.value);
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 this.model.update_other_views(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Added TextBox submit event
r14391
// Handles text submition
handleKeypress: function(e) {
if (e.keyCode == 13) { // Return key
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 this.send({event: 'submit'});
Jonathan Frederic
Added TextBox submit event
r14391 }
},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('TextBoxView', TextBoxView);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });