Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to enable or disable animations #162

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions interface/devtools/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ body {
font-size: 1em;
overflow: hidden;
}
.notransition *, .notransition *::before {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
transition: none !important;
}
#cookie-container {
overflow-y: auto;
flex: 1 1 auto;
Expand Down
10 changes: 10 additions & 0 deletions interface/lib/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,24 @@ export class Animate {
* @param {Element} newPage Page that will be inserted in the container.
* @param {string} direction Which direction to slide the old page towards.
* @param {function} callback Called after the animation is done.
* @param {boolean} animationsEnabled If the animations are enabled or not.
*/
static transitionPage(
container,
oldPage,
newPage,
direction = 'left',
callback = null,
animationsEnabled = true,
) {
if (!animationsEnabled) {
if (oldPage) {
oldPage.remove();
}
container.appendChild(newPage);
callback();
return;
}
const animationTime = '0.3s';

container.addEventListener(
Expand Down
1 change: 1 addition & 0 deletions interface/lib/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Options {
constructor() {
this.advancedCookies = false;
this.devtoolsEnabled = true;
this.animationsEnabled = true;
this.exportFormat = ExportFormats.Ask;
this.extraInfo = ExtraInfos.Nothing;
this.theme = Themes.Auto;
Expand Down
23 changes: 22 additions & 1 deletion interface/lib/optionsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ export class OptionsHandler extends EventEmitter {
this.saveOptions();
}

/**
* Gets whether the animations are enabled or not.
* @return {boolean} True if the animations are enabled, otherwise false.
*/
getAnimationsEnabled() {
// Uses `!==` false in order to be opt-in by default, since it was added at
// a later time.
return this.options.animationsEnabled !== false;
}
/**
* Sets whether the animations are enabled or not.
* @param {boolean} animationsEnabled True if the animations are enabled,
* otherwise false.
*/
setAnimationsEnabled(animationsEnabled) {
this.options.animationsEnabled = animationsEnabled;
this.saveOptions();
}

/**
* Gets the export format used by the export button.
* @return {ExportFormats} One of the supported export format.
Expand Down Expand Up @@ -207,7 +226,9 @@ export class OptionsHandler extends EventEmitter {
* @return {boolean} True if ads are enabled, otherwise false.
*/
getAdsEnabled() {
return this.options.adsEnabled;
// Uses `!==` false in order to be opt-in by default, since it was added at
// a later time.
return this.options.adsEnabled !== false;
}
/**
* Sets whether the ads are enabled or not.
Expand Down
12 changes: 12 additions & 0 deletions interface/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
</div>
</div>

<div class="input-container">
<label for="animations-enabled">Enable Animations</label>
<label class="switch">
<input type="checkbox" id="animations-enabled" aria-describedby="animations-enabled-hint" />
<span class="slider"></span>
</label>
<div class="hint" id="animations-enabled-hint">
When Enabled, Cookie-Editor will show transitions and other various
animations in the interface. This is for appearance only.
</div>
</div>

<div class="input-container">
<label for="export-format">Export Format</label>
<select id="export-format" aria-describedby="export-format-hint">
Expand Down
21 changes: 21 additions & 0 deletions interface/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ document.addEventListener('DOMContentLoaded', async (event) => {
const permissionHandler = new PermissionHandler(browserDetector);
const advancedCookieInput = document.getElementById('advanced-cookie');
const showDevtoolsInput = document.getElementById('devtool-show');
const animationsEnabledInput = document.getElementById('animations-enabled');
const exportFormatInput = document.getElementById('export-format');
const extraInfoInput = document.getElementById('extra-info');
const themeInput = document.getElementById('theme');
Expand All @@ -33,8 +34,10 @@ document.addEventListener('DOMContentLoaded', async (event) => {
*/
function setFormValues() {
console.log('Setting up the form');
handleAnimationsEnabled();
advancedCookieInput.checked = optionHandler.getCookieAdvanced();
showDevtoolsInput.checked = optionHandler.getDevtoolsEnabled();
animationsEnabledInput.checked = optionHandler.getAnimationsEnabled();
exportFormatInput.value = optionHandler.getExportFormat();
extraInfoInput.value = optionHandler.getExtraInfo();
themeInput.value = optionHandler.getTheme();
Expand Down Expand Up @@ -63,6 +66,13 @@ document.addEventListener('DOMContentLoaded', async (event) => {
}
optionHandler.setDevtoolsEnabled(showDevtoolsInput.checked);
});
animationsEnabledInput.addEventListener('change', (event) => {
if (!event.isTrusted) {
return;
}
optionHandler.setAnimationsEnabled(animationsEnabledInput.checked);
handleAnimationsEnabled();
});
exportFormatInput.addEventListener('change', (event) => {
if (!event.isTrusted) {
return;
Expand Down Expand Up @@ -191,4 +201,15 @@ document.addEventListener('DOMContentLoaded', async (event) => {
document.execCommand('Copy');
document.body.removeChild(fakeText);
}

/**
* Enables or disables the animations based on the options.
*/
function handleAnimationsEnabled() {
if (optionHandler.getAnimationsEnabled()) {
document.body.classList.remove('notransition');
} else {
document.body.classList.add('notransition');
}
}
});
6 changes: 6 additions & 0 deletions interface/options/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ body * {
box-sizing: border-box;
text-align: start;
}
.notransition *, .notransition *::before {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
transition: none !important;
}

svg.icon {
height: 1em;
Expand Down
7 changes: 7 additions & 0 deletions interface/popup-mobile/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ body * {
text-align: start;
}

.notransition *, .notransition *::before {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
transition: none !important;
}

button::-moz-focus-inner {
border: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion interface/popup/cookie-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>Cookie-Editor</title>
</head>

<body>
<body class="notransition">
<div id="pageTitle">
<h1 class="container">
Cookie-Editor
Expand Down
19 changes: 19 additions & 0 deletions interface/popup/cookie-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
() => {
disableButtons = false;
},
optionHandler.getAnimationsEnabled(),
);
console.log('after transition');

Expand Down Expand Up @@ -355,6 +356,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
() => {
disableButtons = false;
},
optionHandler.getAnimationsEnabled(),
);

document.getElementById('button-bar-default').classList.remove('active');
Expand Down Expand Up @@ -621,6 +623,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
() => {
disableButtons = false;
},
optionHandler.getAnimationsEnabled(),
);
} else {
containerCookie.appendChild(cookiesListHtml);
Expand Down Expand Up @@ -653,6 +656,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
() => {
disableButtons = false;
},
optionHandler.getAnimationsEnabled(),
);
} else {
containerCookie.appendChild(html);
Expand Down Expand Up @@ -700,6 +704,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
() => {
disableButtons = false;
},
optionHandler.getAnimationsEnabled(),
);
} else {
containerCookie.appendChild(html);
Expand Down Expand Up @@ -763,6 +768,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
() => {
disableButtons = false;
},
optionHandler.getAnimationsEnabled(),
);
} else {
containerCookie.appendChild(html);
Expand All @@ -777,6 +783,17 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
document.getElementById('version').textContent = 'v' + version;
}

/**
* Enables or disables the animations based on the options.
*/
function handleAnimationsEnabled() {
if (optionHandler.getAnimationsEnabled()) {
document.body.classList.remove('notransition');
} else {
document.body.classList.add('notransition');
}
}

/**
* Creates the HTML representation of a cookie.
* @param {string} name Name of the cookie.
Expand Down Expand Up @@ -1048,6 +1065,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
await optionHandler.loadOptions();
themeHandler.updateTheme();
handleAd();
handleAnimationsEnabled();
optionHandler.on('optionsChanged', onOptionsChanged);
cookieHandler.on('cookiesChanged', onCookiesChanged);
cookieHandler.on('ready', showCookiesForTab);
Expand Down Expand Up @@ -1312,6 +1330,7 @@ import { CookieHandlerPopup } from './cookieHandlerPopup.js';
* @param {Option} oldOptions the options before changes.
*/
function onOptionsChanged(oldOptions) {
handleAnimationsEnabled();
if (oldOptions.advancedCookies != optionHandler.getCookieAdvanced()) {
document.querySelector('#advanced-toggle-all').checked =
optionHandler.getCookieAdvanced();
Expand Down
7 changes: 7 additions & 0 deletions interface/popup/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ body * {
text-align: start;
}

.notransition *, .notransition *::before {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
transition: none !important;
}

button::-moz-focus-inner {
border: 0;
}
Expand Down
6 changes: 6 additions & 0 deletions interface/sidepanel/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ body {
font-size: 1em;
overflow: hidden;
}
.notransition *, .notransition *::before {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
transition: none !important;
}
#cookie-container {
overflow-y: auto;
flex: 1 1 auto;
Expand Down
Loading