##// END OF EJS Templates
Removed for () loops where necessary. Replaced with _.each
Removed for () loops where necessary. Replaced with _.each

File last commit:

r14664:9d49e0ed
r14664:9d49e0ed
Show More
widget_int_range.js
220 lines | 8.7 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.
//----------------------------------------------------------------------------
//============================================================================
// IntRangeWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
Jonathan Frederic
Widget require.js fix...
r14627 define(["notebook/js/widgets/widget"], function(WidgetManager){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
var IntSliderView = 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
Attempt 1, HBox and VBox implementation.
r14268 this.$el
Jonathan Frederic
document _keys function and rename to jquery_slider_keys
r14573 .addClass('widget-hbox-single');
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.$slider = $('<div />')
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268 .slider({})
.addClass('slider');
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Put the slider in a container
this.$slider_container = $('<div />')
Jonathan Frederic
Added slider vertical mode, and...
r14296 .addClass('widget-hslider')
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268 .append(this.$slider);
Jonathan Frederic
Set default element to be styled in built-in views
r14314 this.$el_to_style = this.$slider_container; // Set default element to style
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$el.append(this.$slider_container);
// Set defaults.
this.update();
},
Jonathan Frederic
Moved view code into model files
r14252
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
document _keys function and rename to jquery_slider_keys
r14573 // JQuery slider option keys. These keys happen to have a
// one-to-one mapping with the corrosponding keys of the model.
var jquery_slider_keys = ['step', 'max', 'min', 'disabled'];
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(jquery_slider_keys, function(key, i) {
var model_value = this.model.get(key);
if (model_value !== undefined) {
this.$slider.slider("option", key, model_value);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 }
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Added labels to basic widgets
r14292
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 // WORKAROUND FOR JQUERY SLIDER BUG.
// The horizontal position of the slider handle
// depends on the value of the slider at the time
// of orientation change. Before applying the new
// workaround, we set the value to the minimum to
// make sure that the horizontal placement of the
// handle in the vertical slider is always
// consistent.
var orientation = this.model.get('orientation');
var value = this.model.get('min');
this.$slider.slider('option', 'value', value);
this.$slider.slider('option', 'orientation', orientation);
value = this.model.get('value');
this.$slider.slider('option', 'value', value);
Jonathan Frederic
Fixed slider orientation bug for IntSliderView (already done for float)...
r14303
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 // Use the right CSS classes for vertical & horizontal sliders
if (orientation=='vertical') {
this.$slider_container
.removeClass('widget-hslider')
.addClass('widget-vslider');
this.$el
.removeClass('widget-hbox-single')
.addClass('widget-vbox-single');
this.$label
.removeClass('widget-hlabel')
.addClass('widget-vlabel');
Jonathan Frederic
Fixed vertical widget labels
r14297
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 } else {
this.$slider_container
.removeClass('widget-vslider')
.addClass('widget-hslider');
this.$el
.removeClass('widget-vbox-single')
.addClass('widget-hbox-single');
this.$label
.removeClass('widget-vlabel')
.addClass('widget-hlabel');
}
Jonathan Frederic
Added slider vertical mode, and...
r14296
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 locks to update everywhere by using options to pass this...
r14570 this.$label.show();
}
Jonathan Frederic
Added labels to basic widgets
r14292 }
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return IntSliderView.__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.
"slide" : "handleSliderChange"
},
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 handleSliderChange: function(e, ui) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when the slider value is changed.
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', ~~ui.value, {updated_view: this}); // Double bit-wise not to truncate decimel
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
Widget require.js fix...
r14627 WidgetManager.register_widget_view('IntSliderView', IntSliderView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
var IntTextView = 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.$el
Jonathan Frederic
document _keys function and rename to jquery_slider_keys
r14573 .addClass('widget-hbox-single');
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 = $('<input type="text" />')
.addClass('input')
Jonathan Frederic
MAJOR CSS FIXES...
r14295 .addClass('widget-numeric-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
Moved view code into model files
r14252
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) {
var value = this.model.get('value');
if (parseInt(this.$textbox.val()) != value) {
this.$textbox.val(value);
}
if (this.model.get('disabled')) {
this.$textbox.attr('disabled','disabled');
} else {
this.$textbox.removeAttr('disabled');
}
Jonathan Frederic
make JS update comment more descriptive (english)
r14568
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 locks to update everywhere by using options to pass this...
r14570 this.$label.show();
}
Jonathan Frederic
Added labels to basic widgets
r14292 }
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return IntTextView.__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
Added PEP8 style comments to all of the JS code.
r14609
// Fires only when control is validated or looses focus.
"change input" : "handleChanged"
},
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
Use require.js to load widget manager.
r14253
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 // Try to parse value as a float.
var numericalValue = 0;
Jonathan Frederic
jslint /widgets
r14466 if (e.target.value !== '') {
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 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)) {
Jonathan Frederic
jslint /widgets
r14466 if (this.model.get('max') !== undefined) {
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 numericalValue = Math.min(this.model.get('max'), numericalValue);
}
Jonathan Frederic
jslint /widgets
r14466 if (this.model.get('min') !== undefined) {
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 numericalValue = Math.max(this.model.get('min'), numericalValue);
}
// Apply the value if it has changed.
if (numericalValue != this.model.get('value')) {
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', numericalValue, {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 }
}
},
handleChanged: function(e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Applies validated input.
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 if (this.model.get('value') != e.target.value) {
e.target.value = this.model.get('value');
Jonathan Frederic
Moved view code into model files
r14252 }
}
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Widget require.js fix...
r14627 WidgetManager.register_widget_view('IntTextView', IntTextView);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });