Skip to content

Commit c960b97

Browse files
committed
[toc2] simplify position saving
by using a common function & jquery css lists
1 parent 58bd217 commit c960b97

File tree

1 file changed

+8
-29
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/toc2

1 file changed

+8
-29
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@
185185
nb_inner.css(inner_css);
186186
}
187187

188+
var saveTocPosition = function () {
189+
setMd('toc_position', $('#toc-wrapper').css(['left', 'top', 'height', 'width']));
190+
};
191+
188192
var makeUnmakeMinimized = function (cfg, animate) {
189193
var open = cfg.sideBar || cfg.toc_section_display;
190194
var new_css, wrap = $('#toc-wrapper');
@@ -281,20 +285,7 @@
281285
makeUnmakeSidebar(cfg, was_minimized);
282286
}
283287
}, //end of drag function
284-
stop: function(event, ui) { // on save, store toc position
285-
if (liveNotebook) {
286-
IPython.notebook.metadata.toc['toc_position'] = {
287-
'left': $('#toc-wrapper').css('left'),
288-
'top': $('#toc-wrapper').css('top'),
289-
'width': $('#toc-wrapper').css('width'),
290-
'height': $('#toc-wrapper').css('height'),
291-
'right': $('#toc-wrapper').css('right')
292-
};
293-
IPython.notebook.set_dirty();
294-
}
295-
// Ensure position is fixed (again)
296-
$('#toc-wrapper').css('position', 'fixed');
297-
},
288+
stop: saveTocPosition,
298289
containment: 'parent',
299290
snap: 'body, #site',
300291
snapTolerance: 20,
@@ -312,23 +303,11 @@
312303
makeUnmakeMinimized(cfg);
313304
}
314305
},
315-
stop: function(event, ui) { // on save, store toc position
316-
if (liveNotebook) {
317-
IPython.notebook.metadata.toc['toc_position'] = {
318-
'left': $('#toc-wrapper').css('left'),
319-
'top': $('#toc-wrapper').css('top'),
320-
'height': $('#toc-wrapper').css('height'),
321-
'width': $('#toc-wrapper').css('width'),
322-
'right': $('#toc-wrapper').css('right')
323-
};
324-
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
325-
IPython.notebook.set_dirty();
326-
}
327-
},
306+
stop: saveTocPosition,
328307
containment: 'parent',
329308
minHeight: 100,
330309
minWidth: 165,
331-
})
310+
});
332311

333312
// On header/menu/toolbar resize, resize the toc itself
334313
$(window).on('resize', callbackPageResize);
@@ -602,7 +581,7 @@
602581
var wrap = $("#toc-wrapper");
603582
var show = wrap.is(':hidden');
604583
wrap.toggle(show);
605-
setMd('toc_window_display', show);
584+
cfg['toc_window_display'] = setMd('toc_window_display', show);
606585
setNotebookWidth(cfg);
607586
table_of_contents(cfg);
608587
};

0 commit comments

Comments
 (0)