-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPEP 23: Backbone.js Widgets #4374
Merged
Merged
Changes from 1 commit
Commits
Show all changes
474 commits
Select commit
Hold shift + click to select a range
428a8bf
- ModalView can now be docked and undocked
jdfreder 2cf5ad7
- Fixed CSS so it also applies to widgets within modals
jdfreder 108ab2b
Fab CSS
jdfreder 8160877
s/LabelView/HTMLView
jdfreder 09112f4
Added LatexView
jdfreder 73f786b
Remove uneccessary lines in String.js
jdfreder 36f8d83
Add ImageWidget
jdfreder c633979
Added float range widget tests
jdfreder 8995edf
Fixed flushed messages not getting sent with new 'method' message tag
jdfreder cc21fe3
Added float widget tests
jdfreder 7ea0c5b
Added ImageWidget tests
jdfreder b8242a9
Added int range and int widget tests.
jdfreder 6f24736
Fixed backbone event handling for accordion view
jdfreder 60d945e
Added multicontainer widget tests
jdfreder 0678a52
jshint widget.js
jdfreder 400ef7d
Partially implemented selection widget tests
jdfreder 6ba0bab
Removed js test utils commit and rebased with master.
jdfreder ab1a8d2
Added selection widget tests
jdfreder 4e15ad1
Added list modification test to selection widget.
jdfreder 69edada
Added StringWidget tests
jdfreder 8861e54
Added throttling test
jdfreder e86db29
Organized tests.
jdfreder 8af19c3
Removed button.close() test because it caused the test framework to hang
jdfreder c25f02e
jslint /widgets
jdfreder 57bb760
Fixed context of onclick callbacks selection widget views
jdfreder 20fe605
Fixed some spacing in widget.js
jdfreder 8245b9b
Removed comm dependency of widget model and view
jdfreder 5d84782
Moved base widget model and view into widgets/base.js
jdfreder a09d70a
renamed: widget.js -> widgetmanager.js
jdfreder e785146
Fix, require.js needs return of widget manager for other widgets
jdfreder 90f97b8
Made display_view a public method.
jdfreder 3f5f27b
Made widget model state update function public
jdfreder 577ee63
Fixed nonregistered model bug in wiget manager
jdfreder ab24918
Removed unused that from widget manager
jdfreder 45a7ef8
Added parent parameter to on_display callback
jdfreder 6135b20
Added event for widget construction
jdfreder 8ec7166
Decoupled Python Widget from Comm
jdfreder 318baad
Remove redundent _handle_close method
jdfreder 47fda15
s/display/created for display_view stuff
jdfreder c102908
Moved touch logic out of model into view.
jdfreder 6e353ea
Added require.js shims for underscore and backbone
jdfreder 81257c2
Display handler now supports full kwargs
jdfreder 9811ba7
Separate the display from the models on the python side, creating a B…
66c8209
Intermediate changes to javascript side of backbone widgets
a1d2451
Remove the automatic _children_attr and _children_lists_attr.
793dcac
Remove unused code and debugging statements
9a1f2d3
Change accordion to use a children attribute
af63861
Delete unnecessary check for comm object
e3803e4
Move all references to cells to the view objects.
4441be8
Make updates more granular for widgets
010861f
Store views in the models and store child views in the views
3925c2a
Delete the snapshot message handler
a20d81a
Note todos for widgets
8dc15ec
fix a handle_status handler
4a084cc
Fix visible attribute for the very first render
2a81271
Make sure containers transmit the children; take care of case where c…
c691a7b
log the error stack for a kernel javascript error message
49d1da2
Move some Widget class references to BaseWidget
46d68b6
General cleanup of base.js, including indentation fixes and adding vi…
0137755
Get the add/remove css classes working
e234b21
Live updates for children automatically change container views.
a5d454b
Fix the python side of the add/remove class functions to send custom …
0aa8d33
Example notebooks updated.
48132d8
Converted tabs to spaces
jdfreder ebf151f
Added `update_children` pattern to remaining parent widgets
jdfreder a1aa8a3
Revert 2853eb41 's changes to traitlets
jdfreder 14b278e
Fixed JS tests to reflect Jason's changes
jdfreder 313cb90
renamed: wigets_container.js -> widgets_container.js
jdfreder 250e4f8
Added ViewWidget
jdfreder 49568c8
Re-decoupled comm_id from widget models
jdfreder 72af074
Removed console.log, unused
jdfreder 48deda6
Further indentation cleanup
jdfreder 60a426d
Fixed indent of line 450
jdfreder 7eeebf9
Moved view widget into widget.py
jdfreder 43c7823
Fixed indentation in widgetmanager.js
jdfreder 3fb7c52
Added line to dump page html casperjs
jdfreder adcd464
Enabled IPython Server output for Travis debugging
jdfreder c9888ee
Fixed static_url call which is no longer optionally 1 param
jdfreder 14459cf
Revert "Added line to dump page html casperjs"
jdfreder 5f99aad
Revert "Enabled IPython Server output for Travis debugging"
jdfreder 239f408
deleted: wigets_container.js
jdfreder 10a25b0
Print cell output
jdfreder b8e7ee9
Output one more for debugging
jdfreder 61db77c
Remove debug print statements in container tests
jdfreder 4d3ff81
Fixed typo in model_id property
jdfreder 84c0d03
Add widget view options in creating child views
f32e48c
Make the widget keys property traverse the superclasses and accumulat…
2451833
Get rid of keys magic; make the keys very explicit
075fab9
Make widget keys have more explicit inheritance
5e611bf
s/comm_id/model_id (left over from before)
jdfreder 52963fb
Updated comm id comments in view to model id
jdfreder b60a6f9
Completely remove cell from model and view.
jdfreder 2105d1a
Missing view argument when recursively calling widgetmanager.callback…
jdfreder a1286a4
Renamed widget js files
jdfreder c1bdf44
Updated require.js references
jdfreder 032f65b
Removed ViewWidget
jdfreder b4e4da3
add/remove_class now can accept a list of classes
jdfreder 6aabc0c
s/Widget/DOMWidget s/BaseWidget/Widget
jdfreder 1d180d4
s/default_view_name/view_name
jdfreder 888af91
s/_handle_widget_constructed/_call_widget_constructed
jdfreder e141746
Removed sync_method parameter from backbone msg spec
jdfreder 9c567f4
Added callbacks method to view
jdfreder 5334cab
s/widget.js/init.js
jdfreder a165819
renamed: basic_widgets.js -> init.js
jdfreder 6dd1ffd
Remove first three lines of repr widgets
jdfreder e73528c
Fixed _send so it can open a comm if needed.
jdfreder 311bda4
Remove view_name from display
jdfreder b67870c
remove 3rd callback type from on_displayed
jdfreder dfb0eb9
Fixed comments for optional kwargs so they are redundant.
jdfreder f3f38c8
send_state only once for dict signature of set_css
jdfreder cf2d9c4
_model_types, _view_types, _models - and document what keys and value…
jdfreder ed3d721
move backbone sync outside the widget manager class
jdfreder 310f261
remove msg.content.data.view_name and corrosponding create_view param
jdfreder 9877ef3
remove on_create_widget and handle_create_widget callback
jdfreder 33de470
Added note in widget manager why Backbone.sync is there rather
jdfreder 17ae963
re-order handle custom msg and handle recieve state
jdfreder 6d7f1c7
handle_msg a display_model method.
jdfreder 742e09b
Added missing comma
jdfreder d43ea71
Add constructor comment for widget model.
jdfreder 4369d73
Update option-passing for creating child views.
d0e1f9e
this.updating should be a key specific lock
jdfreder 6fe7aad
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
jdfreder 37f98c1
un-nest options.options
jdfreder 592da7d
Removed get_kernel method.
jdfreder 25f40ff
remove length test add_class and remove_class
jdfreder 515cf55
make JS update comment more descriptive (english)
jdfreder 500d8a3
comment model.set, so we know that it triggers update on other views
jdfreder 4e85339
add locks to update everywhere by using options to pass this
jdfreder af3cb8e
toggle button, set $el to button (removing extra div)
jdfreder bdf9a53
add comment views are in *_range
jdfreder 9139587
document _keys function and rename to jquery_slider_keys
jdfreder 8d175cf
s/image_format/format
jdfreder 4139a38
s/flaot/float
jdfreder a8db290
remove .html('');
jdfreder 404faa0
renamed: ../static/notebook/js/widgets/widget_multicontainer.js ->…
jdfreder 10a84ac
Finished renaming Multicontainer to SelectionContainer
jdfreder f0c9c00
Implement a context manager as a property locking mechanism in Widget.
jdfreder 92f4bb5
Add a helper method that acts on the changes made to a list.
jdfreder 304e2e4
Add a comment that explains the notion of the default element
jdfreder 1e8bd2e
Use .apply for calling base with not proto-type.
jdfreder ecbe638
Many checks off the todo list, test fixes
jdfreder 27be0fb
remove unused imports
ivanov daa3b6a
fix typos
ivanov e5dbb96
Dev meeting widget review day 1
jdfreder d8f5efb
Dev meeting Jan 2014, widget review day 2
jdfreder f1c3742
sync=True isntead of a keys list
jdfreder 1da6d0e
Added sync= attr to DOMWidget
jdfreder bff850b
Added sync=True to all view name attrs
jdfreder a76124e
Everyone uses one model
jdfreder a8368df
1-to-1 widget / view mapping
jdfreder f795cc3
Renamed *range test files to match other widget files
jdfreder b6908b1
A lot of bug fixes...
jdfreder 597c46c
More fixes
jdfreder 5cd3303
Fixed *almost* all of the test-detected bugs
jdfreder e1fdcc9
Fix test for selection widgets
jdfreder ed52e82
Got containers and mutlicontainers working! Yay
jdfreder f8345e1
Fab CSS
jdfreder 071fae6
Fix rebase issues
jdfreder a57e02d
Make widget views work with new keyboard manager.
jdfreder be029cd
Update component submodule to point to master
jdfreder 0311a8c
s/Int/CInt s/Float/CFloat
jdfreder c04aab1
Remove O(N) cell by msg-id lookup
jdfreder 0acd418
Added value validation on Python side.
jdfreder 0e56b40
Change orientation to Enum
jdfreder 32716dc
More PEP8 changes
jdfreder bb79d34
containers and selectioncontainers now only allow one of any single c…
jdfreder af37dd3
Added PEP8 style comments to all of the JS code.
jdfreder b25d6b3
Halign dict colons
jdfreder 603e41a
Fix bug in all children containing views
jdfreder 2b9fe45
Make dropdown view DOM swap elements on update.
jdfreder 6d0b62e
Fix the cell reference in views
df4f733
make the saving to python a method of the model, called with callbacks
eea2b79
update example notebooks
bd1ba86
Pass the whole message into the widget manager display_view call
c3a0818
Delete unnecessary save
43cee97
Cherry pick of @jasongrout 's 2bc2f96.
jdfreder 94a5aed
Added support for multiple kernels.
jdfreder 676624e
Fixed widget_manager instance test.
jdfreder f9ac12e
Widget require.js fix
jdfreder 3527bb2
Repr style out for widgets
jdfreder c92edbc
Better implementation of widget _repr_ style display logic.
jdfreder 92e9682
Added a line that was accidently deleted during merge of 4e813c5
jdfreder 262451e
Use is to compare NotImplemented
jdfreder 4e813c5
Rewrite widget syncing
e15e352
Change the callback logic so the order makes more sense:
jdfreder a6ff4f4
Remove residual tabs
jdfreder ff01af6
Reorganized attrs in widget.py
jdfreder 63d2f7a
Added doc strings to properties in widget.py
jdfreder fc964e6
s/custom_content/content
jdfreder 07dc2a7
ict comprehension and list comprehension in pack/unpack widgets
jdfreder 585885a
Document in widget packing that vaues must be JSON-able.
jdfreder 70a076d
Added new CallbackDispatcher class
jdfreder 11ca541
Fixed name conflict with _property_lock
jdfreder b15593f
Remove todo in apply update
jdfreder 5f40d5d
'create' should be handled in sync
jdfreder c6b69b2
Prefer JQuery to Underscore
jdfreder 77e364d
Replace .html with .text everywhere possible
jdfreder 9d49e0e
Removed for () loops where necessary. Replaced with _.each
jdfreder 201886e
Explicitly return null if there aren't any results
jdfreder 07e2df5
- remove second line in create_child_view
jdfreder 1e0859f
Added some small comments to widget code
jdfreder a811539
Use CUnicode for width and height in ImageWidget
jdfreder 3644592
Create base widget classes
jdfreder 1b8ed2a
deleted: widget_float_range.py
jdfreder 2798de1
Move js *RangeWidget code into *Widget
jdfreder 19e4b58
deleted: widget_float_range.js
jdfreder 1d5afc3
Made tests reflect changes to widget naming scheme.
jdfreder 71765e9
deleted: widgets_float_range.js
jdfreder 25a9d02
s/ModalView/PopupView
jdfreder 094e02a
Fixed typo - else -> elif
jdfreder 442154d
Fixed some typos related to _.each loops
jdfreder ddb2afa
Fixed context errors and a couple of typos to get the tests working a…
jdfreder 6ceec8d
Fixed a couple more context typos
jdfreder a341ba2
Updated subcomponents
jdfreder 29cac5a
Fixed bug where views child to other views would not have cell inform…
jdfreder 287a0a7
Removed float widget bound tests,
jdfreder e952756
Adjusted throttling
jdfreder 2af96a6
Float widget views now inherit from int counterparts
jdfreder f3b6c24
Support multiple types in selection widget.
jdfreder 48fcdd1
Replace O(N^2) algorithm with a faster one.
jdfreder 53b368b
s/view_name/_view_name
jdfreder 719d9ac
Added code that removes the views when a model/widget is closed.
jdfreder 615ab9a
Updated widget tutorials 1-2
jdfreder eab8dac
Changed selection widget API to use labels list
jdfreder 6413603
Fixed type in container
jdfreder 4817003
Updated examples 3-6
jdfreder 91c7760
Callback dispatcher return callback value.
jdfreder e4f69ed
Fixed bug in selection widget tests.
jdfreder 796c0ed
Cleanup examples
jdfreder 86eac83
Removed Dialogs example, since PopupWidgets are available.
jdfreder 4c316a8
Moved keyboard_manager logic into a sep. function.
jdfreder 3c96e03
Fixed bug in throttling code.
jdfreder c70540b
Fixed some more example files (see list below)...
jdfreder 65caa63
Updated cell numbering in console example.
jdfreder fac8110
Prevent TextBox from blurring unless explicity by user.
jdfreder 9ab757f
Simplified variable inspector example
jdfreder c8996c4
Fixed bug that prevented popup widget from displaying
jdfreder 217ad48
Removed D3 and Widget Tester examples for now, until they are fixed..
jdfreder 4ebd115
review pass on widgetmanager.js
minrk de90ea1
quick review pass on javascript
minrk 9cf2bba
review pass on Python-side of widgets
minrk 6721e7f
catch NotImplementedError, not NotImplemented
minrk ce69b63
Document _ipython_display_ in custom display logic
minrk 85a0de3
first review pass on widget tests
minrk ae6ac19
review pass on widget examples
minrk 4c141af
Merge pull request #11 from minrk/widgets
jdfreder 27b06ff
Removed blame comment
jdfreder 42d6b44
Simplify get_msg_cell function of notebook.js
jdfreder 5ed9376
Renamed widgets...
jdfreder d661486
Fixed Accordion test broken by last commit
jdfreder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
renamed: basic_widgets.js -> init.js
renamed: init.js -> widget.js
- Loading branch information
commit a165819e48d1e34cf4f5599706f5694c842593c0
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
//---------------------------------------------------------------------------- | ||
// 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 | ||
**/ | ||
|
||
define(["notebook/js/widgetmanager", | ||
"underscore", | ||
"backbone"], | ||
function(widget_manager, underscore, backbone){ | ||
|
||
//-------------------------------------------------------------------- | ||
// WidgetModel class | ||
//-------------------------------------------------------------------- | ||
var WidgetModel = Backbone.Model.extend({ | ||
constructor: function (widget_manager, model_id, comm) { | ||
this.widget_manager = widget_manager; | ||
this.pending_msgs = 0; | ||
this.msg_throttle = 3; | ||
this.msg_buffer = null; | ||
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) { | ||
if (this.comm !== undefined) { | ||
var data = {method: 'custom', custom_content: content}; | ||
this.comm.send(data, callbacks); | ||
} | ||
}, | ||
|
||
// Handle when a widget is closed. | ||
_handle_comm_closed: function (msg) { | ||
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. | ||
// TODO: Handle deletion, like this.destroy(), and delete views, etc. | ||
}, | ||
|
||
|
||
// Handle incoming comm msg. | ||
_handle_comm_msg: function (msg) { | ||
var method = msg.content.data.method; | ||
switch (method) { | ||
case 'update': | ||
this.apply_update(msg.content.data.state); | ||
break; | ||
case 'custom': | ||
this.trigger('msg:custom', msg.content.data.custom_content); | ||
break; | ||
default: | ||
// pass on to widget manager | ||
this.widget_manager.handle_msg(msg, this); | ||
} | ||
}, | ||
|
||
|
||
// Handle when a widget is updated via the python side. | ||
apply_update: function (state) { | ||
this.updating = true; | ||
try { | ||
for (var key in state) { | ||
if (state.hasOwnProperty(key)) { | ||
this.set(key, state[key]); | ||
} | ||
} | ||
//TODO: are there callbacks that make sense in this case? If so, attach them here as an option | ||
this.save(); | ||
} finally { | ||
this.updating = false; | ||
} | ||
}, | ||
|
||
|
||
_handle_status: function (msg, callbacks) { | ||
//execution_state : ('busy', 'idle', 'starting') | ||
if (this.comm !== undefined && msg.content.execution_state ==='idle') { | ||
// Send buffer if this message caused another message to be | ||
// throttled. | ||
if (this.msg_buffer !== null && | ||
this.msg_throttle === this.pending_msgs) { | ||
var data = {method: 'backbone', sync_method: 'update', sync_data: this.msg_buffer}; | ||
this.comm.send(data, callbacks); | ||
this.msg_buffer = null; | ||
} else { | ||
// Only decrease the pending message count if the buffer | ||
// doesn't get flushed (sent). | ||
--this.pending_msgs; | ||
} | ||
} | ||
}, | ||
|
||
|
||
// Custom syncronization logic. | ||
_handle_sync: function (method, options) { | ||
var model_json = this.toJSON(); | ||
var attr; | ||
|
||
// Only send updated state if the state hasn't been changed | ||
// during an update. | ||
if (this.comm !== undefined) { | ||
if (!this.updating) { | ||
if (this.pending_msgs >= this.msg_throttle) { | ||
// 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. | ||
if (method=='patch') { | ||
if (this.msg_buffer === null) { | ||
this.msg_buffer = $.extend({}, model_json); // Copy | ||
} | ||
for (attr in options.attrs) { | ||
this.msg_buffer[attr] = options.attrs[attr]; | ||
} | ||
} else { | ||
this.msg_buffer = $.extend({}, model_json); // Copy | ||
} | ||
|
||
} else { | ||
// We haven't exceeded the throttle, send the message like | ||
// normal. If this is a patch operation, just send the | ||
// changes. | ||
var send_json = model_json; | ||
if (method =='patch') { | ||
send_json = {}; | ||
for (attr in options.attrs) { | ||
send_json[attr] = options.attrs[attr]; | ||
} | ||
} | ||
|
||
var data = {method: 'backbone', sync_data: send_json}; | ||
this.comm.send(data, options.callbacks); | ||
this.pending_msgs++; | ||
} | ||
} | ||
} | ||
|
||
// Since the comm is a one-way communication, assume the message | ||
// arrived. | ||
return model_json; | ||
}, | ||
|
||
}); | ||
|
||
|
||
//-------------------------------------------------------------------- | ||
// WidgetView class | ||
//-------------------------------------------------------------------- | ||
var BaseWidgetView = Backbone.View.extend({ | ||
initialize: function(options) { | ||
this.model.on('change',this.update,this); | ||
this.widget_manager = options.widget_manager; | ||
this.comm_manager = options.widget_manager.comm_manager; | ||
this.options = options.options; | ||
this.child_views = []; | ||
this.model.views.push(this); | ||
}, | ||
|
||
update: function(){ | ||
// update view to be consistent with this.model | ||
// triggered on model change | ||
}, | ||
|
||
child_view: function(model_id, view_name, options) { | ||
// create and return a child view, given a model id for a model and (optionally) a view name | ||
// if the view name is not given, it defaults to the model's default view attribute | ||
var child_model = this.widget_manager.get_model(model_id); | ||
var child_view = this.widget_manager.create_view(child_model, view_name, options); | ||
this.child_views[model_id] = child_view; | ||
return child_view; | ||
}, | ||
|
||
update_child_views: function(old_list, new_list) { | ||
// this function takes an old list and new list of model ids | ||
// views in child_views that correspond to deleted ids are deleted | ||
// views corresponding to added ids are added child_views | ||
|
||
// delete old views | ||
_.each(_.difference(old_list, new_list), function(element, index, list) { | ||
var view = this.child_views[element]; | ||
delete this.child_views[element]; | ||
view.remove(); | ||
}, this); | ||
|
||
// add new views | ||
_.each(_.difference(new_list, old_list), function(element, index, list) { | ||
// this function adds the view to the child_views dictionary | ||
this.child_view(element); | ||
}, this); | ||
}, | ||
|
||
callbacks: function(){ | ||
return this.widget_manager.callbacks(this); | ||
} | ||
|
||
render: function(){ | ||
// render the view. By default, this is only called the first time the view is created | ||
}, | ||
send: function (content) { | ||
this.model.send(content, this.callbacks()); | ||
}, | ||
|
||
touch: function () { | ||
this.model.save(this.model.changedAttributes(), {patch: true, callbacks: this.callbacks()}); | ||
}, | ||
|
||
}); | ||
|
||
var WidgetView = BaseWidgetView.extend({ | ||
initialize: function (options) { | ||
// TODO: make changes more granular (e.g., trigger on visible:change) | ||
this.model.on('change', this.update, this); | ||
this.model.on('msg:custom', this.on_msg, this); | ||
BaseWidgetView.prototype.initialize.apply(this, arguments); | ||
}, | ||
|
||
on_msg: function(msg) { | ||
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) { | ||
var elements = this._get_selector_element(selector); | ||
if (elements.length > 0) { | ||
elements.addClass(class_list); | ||
} | ||
}, | ||
|
||
remove_class: function (selector, class_list) { | ||
var elements = this._get_selector_element(selector); | ||
if (elements.length > 0) { | ||
elements.removeClass(class_list); | ||
} | ||
}, | ||
|
||
update: function () { | ||
// the very first update seems to happen before the element is finished rendering | ||
// so we use setTimeout to give the element time to render | ||
var e = this.$el; | ||
var visible = this.model.get('visible'); | ||
setTimeout(function() {e.toggle(visible)},0); | ||
|
||
var css = this.model.get('_css'); | ||
if (css === undefined) {return;} | ||
for (var selector in css) { | ||
if (css.hasOwnProperty(selector)) { | ||
// Apply the css traits to all elements that match the selector. | ||
var elements = this._get_selector_element(selector); | ||
if (elements.length > 0) { | ||
var css_traits = css[selector]; | ||
for (var css_key in css_traits) { | ||
if (css_traits.hasOwnProperty(css_key)) { | ||
elements.css(css_key, css_traits[css_key]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
|
||
_get_selector_element: function (selector) { | ||
// Get the elements via the css selector. 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. | ||
var elements; | ||
if (selector === undefined || selector === null || selector === '') { | ||
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; | ||
IPython.BaseWidgetView = BaseWidgetView; | ||
|
||
return widget_manager; | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma after brace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!