153 lines
4.2 KiB
JavaScript
153 lines
4.2 KiB
JavaScript
Array.prototype.stableSort = function(cmp) {
|
|
cmp = !!cmp ? cmp : (a, b) => {
|
|
if (a < b) return -1;
|
|
if (a > b) return 1;
|
|
return 0;
|
|
};
|
|
let stabilizedThis = this.map((el, index) => [el, index]);
|
|
let stableCmp = (a, b) => {
|
|
let order = cmp(a[0], b[0]);
|
|
if (order != 0) return order;
|
|
return a[1] - b[1];
|
|
}
|
|
stabilizedThis.sort(stableCmp);
|
|
for (let i=0; i<this.length; i++) {
|
|
this[i] = stabilizedThis[i][0];
|
|
}
|
|
return this;
|
|
}
|
|
|
|
function insertAtEnd(myField, myValue) {
|
|
myField.value += myValue;
|
|
}
|
|
function insertDate(idName) {
|
|
insertAtEnd(document.getElementById(idName),"\n"+getDate()+" ");
|
|
growTextarea(idName)
|
|
}
|
|
|
|
function getDate(){
|
|
var d = new Date();
|
|
var hr = d.getHours();
|
|
var min = d.getMinutes();
|
|
if (min < 10) { min = "0" + min; }
|
|
var day = d.getDate();
|
|
var month = 1+d.getMonth();
|
|
if (month < 10) { month = "0" + month; }
|
|
var year = d.getFullYear().toString().substr(-2);
|
|
return year+"-"+month+"-"+day+" "+hr+":"+min
|
|
}
|
|
|
|
|
|
function growTextarea(name) {
|
|
var el=document.getElementById(name);
|
|
var rows=el.value.split(/\r?\n|\r/);
|
|
el.rows=rows.length+1;
|
|
var cols=40;
|
|
for (var i = 0; i<rows.length; i++) {
|
|
cols=Math.max(cols, rows[i].length);
|
|
}
|
|
el.cols=cols;
|
|
}
|
|
|
|
function reload() {
|
|
location.href=window.location.href;
|
|
}
|
|
|
|
function hidetoggle(name) {
|
|
if (document.getElementById(name).style.display=='inline-block') {
|
|
document.getElementById(name).style.display='none';
|
|
} else {
|
|
document.getElementById(name).style.display='inline-block';
|
|
document.getElementById(name).scrollIntoView();
|
|
if (name == 'disp_add') {
|
|
document.getElementById('add_md').focus();
|
|
}
|
|
if (name == 'disp_edit') {
|
|
document.getElementById('edit_md').focus();
|
|
}
|
|
}
|
|
hideOthers(name);
|
|
}
|
|
|
|
function hideOthers(name) {
|
|
var allElements = document.getElementsByTagName("*");
|
|
for (var i = 0, n = allElements.length; i < n; ++i) {
|
|
var el = allElements[i];
|
|
if (el.id) {
|
|
if ((el.id.startsWith("disp_")) && (el.id!=name)) {
|
|
document.getElementById(el.id).style.display='none';
|
|
}}
|
|
}
|
|
}
|
|
function dropDown(name) {
|
|
dropDownHide();
|
|
document.getElementById(name).classList.toggle("show");
|
|
hideOthers('foo');
|
|
}
|
|
function dropDownHide() {
|
|
var dropdowns = document.getElementsByClassName("dropdown-content");
|
|
var i;
|
|
for (i = 0; i < dropdowns.length; i++) {
|
|
var openDropdown = dropdowns[i];
|
|
if (openDropdown.classList.contains('show')) {
|
|
openDropdown.classList.remove('show');
|
|
}
|
|
}
|
|
}
|
|
function get_cookie(name) {
|
|
var nameEQ = name+"=";
|
|
var ca = document.cookie.split(';');
|
|
for(var i=0;i < ca.length;i++) {
|
|
var c = ca[i];
|
|
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
|
if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); }
|
|
}
|
|
return null
|
|
}
|
|
|
|
function sortMarkdown(boughtOrder=false) {
|
|
var divs = document.getElementsByClassName("entry");
|
|
divs = Array.prototype.slice.call(divs, 0);
|
|
if (boughtOrder) {
|
|
divs.stableSort(orderStringSorter);
|
|
} else {
|
|
divs.stableSort(fullStringSorter);
|
|
}
|
|
var parent = document.getElementById('entry_loop');
|
|
parent.innerHTML = "";
|
|
for(var i = 0, l = divs.length; i < l; i++) {
|
|
parent.appendChild(divs[i]);
|
|
}
|
|
}
|
|
function fullStringSorter(a,b) {
|
|
var aValue=a.children[1].innerHTML;
|
|
var bValue=b.children[1].innerHTML;
|
|
if (aValue < bValue) return -1;
|
|
if (aValue > bValue) return 1;
|
|
return 0;
|
|
}
|
|
function orderStringSorter(a,b) {
|
|
var aValue=a.children[1].innerHTML.substring(0,3);
|
|
var bValue=b.children[1].innerHTML.substring(0,3);
|
|
if ( aValue == "[x]" && bValue == "[ ]" ) return 1;
|
|
if ( aValue == "[ ]" && bValue == "[x]" ) return -1;
|
|
return 0;
|
|
}
|
|
|
|
function scrollBack() {
|
|
var position=parseInt(get_cookie("position"));
|
|
window.scrollTo(0,position);
|
|
}
|
|
|
|
// Close the dropdown menu if the user clicks outside of it
|
|
window.onclick = function(event) {
|
|
if (!event.target.matches('.dropbtn')) {
|
|
dropDownHide();
|
|
}
|
|
}
|
|
document.onscroll = function(event) {
|
|
document.cookie = "position=" + window.scrollY + "; path=" + window.location.pathname;
|
|
}
|
|
window.onload = scrollBack;
|
|
|