Show More
@@ -9,11 +9,13 define([ | |||||
9 |
|
|
9 | //-------------------------------------------------------------------- | |
10 |
|
|
10 | // WidgetManager class | |
11 |
|
|
11 | //-------------------------------------------------------------------- | |
12 |
|
|
12 | var WidgetManager = function (comm_manager, keyboard_manager, notebook) { | |
13 |
|
|
13 | // Public constructor | |
14 |
|
|
14 | WidgetManager._managers.push(this); | |
15 |
|
15 | |||
16 |
|
|
16 | // Attach a comm manager to the | |
|
17 | this.keyboard_manager = keyboard_manager; | |||
|
18 | this.notebook = notebook; | |||
17 |
|
|
19 | this.comm_manager = comm_manager; | |
18 |
|
|
20 | this._models = {}; /* Dictionary of model ids and model instances */ | |
19 |
|
21 | |||
@@ -76,11 +78,13 define([ | |||||
76 |
|
|
78 | // Have the IPython keyboard manager disable its event | |
77 |
|
|
79 | // handling so the widget can capture keyboard input. | |
78 |
|
|
80 | // Note, this is only done on the outer most widgets. | |
79 | IPython.keyboard_manager.register_events(view.$el); |
|
81 | if (this.keyboard_manager) { | |
|
82 | this.keyboard_manager.register_events(view.$el); | |||
80 |
|
|
83 | ||
81 |
|
|
84 | if (view.additional_elements) { | |
82 |
|
|
85 | for (var i = 0; i < view.additional_elements.length; i++) { | |
83 |
|
|
86 | this.keyboard_manager.register_events(view.additional_elements[i]); | |
|
87 | } | |||
84 |
|
|
88 | } | |
85 |
|
|
89 | } | |
86 |
|
|
90 | }; | |
@@ -111,8 +115,8 define([ | |||||
111 |
|
|
115 | WidgetManager.prototype.get_msg_cell = function (msg_id) { | |
112 |
|
|
116 | var cell = null; | |
113 |
|
|
117 | // First, check to see if the msg was triggered by cell execution. | |
114 |
|
|
118 | if (this.notebook) { | |
115 |
|
|
119 | cell = this.notebook.get_msg_cell(msg_id); | |
116 |
|
|
120 | } | |
117 |
|
|
121 | if (cell !== null) { | |
118 |
|
|
122 | return cell; | |
@@ -189,8 +193,5 define([ | |||||
189 |
|
|
193 | this._models[model_id] = widget_model; | |
190 |
|
|
194 | }; | |
191 |
|
195 | |||
192 | // For backwards compatability. |
|
|||
193 | IPython.WidgetManager = WidgetManager; |
|
|||
194 |
|
||||
195 | return WidgetManager; |
|
196 | return WidgetManager; | |
196 |
|
|
197 | }); |
@@ -208,20 +208,20 function(WidgetManager, _, Backbone){ | |||||
208 |
|
208 | |||
209 | _pack_models: function(value) { |
|
209 | _pack_models: function(value) { | |
210 | // Replace models with model ids recursively. |
|
210 | // Replace models with model ids recursively. | |
|
211 | var that = this; | |||
|
212 | var packed; | |||
211 | if (value instanceof Backbone.Model) { |
|
213 | if (value instanceof Backbone.Model) { | |
212 | return value.id; |
|
214 | return value.id; | |
213 |
|
215 | |||
214 | } else if ($.isArray(value)) { |
|
216 | } else if ($.isArray(value)) { | |
215 |
|
|
217 | packed = []; | |
216 | var that = this; |
|
|||
217 | _.each(value, function(sub_value, key) { |
|
218 | _.each(value, function(sub_value, key) { | |
218 | packed.push(that._pack_models(sub_value)); |
|
219 | packed.push(that._pack_models(sub_value)); | |
219 | }); |
|
220 | }); | |
220 | return packed; |
|
221 | return packed; | |
221 |
|
222 | |||
222 | } else if (value instanceof Object) { |
|
223 | } else if (value instanceof Object) { | |
223 |
|
|
224 | packed = {}; | |
224 | var that = this; |
|
|||
225 | _.each(value, function(sub_value, key) { |
|
225 | _.each(value, function(sub_value, key) { | |
226 | packed[key] = that._pack_models(sub_value); |
|
226 | packed[key] = that._pack_models(sub_value); | |
227 | }); |
|
227 | }); |
@@ -3,7 +3,8 | |||||
3 |
|
3 | |||
4 | define([ |
|
4 | define([ | |
5 | "widgets/js/widget", |
|
5 | "widgets/js/widget", | |
6 | ], function(widget){ |
|
6 | "base/js/utils", | |
|
7 | ], function(widget, utils){ | |||
7 |
|
8 | |||
8 | var DropdownView = widget.DOMWidgetView.extend({ |
|
9 | var DropdownView = widget.DOMWidgetView.extend({ | |
9 | render : function(){ |
|
10 | render : function(){ | |
@@ -226,7 +227,7 define([ | |||||
226 | if (item.trim().length == 0) { |
|
227 | if (item.trim().length == 0) { | |
227 | item_html = " "; |
|
228 | item_html = " "; | |
228 | } else { |
|
229 | } else { | |
229 |
item_html = |
|
230 | item_html = utils.escape_html(item); | |
230 | } |
|
231 | } | |
231 | var item_query = '[data-value="' + item + '"]'; |
|
232 | var item_query = '[data-value="' + item + '"]'; | |
232 | var $item_element = that.$buttongroup.find(item_query); |
|
233 | var $item_element = that.$buttongroup.find(item_query); |
@@ -3,12 +3,13 | |||||
3 |
|
3 | |||
4 | define([ |
|
4 | define([ | |
5 | "widgets/js/widget", |
|
5 | "widgets/js/widget", | |
6 | ], function(widget){ |
|
6 | "base/js/utils", | |
|
7 | ], function(widget, utils){ | |||
7 |
|
8 | |||
8 | var AccordionView = widget.DOMWidgetView.extend({ |
|
9 | var AccordionView = widget.DOMWidgetView.extend({ | |
9 | render: function(){ |
|
10 | render: function(){ | |
10 | // Called when view is rendered. |
|
11 | // Called when view is rendered. | |
11 |
var guid = 'panel-group' + |
|
12 | var guid = 'panel-group' + utils.uuid(); | |
12 | this.$el |
|
13 | this.$el | |
13 | .attr('id', guid) |
|
14 | .attr('id', guid) | |
14 | .addClass('panel-group'); |
|
15 | .addClass('panel-group'); | |
@@ -88,7 +89,7 define([ | |||||
88 | // Called when a child is added to children list. |
|
89 | // Called when a child is added to children list. | |
89 | var view = this.create_child_view(model); |
|
90 | var view = this.create_child_view(model); | |
90 | var index = this.containers.length; |
|
91 | var index = this.containers.length; | |
91 |
var uuid = |
|
92 | var uuid = utils.uuid(); | |
92 | var accordion_group = $('<div />') |
|
93 | var accordion_group = $('<div />') | |
93 | .addClass('panel panel-default') |
|
94 | .addClass('panel panel-default') | |
94 | .appendTo(this.$el); |
|
95 | .appendTo(this.$el); | |
@@ -141,7 +142,7 define([ | |||||
141 |
|
142 | |||
142 | render: function(){ |
|
143 | render: function(){ | |
143 | // Called when view is rendered. |
|
144 | // Called when view is rendered. | |
144 |
var uuid = 'tabs'+ |
|
145 | var uuid = 'tabs'+utils.uuid(); | |
145 | var that = this; |
|
146 | var that = this; | |
146 | this.$tabs = $('<div />', {id: uuid}) |
|
147 | this.$tabs = $('<div />', {id: uuid}) | |
147 | .addClass('nav') |
|
148 | .addClass('nav') | |
@@ -189,7 +190,7 define([ | |||||
189 | // Called when a child is added to children list. |
|
190 | // Called when a child is added to children list. | |
190 | var view = this.create_child_view(model); |
|
191 | var view = this.create_child_view(model); | |
191 | var index = this.containers.length; |
|
192 | var index = this.containers.length; | |
192 |
var uuid = |
|
193 | var uuid = utils.uuid(); | |
193 |
|
194 | |||
194 | var that = this; |
|
195 | var that = this; | |
195 | var tab = $('<li />') |
|
196 | var tab = $('<li />') |
General Comments 0
You need to be logged in to leave comments.
Login now