##// END OF EJS Templates
Merge pull request #1 from ipython/master...
Merge pull request #1 from ipython/master Update from ipython/ipython:master

File last commit:

r19366:3d155011
r20633:d587f5ea merge
Show More
widget_string.js
288 lines | 9.2 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Almost done!...
r17198 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
Almost done!...
r17198 define([
"widgets/js/widget",
Jonathan Frederic
Fix all the tests
r17216 "jquery",
MinRK
add bootstrap shim for require...
r17312 "bootstrap",
Jonathan Frederic
Fix all the tests
r17216 ], function(widget, $){
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
Almost done!...
r17198 var HTMLView = widget.DOMWidgetView.extend({
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 render : function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.update(); // Set defaults.
},
update : function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* 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
Moved view code into model files
r14252
Jonathan Frederic
Added LatexView
r14447
Jonathan Frederic
Almost done!...
r17198 var LatexView = widget.DOMWidgetView.extend({
Jonathan Frederic
Added LatexView
r14447 render : function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Added LatexView
r14447 this.update(); // Set defaults.
},
update : function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* 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.
*/
Nicholas Bollweg (Nick)
reversing order of arguments, as text may already exist
r19196 this.typeset(this.$el, this.model.get('value'));
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
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Almost done!...
r17198 var TextareaView = widget.DOMWidgetView.extend({
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 render: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el
Jason Grout
Add semantic classes to top-level containers for single widgets...
r18120 .addClass('widget-hbox widget-textarea');
Jonathan Frederic
Added labels to basic widgets
r14292 this.$label = $('<div />')
.appendTo(this.$el)
Jonathan Frederic
Cleaned up hbox and vbox widget div styles,...
r17929 .addClass('widget-label')
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);
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
Ran function comment conversion tool
r19176 /**
* 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
Ran function comment conversion tool
r19176 /**
* 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
Ran function comment conversion tool
r19176 /**
* 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 {
Nicholas Bollweg (Nick)
reversing order of arguments, as text may already exist
r19196 this.typeset(this.$label, description);
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
Finished style attributes.
r17724
update_attr: function(name, value) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Set a css attr of the widget view.
*/
Jonathan Frederic
Fix padding of widgets.
r19366 if (name == 'padding' || name == 'margin') {
this.$el.css(name, value);
} else {
this.$textbox.css(name, value);
}
Jonathan Frederic
Finished style attributes.
r17724 },
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
Ran function comment conversion tool
r19176 /**
* Handles and validates user input.
*
* 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
Moved view code into model files
r14252
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Almost done!...
r17198 var TextView = widget.DOMWidgetView.extend({
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 render: function(){
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Called when view is rendered.
*/
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el
Jason Grout
Add semantic classes to top-level containers for single widgets...
r18120 .addClass('widget-hbox widget-text');
Jonathan Frederic
Added labels to basic widgets
r14292 this.$label = $('<div />')
Jonathan Frederic
Cleaned up hbox and vbox widget div styles,...
r17929 .addClass('widget-label')
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);
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
Ran function comment conversion tool
r19176 /**
* 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 {
Nicholas Bollweg (Nick)
reversing order of arguments, as text may already exist
r19196 this.typeset(this.$label, description);
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
Finished style attributes.
r17724
update_attr: function(name, value) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Set a css attr of the widget view.
*/
Jonathan Frederic
Fix padding of widgets.
r19366 if (name == 'padding' || name == 'margin') {
this.$el.css(name, value);
} else {
this.$textbox.css(name, value);
}
Jonathan Frederic
Finished style attributes.
r17724 },
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
Ran function comment conversion tool
r19176 /**
* Handles user input.
*
* 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
Ran function comment conversion tool
r19176 /**
* 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'});
weichm
"event" is not defined error in Firefox...
r17803 e.stopPropagation();
e.preventDefault();
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 return false;
}
},
handleBlur: function(e) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* 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?
*/
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 if (e.relatedTarget === null) {
weichm
"event" is not defined error in Firefox...
r17803 e.stopPropagation();
e.preventDefault();
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 return false;
}
},
handleFocusOut: function(e) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Prevent a blur from firing if the blur was not user intended.
* This is a workaround for the return-key focus loss bug.
*/
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 if (e.relatedTarget === null) {
weichm
"event" is not defined error in Firefox...
r17803 e.stopPropagation();
e.preventDefault();
Jonathan Frederic
Prevent TextBox from blurring unless explicity by user.
r14746 return false;
Jonathan Frederic
Added TextBox submit event
r14391 }
},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Almost done!...
r17198
return {
'HTMLView': HTMLView,
'LatexView': LatexView,
'TextareaView': TextareaView,
'TextView': TextView,
};
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });