diff --git a/jupyter_notebook/static/notebook/js/codecell.js b/jupyter_notebook/static/notebook/js/codecell.js index 7577c366b0..ea70a47d54 100644 --- a/jupyter_notebook/static/notebook/js/codecell.js +++ b/jupyter_notebook/static/notebook/js/codecell.js @@ -231,7 +231,7 @@ define([ var that = this; return view_promise.then(function(view) { that.widget_area.show(); - dummy.replaceWith(view.$el); + dummy.replaceWith(view.el); that.widget_views.push(view); // Check the live state of the view's model. diff --git a/jupyter_notebook/static/notebook/js/keyboardmanager.js b/jupyter_notebook/static/notebook/js/keyboardmanager.js index 883c5f308e..be2171b272 100644 --- a/jupyter_notebook/static/notebook/js/keyboardmanager.js +++ b/jupyter_notebook/static/notebook/js/keyboardmanager.js @@ -188,6 +188,7 @@ define([ }; KeyboardManager.prototype.register_events = function (e) { + e = $(e); var that = this; var handle_focus = function () { that.disable(); diff --git a/jupyter_notebook/static/widgets/js/manager.js b/jupyter_notebook/static/widgets/js/manager.js index ee927cb82e..a5425c9879 100644 --- a/jupyter_notebook/static/widgets/js/manager.js +++ b/jupyter_notebook/static/widgets/js/manager.js @@ -4,11 +4,10 @@ define([ "underscore", "backbone", - "jquery", "base/js/utils", "base/js/namespace", "services/kernels/comm" -], function (_, Backbone, $, utils, IPython, comm) { +], function (_, Backbone, utils, IPython, comm) { "use strict"; //-------------------------------------------------------------------- // WidgetManager class @@ -27,7 +26,7 @@ define([ this._models = {}; /* Dictionary of model ids and model instance promises */ // Register with the comm manager. - this.comm_manager.register_target(this.comm_target_name, $.proxy(this._handle_comm_open, this)); + this.comm_manager.register_target(this.comm_target_name, _.bind(this._handle_comm_open, this)); // Load the initial state of the widget manager if a load callback was // registered. @@ -163,7 +162,7 @@ define([ * Note, this is only done on the outer most widgets. */ if (this.keyboard_manager) { - this.keyboard_manager.register_events(view.$el); + this.keyboard_manager.register_events(view.el); if (view.additional_elements) { for (var i = 0; i < view.additional_elements.length; i++) { @@ -247,8 +246,8 @@ define([ var handle_output = null; var handle_clear_output = null; if (cell.output_area) { - handle_output = $.proxy(cell.output_area.handle_output, cell.output_area); - handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area); + handle_output = _.bind(cell.output_area.handle_output, cell.output_area); + handle_clear_output = _.bind(cell.output_area.handle_clear_output, cell.output_area); } // Create callback dictionary using what is known @@ -301,7 +300,7 @@ define([ * model_name: 'WidgetModel', * widget_class: 'jupyter_notebook.widgets.widget_int.IntSlider'}) * .then(function(model) { console.log('Create success!', model); }, - * $.proxy(console.error, console)); + * _.bind(console.error, console)); * * Parameters * ---------- diff --git a/jupyter_notebook/static/widgets/js/widget.js b/jupyter_notebook/static/widgets/js/widget.js index 2481fe89b9..ad563a6cef 100644 --- a/jupyter_notebook/static/widgets/js/widget.js +++ b/jupyter_notebook/static/widgets/js/widget.js @@ -4,10 +4,9 @@ define(["widgets/js/manager", "underscore", "backbone", - "jquery", "base/js/utils", "base/js/namespace", -], function(widgetmanager, _, Backbone, $, utils, IPython){ +], function(widgetmanager, _, Backbone, utils, IPython){ "use strict"; var unpack_models = function unpack_models(value, model) { @@ -15,7 +14,7 @@ define(["widgets/js/manager", * Replace model ids with models recursively. */ var unpacked; - if ($.isArray(value)) { + if (_.isArray(value)) { unpacked = []; _.each(value, function(sub_value, key) { unpacked.push(unpack_models(sub_value, model)); @@ -65,8 +64,8 @@ define(["widgets/js/manager", 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)); + comm.on_close(_.bind(this._handle_comm_closed, this)); + comm.on_msg(_.bind(this._handle_comm_msg, this)); // Assume the comm is alive. this.set_comm_live(true); @@ -274,7 +273,7 @@ define(["widgets/js/manager", // Backbone only remembers the diff of the most recent set() // operation. Calling set multiple times in a row results in a // loss of diff information. Here we keep our own running diff. - this._buffered_state_diff = $.extend(this._buffered_state_diff, this.changedAttributes() || {}); + this._buffered_state_diff = _.extend(this._buffered_state_diff, this.changedAttributes() || {}); return return_value; }, @@ -336,7 +335,7 @@ define(["widgets/js/manager", // Combine updates if it is a 'patch' sync, otherwise replace updates switch (method) { case 'patch': - this.msg_buffer = $.extend(this.msg_buffer || {}, attrs); + this.msg_buffer = _.extend(this.msg_buffer || {}, attrs); break; case 'update': case 'create': @@ -355,7 +354,7 @@ define(["widgets/js/manager", this.pending_msgs++; } } - // Since the comm is a one-way communication, assume the message + // Since the comm is a one-way communication, assume the message // 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. this._buffered_state_diff = {}; @@ -369,7 +368,7 @@ define(["widgets/js/manager", // being the value or the promise of the serialized value var serializers = this.constructor.serializers; if (serializers) { - for (var k in attrs) { + for (k in attrs) { if (serializers[k] && serializers[k].serialize) { attrs[k] = (serializers[k].serialize)(attrs[k], this); } @@ -383,13 +382,11 @@ define(["widgets/js/manager", for (var i=0; i 0) { var trait_key = css[i][1]; var trait_value = css[i][2]; - elements.css(trait_key ,trait_value); + _.each(elements, function(e) { + e.style[trait_key] = trait_value; + }); } } }, - update_classes: function (old_classes, new_classes, $el) { + update_classes: function (old_classes, new_classes, el) { /** - * Update the DOM classes applied to an element, default to this.$el. + * Update the DOM classes applied to an element, default to this.el. */ - if ($el===undefined) { - $el = this.$el; + if (el===undefined) { + el = this.el; } - _.difference(old_classes, new_classes).map(function(c) {$el.removeClass(c);}) - _.difference(new_classes, old_classes).map(function(c) {$el.addClass(c);}) + _.difference(old_classes, new_classes).map(function(c) { el.classList.remove(c); }); + _.difference(new_classes, old_classes).map(function(c) { el.classList.add(c); }); }, - update_mapped_classes: function(class_map, trait_name, previous_trait_value, $el) { + update_mapped_classes: function(class_map, trait_name, previous_trait_value, el) { /** * Update the DOM classes applied to the widget based on a single * trait's value. @@ -681,7 +681,7 @@ define(["widgets/js/manager", * Name of the trait to check the value of. * previous_trait_value: optional string, default '' * Last trait value - * $el: optional jQuery element handle, defaults to this.$el + * el: optional DOM element, defaults to this.el * Element that the classes are applied to. */ var key = previous_trait_value; @@ -692,7 +692,7 @@ define(["widgets/js/manager", key = this.model.get(trait_name); var new_classes = class_map[key] ? class_map[key] : []; - this.update_classes(old_classes, new_classes, $el || this.$el); + this.update_classes(old_classes, new_classes, el || this.el); }, _get_selector_element: function (selector) { @@ -701,9 +701,9 @@ define(["widgets/js/manager", */ var elements; if (!selector) { - elements = this.$el; + elements = [this.el]; } else { - elements = this.$el.find(selector).addBack(selector); + elements = this.el.querySelectorAll(selector); } return elements; }, @@ -711,7 +711,7 @@ define(["widgets/js/manager", typeset: function(element, text){ utils.typeset.apply(null, arguments); }, - }); + }; var ViewList = function(create_view, remove_view, context) { @@ -793,6 +793,9 @@ define(["widgets/js/manager", }, }); + var WidgetView = Backbone.View.extend(WidgetInterface); + var DOMWidgetView = WidgetView.extend(DOMWidgetInterface); + var widget = { 'unpack_models': unpack_models, 'WidgetModel': WidgetModel, @@ -802,7 +805,7 @@ define(["widgets/js/manager", }; // For backwards compatability. - $.extend(IPython, widget); + _.extend(IPython, widget); return widget; }); diff --git a/jupyter_notebook/static/widgets/js/widget_box.js b/jupyter_notebook/static/widgets/js/widget_box.js index 0a374add26..d31501e5af 100644 --- a/jupyter_notebook/static/widgets/js/widget_box.js +++ b/jupyter_notebook/static/widgets/js/widget_box.js @@ -77,7 +77,7 @@ define([ warning: ['alert', 'alert-warning'], danger: ['alert', 'alert-danger'] }; - this.update_mapped_classes(class_map, 'box_style', previous_trait_value, this.$box); + this.update_mapped_classes(class_map, 'box_style', previous_trait_value, this.$box[0]); }, add_child_model: function(model) { diff --git a/jupyter_notebook/static/widgets/js/widget_int.js b/jupyter_notebook/static/widgets/js/widget_int.js index b693c42e2e..c76d7ce6dc 100644 --- a/jupyter_notebook/static/widgets/js/widget_int.js +++ b/jupyter_notebook/static/widgets/js/widget_int.js @@ -461,7 +461,7 @@ define([ warning: ['progress-bar-warning'], danger: ['progress-bar-danger'] }; - this.update_mapped_classes(class_map, 'bar_style', previous_trait_value, this.$bar); + this.update_mapped_classes(class_map, 'bar_style', previous_trait_value, this.$bar[0]); }, update_attr: function(name, value) { diff --git a/jupyter_notebook/static/widgets/js/widget_selection.js b/jupyter_notebook/static/widgets/js/widget_selection.js index 3077d4aa6d..a4220031e1 100644 --- a/jupyter_notebook/static/widgets/js/widget_selection.js +++ b/jupyter_notebook/static/widgets/js/widget_selection.js @@ -113,8 +113,8 @@ define([ 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); + this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$droplabel[0]); + this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$dropbutton[0]); }, update_attr: function(name, value) { @@ -411,7 +411,7 @@ define([ warning: ['btn-warning'], danger: ['btn-danger'] }; - this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$buttongroup.find('button')); + this.update_mapped_classes(class_map, 'button_style', previous_trait_value, this.$buttongroup.find('button')[0]); }, handle_click: function (e) {