Skip to content

Commit

Permalink
Add slide gesture for user sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoNezd committed Jul 2, 2023
1 parent fa98b39 commit a82a0a1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
3 changes: 1 addition & 2 deletions js/cs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "./setPublicPath.js";
import "./general.js";
import "./header.js";
import "./subreddit_sidebar.js";
import "./user_sidebar.js";
import "./sidebars.js";
import "./posts";
console.log("Content script loaded.");
27 changes: 27 additions & 0 deletions js/sidebars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import setupSubredditSidebar from "./subreddit_sidebar.js";
import setupUserSidebar from "./user_sidebar.js";
function setupSidebars() {
const [toggleSub, subSide] = setupSubredditSidebar();
const [toggleUser, userSide] = setupUserSidebar();
document.addEventListener("swiped-right", function (e) {
// sidebar.classList.remove("active");
if (subSide.classList.contains("active")) {
toggleSub();
return;
}
if (!userSide.classList.contains("active")) {
toggleUser();
}
});
document.addEventListener("swiped-left", function (e) {
// sidebar.classList.add("active");
if (userSide.classList.contains("active")) {
toggleUser();
return;
}
if (!subSide.classList.contains("active")) {
toggleSub();
}
});
}
setupSidebars();
16 changes: 2 additions & 14 deletions js/subreddit_sidebar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "swiped-events";
import "~/css/subreddit_sidebar.css";
function setupSidebar() {
export default function setupSidebar() {
const sidebar = document.createElement("div");
const sidebarToggle = document.createElement("div");
const actualSidebar = document.querySelector(".side");
Expand All @@ -22,24 +22,12 @@ function setupSidebar() {
// sidebar.classList.toggle("active");
activeToggle();
};
document.addEventListener("swiped-right", function (e) {
// sidebar.classList.remove("active");
if (sidebar.classList.contains("active")) {
activeToggle();
}
});
document.addEventListener("swiped-left", function (e) {
// sidebar.classList.add("active");
if (!sidebar.classList.contains("active")) {
activeToggle();
}
});
actualSidebar.addEventListener("animationend", () => {
console.log("Animation ended", sidebar.classList);
if (sidebar.classList.contains("abouttodie")) {
sidebar.classList.remove("active");
}
sidebar.classList.remove("showingup", "abouttodie");
});
return [activeToggle, sidebar];
}
setupSidebar();
3 changes: 1 addition & 2 deletions js/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import "./viewport.js";
import "./general.js";
import "./header.js";
import "./subreddit_sidebar.js";
import "./user_sidebar.js";
import "./sidebars.js";
import "./posts";

console.log("oldlander user.js loaded");
4 changes: 2 additions & 2 deletions js/user_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function moveHeaderItems(actualSidebar) {
};
actualSidebar.appendChild(logoutItem);
}
function setupSidebar() {
export default function setupSidebar() {
document.body.classList.remove("with-listing-chooser");
const sidebar = document.createElement("div");
const old_sidebar = document.getElementById("user_sidebar");
Expand Down Expand Up @@ -241,5 +241,5 @@ function setupSidebar() {

setupMultireddits(actualSidebar);
setupSubreddits(actualSidebar);
return [activeToggle, sidebar];
}
setupSidebar();

0 comments on commit a82a0a1

Please sign in to comment.