Merge pull request #1111 from jcb91/t2_2

[toc2] remove unused variables & commented code
This commit is contained in:
Josh Barnes
2017-10-04 18:34:44 +01:00
committed by GitHub
4 changed files with 28 additions and 151 deletions
@@ -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 {
@@ -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) {
@@ -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
// $('<a>').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 = $("<ul/>").addClass("toc-item").attr('id', 'toc-level0');
var ul = $('<ul/>').addClass('toc-item');
// update toc element
$("#toc").empty().append(ul);
st.cell_toc = undefined;
// if cfg.toc_cell=true, add and update a toc cell in the notebook.
if (liveNotebook) {
///look_for_cell_toc(process_cell_toc);
process_cell_toc(cfg, st);
}
//process_cell_toc();
var cell_toc_text = " # Table of Contents\n";
var depth = 1; //var depth = ol_depth(ol);
var depth = 1;
var li = ul; //yes, initialize li with ul!
all_headers = $("#notebook").find(":header"); // update all_headers
var min_lvl = 1 + Number(Boolean(cfg.skip_h1_title)),
@@ -720,8 +670,7 @@
// update navigation menu
if (cfg.navigate_menu) {
var pop_nav = function() { //callback for create_nav_menu
//$('#Navigate_menu').empty().append($("<div/>").attr("id", "navigate_menu").addClass('toc').append(ul.clone().attr('id', 'navigate_menu-level0')))
$('#navigate_menu').empty().append($('#toc-level0').clone().attr('id', 'navigate_menu-level0'))
$('#navigate_menu').empty().append($('#toc > .toc-item').clone());
}
if ($('#Navigate_menu').length == 0) {
create_navigate_menu(pop_nav);
@@ -757,7 +706,6 @@
events[cfg.collapse_to_match_collapsible_headings ? 'on' : 'off'](
'collapse.CollapsibleHeading uncollapse.CollapsibleHeading', callback_toc2_collapsible_headings);
$(window).resize(function() {
$('#toc').css({
maxHeight: $(window).height() - 30
@@ -773,10 +721,8 @@
};
var toggle_toc = function(cfg, st) {
// toggle draw (first because of first-click behavior)
//$("#toc-wrapper").toggle({'complete':function(){
$("#toc-wrapper").toggle({
'progress': function() {
setNotebookWidth(cfg, st);
@@ -791,7 +737,6 @@
table_of_contents(cfg, st);
}
});
};
return {
@@ -1,43 +0,0 @@
{%- extends 'full.tpl' -%}
{%- block header -%}
{{ super() }}
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="toc2.js"></script>
<script>
$( document ).ready(function(){
var cfg={'threshold':6, // depth of toc (number of levels)
'number_sections':true, // sections numbering
'toc_cell':false, // useless here
'toc_window_display':true, // display the toc window
"toc_section_display": "block", // display toc contents in the window
'sideBar':true, // sidebar or floating window
'navigate_menu':false // navigation menu (only in liveNotebook -- do not change)
}
var st={}; // some variables used in the script
st.rendering_toc_cell = false;
st.config_loaded = false;
st.extension_initialized=false;
st.nbcontainer_marginleft = $('#notebook-container').css('margin-left')
st.nbcontainer_marginright = $('#notebook-container').css('margin-right')
st.nbcontainer_width = $('#notebook-container').css('width')
st.oldTocHeight = undefined
st.cell_toc = undefined;
st.toc_index=0;
// fire the main function with these parameters
table_of_contents(cfg,st);
});
</script>
{%- endblock header -%}