##// END OF EJS Templates
Fix typo, static msg content c&p from button widget view.
Fix typo, static msg content c&p from button widget view.

File last commit:

r14405:86acbc1e
r14405:86acbc1e
Show More
widget.js
625 lines | 22.9 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Added widjet.js...
r14224 //----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// WidgetModel, WidgetView, and WidgetManager
//============================================================================
/**
* Base Widget classes
* @module IPython
* @namespace IPython
* @submodule widget
*/
Jonathan Frederic
Handle widget hide/show logic...
r14237 "use strict";
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 // Use require.js 'define' method so that require.js is intelligent enough to
// syncronously load everything within this file when it is being 'required'
// elsewhere.
Jonathan Frederic
Updated require js references, now absolute paths are used
r14285 define(["components/underscore/underscore-min",
"components/backbone/backbone-min",
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 ], function(underscore, backbone){
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342
//--------------------------------------------------------------------
// WidgetModel class
//--------------------------------------------------------------------
var WidgetModel = Backbone.Model.extend({
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 constructor: function(comm_manager, comm, widget_manager) {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 this.comm_manager = comm_manager;
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 this.widget_manager = widget_manager;
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 this.pending_msgs = 0;
this.msg_throttle = 3;
this.msg_buffer = null;
this.views = {};
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 this._custom_msg_callbacks = [];
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342
// Remember comm associated with the model.
this.comm = comm;
comm.model = this;
// Hook comm messages up to model.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 comm.on_close($.proxy(this._handle_comm_closed, this));
comm.on_msg($.proxy(this._handle_comm_msg, this));
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342
return Backbone.Model.apply(this);
},
update_other_views: function(caller) {
this.last_modified_view = caller;
this.save(this.changedAttributes(), {patch: true});
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 for (var cell in this.views) {
var views = this.views[cell];
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 for (var view_index in views) {
var view = views[view_index];
if (view !== caller) {
view.update();
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 }
Jonathan Frederic
Added apply method to base model....
r14227 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
},
Jonathan Frederic
Added support for custom widget msgs
r14387
Jonathan Frederic
Made scroll to bottom use msgs...
r14403
send: function(content, cell) {
Jonathan Frederic
Added support for custom widget msgs
r14387
// Used the last modified view as the sender of the message. This
// will insure that any python code triggered by the sent message
// can create and display widgets and output.
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 if (cell === undefined) {
if (this.last_modified_view != undefined &&
this.last_modified_view.cell != undefined) {
cell = this.last_modified_view.cell;
}
Jonathan Frederic
Added support for custom widget msgs
r14387 }
var callbacks = this._make_callbacks(cell);
Jonathan Frederic
Changed button to use custom messages instead of state to communicate events.
r14400 var data = {'custom_content': content};
Jonathan Frederic
Added support for custom widget msgs
r14387 this.comm.send(data, callbacks);
},
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385 on_view_displayed: function (callback) {
this._view_displayed_callback = callback;
Jonathan Frederic
Added support for custom widget msgs
r14387 },
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385
on_close: function (callback) {
this._close_callback = callback;
Jonathan Frederic
Added support for custom widget msgs
r14387 },
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 on_msg: function (callback, remove) {
if (remove) {
var found_index = -1;
for (var index in this._custom_msg_callbacks) {
if (callback === this._custom_msg_callbacks[index]) {
found_index = index;
break;
}
}
if (found_index >= 0) {
this._custom_msg_callbacks.splice(found_index, 1);
}
} else {
this._custom_msg_callbacks.push(callback)
}
Jonathan Frederic
Added support for custom widget msgs
r14387 },
_handle_custom_msg: function (content) {
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 for (var index in this._custom_msg_callbacks) {
Jonathan Frederic
Added support for custom widget msgs
r14387 try {
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 this._custom_msg_callbacks[index](content);
Jonathan Frederic
Added support for custom widget msgs
r14387 } catch (e) {
console.log("Exception in widget model msg callback", e, content);
}
}
},
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 // Handle when a widget is closed.
_handle_comm_closed: function (msg) {
Jonathan Frederic
Changed add_class and remove_class to use messages instead of stateful communication
r14399 this._execute_views_method('remove');
Jonathan Frederic
Properly dispose of widget model. Delete comm's ref to...
r14386 delete this.comm.model; // Delete ref so GC will collect widget model.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 },
// Handle incomming comm msg.
_handle_comm_msg: function (msg) {
var method = msg.content.data.method;
switch (method){
case 'display':
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385 // Try to get the cell.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 var cell = this._get_msg_cell(msg.parent_header.msg_id);
if (cell == null) {
console.log("Could not determine where the display" +
" message was from. Widget will not be displayed")
} else {
this._display_view(msg.content.data.view_name,
msg.content.data.parent,
cell);
}
break;
case 'update':
this._handle_update(msg.content.data.state);
break;
Jonathan Frederic
Changed add_class and remove_class to use messages instead of stateful communication
r14399 case 'add_class':
case 'remove_class':
var selector = msg.content.data.selector;
var class_list = msg.content.data.class_list;
this._execute_views_method(method, selector, class_list);
break;
Jonathan Frederic
Added support for custom widget msgs
r14387 case 'custom':
this._handle_custom_msg(msg.content.data.custom_content);
break;
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 }
},
// Handle when a widget is updated via the python side.
_handle_update: function (state) {
this.updating = true;
try {
for (var key in state) {
if (state.hasOwnProperty(key)) {
if (key == "_css"){
Jonathan Frederic
Added more comments to widget model JS
r14384
// Set the css value of the model as an attribute
// instead of a backbone trait because we are only
// interested in backend css -> frontend css. In
// other words, if the css dict changes in the
// frontend, we don't need to push the changes to
// the backend.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 this.css = state[key];
} else {
this.set(key, state[key]);
}
}
}
this.id = this.comm.comm_id;
this.save();
} finally {
this.updating = false;
}
},
_handle_status: function (cell, msg) {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 //execution_state : ('busy', 'idle', 'starting')
if (msg.content.execution_state=='idle') {
// Send buffer if this message caused another message to be
// throttled.
if (this.msg_buffer != null &&
Jonathan Frederic
Fixed typos in throttling code.
r14346 this.msg_throttle == this.pending_msgs) {
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var cell = this._get_msg_cell(msg.parent_header.msg_id);
var callbacks = this._make_callbacks(cell);
Jonathan Frederic
Fixed typos in throttling code.
r14346 var data = {sync_method: 'update', sync_data: this.msg_buffer};
this.comm.send(data, callbacks);
this.msg_buffer = null;
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 } else {
// Only decrease the pending message count if the buffer
// doesn't get flushed (sent).
--this.pending_msgs;
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
},
// Custom syncronization logic.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 _handle_sync: function (method, options) {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 var model_json = this.toJSON();
// Only send updated state if the state hasn't been changed
// during an update.
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) {
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 this.msg_buffer = $.extend({}, model_json); // Copy
}
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 for (var attr in options.attrs) {
this.msg_buffer[attr] = options.attrs[attr];
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 } else {
this.msg_buffer = $.extend({}, model_json); // Copy
}
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 } 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 (var attr in options.attrs) {
send_json[attr] = options.attrs[attr];
}
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342
var data = {sync_method: method, sync_data: send_json};
Jonathan Frederic
Fixed bug that prevent model.save() from being called on...
r14353
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var cell = null;
Jonathan Frederic
Fixed bug that prevent model.save() from being called on...
r14353 if (this.last_modified_view != undefined && this.last_modified_view != null) {
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 cell = this.last_modified_view.cell;
Jonathan Frederic
Fixed bug that prevent model.save() from being called on...
r14353 }
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var callbacks = this._make_callbacks(cell);
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 this.comm.send(data, callbacks);
this.pending_msgs++;
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
// Since the comm is a one-way communication, assume the message
// arrived.
return model_json;
},
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385 _handle_view_displayed: function(view) {
if (this._view_displayed_callback) {
try {
this._view_displayed_callback(view)
} catch (e) {
console.log("Exception in widget model view displayed callback", e, view, this);
}
}
Jonathan Frederic
Added support for custom widget msgs
r14387 },
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385
Jonathan Frederic
Changed add_class and remove_class to use messages instead of stateful communication
r14399 _execute_views_method: function (/* method_name, [argument0], [argument1], [...] */) {
var method_name = arguments[0];
var args = null;
if (arguments.length > 1) {
args = [].splice.call(arguments,1);
}
for (var cell in this.views) {
var views = this.views[cell];
for (var view_index in views) {
var view = views[view_index];
var method = view[method_name];
if (args === null) {
method.apply(view);
} else {
method.apply(view, args);
}
}
}
},
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 // Create view that represents the model.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 _display_view: function (view_name, parent_comm_id, cell) {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 var new_views = [];
Jonathan Frederic
Better comments in _display_view
r14383 // Try creating and adding the view to it's parent.
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 var displayed = false;
if (parent_comm_id != undefined) {
var parent_comm = this.comm_manager.comms[parent_comm_id];
var parent_model = parent_comm.model;
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var parent_views = parent_model.views[cell];
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 for (var parent_view_index in parent_views) {
var parent_view = parent_views[parent_view_index];
if (parent_view.display_child != undefined) {
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var view = this._create_view(view_name, cell);
Jonathan Frederic
Dont err if view name isn't registered.
r14382 if (view != null) {
new_views.push(view);
parent_view.display_child(view);
displayed = true;
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385 this._handle_view_displayed(view);
Jonathan Frederic
Dont err if view name isn't registered.
r14382 }
Jonathan Frederic
Updated require js references, now absolute paths are used
r14285 }
}
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
Jonathan Frederic
Better comments in _display_view
r14383 // If no parent view is defined or exists. Add the view's
// element to cell's widget div.
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 if (!displayed) {
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var view = this._create_view(view_name, cell);
Jonathan Frederic
Dont err if view name isn't registered.
r14382 if (view != null) {
new_views.push(view);
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378
Jonathan Frederic
Dont err if view name isn't registered.
r14382 if (cell.widget_subarea != undefined && cell.widget_subarea != null) {
cell.widget_area.show();
cell.widget_subarea.append(view.$el);
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385 this._handle_view_displayed(view);
Jonathan Frederic
Dont err if view name isn't registered.
r14382 }
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
Jonathan Frederic
Better comments in _display_view
r14383 // Force the new view(s) to update their selves
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 for (var view_index in new_views) {
var view = new_views[view_index];
view.update();
}
},
// Create a view
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 _create_view: function (view_name, cell) {
Jonathan Frederic
Dont err if view name isn't registered.
r14382 var view_type = this.widget_manager.widget_view_types[view_name];
if (view_type != undefined && view_type != null) {
var view = new view_type({model: this});
view.render();
if (this.views[cell]==undefined) {
this.views[cell] = []
Jonathan Frederic
Updated require js references, now absolute paths are used
r14285 }
Jonathan Frederic
Dont err if view name isn't registered.
r14382 this.views[cell].push(view);
view.cell = cell;
Jonathan Frederic
Updated require js references, now absolute paths are used
r14285
Jonathan Frederic
Dont err if view name isn't registered.
r14382 // Handle when the view element is remove from the page.
var that = this;
view.$el.on("remove", function(){
var index = that.views[cell].indexOf(view);
if (index > -1) {
that.views[cell].splice(index, 1);
}
view.remove(); // Clean-up view
if (that.views[cell].length()==0) {
delete that.views[cell];
}
// Close the comm if there are no views left.
if (that.views.length()==0) {
Jonathan Frederic
Added on_view_displayed and on_close callbacks to widget manager.
r14385 if (that._close_callback) {
try {
that._close_callback(that)
} catch (e) {
console.log("Exception in widget model close callback", e, that);
}
}
Jonathan Frederic
Dont err if view name isn't registered.
r14382 that.comm.close();
Jonathan Frederic
Properly dispose of widget model. Delete comm's ref to...
r14386 delete that.comm.model; // Delete ref so GC will collect widget model.
Jonathan Frederic
Dont err if view name isn't registered.
r14382 }
});
return view;
}
return null;
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 },
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 // Build a callback dict.
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 _make_callbacks: function (cell) {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 var callbacks = {};
Jonathan Frederic
Cleaned up _make_callbacks method of widget model class
r14389 if (cell != null) {
// Try to get output handlers
var handle_output = null;
var handle_clear_output = null;
if (cell.output_area != undefined && cell.output_area != null) {
handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
}
// Create callback dict usign what is known
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 var that = this;
callbacks = {
iopub : {
Jonathan Frederic
Cleaned up _make_callbacks method of widget model class
r14389 output : handle_output,
clear_output : handle_clear_output,
Jonathan Frederic
Remove some empty space
r14390
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 status : function(msg){
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 that._handle_status(cell, msg);
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278 },
Jonathan Frederic
Added more comments to widget model JS
r14384
// Special function only registered by widget messages.
// Allows us to get the cell for a message so we know
// where to add widgets if the code requires it.
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 get_cell : function() {
Jonathan Frederic
Cleaned up _make_callbacks method of widget model class
r14389 return cell;
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 },
},
};
}
return callbacks;
},
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 // Get the output area corresponding to the msg_id.
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 // cell is an instance of IPython.Cell
_get_msg_cell: function (msg_id) {
Jonathan Frederic
Fixed typos in throttling code.
r14346
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 // First, check to see if the msg was triggered by cell execution.
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 var cell = this.widget_manager.get_msg_cell(msg_id);
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 if (cell != null) {
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 return cell;
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
Jonathan Frederic
Fixed callback mapping for widget spawned widgets
r14316
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 // Second, check to see if a get_cell callback was defined
// for the message. get_cell callbacks are registered for
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 // widget messages, so this block is actually checking to see if the
// message was triggered by a widget.
var kernel = this.comm_manager.kernel;
var callbacks = kernel.get_callbacks_for_msg(msg_id);
if (callbacks != undefined &&
callbacks.iopub != undefined &&
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 callbacks.iopub.get_cell != undefined) {
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 return callbacks.iopub.get_cell();
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 // Not triggered by a cell or widget (no get_cell callback
Jonathan Frederic
Moved the logic to get a cell by message id into the notebook.js....
r14371 // exists).
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 return null;
},
});
//--------------------------------------------------------------------
// WidgetView class
//--------------------------------------------------------------------
var WidgetView = Backbone.View.extend({
initialize: function() {
this.visible = true;
this.model.on('change',this.update,this);
},
Jonathan Frederic
Changed add_class and remove_class to use messages instead of stateful communication
r14399 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);
}
},
Jonathan Frederic
Made scroll to bottom use msgs...
r14403
send: function(content) {
Jonathan Frederic
Fix typo, static msg content c&p from button widget view.
r14405 this.model.send(content, this.cell);
Jonathan Frederic
Made scroll to bottom use msgs...
r14403 },
Jonathan Frederic
Changed add_class and remove_class to use messages instead of stateful communication
r14399
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 update: function() {
if (this.model.get('visible') != undefined) {
if (this.visible != this.model.get('visible')) {
this.visible = this.model.get('visible');
if (this.visible) {
this.$el.show();
} else {
this.$el.hide();
Jonathan Frederic
Added `visible` property to all widgets
r14311 }
}
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
if (this.model.css != undefined) {
for (var selector in this.model.css) {
if (this.model.css.hasOwnProperty(selector)) {
Jonathan Frederic
Remove some empty space
r14390
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 // Apply the css traits to all elements that match the selector.
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 var elements = this._get_selector_element(selector);
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 if (elements.length > 0) {
var css_traits = this.model.css[selector];
for (var css_key in css_traits) {
if (css_traits.hasOwnProperty(css_key)) {
elements.css(css_key, css_traits[css_key]);
Jonathan Frederic
Added widjet.js...
r14224 }
}
}
}
}
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
},
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 _get_selector_element: function(selector) {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 // 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 = this.$el.find(selector);
Jonathan Frederic
Changed add_class and remove_class to use messages instead of stateful communication
r14399 if (selector===undefined || selector===null || selector=='') {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 if (this.$el_to_style == undefined) {
elements = this.$el;
} else {
elements = this.$el_to_style;
Jonathan Frederic
Added add_class and remove_class methods.
r14313 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
return elements;
},
});
//--------------------------------------------------------------------
// WidgetManager class
//--------------------------------------------------------------------
var WidgetManager = function(){
this.comm_manager = null;
this.widget_model_types = {};
this.widget_view_types = {};
var that = this;
Backbone.sync = function(method, model, options, error) {
Jonathan Frederic
Prviatize methods that should not be called externally...
r14379 var result = model._handle_sync(method, options);
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 if (options.success) {
options.success(result);
}
};
}
WidgetManager.prototype.attach_comm_manager = function (comm_manager) {
this.comm_manager = comm_manager;
// Register already register widget model types with the comm manager.
for (var widget_model_name in this.widget_model_types) {
Jonathan Frederic
Privatize _handle_com_open of WidgetManager
r14380 this.comm_manager.register_target(widget_model_name, $.proxy(this._handle_com_open, this));
Jonathan Frederic
Removed require.js scheme since it forces async event driven model,...
r14257 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
Jonathan Frederic
Handle widget hide/show logic...
r14237
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 WidgetManager.prototype.register_widget_model = function (widget_model_name, widget_model_type) {
// Register the widget with the comm manager. Make sure to pass this object's context
// in so `this` works in the call back.
if (this.comm_manager!=null) {
Jonathan Frederic
Privatize _handle_com_open of WidgetManager
r14380 this.comm_manager.register_target(widget_model_name, $.proxy(this._handle_com_open, this));
Jonathan Frederic
Removed require.js scheme since it forces async event driven model,...
r14257 }
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 this.widget_model_types[widget_model_name] = widget_model_type;
}
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) {
this.widget_view_types[widget_view_name] = widget_view_type;
}
Jonathan Frederic
Lots of updates to widget(s) js...
r14263
Jonathan Frederic
LOTS OF WIDGET CHANGES...
r14278
Jonathan Frederic
Moved get_msg_cell which depends on notebook specific logic...
r14378 WidgetManager.prototype.get_msg_cell = function (msg_id) {
if (IPython.notebook != undefined && IPython.notebook != null) {
return IPython.notebook.get_msg_cell(msg_id);
}
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 }
Jonathan Frederic
Added on_create_widget callback to WidgetManager
r14381
WidgetManager.prototype.on_create_widget = function (callback) {
this._create_widget_callback = callback;
}
WidgetManager.prototype._handle_create_widget = function (widget_model) {
if (this._create_widget_callback) {
try {
this._create_widget_callback(widget_model);
} catch (e) {
console.log("Exception in WidgetManager callback", e, widget_model);
}
}
}
Jonathan Frederic
Use require.js where possible.
r14255
Jonathan Frederic
Added widjet.js...
r14224
Jonathan Frederic
Privatize _handle_com_open of WidgetManager
r14380 WidgetManager.prototype._handle_com_open = function (comm, msg) {
var widget_type_name = msg.content.target_name;
var widget_model = new this.widget_model_types[widget_type_name](this.comm_manager, comm, this);
Jonathan Frederic
Added on_create_widget callback to WidgetManager
r14381 this._handle_create_widget(widget_model);
Jonathan Frederic
Privatize _handle_com_open of WidgetManager
r14380 }
Jonathan Frederic
Added on_create_widget callback to WidgetManager
r14381
Jonathan Frederic
Privatize _handle_com_open of WidgetManager
r14380
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 //--------------------------------------------------------------------
// Init code
//--------------------------------------------------------------------
IPython.WidgetManager = WidgetManager;
IPython.WidgetModel = WidgetModel;
IPython.WidgetView = WidgetView;
Jonathan Frederic
Added widjet.js...
r14224
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 if (IPython.widget_manager==undefined || IPython.widget_manager==null) {
IPython.widget_manager = new WidgetManager();
}
Jonathan Frederic
Remove some empty space
r14390
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 return IPython.widget_manager;
Jonathan Frederic
Lots of updates to widget(s) js...
r14263 });