Skip to content

Commit fe69131

Browse files
committed
[toc2] move addSaveAsWithToc definition into main.js
since it's only used there anyway
1 parent 37e1099 commit fe69131

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ define([
116116
return cfg;
117117
}
118118

119+
// extra download as html with toc menu (needs IPython kernel)
120+
function addSaveAsWithToc() {
121+
if (IPython.notebook.metadata.kernelspec.language == 'python') {
122+
if ($('#save_html_with_toc').length == 0) {
123+
$('#save_checkpoint').after("<li id='save_html_with_toc'/>")
124+
$('#save_html_with_toc')
125+
.append($('<a/>').text('Save as HTML (with toc)').attr("href", "#"))
126+
.on('click', function (evt) {
127+
if (IPython.notebook.metadata.kernelspec.language == 'python') {
128+
var code = "!jupyter nbconvert '" + IPython.notebook.notebook_name + "' --template toc2";
129+
console.log('[toc2] running:', code);
130+
IPython.notebook.kernel.execute(code);
131+
}
132+
else {
133+
alert('Sorry; this only works with a IPython kernel');
134+
$('#save_html_with_toc').remove();
135+
}
136+
});
137+
}
138+
}
139+
else {
140+
$('#save_html_with_toc').remove()
141+
}
142+
}
119143

120144

121145

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,34 +110,6 @@ function highlight_toc_item(evt, data) {
110110
}
111111
}
112112

113-
114-
// extra download as html with toc menu (needs IPython kernel)
115-
function addSaveAsWithToc() {
116-
var saveAsWithToc = $('#save_html_with_toc').length == 0
117-
var IPythonKernel = IPython.notebook.metadata.kernelspec.language == "python"
118-
if (IPythonKernel) {
119-
if ($('#save_html_with_toc').length == 0) {
120-
$('#save_checkpoint').after("<li id='save_html_with_toc'/>")
121-
$('#save_html_with_toc').append($('<a/>').text('Save as HTML (with toc)').attr("href", "#"))
122-
$('#save_html_with_toc').click(function() {
123-
var IPythonKernel = IPython.notebook.metadata.kernelspec.language == "python"
124-
if (IPythonKernel) {
125-
var code = "!jupyter nbconvert '" + IPython.notebook.notebook_name + "' --template toc2"
126-
console.log(code)
127-
IPython.notebook.kernel.execute(code)
128-
} else {
129-
alert("Sorry; this only works with a IPython kernel");
130-
$('#save_html_with_toc').remove();
131-
}
132-
})
133-
}
134-
} else {
135-
if ($('#save_html_with_toc').length > 0) $('#save_html_with_toc').remove()
136-
}
137-
}
138-
139-
140-
141113
var create_navigate_menu = function(callback) {
142114
$('#kernel_menu').parent().after('<li id="Navigate"/>')
143115
$('#Navigate').addClass('dropdown').append($('<a/>').attr('href', '#').attr('id', 'Navigate_sub'))

0 commit comments

Comments
 (0)