Skip to content

Commit

Permalink
add themes and icon for home button
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanroj23 committed Jan 11, 2025
1 parent 2129ebd commit ba6f79b
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 22 deletions.
Binary file added favicon.ico
Binary file not shown.
Binary file added icons/tg192transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "Topical Guide",
"short_name": "TopicalGuide",
"name": "Topics",
"short_name": "Topics",
"description": "A way to study the topical guide",
"start_url": "/topics/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#007aff",
"background_color": "#1A1A2E",
"theme_color": "#1A1A2E",
"icons": [
{
"src": "icons/tg192.png",
Expand Down
4 changes: 2 additions & 2 deletions topics/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#007aff">
<meta name="theme-color" content="#1A1A2E">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Topics">

Expand All @@ -21,7 +21,7 @@
<body onload="pageLoaded()">
<div class="inner-body">
<div class="inner-body-header" id="inner_body_header">
<a id="inner_body_header_link"></a>
<a id="inner_body_header_link">Topics</a>
</div>
<div class="scrollable-verses-parent" id="scrollable_verses_parent">
<div class="toc-parent" id="toc_parent">
Expand Down
10 changes: 6 additions & 4 deletions topics/topics.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ color: #B0BEC5;
"wdth" 100;
}

.home-logo{
height:100%;
}

.dark-mode-midnight{
background: #1A1A2E;
color: #F1F1F1;
Expand Down Expand Up @@ -67,13 +71,11 @@ color: #E4E4E4;
height:7vh;
}

.home-button, .home-button-spacer {
padding-left:3%;
padding-right:3%
}

.home-button-spacer{
color:#ffffff00;
height:100%;
aspect-ratio:1;
}

#inner_body_header_link {
Expand Down
94 changes: 82 additions & 12 deletions topics/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@
let allVerseDivs;
let globalLastRead = {};

let themes = [
"dark-mode-midnight",
"dark-mode-classic",
"dark-mode-charcoal",
"dark-mode-deep-space",
"dark-mode-slate",
"dark-mode-elegant",
]

// Localstorage stuff

function setLocalStorageString(name, value){
localStorage.setItem(name, value);
}

function getLocalStorageString(name){
return localStorage.getItem(name);
}

function setLocalStorageDict(name, dict){
localStorage.setItem(name, JSON.stringify(dict));
}
Expand Down Expand Up @@ -150,7 +167,7 @@ function addVerseForTopic(verseToGet, counter){
const scrollableVersesParent = document.getElementById('scrollable_verses_parent');

// create divs
const parentDiv = createDiv('scrollable-verse', 'div', '', `verse_${counter}`);
const scrollableVerseDiv = createDiv('scrollable-verse', 'div', '', `verse_${counter}`);
const verseLink = createDiv('verse-link', 'a');
const verseTitle = createDiv('verse-title', 'div', `${verseToGet.replace("_", " ")}`);
verseTitle.classList.add('roboto-medium');
Expand All @@ -175,9 +192,9 @@ function addVerseForTopic(verseToGet, counter){

// create hierarchy of divs
verseLink.appendChild(verseTitle)
parentDiv.appendChild(verseLink);
parentDiv.appendChild(verseContent);
scrollableVersesParent.appendChild(parentDiv);
scrollableVerseDiv.appendChild(verseLink);
scrollableVerseDiv.appendChild(verseContent);
scrollableVersesParent.appendChild(scrollableVerseDiv);
}

let topicIdx;
Expand Down Expand Up @@ -226,15 +243,17 @@ function addDivSeeAlso(seeAlso){
const toSplit = seeAlso.replace("See also ", "");
const seeAlsoList = toSplit.split("; ")

const seeAlsoDiv = createDiv('see-also', 'div', "See also ")
const seeAlsoDiv = createDiv('scrollable-verse', 'div')
const seeAlsoContentDiv = createDiv('verse-content', 'div', "See also ")

for (const s of seeAlsoList){
const a = createDiv('see-also-inner', 'a', s+'; ');
a.href = `/topics/?topic=${topics_dict[s]}`;
seeAlsoDiv.appendChild(a);
seeAlsoContentDiv.appendChild(a);
}

const scrollableVersesParent = document.getElementById('scrollable_verses_parent');
seeAlsoDiv.appendChild(seeAlsoContentDiv);
scrollableVersesParent.appendChild(seeAlsoDiv);
}

Expand Down Expand Up @@ -273,6 +292,51 @@ function addDivForSearch(){
scrollableVersesParent.prepend(search);
}

function themePickerOnclick(){
this.className = "theme-picker";
let nextTheme = themes[0];
let useNext = false;
for (const theme of themes){
if (useNext){
nextTheme = theme;
break;
}
if (theme == currentTheme){
useNext = true;
}
}

currentTheme = nextTheme;
setLocalStorageString('theme', currentTheme);
this.classList.add(currentTheme)
document.body.className = currentTheme;
}

let currentTheme;

function initTheme(){
const savedTheme = getLocalStorageString('theme');
if (savedTheme){
currentTheme = savedTheme;
}
else{
currentTheme = themes[0];
}
return currentTheme;
}

function addDivForThemePicker(){
const themePicker = createDiv('theme-picker', 'div', 'Change Theme');
const currentTheme = initTheme();
themePicker.classList.add(currentTheme);
document.body.classList.add(currentTheme);
themePicker.onclick = themePickerOnclick;


const scrollableVersesParent = document.getElementById('toc_parent');
scrollableVersesParent.prepend(themePicker);
}

function addDivForTopic(topic){
const tocTopic = createDiv('toc-topic', 'div');
const tocTopicA = createDiv('toc-topic-a', 'a', topic[1]);
Expand All @@ -294,7 +358,10 @@ function afterLoadingVerses(){
else{
if (topicIdx in globalLastRead){
const last_read = globalLastRead[topicIdx];
document.getElementById(last_read).scrollIntoView();
const last_read_div = document.getElementById(last_read);
if (last_read_div){
last_read_div.scrollIntoView();
}
}
}

Expand All @@ -303,6 +370,7 @@ function afterLoadingVerses(){

function setupTopicListPage(){
addDivForSearch();
addDivForThemePicker();
for (const topic of topics_list){
addDivForTopic(topic);
}
Expand All @@ -322,9 +390,12 @@ function getTopicDisplayName(topic){
function addHomeButton(){
const homeButton = createDiv('home-button', 'a')
const homeButtonSpacer = createDiv('home-button-spacer', 'div')
homeButton.textContent = String.fromCharCode(8801);
homeButton.href = "/topics/"
homeButtonSpacer.textContent = String.fromCharCode(8801);
const homeLogo = createDiv('home-logo', 'img');
homeLogo.src = "/icons/tg192transparent.png";
homeButtonSpacer.src = "/icons/tg192transparent.png";
homeButton.appendChild(homeLogo);

const parent = document.getElementById('inner_body_header');
const child = document.getElementById('inner_body_header_link');
parent.insertBefore(homeButton, child);
Expand All @@ -334,10 +405,9 @@ function addHomeButton(){
//onload
function pageLoaded() {
const params = new URLSearchParams(window.location.search);
if (params.has('colormode')){
document.body.classList.add(`dark-mode-${params.get('colormode')}`);
}
if (params.has('topic')){
document.body.className = initTheme();

const topic = params.get('topic')
const header_link = document.getElementById("inner_body_header_link")
header_link.classList.add('roboto-medium');
Expand Down

0 comments on commit ba6f79b

Please sign in to comment.