diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css b/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css index c796833..64497f5 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css @@ -14,32 +14,32 @@ nbextension-configurator background-color: #DAA520; } -#toc-level0 a { - color: #333333; /* default - alterable via nbextension-configurator */ +#toc a { + color: #333333; /* default - alterable via nbextension-configurator */ text-decoration: none; } #navigate_menu li > span:hover {background-color: #f1f1f1} -/* Move menus and tooolbar to the left, following @Kevin-McIsaac suggestion +/* Move menus and tooolbar to the left, following @Kevin-McIsaac suggestion +This is now done in javascript, if the relevant option is selected div#menubar-container, div#header-container { width: auto; padding-left: 20px; }*/ #navigate_menu { - /*display: block;*/ list-style-type: none; - max-width: 800px; - min-width: 100px; - width: 250px; + max-width: 800px; + min-width: 100px; + width: 250px; overflow: auto; } #navigate_menu a { list-style-type: none; - color: #333333; /* default - alterable via nbextension-configurator */ + color: #333333; /* default - alterable via nbextension-configurator */ text-decoration: none; } @@ -49,29 +49,20 @@ padding-left: 20px; list-style-type: none; } -#navigate_menu-level0 {padding-left: 0px;} -#navigate_menu-level0 ul {padding-left: 0px;} - +#navigate_menu > .toc-item, +#navigate_menu ul { + padding-left: 0px; +} .toc { max-height: 500px; padding: 0px; overflow-y: auto; font-weight: normal; - color: #333333; /* default - alterable via nbextension-configurator */ + color: #333333; /* default - alterable via nbextension-configurator */ white-space: nowrap; overflow-x: auto; -} - -.toc ol.toc-item { - counter-reset: item; - list-style: none; - padding: 0.1em; - } - -.toc ol.toc-item li { - display: block; - } +} .toc ul.toc-item { list-style-type: none; @@ -79,14 +70,6 @@ padding-left: 20px; margin: 0; } -.toc ol.toc-item li:before { - font-size: 90%; - font-family: Georgia, Times New Roman, Times, serif; - counter-increment: item; - content: counters(item, ".")" "; - } - - .float-wrapper { position: fixed !important; top: 120px; @@ -95,7 +78,7 @@ padding-left: 20px; border: thin solid rgba(0, 0, 0, 0.38); border-radius: 5px; padding:10px; - background-color: #fff; /* default - alterable via nbextension-configurator */ + background-color: #fff; /* default - alterable via nbextension-configurator */ opacity: .8; z-index: 100; overflow: hidden; @@ -108,19 +91,13 @@ padding-left: 20px; position: fixed !important; width: 212px; max-width: 28%; - background-color: #fff; /* default - alterable via nbextension-configurator */ + background-color: #fff; /* default - alterable via nbextension-configurator */ border-style: solid; - border-color: #eeeeee; /* default - alterable via nbextension-configurator */ + border-color: #eeeeee; /* default - alterable via nbextension-configurator */ opacity: .99; overflow: hidden; } - -.col-md-9 { - overflow:hidden; - margin-left: 14%; - width: 80%} - #toc-wrapper.closed { min-width: 100px; width: auto; @@ -176,14 +153,14 @@ padding-left: 20px; #toc-wrapper .toc-item-num { font-style: normal; font-family: Georgia, Times New Roman, Times, serif; - color: black; /* default - alterable via nbextension-configurator */ + color: black; /* default - alterable via nbextension-configurator */ } /* These colors are now specified in js, after reading the extension's config stored in system and updated using the nbextension-configurator -.toc-item-highlight-select {background-color: Gold} -.toc-item-highlight-execute {background-color: red} +.toc-item-highlight-select {background-color: Gold} +.toc-item-highlight-execute {background-color: red} .toc-item-highlight-execute.toc-item-highlight-select {background-color: Gold} */ .toc-item .fa-fw:first-child { diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js index 07f8ad6..964fb9a 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js @@ -146,7 +146,7 @@ define([ function create_additional_css() { var sheet = document.createElement('style') - sheet.innerHTML = "#toc-level0 li > span:hover { background-color: " + cfg.colors.hover_highlight + " }\n" + + sheet.innerHTML = "#toc li > span:hover { background-color: " + cfg.colors.hover_highlight + " }\n" + ".toc-item-highlight-select {background-color: " + cfg.colors.selected_highlight + "}\n" + ".toc-item-highlight-execute {background-color: " + cfg.colors.running_highlight + "}\n" + ".toc-item-highlight-execute.toc-item-highlight-select {background-color: " + cfg.colors.selected_highlight + "}" @@ -157,7 +157,7 @@ define([ } // Using custom colors sheet.innerHTML += ".float-wrapper, .sidebar-wrapper { background-color: " + cfg.colors.wrapper_background + "}"; - sheet.innerHTML += "#toc-level0 a, #navigate_menu a, .toc { color: " + cfg.colors.navigate_text + "}"; + sheet.innerHTML += "#toc a, #navigate_menu a, .toc { color: " + cfg.colors.navigate_text + "}"; sheet.innerHTML += "#toc-wrapper .toc-item-num { color: " + cfg.colors.navigate_num + "}"; sheet.innerHTML += ".sidebar-wrapper { border-color: " + cfg.colors.sidebar_border + "}"; sheet.innerHTML += ".highlight_on_scroll { border-left: solid 4px " + cfg.colors.on_scroll + '}'; @@ -171,7 +171,6 @@ define([ var previous_get_callbacks = CodeCell.prototype.get_callbacks; CodeCell.prototype.get_callbacks = function() { - var that = this; var callbacks = previous_get_callbacks.apply(this, arguments); var prev_reply_callback = callbacks.shell.reply; callbacks.shell.reply = function(msg) { @@ -195,7 +194,6 @@ define([ function excute_codecell_callback(evt, data) { - var cell = data.cell; highlight_toc_item(evt, data); } @@ -210,10 +208,10 @@ define([ } var toc_init = function() { - // read configuration, then call toc + // read configuration, then call toc cfg = read_config(cfg, function() { table_of_contents(cfg, st); - }); // called after config is stable + }); // called after config is stable // event: render toc for each markdown cell modification $([IPython.events]).on("rendered.MarkdownCell", function(evt, data) { diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js index 0ad8c6e..e4b835a 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js @@ -56,7 +56,6 @@ var trg_id = $(evt.currentTarget).attr('data-toc-modified-id'); // use native scrollIntoView method with semi-unique id // ! browser native click does't follow links on all browsers - // $('').attr('href', window.location.href.split('#')[0] + '#' + trg_id)[0].click(); document.getElementById(trg_id).scrollIntoView(true) if (liveNotebook) { // use native document method as jquery won't cope with characters @@ -83,16 +82,6 @@ return a; }; - var ol_depth = function(element) { - // get depth of nested ol - var d = 0; - while (element.prop("tagName").toLowerCase() == 'ol') { - d += 1; - element = element.parent(); - } - return d; - }; - function highlight_toc_item(evt, data) { var c = $(data.cell.element); if (c.length < 1) { @@ -232,8 +221,6 @@ .text('[+]') .attr('title', 'Show ToC'); } else { - // $('#toc-wrapper').css({height: IPython.notebook.metadata.toc.toc_position['height']}); - // $('#toc').css({height: IPython.notebook.metadata.toc.toc_position['height']}); $('#toc-wrapper').css({ height: st.oldTocHeight }); @@ -272,9 +259,7 @@ IPython.notebook.set_dirty(); } - //$('.toc-item-num').toggle(); cfg.number_sections ? $('.toc-item-num').show() : $('.toc-item-num').hide() - //table_of_contents(); return false; }) ).append( @@ -386,7 +371,6 @@ }, start: function(event, ui) { $(this).width($(this).width()); - //$(this).css('position', 'fixed'); }, stop: function(event, ui) { // on save, store toc position if (liveNotebook) { @@ -400,8 +384,6 @@ $('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height()) IPython.notebook.set_dirty(); } - // Ensure position is fixed (again) - //$(this).css('position', 'fixed'); } }) @@ -415,8 +397,6 @@ }); } - - // restore toc position at load if (liveNotebook) { if (IPython.notebook.metadata.toc['toc_position'] !== undefined) { @@ -450,8 +430,7 @@ } // if toc-wrapper is undefined (first run(?), then hide it) - if ($('#toc-wrapper').css('display') == undefined) $('#toc-wrapper').css('display', "none") //block - //}; + if ($('#toc-wrapper').css('display') == undefined) $('#toc-wrapper').css('display', "none"); $('#site').bind('siteHeight', function() { if (cfg.sideBar) $('#toc-wrapper').css('height', $('#site').height()); @@ -460,7 +439,6 @@ $('#site').trigger('siteHeight'); // Initial style - ///sideBar = cfg['sideBar'] if (cfg.sideBar) { $('#toc-wrapper').addClass('sidebar-wrapper'); if (!liveNotebook) { @@ -504,7 +482,6 @@ //loop over all headers all_headers.each(function(i, h) { var top_of_element = $(h).offset().top; - // var bottom_of_element = $(h).offset().top + $(h).outerHeight(); if ((bottom_of_screen > top_of_element) && (top_of_screen < top_of_element)) { // The element is visible @@ -533,22 +510,6 @@ // Its contents are automatically updated. // Optionnaly, the sections in the toc can be numbered. - - function look_for_cell_toc(callb) { // look for a possible toc cell - var cells = IPython.notebook.get_cells(); - var lcells = cells.length; - for (var i = 0; i < lcells; i++) { - if (cells[i].metadata.toc == "true") { - cell_toc = cells[i]; - toc_index = i; - //console.log("Found a cell_toc",i); - break; - } - } - callb && callb(i); - } - // then process the toc cell: - function process_cell_toc(cfg, st) { // look for a possible toc cell var cells = IPython.notebook.get_cells(); @@ -557,7 +518,6 @@ if (cells[i].metadata.toc == "true") { st.cell_toc = cells[i]; st.toc_index = i; - //console.log("Found a cell_toc",i); break; } } @@ -568,7 +528,6 @@ if (cfg.toc_cell) { if (st.cell_toc == undefined) { st.rendering_toc_cell = true; - //console.log("********* Toc undefined - Inserting toc_cell"); st.cell_toc = IPython.notebook.select(0).insert_cell_above("markdown"); st.cell_toc.metadata.toc = "true"; } @@ -607,9 +566,6 @@ var callback_collapser = function(evt) { var clicked_i = $(evt.currentTarget); var trg_id = clicked_i.siblings('a').attr('data-toc-modified-id'); - var anchors = $('.toc .toc-item > li > span > a').filter(function(idx, elt) { - return $(elt).attr('data-toc-modified-id') === trg_id; - }); var show = clicked_i.hasClass('fa-caret-right'); collapse_by_id(trg_id, show); }; @@ -624,29 +580,23 @@ var toc_wrapper = $("#toc-wrapper"); - // var toc_index=0; if (toc_wrapper.length === 0) { // toc window doesn't exist at all create_toc_div(cfg, st); // create it highlightTocItemOnScroll(cfg, st); // initialize highlighting on scroll } - var segments = []; - var ul = $("