|
14 | 14 |
|
15 | 15 | // globally-used status variables:
|
16 | 16 | var rendering_toc_cell = false;
|
17 |
| - // oldTocSize also becomes the default size for a floating toc in a |
18 |
| - // non-live notebook |
19 |
| - var oldTocSize = {height: 'calc(100% - 180px)', width: '200px'}; |
| 17 | + // toc_position default also serves as the defaults for a non-live notebook |
| 18 | + var toc_position = {height: 'calc(100% - 180px)', width: '20%', left: '10px', top: '150px'}; |
20 | 19 |
|
21 | 20 | try {
|
22 | 21 | // this will work in a live notebook because nbextensions & custom.js
|
|
188 | 187 | }
|
189 | 188 |
|
190 | 189 | var saveTocPosition = function () {
|
191 |
| - setMd('toc_position', $('#toc-wrapper').css(['left', 'top', 'height', 'width'])); |
| 190 | + var toc_wrapper = $('#toc-wrapper'); |
| 191 | + var new_values = toc_wrapper.hasClass('sidebar-wrapper') ? ['width'] : ['left', 'top', 'height', 'width']; |
| 192 | + $.extend(toc_position, toc_wrapper.css(new_values)); |
| 193 | + setMd('toc_position', toc_position); |
192 | 194 | };
|
193 | 195 |
|
194 | 196 | var makeUnmakeMinimized = function (cfg, animate) {
|
|
197 | 199 | var anim_opts = {duration: animate ? 'fast' : 0};
|
198 | 200 | if (open) {
|
199 | 201 | $('#toc').show();
|
200 |
| - new_css = cfg.sideBar ? {} : oldTocSize; |
| 202 | + new_css = cfg.sideBar ? {} : {height: toc_position.height, width: toc_position.width}; |
201 | 203 | }
|
202 | 204 | else {
|
203 |
| - oldTocSize = wrap.css(['height', 'width']); |
204 | 205 | new_css = {
|
205 | 206 | height: wrap.outerHeight() - wrap.find('#toc').outerHeight(),
|
206 | 207 | };
|
|
215 | 216 | return open;
|
216 | 217 | };
|
217 | 218 |
|
218 |
| - var makeUnmakeSidebar = function (cfg, save_size) { |
| 219 | + var makeUnmakeSidebar = function (cfg) { |
219 | 220 | var make_sidebar = cfg.sideBar;
|
220 | 221 | var view_rect = (liveNotebook ? document.getElementById('site') : document.body).getBoundingClientRect();
|
221 | 222 | var wrap = $('#toc-wrapper')
|
|
225 | 226 | wrap.children('.ui-resizable-se').toggleClass('ui-icon', !make_sidebar);
|
226 | 227 | wrap.children('.ui-resizable-e').toggleClass('ui-icon ui-icon-grip-dotted-vertical', make_sidebar);
|
227 | 228 | if (make_sidebar) {
|
228 |
| - if (save_size) { |
229 |
| - oldTocSize = wrap.css(['height', 'width']); |
230 |
| - } |
231 | 229 | wrap.css({top: view_rect.top, height: '', left: 0});
|
232 | 230 | }
|
233 | 231 | else {
|
234 |
| - wrap.css({height: oldTocSize.height, width: oldTocSize.width}); |
| 232 | + wrap.css({height: toc_position.height}); |
235 | 233 | }
|
236 | 234 | setNotebookWidth(cfg);
|
237 | 235 | };
|
|
280 | 278 | ui.position.left = 0;
|
281 | 279 | }
|
282 | 280 | if (make_sidebar !== cfg.sideBar) {
|
283 |
| - var was_minimized = cfg.toc_section_display; |
284 | 281 | cfg.toc_section_display = setMd('toc_section_display', true);
|
285 | 282 | cfg.sideBar = setMd('sideBar', make_sidebar);
|
286 | 283 | makeUnmakeMinimized(cfg);
|
287 |
| - makeUnmakeSidebar(cfg, was_minimized); |
| 284 | + makeUnmakeSidebar(cfg); |
288 | 285 | }
|
289 | 286 | }, //end of drag function
|
290 | 287 | stop: saveTocPosition,
|
|
318 | 315 | $(window).on('resize', callbackPageResize);
|
319 | 316 | if (liveNotebook) {
|
320 | 317 | events.on("resize-header.Page toggle-all-headers", callbackPageResize);
|
321 |
| - // restore toc position at load |
322 |
| - var toc_pos = IPython.notebook.metadata.toc.toc_position; |
323 |
| - if (toc_pos !== undefined) { |
324 |
| - toc_wrapper.css(cfg.sideBar ? {width: toc_pos.width} : toc_pos); |
325 |
| - oldTocSize.width = toc_pos.width; |
326 |
| - oldTocSize.height = toc_pos.height; |
327 |
| - } |
| 318 | + $.extend(toc_position, IPython.notebook.metadata.toc.toc_position); |
328 | 319 | }
|
329 | 320 | else {
|
330 | 321 | // default to true for non-live notebook
|
331 | 322 | $.extend(true, cfg, {toc_window_display: true, toc_section_display: true});
|
332 | 323 | }
|
| 324 | + // restore toc position at load |
| 325 | + toc_wrapper.css(cfg.sideBar ? {width: toc_position.width} : toc_position); |
333 | 326 | // older toc2 versions stored string representations, so update those
|
334 | 327 | if (cfg.toc_window_display === 'none') {
|
335 | 328 | cfg.toc_window_display = setMd('toc_window_display', false);
|
|
0 commit comments