remember state of folds

This commit is contained in:
ville rantanen
2018-01-04 20:32:42 +02:00
parent 468a00b21d
commit b3d509e19d

View File

@@ -7,10 +7,10 @@
TABLE { width: 100%; } TABLE { width: 100%; }
HR { height:5px; border: 0px;} HR { height:5px; border: 0px;}
TD { vertical-align: top; width: 10%; } TD { vertical-align: top; width: 10%; }
LI { LI {
text-indent:-1.3em; text-indent:-1.3em;
padding-left:1.4em; padding-left:1.4em;
list-style-type:none; list-style-type:none;
overflow: hidden; overflow: hidden;
margin-bottom: 0.2em; margin-bottom: 0.2em;
} }
@@ -31,7 +31,7 @@
A:focus { text-decoration: underline; } A:focus { text-decoration: underline; }
#filter { width: 100%; } #filter { width: 100%; }
#search { width: 100%; display: table; } #search { width: 100%; display: table; }
.search_span { display: table-cell; text-align: center; vertical-align: middle; .search_span { display: table-cell; text-align: center; vertical-align: middle;
padding-left: 0.1em; padding-right: 0.1em; } padding-left: 0.1em; padding-right: 0.1em; }
.head { font-size: 16px; text-align:left; padding-top: 0.2em; margin-bottom: -0.5em; } .head { font-size: 16px; text-align:left; padding-top: 0.2em; margin-bottom: -0.5em; }
#menu { font-size: 12px; width: 3em; } #menu { font-size: 12px; width: 3em; }
@@ -49,7 +49,7 @@
</STYLE> </STYLE>
<script language="javascript"> <script language="javascript">
function init() { function init() {
var head = document.head; var head = document.head;
if (config.style!=null) { if (config.style!=null) {
var link = document.createElement('link'); var link = document.createElement('link');
link.type = 'text/css'; link.type = 'text/css';
@@ -70,8 +70,8 @@ function init() {
if (!config.search) { if (!config.search) {
document.getElementById('search').style.display='none'; document.getElementById('search').style.display='none';
} }
if (config.columns==1 || narrow_window()) { if (config.columns==1 || narrow_window()) {
make_menu(); make_menu();
} }
document.getElementById("open_blank_arrow").innerHTML=config.arrows[0]; document.getElementById("open_blank_arrow").innerHTML=config.arrows[0];
document.getElementById("filter").focus(); document.getElementById("filter").focus();
@@ -90,7 +90,7 @@ String.prototype.capitalizeFirstLetter = function() {
function make_link(md) { function make_link(md) {
var match=linkReg.exec(md); var match=linkReg.exec(md);
if (match != null) { if (match != null) {
return "<li>"+match[1]+"<a href=\""+match[3]+"\">"+match[2]+"</a>"+match[4]; return "<li>"+match[1]+"<a href=\""+match[3]+"\">"+match[2]+"</a>"+match[4];
} }
match=linkPlain.exec(md); match=linkPlain.exec(md);
@@ -104,7 +104,7 @@ function make_head(c,index="") {
var name=c.substring(1).trim(); var name=c.substring(1).trim();
var head=c.replace(/ /g,"&nbsp;"); var head=c.replace(/ /g,"&nbsp;");
var id=name.replace(/ /g,"")+"_"+index; var id=name.replace(/ /g,"")+"_"+index;
return '<a name="'+name+'" id="anchor_'+id+'" onclick="fold_content(\''+id+'\')">'+ return '<a name="'+name+'" id="anchor_'+id+'" onclick="fold_toggle(\''+id+'\')">'+
'<div class=head align=center id="head_'+id+'">'+head+'</div></a>'+ '<div class=head align=center id="head_'+id+'">'+head+'</div></a>'+
'<hr WIDTH="100%" SIZE=3 NOSHADE>'; '<hr WIDTH="100%" SIZE=3 NOSHADE>';
} }
@@ -148,7 +148,7 @@ function filter(ev) {
if (c>1) { if (c>1) {
document.getElementById('filter').focus(); document.getElementById('filter').focus();
} }
} }
} }
function no_filter(){} function no_filter(){}
@@ -172,13 +172,13 @@ function search_hits(needle) {
} }
} }
var match=linkReg.exec(linkList[l].toLowerCase()); var match=linkReg.exec(linkList[l].toLowerCase());
if (match != null ) { if (match != null ) {
/* matches to markdown link */ /* matches to markdown link */
if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); } if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); }
continue continue
} }
match=linkPlain.exec(linkList[l].toLowerCase()); match=linkPlain.exec(linkList[l].toLowerCase());
if (match != null ) { if (match != null ) {
/* matches to plain link */ /* matches to plain link */
if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); } if ( match[2].indexOf(needle)>-1 ) { hitList.push(l); }
continue continue
@@ -248,7 +248,7 @@ function reload_source() {
location.href=config.source location.href=config.source
} }
function get_URL(s) { function get_URL(s) {
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() xmlhttp.onreadystatechange=function()
{ if (xmlhttp.readyState==4 && xmlhttp.status==200) { if (xmlhttp.readyState==4 && xmlhttp.status==200)
@@ -258,8 +258,8 @@ function get_URL(s) {
xmlhttp.send(); xmlhttp.send();
} }
function read_links() { function read_links() {
get_URL(config.source); get_URL(config.source);
} }
function parse_links(s) { function parse_links(s) {
@@ -271,15 +271,15 @@ function parse_links(s) {
} }
} }
linkList=links.slice(0); linkList=links.slice(0);
init(); init();
} }
function keyboard_entry(ev) { function keyboard_entry(ev) {
var kC=ev.keyCode; var kC=ev.keyCode;
var k=String.fromCharCode(ev.keyCode); var k=String.fromCharCode(ev.keyCode);
if ( document.activeElement === document.getElementById("filter")) { if ( document.activeElement === document.getElementById("filter")) {
return return
} }
if (/S/.test(k)) { if (/S/.test(k)) {
document.getElementById("filter").focus(); document.getElementById("filter").focus();
} }
if (/N/.test(k)) { if (/N/.test(k)) {
@@ -287,8 +287,8 @@ function keyboard_entry(ev) {
} }
} }
function keyboard_control(ev) { function keyboard_control(ev) {
var kC=ev.keyCode; var kC=ev.keyCode;
var k=String.fromCharCode(ev.keyCode); var k=String.fromCharCode(ev.keyCode);
if (ev.ctrlKey) { if (ev.ctrlKey) {
if (k=='C') { if (k=='C') {
document.getElementById("filter").value=''; document.getElementById("filter").value='';
@@ -305,7 +305,7 @@ function toggle_blank() {
span.attributes['data']="false"; span.attributes['data']="false";
} else { } else {
span.attributes['data']="true"; span.attributes['data']="true";
} }
} else { } else {
span.attributes['data']="true" span.attributes['data']="true"
} }
@@ -354,33 +354,83 @@ function filter_cookies(cookies,name) {
} }
} }
} }
return null return null;
} }
function fold_content(name) { function fold_toggle(name,save_state = true) {
if (!narrow_window()) { return } if (!narrow_window()) { return }
if (!config.foldCategories) { return } if (!config.foldCategories) { return }
var title = document.getElementById("head_"+name); var title = document.getElementById("head_"+name);
var el = document.getElementById("content_"+name); var el = document.getElementById("content_"+name);
el.hidden = ! el.hidden; el.hidden = ! el.hidden;
title.classList.toggle("fold_plus"); title.classList.toggle("fold_plus");
if (save_state) {
set_cookie("fold",fold_get_state());
}
}
function fold_set(name,value) {
if (!narrow_window()) { return }
if (!config.foldCategories) { return }
var title = document.getElementById("head_"+name);
var el = document.getElementById("content_"+name);
el.hidden = value;
if (value) {
title.classList.add("fold_plus");
} else {
title.classList.remove("fold_plus");
}
} }
function fold_initial() { function fold_initial() {
if (!narrow_window()) { return } if (!narrow_window()) { return }
if (!config.foldCategories) { return } if (!config.foldCategories) { return }
var state = get_cookie("fold");
if (state !== null) {
fold_set_state(state);
return;
}
var slides = document.getElementsByClassName("head"); var slides = document.getElementsByClassName("head");
for(var i = 0; i < slides.length; i++) { for(var i = 0; i < slides.length; i++) {
var el = slides.item(i); var el = slides.item(i);
var rect = el.getBoundingClientRect(); var rect = el.getBoundingClientRect();
if (window.innerHeight*1.5 < rect.top) { if (window.innerHeight*1.5 < rect.top) {
var name = el.id.replace("head_",""); var name = el.id.replace("head_","");
fold_content(name); fold_toggle(name);
} }
} }
} }
function fold_get_state() {
var slides = document.getElementsByClassName("head");
var state = "";
for(var i = 0; i < slides.length; i++) {
var title = slides.item(i);
var name = title.id.replace("head_","");
var el = document.getElementById("content_"+name);
if (el.hidden) {
state += '-';
} else {
state += '+';
}
}
return state;
}
function fold_set_state(state) {
var slides = document.getElementsByClassName("head");
for(var i = 0; i < slides.length; i++) {
var title = slides.item(i);
var name = title.id.replace("head_","");
if (state[i] == '-') {
fold_set(name, true);
}
if (state[i] == '+') {
fold_set(name, false);
}
}
return;
}
function set_cookie(name,value) { function set_cookie(name,value) {
// Save cookies for 2 hours // Save cookies for 2 hours
document.cookie = name + "=" + value.toString() + "&" + window.location.pathname + document.cookie = name + "=" + value.toString() + "&" + window.location.pathname +
";path=" + window.location.pathname + ";max-age="+ (60*60*2).toString() + ";"; ";path=" + window.location.pathname + ";max-age="+ (60*60*2).toString() + ";";
} }
document.onkeyup=keyboard_entry; document.onkeyup=keyboard_entry;
document.onkeydown=keyboard_control; document.onkeydown=keyboard_control;