Skip to content

Commit

Permalink
Use session cookies and modernize javascripts
Browse files Browse the repository at this point in the history
Modernisations:
- replace 'var' by 'let' or 'const'
- replace short function expressions by arrow functions
- more consistent curly brace placing
  • Loading branch information
doxygen committed Oct 30, 2023
1 parent 92a469a commit f4faaf1
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 770 deletions.
30 changes: 14 additions & 16 deletions deps/jquery/cookie.js
Expand Up @@ -3,47 +3,45 @@
Copyright (c) 2023 Dimitri van Heesch
Released under MIT license.
*/
var Cookie =
{
let Cookie = {
cookie_namespace: 'doxygen_',

readSetting: function(cookie,defVal) {
readSetting(cookie,defVal) {
if (window.chrome) {
var val = localStorage.getItem(this.cookie_namespace+cookie);
const val = localStorage.getItem(this.cookie_namespace+cookie);
if (val) return val;
} else {
var myCookie = this.cookie_namespace+cookie+"=";
let myCookie = this.cookie_namespace+cookie+"=";
if (document.cookie) {
var index = document.cookie.indexOf(myCookie);
const index = document.cookie.indexOf(myCookie);
if (index != -1) {
var valStart = index + myCookie.length;
var valEnd = document.cookie.indexOf(";", valStart);
const valStart = index + myCookie.length;
let valEnd = document.cookie.indexOf(";", valStart);
if (valEnd == -1) {
valEnd = document.cookie.length;
}
var val = document.cookie.substring(valStart, valEnd);
return val;
return document.cookie.substring(valStart, valEnd);
}
}
}
return defVal;
},

writeSetting: function(cookie,val,days=10*365) { // 10 years -> forever
writeSetting(cookie,val,days=10*365) { // default days='forever', 0=session cookie, -1=delete
if (window.chrome) {
localStorage.setItem(this.cookie_namespace+cookie,val);
} else {
var date = new Date();
let date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expiration = date.toGMTString();
const expiration = days!=0 ? "expires="+date.toGMTString()+";" : "";
document.cookie = this.cookie_namespace + cookie + "=" +
val + "; SameSite=Lax; expires=" + expiration+"; path=/";
val + "; SameSite=Lax;" + expiration + "path=/";
}
},

eraseSetting: function(cookie) {
eraseSetting(cookie) {
if (window.chrome) {
var val = localStorage.removeItem(this.cookie_namespace+cookie);
const val = localStorage.removeItem(this.cookie_namespace+cookie);
if (val) return val;
} else {
this.writeSetting(cookie,'',-1);
Expand Down
26 changes: 26 additions & 0 deletions templates/html/.eslintrc.js
@@ -0,0 +1,26 @@
module.exports = {
"env": {
"browser": true,
"es2021": true,
"jquery": true
},
"extends": "eslint:recommended",
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
}
}
8 changes: 4 additions & 4 deletions templates/html/clipboard.js
Expand Up @@ -27,10 +27,10 @@ SOFTWARE.
*/

clipboard_title = "$copy_to_clipboard_text"
clipboard_icon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>`
clipboard_successIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z"/></svg>`
clipboard_successDuration = 1000
let clipboard_title = "$copy_to_clipboard_text"
let clipboard_icon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>`
let clipboard_successIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z"/></svg>`
let clipboard_successDuration = 1000

$(document).ready(function() {
if(navigator.clipboard) {
Expand Down
74 changes: 18 additions & 56 deletions templates/html/darkmode_toggle.js
Expand Up @@ -64,27 +64,27 @@ class DarkModeToggle extends HTMLElement {
toggleButton.tabIndex = 0;

function addButton() {
var titleArea = document.getElementById("titlearea");
var searchBox = document.getElementById("MSearchBox");
var mainMenu = document.getElementById("main-menu");
var navRow1 = document.getElementById("navrow1");
var mainMenuVisible = false;
const titleArea = document.getElementById("titlearea");
const searchBox = document.getElementById("MSearchBox");
const mainMenu = document.getElementById("main-menu");
const navRow1 = document.getElementById("navrow1");
let mainMenuVisible = false;
if (mainMenu) {
var menuStyle = window.getComputedStyle(mainMenu);
const menuStyle = window.getComputedStyle(mainMenu);
mainMenuVisible = menuStyle.display!=='none'
}
var searchBoxPos1 = document.getElementById("searchBoxPos1");
const searchBoxPos1 = document.getElementById("searchBoxPos1");
if (searchBox) { // (1) search box visible
searchBox.parentNode.appendChild(toggleButton)
} else if (navRow1) { // (2) no search box, static menu bar
var li = document.createElement('li');
const li = document.createElement('li');
li.style = 'float: right;'
li.appendChild(toggleButton);
toggleButton.style = 'width: 24px; height: 25px; padding-top: 11px; float: right;';
var row = document.querySelector('#navrow1 > ul:first-of-type');
const row = document.querySelector('#navrow1 > ul:first-of-type');
row.appendChild(li)
} else if (mainMenu && mainMenuVisible) { // (3) no search box + dynamic menu bar expanded
var li = document.createElement('li');
const li = document.createElement('li');
li.style = 'float: right;'
li.appendChild(toggleButton);
toggleButton.style = 'width: 14px; height: 36px; padding-top: 10px; float: right;';
Expand All @@ -99,19 +99,11 @@ class DarkModeToggle extends HTMLElement {
}
}

$(document).ready(function(){
addButton();
})
$(window).resize(function(){
addButton();
})
var inFocus = false;
$(document).focusin(function(e) {
inFocus = true;
})
$(document).focusout(function(e) {
inFocus = false;
})
$(document).ready(() => addButton());
$(window).resize(() => addButton());
let inFocus = false;
$(document).focusin(() => inFocus = true);
$(document).focusout(() => inFocus = false);
$(document).keyup(function(e) {
if (e.keyCode==27 && !inFocus) { // escape key maps to keycode `27`
e.stopPropagation();
Expand All @@ -129,32 +121,6 @@ class DarkModeToggle extends HTMLElement {
this.onkeypress=function(e){if (e.keyCode==13) { this.toggleDarkMode(); }};
}

static createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";

document.cookie = name + "=" + value + expires + "; path=/";
}

static readCookie(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;
}

static eraseCookie(name) {
DarkModeToggle.createCookie(name, "", -1);
}

/**
* @returns `true` for dark-mode, `false` for light-mode system preference
*/
Expand Down Expand Up @@ -213,20 +179,16 @@ class DarkModeToggle extends HTMLElement {
}

static setDarkModeVisibility(enable) {
var darkModeStyle, lightModeStyle;
let darkModeStyle, lightModeStyle;
if(enable) {
darkModeStyle = 'inline-block';
lightModeStyle = 'none'
} else {
darkModeStyle = 'none';
lightModeStyle = 'inline-block'
}
document.querySelectorAll('.dark-mode-visible').forEach(function(el) {
el.style.display = darkModeStyle;
});
document.querySelectorAll('.light-mode-visible').forEach(function(el) {
el.style.display = lightModeStyle;
});
document.querySelectorAll('.dark-mode-visible' ).forEach(el => el.style.display = darkModeStyle);
document.querySelectorAll('.light-mode-visible').forEach(el => el.style.display = lightModeStyle);
}
static enableDarkMode(enable) {
if(enable) {
Expand Down
69 changes: 32 additions & 37 deletions templates/html/dynsections.js
Expand Up @@ -22,13 +22,12 @@
@licend The above is the entire license notice for the JavaScript code in this file
*/
function toggleVisibility(linkObj)
{
var base = $(linkObj).attr('id');
var summary = $('#'+base+'-summary');
var content = $('#'+base+'-content');
var trigger = $('#'+base+'-trigger');
var src=$(trigger).attr('src');
function toggleVisibility(linkObj) {
const base = $(linkObj).attr('id');
const summary = $('#'+base+'-summary');
const content = $('#'+base+'-content');
const trigger = $('#'+base+'-trigger');
const src=$(trigger).attr('src');
if (content.is(':visible')===true) {
content.hide();
summary.show();
Expand All @@ -43,20 +42,18 @@ function toggleVisibility(linkObj)
return false;
}

function updateStripes()
{
function updateStripes() {
$('table.directory tr').
removeClass('even').filter(':visible:even').addClass('even');
$('table.directory tr').
removeClass('odd').filter(':visible:odd').addClass('odd');
}

function toggleLevel(level)
{
function toggleLevel(level) {
$('table.directory tr').each(function() {
var l = this.id.split('_').length-1;
var i = $('#img'+this.id.substring(3));
var a = $('#arr'+this.id.substring(3));
const l = this.id.split('_').length-1;
const i = $('#img'+this.id.substring(3));
const a = $('#arr'+this.id.substring(3));
if (l<level+1) {
i.removeClass('iconfopen iconfclosed').addClass('iconfopen');
a.html('&#9660;');
Expand All @@ -72,33 +69,32 @@ function toggleLevel(level)
updateStripes();
}

function toggleFolder(id)
{
function toggleFolder(id) {
// the clicked row
var currentRow = $('#row_'+id);
const currentRow = $('#row_'+id);

// all rows after the clicked row
var rows = currentRow.nextAll("tr");
const rows = currentRow.nextAll("tr");

var re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub
const re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub

// only match elements AFTER this one (can't hide elements before)
var childRows = rows.filter(function() { return this.id.match(re); });
const childRows = rows.filter(function() { return this.id.match(re); });

// first row is visible we are HIDING
if (childRows.filter(':first').is(':visible')===true) {
// replace down arrow by right arrow for current row
var currentRowSpans = currentRow.find("span");
const currentRowSpans = currentRow.find("span");
currentRowSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
currentRowSpans.filter(".arrow").html('&#9658;');
rows.filter("[id^=row_"+id+"]").hide(); // hide all children
} else { // we are SHOWING
// replace right arrow by down arrow for current row
var currentRowSpans = currentRow.find("span");
const currentRowSpans = currentRow.find("span");
currentRowSpans.filter(".iconfclosed").removeClass("iconfclosed").addClass("iconfopen");
currentRowSpans.filter(".arrow").html('&#9660;');
// replace down arrows by right arrows for child rows
var childRowsSpans = childRows.find("span");
const childRowsSpans = childRows.find("span");
childRowsSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
childRowsSpans.filter(".arrow").html('&#9658;');
childRows.show(); //show all children
Expand All @@ -107,11 +103,10 @@ function toggleFolder(id)
}


function toggleInherit(id)
{
var rows = $('tr.inherit.'+id);
var img = $('tr.inherit_header.'+id+' img');
var src = $(img).attr('src');
function toggleInherit(id) {
const rows = $('tr.inherit.'+id);
const img = $('tr.inherit_header.'+id+' img');
const src = $(img).attr('src');
if (rows.filter(':first').is(':visible')===true) {
rows.css('display','none');
$(img).attr('src',src.substring(0,src.length-8)+'closed.png');
Expand All @@ -121,10 +116,10 @@ function toggleInherit(id)
}
}

var opened=true;
let opened=true;
// in case HTML_COLORSTYLE is LIGHT or DARK the vars will be replaced, so we write them out explicitly and use double quotes
var plusImg = [ "var(--fold-plus-image)", "var(--fold-plus-image-relpath)" ];
var minusImg = [ "var(--fold-minus-image)", "var(--fold-minus-image-relpath)" ];
const plusImg = [ "var(--fold-plus-image)", "var(--fold-plus-image-relpath)" ];
const minusImg = [ "var(--fold-minus-image)", "var(--fold-minus-image-relpath)" ];

// toggle all folding blocks
function codefold_toggle_all(relPath) {
Expand All @@ -146,8 +141,8 @@ function codefold_toggle(id) {
$('#foldclosed'+id).toggle();
}
function init_codefold(relPath) {
$('span[class=lineno]').css(
{'padding-right':'4px',
$('span[class=lineno]').css({
'padding-right':'4px',
'margin-right':'2px',
'display':'inline-block',
'width':'54px',
Expand All @@ -162,18 +157,18 @@ function init_codefold(relPath) {
// add toggle controls to lines with fold divs
$('div[class=foldopen]').each(function() {
// extract specific id to use
var id = $(this).attr('id').replace('foldopen','');
const id = $(this).attr('id').replace('foldopen','');
// extract start and end foldable fragment attributes
var start = $(this).attr('data-start');
var end = $(this).attr('data-end');
const start = $(this).attr('data-start');
const end = $(this).attr('data-end');
// replace normal fold span with controls for the first line of a foldable fragment
$(this).find('span[class=fold]:first').replaceWith('<span class="fold" '+
'onclick="javascript:codefold_toggle(\''+id+'\');" '+
'style="background-image:'+minusImg[relPath]+';"></span>');
// append div for folded (closed) representation
$(this).after('<div id="foldclosed'+id+'" class="foldclosed" style="display:none;"></div>');
// extract the first line from the "open" section to represent closed content
var line = $(this).children().first().clone();
const line = $(this).children().first().clone();
// remove any glow that might still be active on the original line
$(line).removeClass('glow');
if (start) {
Expand Down

0 comments on commit f4faaf1

Please sign in to comment.