Skip to content

Commit

Permalink
Support for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
kuogi committed Sep 27, 2023
1 parent b13f334 commit fe50522
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/app/main.content.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,8 @@ class Content {
}
}
}

updateMobileSectionsVisibilityState(forcedState) {
return this.#currentSectionsElement.classList.toggle('show', forcedState);
}
}
46 changes: 40 additions & 6 deletions src/app/main.header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class Header {
#onChangeListeners = [];
#onSidebarUpdateListener = [];
#onCompassUpdateListener = [];

#headerMenu;
#headerCompass;
#headerDescription;
#headerProjectName;
#fakeHeaderTitle;
Expand All @@ -9,14 +13,16 @@ class Header {
const headerMenu = document.createElement('div');
headerMenu.classList.add('menu');
headerMenu.addEventListener('click', () => {
/*const state = leftContainer.classList.toggle('show');
headerMenu.classList.toggle('show', state);
this.#pageSections.classList.remove('show');
headerCompass.classList.remove('show');*/
for(const listener of this.#onSidebarUpdateListener) {
try {
listener();
} catch(e) {}
}
});
headerMenu.appendChild(document.createElement('div'));
headerMenu.appendChild(document.createElement('div'));
headerMenu.appendChild(document.createElement('div'));
this.#headerMenu = headerMenu;

const headerIcon = document.createElement('img');
headerIcon.src = '/src/assets/splash/telegram-logo.svg';
Expand All @@ -35,10 +41,14 @@ class Header {
const headerCompass = document.createElement('img');
headerCompass.classList.add('header-compass');
headerCompass.addEventListener('click', () => {
//const state = this.#pageSections.classList.toggle('show');
//headerCompass.classList.toggle('show', state);
for(const listener of this.#onCompassUpdateListener) {
try {
listener();
} catch(e) {}
}
});
headerCompass.src = '/src/icons/compass.svg';
this.#headerCompass = headerCompass;

const headerDescription = document.createElement('div');
headerDescription.classList.add('description');
Expand Down Expand Up @@ -112,6 +122,30 @@ class Header {
}
}

updateSidebarMobileVisibilityState(state) {
this.#headerMenu.classList.toggle('show', state);
}

addOnSidebarUpdateListener(callback) {
if (typeof callback === 'function') {
this.#onSidebarUpdateListener.push(callback);
}
}

updateCompassVisibilityState(state) {
this.#headerCompass.classList.toggle('visible', state);
}

updateCompassExpandedState(state) {
this.#headerCompass.classList.toggle('show', state);
}

addOnCompassUpdateListener(callback) {
if (typeof callback === 'function') {
this.#onCompassUpdateListener.push(callback);
}
}

#appendTitleUpdateOnActiveTabUpdate() {
this.#onChangeListeners.push((id) => {
document.title = id + ' Documentation';
Expand Down
20 changes: 20 additions & 0 deletions src/app/main.home.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,30 @@ class HomePage {

this.#headerInstance.addOnActiveTabUpdate((id) => {
this.#sidebarInstance.loadSidebar(id);
this.#headerInstance.updateCompassVisibilityState(false);
this.#headerInstance.updateCompassExpandedState(false);
this.#contentInstance.clearBoard();
});

this.#headerInstance.addOnSidebarUpdateListener(() => {
const state = this.#sidebarInstance.updateMobileVisibilityState();
this.#headerInstance.updateSidebarMobileVisibilityState(state);
this.#headerInstance.updateCompassExpandedState(false);
this.#contentInstance.updateMobileSectionsVisibilityState(false);
});

this.#headerInstance.addOnCompassUpdateListener(() => {
const state = this.#contentInstance.updateMobileSectionsVisibilityState();
this.#headerInstance.updateCompassExpandedState(state);
this.#sidebarInstance.updateMobileVisibilityState(false);
this.#headerInstance.updateSidebarMobileVisibilityState(false);
});

this.#sidebarInstance.addOnSelectedFileUpdate((file) => {
this.#headerInstance.updateSidebarMobileVisibilityState(false);
this.#headerInstance.updateCompassVisibilityState(true);
this.#headerInstance.updateCompassExpandedState(false);
this.#sidebarInstance.updateMobileVisibilityState(false);
this.#contentInstance.loadFile(file);
});
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/main.sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class Sidebar {

return leftContainer;
}

updateMobileVisibilityState(forcedState) {
const state = this.#leftContainer.classList.toggle('show', forcedState);
this.#leftSidebar.classList.add('expanded');
this.#searchBar.classList.remove('expanded');
return state;
}

#createSearchBar() {
const searchIcon = document.createElement('img');
Expand Down

0 comments on commit fe50522

Please sign in to comment.