##// END OF EJS Templates
MAJOR CSS FIXES...
MAJOR CSS FIXES Fixed jquery slider horizontal style Fixed label alignment

File last commit:

r14295:671a5c3c
r14295:671a5c3c
Show More
float_range.js
151 lines | 5.4 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Updated require js references, now absolute paths are used
r14285 require(["notebook/js/widget"], function(){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var FloatRangeWidgetModel = IPython.WidgetModel.extend({});
IPython.notebook.widget_manager.register_widget_model('FloatRangeWidgetModel', FloatRangeWidgetModel);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var FloatSliderView = IPython.WidgetView.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)
.addClass('widget-label')
.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
MAJOR CSS FIXES...
r14295 .addClass('widget-slider')
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268 .append(this.$slider);
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 // Handles: Backend -> Frontend Sync
// Frontent -> Frontend Sync
update : function(){
// Slider related keys.
var _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'];
for (var index in _keys) {
var key = _keys[index];
if (this.model.get(key) != undefined) {
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
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 },
// Handles: User input
events: { "slide" : "handleSliderChange" },
handleSliderChange: function(e, ui) {
this.model.set('value', ui.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
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 IPython.notebook.widget_manager.register_widget_view('FloatSliderView', FloatSliderView);
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 var FloatTextView = IPython.WidgetView.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)
.addClass('widget-label')
.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);
this.update(); // Set defaults.
},
Jonathan Frederic
Moved view code into model files
r14252
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 // Handles: Backend -> Frontend Sync
// Frontent -> Frontend Sync
update : function(){
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');
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
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;
if (e.target.value != '') {
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)) {
if (this.model.get('max') != undefined) {
numericalValue = Math.min(this.model.get('max'), numericalValue);
}
if (this.model.get('min') != undefined) {
numericalValue = Math.max(this.model.get('min'), numericalValue);
}
// Apply the value if it has changed.
if (numericalValue != this.model.get('value')) {
this.changing = true;
this.model.set('value', numericalValue);
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 this.model.update_other_views(this);
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
Lots of updates to widget(s) js...
r14263 IPython.notebook.widget_manager.register_widget_view('FloatTextView', FloatTextView);
});