|
18 | 18 | "cell_type": "markdown",
|
19 | 19 | "metadata": {},
|
20 | 20 | "source": [
|
21 |
| - "The CSS and Javascript of the HTML notebook can be customized through the files in `~/.ipython/profile_default/static/custom`, where `~` is your `HOME` directory, and `default` is your IPython profile. In this short recipe, we will use this feature to add a new button in the notebook toolbar on top of every notebook. Specifically, this button renumbers linearly all code cells." |
| 21 | + "The CSS and Javascript of the HTML notebook can be customized through the files in `~/.jupyter/custom` directory, where `~` is your `HOME` directory, (if you are using IPython < 4.x, the location is `~/.ipython/profile_default/static/custom`, where `default` is your IPython profile). In this short recipe, we will use this feature to add a new button in the notebook toolbar on top of every notebook. Specifically, this button renumbers linearly all code cells." |
22 | 22 | ]
|
23 | 23 | },
|
24 | 24 | {
|
|
39 | 39 | "%%javascript\n",
|
40 | 40 | "// This function allows us to add buttons \n",
|
41 | 41 | "// to the notebook toolbar.\n",
|
42 |
| - "IPython.toolbar.add_buttons_group([\n", |
| 42 | + "// If using IPython < 4.x, replace 'Jupyter' everywhere below\n", |
| 43 | + "// with 'IPython'\n", |
| 44 | + "Jupyter.toolbar.add_buttons_group([\n", |
43 | 45 | "{\n",
|
44 | 46 | " // The button's label.\n",
|
45 | 47 | " 'label': 'renumber all code cells',\n",
|
46 | 48 | " \n",
|
47 | 49 | " // The button's icon.\n",
|
48 | 50 | " // See a list of Font-Awesome icons here:\n",
|
49 | 51 | " // http://fortawesome.github.io/Font-Awesome/icons/\n",
|
50 |
| - " 'icon': 'fa-list-ol',\n", |
| 52 | + " 'icon': 'fa-list-ol', // 'icon-list-ol' for older IPython\n", |
51 | 53 | " \n",
|
52 | 54 | " // The callback function.\n",
|
53 | 55 | " 'callback': function () {\n",
|
54 | 56 | " \n",
|
55 | 57 | " // We retrieve the lists of all cells.\n",
|
56 |
| - " var cells = IPython.notebook.get_cells();\n", |
| 58 | + " var cells = Jupyter.notebook.get_cells();\n", |
57 | 59 | " \n",
|
58 | 60 | " // We only keep the code cells.\n",
|
59 | 61 | " cells = cells.filter(function(c)\n",
|
60 | 62 | " {\n",
|
61 |
| - " return c instanceof IPython.CodeCell; \n", |
| 63 | + " return c instanceof Jupyter.CodeCell; \n", |
62 | 64 | " })\n",
|
63 | 65 | " \n",
|
64 | 66 | " // We set the input prompt of all code cells.\n",
|
|
80 | 82 | "cell_type": "markdown",
|
81 | 83 | "metadata": {},
|
82 | 84 | "source": [
|
83 |
| - "2. To make these changes permanent, i.e. to add this button on every notebook, we can open (or create, if necesary) the file `~/.jupyter/custom/custom.js` (for IPython before 4.0.0 use `~/.ipython/profile_default/static/custom/custom.js`) and add the following code:" |
| 85 | + "2. To make these changes permanent, i.e. to add this button on every notebook, we can open (or create, if necesary) the file `~/.jupyter/custom/custom.js` and add the code below. For IPython before 3.x and older, use file `~/.ipython/profile_default/static/custom/custom.js` and replace all occurences of `Jupyter` in the code with `IPython`." |
84 | 86 | ]
|
85 | 87 | },
|
86 | 88 | {
|
87 | 89 | "cell_type": "markdown",
|
88 | 90 | "metadata": {},
|
89 | 91 | "source": [
|
90 | 92 | "```javascript\n",
|
91 |
| - "$([IPython.events]).on('app_initialized.NotebookApp',\n", |
| 93 | + "$([Jupyter.events]).on('app_initialized.NotebookApp',\n", |
92 | 94 | " function(){\n",
|
93 | 95 | "\n",
|
94 | 96 | " // Copy of the Javascript code above (step 1).\n",
|
95 |
| - " IPython.toolbar.add_buttons_group([\n", |
| 97 | + " Jupyter.toolbar.add_buttons_group([\n", |
96 | 98 | " {\n",
|
97 | 99 | " // The button's label.\n",
|
98 | 100 | " 'label': 'renumber all code cells',\n",
|
99 | 101 | "\n",
|
100 | 102 | " // The button's icon.\n",
|
101 | 103 | " // See a list of Font-Awesome icons here:\n",
|
102 | 104 | " // http://fortawesome.github.io/Font-Awesome/icons/\n",
|
103 |
| - " 'icon': 'fa-list-ol',\n", |
| 105 | + " 'icon': 'fa-list-ol', // 'icon-list-ol' for older IPython\n", |
104 | 106 | "\n",
|
105 | 107 | " // The callback function.\n",
|
106 | 108 | " 'callback': function () {\n",
|
107 | 109 | "\n",
|
108 | 110 | " // We retrieve the lists of all cells.\n",
|
109 |
| - " var cells = IPython.notebook.get_cells();\n", |
| 111 | + " var cells = Jupyter.notebook.get_cells();\n", |
110 | 112 | "\n",
|
111 | 113 | " // We only keep the code cells.\n",
|
112 | 114 | " cells = cells.filter(function(c)\n",
|
113 | 115 | " {\n",
|
114 |
| - " return c instanceof IPython.CodeCell; \n", |
| 116 | + " return c instanceof Jupyter.CodeCell; \n", |
115 | 117 | " })\n",
|
116 | 118 | "\n",
|
117 | 119 | " // We set the input prompt of all code cells.\n",
|
|
0 commit comments