##// END OF EJS Templates
Removes unnecessary parameter from ContentManager.delete_notebook
Removes unnecessary parameter from ContentManager.delete_notebook

File last commit:

r18169:ec412e90
r18629:3b2ce203
Show More
widget_selection.js
472 lines | 18.4 KiB | application/javascript | JavascriptLexer
/ IPython / html / static / widgets / js / widget_selection.js
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
Done with major changes,...
r17199 "base/js/utils",
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, utils, $){
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366
Jonathan Frederic
Almost done!...
r17198 var DropdownView = widget.DOMWidgetView.extend({
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 render : function(){
MinRK
quick review pass on javascript
r14792 // 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-dropdown');
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.$buttongroup = $('<div />')
Jonathan Frederic
Fixed indentation
r14365 .addClass('widget_item')
.addClass('btn-group')
.appendTo(this.$el);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$droplabel = $('<button />')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('btn btn-default')
Jonathan Frederic
Fixed indentation
r14365 .addClass('widget-combo-btn')
MinRK
use non-breaking space for button with no description...
r15329 .html("&nbsp;")
Jonathan Frederic
Fixed indentation
r14365 .appendTo(this.$buttongroup);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$dropbutton = $('<button />')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('btn btn-default')
Jonathan Frederic
Fixed indentation
r14365 .addClass('dropdown-toggle')
.addClass('widget-combo-carrot-btn')
.attr('data-toggle', 'dropdown')
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 .append($('<span />').addClass("caret"))
Jonathan Frederic
Fixed indentation
r14365 .appendTo(this.$buttongroup);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.$droplist = $('<ul />')
Jonathan Frederic
Fixed indentation
r14365 .addClass('dropdown-menu')
.appendTo(this.$buttongroup);
Jonathan Frederic
Added Bootstrap specific classes,...
r17728
this.model.on('change:button_style', function(model, value) {
this.update_button_style();
}, this);
this.update_button_style('');
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
// Set defaults.
this.update();
},
Jonathan Frederic
Removed require.js scheme since it forces async event driven model,...
r14257
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
Better fix for empty dropdown button alignment...
r14359
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 if (options === undefined || options.updated_view != this) {
MinRK
Make `SelectionWidget.values` a dict...
r15024 var selected_item_text = this.model.get('value_name');
MinRK
handle empty string in ToggleButtonsWidget
r15332 if (selected_item_text.trim().length === 0) {
MinRK
use non-breaking space for button with no description...
r15329 this.$droplabel.html("&nbsp;");
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 } else {
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 this.$droplabel.text(selected_item_text);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 }
MinRK
Make `SelectionWidget.values` a dict...
r15024 var items = this.model.get('value_names');
Jonathan Frederic
Make dropdown view DOM swap elements on update.
r14616 var $replace_droplist = $('<ul />')
.addClass('dropdown-menu');
Jonathan Frederic
Partial implementation of styles
r17723 // Copy the style
$replace_droplist.attr('style', this.$droplist.attr('style'));
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var that = this;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, i) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var item_button = $('<a href="#"/>')
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 .text(item)
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .on('click', $.proxy(that.handle_click, that));
Jonathan Frederic
Make dropdown view DOM swap elements on update.
r14616 $replace_droplist.append($('<li />').append(item_button));
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Make dropdown view DOM swap elements on update.
r14616 this.$droplist.replaceWith($replace_droplist);
this.$droplist.remove();
this.$droplist = $replace_droplist;
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570
if (this.model.get('disabled')) {
this.$buttongroup.attr('disabled','disabled');
this.$droplabel.attr('disabled','disabled');
this.$dropbutton.attr('disabled','disabled');
this.$droplist.attr('disabled','disabled');
} else {
this.$buttongroup.removeAttr('disabled');
this.$droplabel.removeAttr('disabled');
this.$dropbutton.removeAttr('disabled');
this.$droplist.removeAttr('disabled');
}
Jonathan Frederic
Added labels to basic widgets
r14292
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
Many checks off the todo list, test fixes
r14583 return DropdownView.__super__.update.apply(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
jslint /widgets
r14466
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 update_button_style: function(previous_trait_value) {
var class_map = {
primary: ['btn-primary'],
success: ['btn-success'],
info: ['btn-info'],
warning: ['btn-warning'],
danger: ['btn-danger']
};
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$droplabel);
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$dropbutton);
},
Jonathan Frederic
Partial implementation of styles
r17723 update_attr: function(name, value) {
// Set a css attr of the widget view.
if (name.substring(0, 6) == 'border' || name == 'background' || name == 'color') {
this.$droplabel.css(name, value);
this.$dropbutton.css(name, value);
this.$droplist.css(name, value);
} else if (name == 'width') {
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 this.$droplist.css(name, value);
this.$droplabel.css(name, value);
} else if (name == 'padding') {
this.$droplist.css(name, value);
this.$buttongroup.css(name, value);
} else if (name == 'margin') {
this.$buttongroup.css(name, value);
Jonathan Frederic
Partial implementation of styles
r17723 } else if (name == 'height') {
Jonathan Frederic
Finished style attributes.
r17724 this.$droplabel.css(name, value);
Jonathan Frederic
Partial implementation of styles
r17723 this.$dropbutton.css(name, value);
} else {
this.$droplist.css(name, value);
Jonathan Frederic
Finished style attributes.
r17724 this.$droplabel.css(name, value);
Jonathan Frederic
Partial implementation of styles
r17723 }
},
Jonathan Frederic
jslint /widgets
r14466 handle_click: function (e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a value is clicked.
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.
MinRK
Make `SelectionWidget.values` a dict...
r15024 this.model.set('value_name', $(e.target).text(), {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
jslint /widgets
r14466 },
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
});
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Almost done!...
r17198 var RadioButtonsView = widget.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
Jason Grout
Add semantic classes to top-level containers for single widgets...
r18120 .addClass('widget-hbox widget-radio');
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
MAJOR CSS FIXES...
r14295 this.$container = $('<div />')
.appendTo(this.$el)
Jonathan Frederic
Added a class for RadioButtons container...
r15364 .addClass('widget-radio-box');
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 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) {
// Add missing items to the DOM.
MinRK
Make `SelectionWidget.values` a dict...
r15024 var items = this.model.get('value_names');
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var disabled = this.model.get('disabled');
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var that = this;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, index) {
var item_query = ' :input[value="' + item + '"]';
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 if (that.$el.find(item_query).length === 0) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var $label = $('<label />')
.addClass('radio')
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 .text(item)
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .appendTo(that.$container);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570
$('<input />')
.attr('type', 'radio')
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .addClass(that.model)
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 .val(item)
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 .prependTo($label)
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .on('click', $.proxy(that.handle_click, that));
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 }
Jonathan Frederic
Fixed a couple more context typos
r14687 var $item_element = that.$container.find(item_query);
MinRK
Make `SelectionWidget.values` a dict...
r15024 if (that.model.get('value_name') == item) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 $item_element.prop('checked', true);
} else {
$item_element.prop('checked', false);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 }
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 $item_element.prop('disabled', disabled);
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 // Remove items that no longer exist.
this.$container.find('input').each(function(i, obj) {
var value = $(obj).val();
var found = false;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, index) {
if (item == value) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 found = true;
Jonathan Frederic
Fixed some typos related to _.each loops
r14678 return false;
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
add locks to update everywhere by using options to pass this...
r14570
if (!found) {
$(obj).parent().remove();
}
});
Jonathan Frederic
Added labels to basic widgets
r14292
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
Many checks off the todo list, test fixes
r14583 return RadioButtonsView.__super__.update.apply(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
jslint /widgets
r14466
Jonathan Frederic
Finished style attributes.
r17724 update_attr: function(name, value) {
// Set a css attr of the widget view.
this.$container.css(name, value);
},
Jonathan Frederic
jslint /widgets
r14466 handle_click: function (e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a value is clicked.
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.
MinRK
Make `SelectionWidget.values` a dict...
r15024 this.model.set('value_name', $(e.target).val(), {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
jslint /widgets
r14466 },
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Almost done!...
r17198
Jonathan Frederic
Added togglebutton group
r14258
Jonathan Frederic
Almost done!...
r17198 var ToggleButtonsView = widget.DOMWidgetView.extend({
Jonathan Frederic
Finished style attributes.
r17724 initialize: function() {
this._css_state = {};
ToggleButtonsView.__super__.initialize.apply(this, arguments);
},
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
Jason Grout
Add semantic classes to top-level containers for single widgets...
r18120 .addClass('widget-hbox widget-toggle-buttons');
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.$buttongroup = $('<div />')
.addClass('btn-group')
.attr('data-toggle', 'buttons-radio')
.appendTo(this.$el);
Jonathan Frederic
Added Bootstrap specific classes,...
r17728
this.model.on('change:button_style', function(model, value) {
this.update_button_style();
}, this);
this.update_button_style('');
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 this.update();
},
Jonathan Frederic
Added togglebutton group
r14258
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) {
// Add missing items to the DOM.
MinRK
Make `SelectionWidget.values` a dict...
r15024 var items = this.model.get('value_names');
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var disabled = this.model.get('disabled');
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var that = this;
MinRK
handle empty string in ToggleButtonsWidget
r15332 var item_html;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, index) {
MinRK
handle empty string in ToggleButtonsWidget
r15332 if (item.trim().length == 0) {
item_html = "&nbsp;";
} else {
Jonathan Frederic
Done with major changes,...
r17199 item_html = utils.escape_html(item);
MinRK
handle empty string in ToggleButtonsWidget
r15332 }
var item_query = '[data-value="' + item + '"]';
var $item_element = that.$buttongroup.find(item_query);
if (!$item_element.length) {
$item_element = $('<button/>')
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 .attr('type', 'button')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('btn btn-default')
MinRK
handle empty string in ToggleButtonsWidget
r15332 .html(item_html)
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .appendTo(that.$buttongroup)
MinRK
handle empty string in ToggleButtonsWidget
r15332 .attr('data-value', item)
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .on('click', $.proxy(that.handle_click, that));
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 that.update_style_traits($item_element);
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 }
MinRK
Make `SelectionWidget.values` a dict...
r15024 if (that.model.get('value_name') == item) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 $item_element.addClass('active');
} else {
$item_element.removeClass('active');
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 }
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 $item_element.prop('disabled', disabled);
});
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 // Remove items that no longer exist.
this.$buttongroup.find('button').each(function(i, obj) {
MinRK
handle empty string in ToggleButtonsWidget
r15332 var value = $(obj).data('value');
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var found = false;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, index) {
if (item == value) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 found = true;
Jonathan Frederic
Fixed some typos related to _.each loops
r14678 return false;
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
add locks to update everywhere by using options to pass this...
r14570 if (!found) {
$(obj).remove();
}
});
Jonathan Frederic
Added labels to basic widgets
r14292
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
Many checks off the todo list, test fixes
r14583 return ToggleButtonsView.__super__.update.apply(this);
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 },
Jonathan Frederic
jslint /widgets
r14466
Jonathan Frederic
Finished style attributes.
r17724 update_attr: function(name, value) {
// Set a css attr of the widget view.
this._css_state[name] = value;
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 this.update_style_traits();
Jonathan Frederic
Finished style attributes.
r17724 },
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 update_style_traits: function(button) {
Jonathan Frederic
Finished style attributes.
r17724 for (var name in this._css_state) {
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 if (this._css_state.hasOwnProperty(name)) {
if (name == 'margin') {
this.$buttongroup.css(name, this._css_state[name]);
} else if (name != 'width') {
if (button) {
button.css(name, this._css_state[name]);
} else {
this.$buttongroup.find('button').css(name, this._css_state[name]);
}
}
Jonathan Frederic
Finished style attributes.
r17724 }
}
},
Jonathan Frederic
Added Bootstrap specific classes,...
r17728 update_button_style: function(previous_trait_value) {
var class_map = {
primary: ['btn-primary'],
success: ['btn-success'],
info: ['btn-info'],
warning: ['btn-warning'],
danger: ['btn-danger']
};
this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$buttongroup.find('button'));
},
Jonathan Frederic
jslint /widgets
r14466 handle_click: function (e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a value is clicked.
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.
MinRK
handle empty string in ToggleButtonsWidget
r15332 this.model.set('value_name', $(e.target).data('value'), {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 },
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });
Jonathan Frederic
Almost done!...
r17198
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
Almost done!...
r17198 var SelectView = widget.DOMWidgetView.extend({
Jonathan Frederic
Added ListBoxView
r14375 render : function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Called when view is rendered.
Jonathan Frederic
Added ListBoxView
r14375 this.$el
Jason Grout
Add semantic classes to top-level containers for single widgets...
r18120 .addClass('widget-hbox widget-select');
Jonathan Frederic
Added ListBoxView
r14375 this.$label = $('<div />')
.appendTo(this.$el)
Jonathan Frederic
Cleaned up hbox and vbox widget div styles,...
r17929 .addClass('widget-label')
Jonathan Frederic
Added ListBoxView
r14375 .hide();
this.$listbox = $('<select />')
Jonathan Frederic
Widget bootstrap3 fixes
r16952 .addClass('widget-listbox form-control')
Jonathan Frederic
Added ListBoxView
r14375 .attr('size', 6)
.appendTo(this.$el);
this.update();
},
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) {
// Add missing items to the DOM.
MinRK
Make `SelectionWidget.values` a dict...
r15024 var items = this.model.get('value_names');
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 var that = this;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, index) {
MinRK
don't use contains in SelectWidget item_query...
r18169 var item_query = 'option[value_name="' + item + '"]';
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 if (that.$listbox.find(item_query).length === 0) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 $('<option />')
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 .text(item)
MinRK
Make `SelectionWidget.values` a dict...
r15024 .attr('value_name', item)
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 .appendTo(that.$listbox)
.on('click', $.proxy(that.handle_click, that));
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 }
});
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570
// Select the correct element
MinRK
Make `SelectionWidget.values` a dict...
r15024 this.$listbox.val(this.model.get('value_name'));
Jonathan Frederic
Added ListBoxView
r14375
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 // Disable listbox if needed
var disabled = this.model.get('disabled');
this.$listbox.prop('disabled', disabled);
// Remove items that no longer exist.
this.$listbox.find('option').each(function(i, obj) {
Jonathan Frederic
Replace .html with .text everywhere possible
r14663 var value = $(obj).text();
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 var found = false;
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 _.each(items, function(item, index) {
if (item == value) {
Jonathan Frederic
add locks to update everywhere by using options to pass this...
r14570 found = true;
Jonathan Frederic
Fixed some typos related to _.each loops
r14678 return false;
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
add locks to update everywhere by using options to pass this...
r14570
if (!found) {
$(obj).remove();
}
});
Jonathan Frederic
Added ListBoxView
r14375
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 ListBoxView
r14375 }
Jonathan Frederic
Renamed widgets......
r14834 return SelectView.__super__.update.apply(this);
Jonathan Frederic
Added ListBoxView
r14375 },
Jonathan Frederic
jslint /widgets
r14466
Jonathan Frederic
Finished style attributes.
r17724 update_attr: function(name, value) {
// Set a css attr of the widget view.
this.$listbox.css(name, value);
},
Jonathan Frederic
jslint /widgets
r14466 handle_click: function (e) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a value is clicked.
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.
MinRK
Make `SelectionWidget.values` a dict...
r15024 this.model.set('value_name', $(e.target).text(), {updated_view: this});
Jonathan Frederic
Moved touch logic out of model into view....
r14482 this.touch();
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 },
Jonathan Frederic
Added ListBoxView
r14375 });
Jonathan Frederic
Almost done!...
r17198
return {
'DropdownView': DropdownView,
'RadioButtonsView': RadioButtonsView,
'ToggleButtonsView': ToggleButtonsView,
'SelectView': SelectView,
};
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });