Show More
@@ -64,7 +64,7 define([ | |||||
64 | // add a cell type drop down to the maintoolbar. |
|
64 | // add a cell type drop down to the maintoolbar. | |
65 | // triggered when the pseudo action `<add_celltype_list>` is |
|
65 | // triggered when the pseudo action `<add_celltype_list>` is | |
66 | // encountered when building a toolbar. |
|
66 | // encountered when building a toolbar. | |
67 | MainToolBar.prototype.add_celltype_list = function () { |
|
67 | MainToolBar.prototype._pseudo_actions.add_celltype_list = function () { | |
68 | var that = this; |
|
68 | var that = this; | |
69 | var sel = $('<select/>') |
|
69 | var sel = $('<select/>') | |
70 | .attr('id','cell_type') |
|
70 | .attr('id','cell_type') | |
@@ -105,7 +105,7 define([ | |||||
105 |
|
105 | |||
106 | }; |
|
106 | }; | |
107 |
|
107 | |||
108 | MainToolBar.prototype.add_celltoolbar_list = function () { |
|
108 | MainToolBar.prototype._pseudo_actions.add_celltoolbar_list = function () { | |
109 | var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:'); |
|
109 | var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:'); | |
110 | var select = $('<select/>') |
|
110 | var select = $('<select/>') | |
111 | .attr('id', 'ctb_select') |
|
111 | .attr('id', 'ctb_select') |
@@ -22,11 +22,10 define([ | |||||
22 | } |
|
22 | } | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
|
25 | ToolBar.prototype._pseudo_actions={}; | |||
25 |
|
26 | |||
26 | // thought, this might not be the best way as dict might not keep the right order. |
|
27 | ||
27 | // Might want to put the group name as second to make it optional |
|
28 | ToolBar.prototype.construct = function (config) { | |
28 | // |
|
|||
29 | ToolBar.prototype.construct = function (config) { |
|
|||
30 | for(var k in config){ |
|
29 | for(var k in config){ | |
31 | this.add_buttons_group(config[k][0],k[1]); |
|
30 | this.add_buttons_group(config[k][0],k[1]); | |
32 | } |
|
31 | } | |
@@ -96,7 +95,7 define([ | |||||
96 | var _pseudo_action; |
|
95 | var _pseudo_action; | |
97 | try{ |
|
96 | try{ | |
98 | _pseudo_action = list.slice(1,-1); |
|
97 | _pseudo_action = list.slice(1,-1); | |
99 | this[_pseudo_action](); |
|
98 | this._pseudo_actions[_pseudo_action].call(this); | |
100 | } catch (e) { |
|
99 | } catch (e) { | |
101 | console.warn('ouch, calling ', _pseudo_action, 'does not seem to work...:', e); |
|
100 | console.warn('ouch, calling ', _pseudo_action, 'does not seem to work...:', e); | |
102 | } |
|
101 | } | |
@@ -107,37 +106,37 define([ | |||||
107 | if( group_id !== undefined ) { |
|
106 | if( group_id !== undefined ) { | |
108 | btn_group.attr('id',group_id); |
|
107 | btn_group.attr('id',group_id); | |
109 | } |
|
108 | } | |
110 | var el; |
|
|||
111 | for(var i=0; i < list.length; i++) { |
|
109 | for(var i=0; i < list.length; i++) { | |
112 |
|
110 | |||
113 | // IIFE because javascript don't have loop scope so |
|
111 | // IIFE because javascript don't have loop scope so | |
114 | // action_name would otherwise be the same on all iteration |
|
112 | // action_name would otherwise be the same on all iteration | |
115 | // of the loop |
|
113 | // of the loop | |
116 | // TODO: Indent this thing once reviewed: |
|
114 | (function(i,list){ | |
117 | (function(){ |
|
115 | var el = list[i]; | |
118 | el = list[i]; |
|
116 | var action_name; | |
119 |
var action |
|
117 | var action; | |
120 | var action; |
|
118 | if(typeof(el) === 'string'){ | |
121 | if(typeof(el) === 'string'){ |
|
119 | action = that.actions.get(el); | |
122 |
action = |
|
120 | action_name = el; | |
123 | action_name = el; |
|
|||
124 |
|
121 | |||
125 | } |
|
122 | } | |
126 | var button = $('<button/>') |
|
123 | var button = $('<button/>') | |
127 | .addClass('btn btn-default') |
|
124 | .addClass('btn btn-default') | |
128 | .attr("title", el.label||action.help) |
|
125 | .attr("title", el.label||action.help) | |
129 | .append( |
|
126 | .append( | |
130 | $("<i/>").addClass(el.icon||action.icon).addClass('fa') |
|
127 | $("<i/>").addClass(el.icon||action.icon).addClass('fa') | |
131 | ); |
|
128 | ); | |
132 | var id = el.id; |
|
129 | var id = el.id; | |
133 | if( id !== undefined ) |
|
130 | if( id !== undefined ){ | |
134 | button.attr('id',id); |
|
131 | button.attr('id',id); | |
135 | var fun = el.callback|| function(){ |
|
132 | } | |
136 |
t |
|
133 | button.attr('data-jupyter-action', action_name); | |
137 | }; |
|
134 | var fun = el.callback|| function(){ | |
138 | button.click(fun); |
|
135 | that.actions.call(action_name); | |
139 | btn_group.append(button); |
|
136 | }; | |
140 | })(); |
|
137 | button.click(fun); | |
|
138 | btn_group.append(button); | |||
|
139 | })(i,list); | |||
141 | // END IIFE |
|
140 | // END IIFE | |
142 | } |
|
141 | } | |
143 | $(this.selector).append(btn_group); |
|
142 | $(this.selector).append(btn_group); |
@@ -66,8 +66,7 casper.notebook_test(function () { | |||||
66 | IPython.notebook.select(0); |
|
66 | IPython.notebook.select(0); | |
67 | cell.clear_output(); |
|
67 | cell.clear_output(); | |
68 | cell.set_text('a=13; print(a)'); |
|
68 | cell.set_text('a=13; print(a)'); | |
69 | // 'run button' is the first of the forth group in default config. |
|
69 | $("button[data-jupyter-action='ipython.save-notebook']")[0].click() | |
70 | $('#maintoolbar .btn-group:nth(4) .btn:first').click(); |
|
|||
71 | }); |
|
70 | }); | |
72 |
|
71 | |||
73 | this.wait_for_output(0); |
|
72 | this.wait_for_output(0); |
@@ -29,8 +29,7 casper.notebook_test(function () { | |||||
29 | $('#cell_type').val('markdown').change(); |
|
29 | $('#cell_type').val('markdown').change(); | |
30 | var cell = IPython.notebook.get_selected_cell(); |
|
30 | var cell = IPython.notebook.get_selected_cell(); | |
31 | cell.set_text('*Baz*'); |
|
31 | cell.set_text('*Baz*'); | |
32 | // 'run button' is the first of the forth group in default config. |
|
32 | $("button[data-jupyter-action='ipython.save-notebook']")[0].click(); | |
33 | $('#maintoolbar .btn-group:nth(4) .btn:first').click(); |
|
|||
34 | return cell.get_rendered(); |
|
33 | return cell.get_rendered(); | |
35 | }); |
|
34 | }); | |
36 | this.test.assertEquals(output.trim(), '<p><em>Baz</em></p>', 'Markdown toolbar items work.'); |
|
35 | this.test.assertEquals(output.trim(), '<p><em>Baz</em></p>', 'Markdown toolbar items work.'); |
General Comments 0
You need to be logged in to leave comments.
Login now