##// END OF EJS Templates
Add order respecting method
Add order respecting method

File last commit:

r17174:4f205192
r17174:4f205192
Show More
widget.js
516 lines | 19.1 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 //----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// Base Widget Model and View classes
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
Jonathan Frederic
Updated require references to point to new files
r15427 define(["widgets/js/manager",
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 "underscore",
"backbone"],
Jonathan Frederic
s/Underscore/_
r14897 function(WidgetManager, _, Backbone){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 var WidgetModel = Backbone.Model.extend({
constructor: function (widget_manager, model_id, comm) {
MinRK
quick review pass on javascript
r14792 // Constructor
Jonathan Frederic
Add constructor comment for widget model.
r14561 //
// Creates a WidgetModel instance.
//
// Parameters
// ----------
// widget_manager : WidgetManager instance
// model_id : string
// An ID unique to this model.
// comm : Comm instance (optional)
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.widget_manager = widget_manager;
Jonathan Frederic
Keep a running diff instead of forcing a full state update
r15280 this._buffered_state_diff = {};
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.pending_msgs = 0;
this.msg_buffer = null;
Jonathan Frederic
this.updating should be a key specific lock
r14563 this.key_value_lock = null;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.id = model_id;
this.views = [];
if (comm !== undefined) {
// Remember comm associated with the model.
this.comm = comm;
comm.model = this;
// Hook comm messages up to model.
comm.on_close($.proxy(this._handle_comm_closed, this));
comm.on_msg($.proxy(this._handle_comm_msg, this));
}
return Backbone.Model.apply(this);
},
send: function (content, callbacks) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Send a custom msg over the comm.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 if (this.comm !== undefined) {
Jonathan Frederic
s/custom_content/content
r14655 var data = {method: 'custom', content: content};
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.comm.send(data, callbacks);
Jonathan Frederic
Fixed bug in throttling code.
r14741 this.pending_msgs++;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 }
},
_handle_comm_closed: function (msg) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a widget is closed.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.trigger('comm:close');
delete this.comm.model; // Delete ref so GC will collect widget model.
delete this.comm;
delete this.model_id; // Delete id from model so widget manager cleans up.
Jonathan Frederic
Added code that removes the views when a model/widget is closed.
r14704 _.each(this.views, function(view, i) {
view.remove();
});
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
_handle_comm_msg: function (msg) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle incoming comm msg.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 var method = msg.content.data.method;
switch (method) {
case 'update':
this.apply_update(msg.content.data.state);
break;
case 'custom':
Jonathan Frederic
s/custom_content/content
r14655 this.trigger('msg:custom', msg.content.data.content);
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 break;
Jonathan Frederic
handle_msg a display_model method.
r14559 case 'display':
Jason Grout
Pass the whole message into the widget manager display_view call...
r14620 this.widget_manager.display_view(msg, this);
Jonathan Frederic
Add displayed property....
r15955 this.trigger('displayed');
Jonathan Frederic
handle_msg a display_model method.
r14559 break;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 }
},
apply_update: function (state) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle when a widget is updated via the python side.
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(state, function(value, key) {
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 that.key_value_lock = [key, value];
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 try {
Jonathan Frederic
Fixed, set on recieve update triggering echos.
r15283 WidgetModel.__super__.set.apply(that, [key, that._unpack_models(value)]);
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 } finally {
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 that.key_value_lock = null;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 }
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
_handle_status: function (msg, callbacks) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle status msgs.
// execution_state : ('busy', 'idle', 'starting')
Jonathan Frederic
Fixed *almost* all of the test-detected bugs
r14596 if (this.comm !== undefined) {
if (msg.content.execution_state ==='idle') {
// Send buffer if this message caused another message to be
// throttled.
if (this.msg_buffer !== null &&
Jonathan Frederic
Added parentheses to emphasize order of op.
r15369 (this.get('msg_throttle') || 3) === this.pending_msgs) {
Jonathan Frederic
Fixed *almost* all of the test-detected bugs
r14596 var data = {method: 'backbone', sync_method: 'update', sync_data: this.msg_buffer};
MinRK
quick review pass on javascript
r14792 this.comm.send(data, callbacks);
Jonathan Frederic
Fixed *almost* all of the test-detected bugs
r14596 this.msg_buffer = null;
} else {
--this.pending_msgs;
}
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 }
}
},
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 callbacks: function(view) {
Jason Grout
Rewrite widget syncing...
r14639 // Create msg callbacks for a comm msg.
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 var callbacks = this.widget_manager.callbacks(view);
if (callbacks.iopub === undefined) {
callbacks.iopub = {};
}
Jason Grout
Rewrite widget syncing...
r14639 var that = this;
callbacks.iopub.status = function (msg) {
that._handle_status(msg, callbacks);
MinRK
quick review pass on javascript
r14792 };
Jason Grout
Rewrite widget syncing...
r14639 return callbacks;
},
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546
Jonathan Frederic
Only send diff message if diff isn't corrupt....
r15279 set: function(key, val, options) {
// Set a value.
Jonathan Frederic
Keep a running diff instead of forcing a full state update
r15280 var return_value = WidgetModel.__super__.set.apply(this, arguments);
// Backbone only remembers the diff of the most recent set()
Jonathan Frederic
Fixed typo
r15281 // operation. Calling set multiple times in a row results in a
Jonathan Frederic
Keep a running diff instead of forcing a full state update
r15280 // loss of diff information. Here we keep our own running diff.
this._buffered_state_diff = $.extend(this._buffered_state_diff, this.changedAttributes() || {});
return return_value;
Jonathan Frederic
Only send diff message if diff isn't corrupt....
r15279 },
Jason Grout
Rewrite widget syncing...
r14639 sync: function (method, model, options) {
Jonathan Frederic
Added some small comments to widget code
r14668 // Handle sync to the back-end. Called when a model.save() is called.
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640
// Make sure a comm exists.
var error = options.error || function() {
console.error('Backbone sync error:', arguments);
MinRK
quick review pass on javascript
r14792 };
Jason Grout
Rewrite widget syncing...
r14639 if (this.comm === undefined) {
error();
return false;
}
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 // Delete any key value pairs that the back-end already knows about.
Jonathan Frederic
Revert "Fix incorrect usage of attrs"...
r15274 var attrs = (method === 'patch') ? options.attrs : model.toJSON(options);
Jason Grout
Rewrite widget syncing...
r14639 if (this.key_value_lock !== null) {
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 var key = this.key_value_lock[0];
var value = this.key_value_lock[1];
if (attrs[key] === value) {
delete attrs[key];
Jason Grout
Rewrite widget syncing...
r14639 }
}
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 // Only sync if there are attributes to send to the back-end.
Jonathan Frederic
Only send diff message if diff isn't corrupt....
r15279 attrs = this._pack_models(attrs);
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 if (_.size(attrs) > 0) {
Jonathan Frederic
Fixed bug in throttling code.
r14741
// If this message was sent via backbone itself, it will not
// have any callbacks. It's important that we create callbacks
// so we can listen for status messages, etc...
var callbacks = options.callbacks || this.callbacks();
// Check throttle.
Jonathan Frederic
Added parentheses to emphasize order of op.
r15369 if (this.pending_msgs >= (this.get('msg_throttle') || 3)) {
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 // The throttle has been exceeded, buffer the current msg so
// it can be sent once the kernel has finished processing
// some of the existing messages.
// Combine updates if it is a 'patch' sync, otherwise replace updates
switch (method) {
case 'patch':
Jonathan Frederic
Prefer JQuery to Underscore
r14662 this.msg_buffer = $.extend(this.msg_buffer || {}, attrs);
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 break;
case 'update':
Jonathan Frederic
'create' should be handled in sync
r14661 case 'create':
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 this.msg_buffer = attrs;
break;
default:
error();
return false;
}
this.msg_buffer_callbacks = callbacks;
} else {
// We haven't exceeded the throttle, send the message like
Jonathan Frederic
Fixed bug in throttling code.
r14741 // normal.
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 var data = {method: 'backbone', sync_data: attrs};
this.comm.send(data, callbacks);
this.pending_msgs++;
}
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 }
// Since the comm is a one-way communication, assume the message
Jason Grout
Rewrite widget syncing...
r14639 // arrived. Don't call success since we don't have a model back from the server
// this means we miss out on the 'sync' event.
Jonathan Frederic
Keep a running diff instead of forcing a full state update
r15280 this._buffered_state_diff = {};
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
Jason Grout
Rewrite widget syncing...
r14639 save_changes: function(callbacks) {
Jonathan Frederic
Remove residual tabs
r14651 // Push this model's state to the back-end
//
// This invokes a Backbone.Sync.
Jonathan Frederic
Keep a running diff instead of forcing a full state update
r15280 this.save(this._buffered_state_diff, {patch: true, callbacks: callbacks});
Jason Grout
make the saving to python a method of the model, called with callbacks...
r14618 },
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 _pack_models: function(value) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Replace models with model ids recursively.
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 if (value instanceof Backbone.Model) {
return value.id;
Jonathan Frederic
Added ability to pack and unpack arrays.
r15063
} else if ($.isArray(value)) {
var packed = [];
var that = this;
_.each(value, function(sub_value, key) {
packed.push(that._pack_models(sub_value));
});
return packed;
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 } else if (value instanceof Object) {
var packed = {};
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(value, function(sub_value, key) {
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 packed[key] = that._pack_models(sub_value);
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return packed;
Jonathan Frederic
Added ability to pack and unpack arrays.
r15063
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 } else {
return value;
}
},
_unpack_models: function(value) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Replace model ids with models recursively.
Jonathan Frederic
Added ability to pack and unpack arrays.
r15063 if ($.isArray(value)) {
var unpacked = [];
var that = this;
_.each(value, function(sub_value, key) {
unpacked.push(that._unpack_models(sub_value));
});
return unpacked;
} else if (value instanceof Object) {
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 var unpacked = {};
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(value, function(sub_value, key) {
Jonathan Frederic
Fixed context errors and a couple of typos to get the tests working again
r14686 unpacked[key] = that._unpack_models(sub_value);
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 });
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return unpacked;
Jonathan Frederic
Added ability to pack and unpack arrays.
r15063
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 } else {
var model = this.widget_manager.get_model(value);
MinRK
quick review pass on javascript
r14792 if (model) {
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 return model;
} else {
return value;
}
}
},
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 });
Jonathan Frederic
Widget require.js fix...
r14627 WidgetManager.register_widget_model('WidgetModel', WidgetModel);
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var WidgetView = Backbone.View.extend({
Jonathan Frederic
un-nest options.options
r14565 initialize: function(parameters) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Public constructor.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.model.on('change',this.update,this);
Jonathan Frederic
un-nest options.options
r14565 this.options = parameters.options;
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 this.child_model_views = {};
this.child_views = {};
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.model.views.push(this);
},
update: function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Triggered on model change.
//
// Update view to be consistent with this.model
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598 create_child_view: function(child_model, options) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Create and return a child view.
//
Jason Grout
Fix the cell reference in views...
r14617 // -given a model and (optionally) a view name if the view name is
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // not given, it defaults to the model's default view attribute.
Jonathan Frederic
Remove residual tabs
r14651
Jason Grout
Fix the cell reference in views...
r14617 // TODO: this is hacky, and makes the view depend on this cell attribute and widget manager behavior
Jonathan Frederic
Remove residual tabs
r14651 // it would be great to have the widget manager add the cell metadata
// to the subview without having to add it here.
Jonathan Frederic
Fixed bug where views child to other views would not have cell information
r14689 var child_view = this.model.widget_manager.create_view(child_model, options || {}, this);
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172
// Associate the view id with the model id.
if (this.child_model_views[child_model.id] === undefined) {
this.child_model_views[child_model.id] = [];
}
this.child_model_views[child_model.id].push(child_view.id);
// Remember the view by id.
this.child_views[child_view.id] = child_view;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 return child_view;
},
Jonathan Frederic
Got containers and mutlicontainers working! Yay
r14598
delete_child_view: function(child_model, options) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Delete a child view that was previously created using create_child_view.
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 var view_ids = this.child_model_views[child_model.id];
if (view_ids !== undefined) {
Jonathan Frederic
Fixed buggy behavior
r17173 // Only delete the first view in the list.
var view_id = view_ids[0];
var view = this.child_views[view_id];
delete this.child_views[view_id];
delete view_ids[0];
child_model.views.pop(view);
// Remove the view list specific to this model if it is empty.
if (view_ids.length === 0) {
delete this.child_model_views[child_model.id];
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 }
Jonathan Frederic
Fixed buggy behavior
r17173 return view;
Jonathan Frederic
- remove second line in create_child_view...
r14667 }
Jonathan Frederic
Fixed buggy behavior
r17173 return null;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
Jonathan Frederic
Add order respecting method
r17174 do_diff: function(old_list, new_list, removed_callback, added_callback, respect_order) {
Jonathan Frederic
Add a helper method that acts on the changes made to a list.
r14580 // Difference a changed list and call remove and add callbacks for
// each removed and added item in the new list.
//
// Parameters
// ----------
// old_list : array
// new_list : array
// removed_callback : Callback(item)
// Callback that is called for each item removed.
// added_callback : Callback(item)
// Callback that is called for each item added.
Jonathan Frederic
Add order respecting method
r17174 // [respect_order] : bool [True]
// Whether or not the order of the list matters.
if (respect_order || respect_order===undefined) {
// Walk the lists until an unequal entry is found.
var i;
for (i = 0; i < new_list.length; i++) {
if (i < old_list.length || new_list[i] !== old_list[i]) {
break;
}
}
Jonathan Frederic
Add a helper method that acts on the changes made to a list.
r14580
Jonathan Frederic
Add order respecting method
r17174 // Remove the non-matching items from the old list.
for (var j = i; j < old_list.length; j++) {
console.log(j, old_list.length, old_list[j]);
removed_callback(old_list[j]);
}
Jonathan Frederic
Add a helper method that acts on the changes made to a list.
r14580
Jonathan Frederic
Add order respecting method
r17174 // Add the rest of the new list items.
for (i; i < new_list.length; i++) {
added_callback(new_list[i]);
}
} else {
// removed items
_.each(this.difference(old_list, new_list), function(item, index, list) {
removed_callback(item);
}, this);
// added items
_.each(this.difference(new_list, old_list), function(item, index, list) {
added_callback(item);
}, this);
}
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 },
Jonathan Frederic
Add a helper method that acts on the changes made to a list.
r14580
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 difference: function(a, b) {
// Calculate the difference of two lists by contents.
//
// This function is like the underscore difference function
// except it will not fail when given a list with duplicates.
// i.e.:
// diff([1, 2, 2, 3], [3, 2])
// Underscores results:
// [1]
// This method:
// [1, 2]
var contents = a.slice(0);
var found_index;
for (var i = 0; i < b.length; i++) {
found_index = _.indexOf(contents, b[i]);
if (found_index >= 0) {
contents.splice(found_index, 1);
}
}
return contents;
},
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 callbacks: function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Create msg callbacks for a comm msg.
Jonathan Frederic
Change the callback logic so the order makes more sense:...
r14640 return this.model.callbacks(this);
Jonathan Frederic
Added missing comma
r14560 },
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546
render: function(){
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Render the view.
//
// By default, this is only called the first time the view is created
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 send: function (content) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Send a custom msg associated with this view.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.model.send(content, this.callbacks());
},
touch: function () {
Jason Grout
Rewrite widget syncing...
r14639 this.model.save_changes(this.callbacks());
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
});
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 var DOMWidgetView = WidgetView.extend({
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 initialize: function (options) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Public constructor
// In the future we may want to make changes more granular
// (e.g., trigger on visible:change).
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 this.model.on('change', this.update, this);
this.model.on('msg:custom', this.on_msg, this);
Jonathan Frederic
Many checks off the todo list, test fixes
r14583 DOMWidgetView.__super__.initialize.apply(this, arguments);
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
on_msg: function(msg) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Handle DOM specific msgs.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 switch(msg.msg_type) {
case 'add_class':
this.add_class(msg.selector, msg.class_list);
break;
case 'remove_class':
this.remove_class(msg.selector, msg.class_list);
break;
}
},
add_class: function (selector, class_list) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Add a DOM class to an element.
Jonathan Frederic
remove length test add_class and remove_class
r14567 this._get_selector_element(selector).addClass(class_list);
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
remove_class: function (selector, class_list) {
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609 // Remove a DOM class from an element.
Jonathan Frederic
remove length test add_class and remove_class
r14567 this._get_selector_element(selector).removeClass(class_list);
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
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.
// The very first update seems to happen before the element is
// finished rendering so we use setTimeout to give the element time
// to render
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 var e = this.$el;
var visible = this.model.get('visible');
MinRK
quick review pass on javascript
r14792 setTimeout(function() {e.toggle(visible);},0);
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546
var css = this.model.get('_css');
if (css === undefined) {return;}
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 var that = this;
_.each(css, function(css_traits, selector){
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 // Apply the css traits to all elements that match the selector.
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 var elements = that._get_selector_element(selector);
Jonathan Frederic
Removed for () loops where necessary. Replaced with _.each
r14664 if (elements.length > 0) {
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 _.each(css_traits, function(css_value, css_key){
elements.css(css_key, css_value);
});
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 }
Jonathan Frederic
Allow a widget to be displayed more than once within a parent widget.
r17172 });
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 },
_get_selector_element: function (selector) {
MinRK
quick review pass on javascript
r14792 // Get the elements via the css selector.
Jonathan Frederic
Added PEP8 style comments to all of the JS code.
r14609
// If the selector is blank, apply the style to the $el_to_style
// element. If the $el_to_style element is not defined, use apply
// the style to the view's element.
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 var elements;
MinRK
quick review pass on javascript
r14792 if (!selector) {
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 if (this.$el_to_style === undefined) {
elements = this.$el;
} else {
elements = this.$el_to_style;
}
} else {
elements = this.$el.find(selector);
}
return elements;
},
});
IPython.WidgetModel = WidgetModel;
IPython.WidgetView = WidgetView;
Jonathan Frederic
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
r14564 IPython.DOMWidgetView = DOMWidgetView;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546
Jonathan Frederic
Widget require.js fix...
r14627 // Pass through WidgetManager namespace.
return WidgetManager;
Jonathan Frederic
renamed: basic_widgets.js -> init.js...
r14546 });