Skip to content

Commit 885e383

Browse files
committed
Added alert if WebStorage isn't available
1 parent fe27738 commit 885e383

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

notebook-snippet-manager.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
define(['base/js/namespace', 'jquery', 'base/js/dialog'], function(Jupyter, $, dialog) {
2+
function storageAvailable(type) {
3+
try {
4+
var storage = window[type];
5+
var x = '__storage_test__';
6+
storage.setItem(x, x);
7+
storage.removeItem(x);
8+
return true;
9+
} catch (e) {
10+
return false;
11+
}
12+
}
13+
214
function add_cell_to_snippet_manager() {
315
var selected_cell = Jupyter.notebook.get_selected_cell();
416
var selected_content = selected_cell.get_text();
@@ -57,7 +69,19 @@ define(['base/js/namespace', 'jquery', 'base/js/dialog'], function(Jupyter, $, d
5769

5870
function load_ipython_extension() {
5971
console.log("Loading notebook-snippet-manager extension...");
60-
place_snippet_manager_buttons();
72+
if (storageAvailable('localStorage')) {
73+
place_snippet_manager_buttons();
74+
} else {
75+
var modal_text = "It looks like you have the snippet-manager";
76+
modal_text += " enabled but your browser doesn't support WebStorage.";
77+
modal_text += " Please switch to a browser with WebStorage to use snippet-manager.";
78+
var modal_content = $('<p/>').html(modal_text);
79+
dialog.modal({
80+
'title': 'WebStorage Unavaialble',
81+
'body': modal_content,
82+
'buttons': {OK: {}}
83+
});
84+
}
6185
}
6286

6387
return {

0 commit comments

Comments
 (0)