Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Remember user preference for the visibility of the "about" panel (#276)
Browse files Browse the repository at this point in the history
* sidebar.toggle() now takes a boolean to tell if ths action was user-generated or not, to store this preference in the sessionStorage of the user's browser

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>

* Added the hooks to toggle sidebar if not visible when showing the button_info, according to the last user's choice

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>

* Fixed trailing spaces

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>

* Fixed the bad formatting

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>

* Changed sessionStorage name from sidebarUserPreferenceVisible to keepSidebarVisible

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>

* Renamed sidebar.userPreferenceVisibility() to sidebar.keepSidebarVisible()

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>

* Make it compile

Co-authored-by: kamil4 <kamil.01482@iskra.name>
  • Loading branch information
LouisVallat and kamil4 authored Nov 22, 2021
1 parent 63828eb commit a071305
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
10 changes: 8 additions & 2 deletions scripts/main/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ header.bind = function () {
multiselect.bind();
lychee.load();
});
header.dom("#button_info_album").on(eventName, sidebar.toggle);
header.dom("#button_info").on(eventName, sidebar.toggle);
header.dom("#button_info_album").on(eventName, function () {
sidebar.toggle(true);
});
header.dom("#button_info").on(eventName, function () {
sidebar.toggle(true);
});
header.dom(".button--map-albums").on(eventName, function () {
lychee.gotoMap();
});
Expand Down Expand Up @@ -350,6 +354,7 @@ header.setMode = function (mode) {
);
} else if (album.isTagAlbum()) {
$("#button_info_album").show();
if (sidebar.keepSidebarVisible() && !visible.sidebar()) sidebar.toggle(false);
$("#button_move_album").hide();
$(".button_add, .header__divider", ".header__toolbar--album").hide();
tabindex.makeFocusable($("#button_info_album"));
Expand All @@ -371,6 +376,7 @@ header.setMode = function (mode) {
}
} else {
$("#button_info_album").show();
if (sidebar.keepSidebarVisible() && !visible.sidebar()) sidebar.toggle(false);
tabindex.makeFocusable($("#button_info_album"));
if (album.isUploadable()) {
$(
Expand Down
2 changes: 1 addition & 1 deletion scripts/main/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ $(document).ready(function () {
})
.bind(["i", "ContextMenu"], function () {
if (!visible.multiselect()) {
sidebar.toggle();
sidebar.toggle(true);
return false;
}
})
Expand Down
8 changes: 4 additions & 4 deletions scripts/main/lychee.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ lychee.load = function (autoplay = true) {

// Show Album -> it's below the map
if (visible.photo()) view.photo.hide();
if (visible.sidebar()) sidebar.toggle();
if (visible.sidebar()) sidebar.toggle(false);
if (album.json && albumID === album.json.id) {
view.album.title();
}
Expand Down Expand Up @@ -503,7 +503,7 @@ lychee.load = function (autoplay = true) {

// Show Album -> it's below the map
if (visible.photo()) view.photo.hide();
if (visible.sidebar()) sidebar.toggle();
if (visible.sidebar()) sidebar.toggle(false);
mapview.open();
lychee.footer_hide();
} else if (albumID == "search") {
Expand All @@ -519,7 +519,7 @@ lychee.load = function (autoplay = true) {
tabindex.makeUnfocusable(lychee.imageview);
}
if (visible.mapview()) mapview.close();
if (visible.sidebar() && album.isSmartID(albumID)) sidebar.toggle();
if (visible.sidebar() && album.isSmartID(albumID)) sidebar.toggle(false);
$("#sensitive_warning").hide();
if (album.json && albumID === album.json.id) {
view.album.title();
Expand All @@ -543,7 +543,7 @@ lychee.load = function (autoplay = true) {
photo.json = null;

// Hide sidebar
if (visible.sidebar()) sidebar.toggle();
if (visible.sidebar()) sidebar.toggle(false);

// Show Albums
if (visible.photo()) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/main/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ search.find = function (term) {

setTimeout(() => {
if (visible.photo()) view.photo.hide();
if (visible.sidebar()) sidebar.toggle();
if (visible.sidebar()) sidebar.toggle(false);
if (visible.mapview()) mapview.close();

header.setMode("albums");
Expand Down
9 changes: 8 additions & 1 deletion scripts/main/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ sidebar.triggerSearch = function (search_string) {
lychee.goto("search/" + encodeURIComponent(search_string));
};

sidebar.toggle = function () {
sidebar.keepSidebarVisible = function () {
let v = sessionStorage.getItem("keepSidebarVisible");
return v !== null ? v === "true" : false;
};

sidebar.toggle = function (is_user_initiated) {
if (visible.sidebar() || visible.sidebarbutton()) {
header.dom(".button--info").toggleClass("active");
lychee.content.toggleClass("content--sidebar");
Expand All @@ -116,6 +121,8 @@ sidebar.toggle = function () {
sidebar.dom().toggleClass("active");
photo.updateSizeLivePhotoDuringAnimation();

if (is_user_initiated) sessionStorage.setItem("keepSidebarVisible", visible.sidebar());

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/view/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ $(document).ready(function () {
});

// Infobox
header.dom("#button_info").on("click", sidebar.toggle);
header.dom("#button_info").on("click", function () {
sidebar.toggle(true);
});

// Load photo
loadPhotoInfo(photoID);
Expand Down

0 comments on commit a071305

Please sign in to comment.