##// END OF EJS Templates
Ahhh bug fix!
Ahhh bug fix!

File last commit:

r16952:52e7eb2b
r17180:4822497b
Show More
widget_string.js
248 lines | 9.0 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
Updated require references to point to new files
r15427 define(["widgets/js/widget"], function(WidgetManager){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
var HTMLView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 render : function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.update(); // Set defaults.
},
update : function(){
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // Update the contents of this view
//
// Called when the model is changed. The model may have been
// changed by another view or by a state update from the back-end.
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 this.$el.html(this.model.get('value')); // CAUTION! .html(...) CALL MANDITORY!!!
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return HTMLView.__super__.update.apply(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
});
Jonathan Frederic
Widget require.js fix...
r14627 WidgetManager.register_widget_view('HTMLView', HTMLView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Added LatexView
r14447
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 var LatexView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Added LatexView
r14447 render : function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Added LatexView
r14447 this.update(); // Set defaults.
},
update : function(){
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // Update the contents of this view
//
// Called when the model is changed. The model may have been
// changed by another view or by a state update from the back-end.
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 this.$el.text(this.model.get('value'));
Jonathan Frederic
Remove uneccessary lines in String.js
r14448 MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$el.get(0)]);
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return LatexView.__super__.update.apply(this);
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 },
Jonathan Frederic
Added LatexView
r14447 });
Jonathan Frederic
Widget require.js fix...
r14627 WidgetManager.register_widget_view('LatexView', LatexView);
Jonathan Frederic
Added LatexView
r14447
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Renamed widgets......
r14834 var TextareaView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 render: function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 .addClass('widget-hbox');
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
Widget bootstrap3 fixes
r16952 .addClass('widget-text form-control')
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
Jason Grout
Remove the automatic _children_attr and _children_lists_attr....
r14487 this.model.on('msg:custom', $.proxy(this._handle_textarea_msg, this));
Jessica B. Hamrick
Add placeholder to textarea as well as text
r16323 this.model.on('change:placeholder', function(model, value, options) {
this.update_placeholder(value);
}, this);
this.update_placeholder();
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 },
_handle_textarea_msg: function (content){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a custom msg is recieved from the back-end.
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 if (content.method == "scroll_to_bottom") {
this.scroll_to_bottom();
}
},
Jessica B. Hamrick
Add placeholder to textarea as well as text
r16323 update_placeholder: function(value) {
if (!value) {
value = this.model.get('placeholder');
}
this.$textbox.attr('placeholder', value);
},
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 scroll_to_bottom: function (){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Scroll the text-area view to the bottom.
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 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
add locks to update everywhere by using options to pass this...
r14570 update: function(options){
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // Update the contents of this view
//
// Called when the model is changed. The model may have been
// changed by another view or by a state update from the back-end.
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 if (options === undefined || options.updated_view != this) {
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
add locks to update everywhere by using options to pass this...
r14570 var disabled = this.model.get('disabled');
this.$textbox.prop('disabled', disabled);
Jonathan Frederic
Made TextArea and TextBox views compatable with disabled property
r14302
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var description = this.model.get('description');
if (description.length === 0) {
this.$label.hide();
} else {
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 this.$label.text(description);
Jonathan Frederic
Add latex support in widget labels,...
r16817 MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 this.$label.show();
}
Jonathan Frederic
Added labels to basic widgets
r14292 }
Jonathan Frederic
Renamed widgets......
r14834 return TextareaView.__super__.update.apply(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 events: {
// Dictionary of events and their handlers.
Jonathan Frederic
Halign dict colons
r14610 "keyup textarea" : "handleChanging",
"paste textarea" : "handleChanging",
"cut textarea" : "handleChanging"
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 },
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
handleChanging: function(e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handles and validates user input.
Jonathan Frederic
comment model.set, so we know that it triggers update on other views
r14569
// Calling model.set will trigger all of the other views of the
// model to update.
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 this.model.set('value', e.target.value, {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
});
Jonathan Frederic
Renamed widgets......
r14834 WidgetManager.register_widget_view('TextareaView', TextareaView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Renamed widgets......
r14834 var TextView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 render: function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 .addClass('widget-hbox-single');
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
Widget bootstrap3 fixes
r16952 .addClass('widget-text form-control')
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.
Jessica B. Hamrick
Add placeholder attribute to text widgets
r16321 this.model.on('change:placeholder', function(model, value, options) {
this.update_placeholder(value);
}, this);
Jessica B. Hamrick
Make sure to update the placeholder on render as well
r16322
this.update_placeholder();
Jessica B. Hamrick
Add placeholder attribute to text widgets
r16321 },
update_placeholder: function(value) {
if (!value) {
value = this.model.get('placeholder');
}
this.$textbox.attr('placeholder', value);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 update: function(options){
Jonathan Frederic
make JS update comment more descriptive (english)
r14568 // Update the contents of this view
//
// Called when the model is changed. The model may have been
// changed by another view or by a state update from the back-end.
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 if (options === undefined || options.updated_view != this) {
if (this.$textbox.val() != this.model.get('value')) {
this.$textbox.val(this.model.get('value'));
}
var disabled = this.model.get('disabled');
this.$textbox.prop('disabled', disabled);
var description = this.model.get('description');
if (description.length === 0) {
this.$label.hide();
} else {
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 this.$label.text(description);
Jonathan Frederic
Add latex support in widget labels,...
r16817 MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 this.$label.show();
}
Jonathan Frederic
Added labels to basic widgets
r14292 }
Jonathan Frederic
Renamed widgets......
r14834 return TextView.__super__.update.apply(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 events: {
// Dictionary of events and their handlers.
Jonathan Frederic
Halign dict colons
r14610 "keyup input" : "handleChanging",
"paste input" : "handleChanging",
"cut input" : "handleChanging",
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 "keypress input" : "handleKeypress",
"blur input" : "handleBlur",
"focusout input" : "handleFocusOut"
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 },
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
handleChanging: function(e) {
Jonathan Frederic
Fixed bug in throttling code.
r14741 // Handles user input.
Jonathan Frederic
comment model.set, so we know that it triggers update on other views
r14569 // Calling model.set will trigger all of the other views of the
// model to update.
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 this.model.set('value', e.target.value, {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Added TextBox submit event
r14391
handleKeypress: function(e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handles text submition
Jonathan Frederic
Added TextBox submit event
r14391 if (e.keyCode == 13) { // Return key
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 this.send({event: 'submit'});
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 event.stopPropagation();
event.preventDefault();
return false;
}
},
handleBlur: function(e) {
// Prevent a blur from firing if the blur was not user intended.
// This is a workaround for the return-key focus loss bug.
// TODO: Is the original bug actually a fault of the keyboard
// manager?
if (e.relatedTarget === null) {
event.stopPropagation();
event.preventDefault();
return false;
}
},
handleFocusOut: function(e) {
// Prevent a blur from firing if the blur was not user intended.
// This is a workaround for the return-key focus loss bug.
if (e.relatedTarget === null) {
event.stopPropagation();
event.preventDefault();
return false;
Jonathan Frederic
Added TextBox submit event
r14391 }
},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Renamed widgets......
r14834 WidgetManager.register_widget_view('TextView', TextView);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });