##// END OF EJS Templates
comment model.set, so we know that it triggers update on other views
comment model.set, so we know that it triggers update on other views

File last commit:

r14569:500d8a37
r14569:500d8a37
Show More
widget_float_range.js
269 lines | 10.0 KiB | application/javascript | JavascriptLexer
/ IPython / html / static / notebook / js / widgets / widget_float_range.js
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.
//----------------------------------------------------------------------------
//============================================================================
// FloatRangeWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
Jonathan Frederic
Updated require.js references
r14537 define(["notebook/js/widgets/widget"], function(widget_manager){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var FloatRangeWidgetModel = IPython.WidgetModel.extend({});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var FloatSliderView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 // Called when view is rendered.
render : function(){
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 />')
.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
Lots of updates to widget(s) js...
r14263 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
Lots of updates to widget(s) js...
r14263 // Slider related keys.
Jonathan Frederic
Fix slider orientation change, value-handle-offset bug
r14301 var _keys = ['step', 'max', 'min', 'disabled'];
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 for (var index in _keys) {
var key = _keys[index];
Jonathan Frederic
jslint /widgets
r14466 if (this.model.get(key) !== undefined) {
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$slider.slider("option", key, this.model.get(key));
}
Jonathan Frederic
Moved view code into model files
r14252 }
Jonathan Frederic
Added labels to basic widgets
r14292
Jonathan Frederic
Fix slider orientation change, value-handle-offset bug
r14301 // 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.
Jonathan Frederic
Added slider vertical mode, and...
r14296 var orientation = this.model.get('orientation');
Jonathan Frederic
Fix slider orientation change, value-handle-offset bug
r14301 var value = this.model.get('min');
this.$slider.slider('option', 'value', value);
this.$slider.slider('option', 'orientation', orientation);
Jonathan Frederic
jslint /widgets
r14466 value = this.model.get('value');
Jonathan Frederic
Fix slider orientation change, value-handle-offset bug
r14301 this.$slider.slider('option', 'value', value);
// Use the right CSS classes for vertical & horizontal sliders
Jonathan Frederic
Added slider vertical mode, and...
r14296 if (orientation=='vertical') {
this.$slider_container
.removeClass('widget-hslider')
.addClass('widget-vslider');
this.$el
.removeClass('widget-hbox-single')
Jonathan Frederic
Fixed vertical widget labels
r14297 .addClass('widget-vbox-single');
this.$label
.removeClass('widget-hlabel')
.addClass('widget-vlabel');
Jonathan Frederic
Added slider vertical mode, and...
r14296 } else {
this.$slider_container
.removeClass('widget-vslider')
.addClass('widget-hslider');
this.$el
Jonathan Frederic
Fixed vertical widget labels
r14297 .removeClass('widget-vbox-single')
Jonathan Frederic
Added slider vertical mode, and...
r14296 .addClass('widget-hbox-single');
Jonathan Frederic
Fixed vertical widget labels
r14297 this.$label
.removeClass('widget-vlabel')
.addClass('widget-hlabel');
Jonathan Frederic
Added slider vertical mode, and...
r14296 }
Jonathan Frederic
Added labels to basic widgets
r14292 var description = this.model.get('description');
Jonathan Frederic
jslint /widgets
r14466 if (description.length === 0) {
Jonathan Frederic
Added labels to basic widgets
r14292 this.$label.hide();
} else {
this.$label.html(description);
this.$label.show();
}
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 return IPython.DOMWidgetView.prototype.update.call(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
// Handles: User input
events: { "slide" : "handleSliderChange" },
handleSliderChange: function(e, ui) {
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
Lots of updates to widget(s) js...
r14263 this.model.set('value', ui.value);
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
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('FloatSliderView', FloatSliderView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var FloatTextView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 // Called when view is rendered.
render : function(){
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 />')
.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
Lots of updates to widget(s) js...
r14263 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
Lots of updates to widget(s) js...
r14263 var value = this.model.get('value');
if (!this.changing && parseFloat(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
Added labels to basic widgets
r14292
var description = this.model.get('description');
Jonathan Frederic
jslint /widgets
r14466 if (description.length === 0) {
Jonathan Frederic
Added labels to basic widgets
r14292 this.$label.hide();
} else {
this.$label.html(description);
this.$label.show();
}
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 return IPython.DOMWidgetView.prototype.update.call(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
Use require.js to load widget manager.
r14253
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
events: {"keyup input" : "handleChanging",
"paste input" : "handleChanging",
"cut input" : "handleChanging",
"change input" : "handleChanged"}, // Fires only when control is validated or looses focus.
// Handles and validates user input.
handleChanging: function(e) {
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.0;
Jonathan Frederic
jslint /widgets
r14466 if (e.target.value !== '') {
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 numericalValue = parseFloat(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')) {
this.changing = true;
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
Lots of updates to widget(s) js...
r14263 this.model.set('value', numericalValue);
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.changing = false;
}
}
},
// Applies validated input.
handleChanged: function(e) {
// Update the textbox
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
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('FloatTextView', FloatTextView);
Jonathan Frederic
Added ProgressView
r14298
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var ProgressView = IPython.DOMWidgetView.extend({
Jonathan Frederic
Added ProgressView
r14298
// Called when view is rendered.
render : function(){
this.$el
.addClass('widget-hbox-single')
.html('');
this.$label = $('<div />')
.appendTo(this.$el)
.addClass('widget-hlabel')
.hide();
this.$progress = $('<div />')
.addClass('progress')
.addClass('widget-progress')
.appendTo(this.$el);
Jonathan Frederic
Set default element to be styled in built-in views
r14314 this.$el_to_style = this.$progress; // Set default element to style
Jonathan Frederic
Added ProgressView
r14298 this.$bar = $('<div />')
.addClass('bar')
.css('width', '50%')
.appendTo(this.$progress);
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
Added ProgressView
r14298 var value = this.model.get('value');
var max = this.model.get('max');
var min = this.model.get('min');
var percent = 100.0 * (value - min) / (max - min);
this.$bar.css('width', percent + '%');
var description = this.model.get('description');
Jonathan Frederic
jslint /widgets
r14466 if (description.length === 0) {
Jonathan Frederic
Added ProgressView
r14298 this.$label.hide();
} else {
this.$label.html(description);
this.$label.show();
}
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 return IPython.DOMWidgetView.prototype.update.call(this);
Jonathan Frederic
Added ProgressView
r14298 },
});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('ProgressView', ProgressView);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });