Skip to content

Commit 618b4e0

Browse files
authored
Merge pull request #342 from Pyrojet99/325/feature/filters-checkbox
325/feature/filters checkbox
2 parents d462c7f + 9dd4255 commit 618b4e0

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

src/css/_BRmain.scss

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,6 @@ body.BRfullscreenActive {
178178
font-weight: bold;
179179
}
180180

181-
/* High contrast mode */
182-
.high-contrast {
183-
.BRpagediv1up { background-color: white; }
184-
.BRpagedivthumb { background-color: white; }
185-
.BRpageview img,
186-
.BRtwopageview img {
187-
-webkit-filter: grayscale(100%) brightness(120%);
188-
filter: grayscale(100%) brightness(120%);
189-
}
190-
}
191-
192181
.BRaction {
193182
margin-left: 5px;
194183
margin-right: 5px;
@@ -270,3 +259,9 @@ body.BRfullscreenActive {
270259
.BRaction { padding: 8px 16px; }
271260
}
272261
}
262+
263+
/* filters */
264+
.filter-applied {
265+
.BRpagediv1up { background-color: white; }
266+
.BRpagedivthumb { background-color: white; }
267+
}

src/css/_MobileNav.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ html.mm-background .BookReader {
133133

134134
}
135135

136+
.BRcheckbox-label-filters {
137+
position: relative;
138+
bottom: 2px;
139+
}
140+
136141
/* Desktop Only */
137142
@media (min-width: ($brBreakPointMobile + 1)) {
138143
.BRtoolbar.responsive { display: block; }

src/js/plugins/plugin.mobile_nav.js

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@
1111

1212
import * as utils from '../BookReader/utils.js';
1313

14+
//contains all filters and labels for checkboxs
15+
const FILTERLIST = [
16+
{
17+
filter: "grayscale(100%)",
18+
label: "Grayscale"
19+
},
20+
{
21+
filter: "brightness(120%)",
22+
label: "High brightness"
23+
},
24+
{
25+
filter: "invert(100%)",
26+
label: "Inverted (dark mode)"
27+
},
28+
{
29+
filter: "contrast(120%)",
30+
label: "High contrast"
31+
},
32+
]
33+
1434
jQuery.extend(BookReader.defaultOptions, {
1535
enableMobileNav: true,
1636
mobileNavTitle: 'Internet Archive',
@@ -70,9 +90,8 @@ BookReader.prototype.initToolbar = (function (super_) {
7090
}
7191
});
7292

73-
// High contrast button
74-
$drawerEl.find('.high-contrast-button').click(
75-
() => this.refs.$br.toggleClass('high-contrast'));
93+
//apply filters when checkboxs clicked
94+
$drawerEl.find('.BRcheckbox-filters').click(() => applyFilters($drawerEl, this));
7695

7796
// Bind mobile switch buttons
7897
$drawerEl.find('.DrawerLayoutButton.one_page_mode').click(
@@ -148,13 +167,24 @@ BookReader.prototype.buildToolbarElement = (function (super_) {
148167
*/
149168
BookReader.prototype.buildMobileDrawerElement = function() {
150169
let experimentalHtml = '';
170+
//builds filters checkbox html
151171
if (this.enableExperimentalControls) {
152172
experimentalHtml = `
153-
<p class="DrawerSettingsTitle">Experimental (may not work)</p>
154-
<button class="BRaction default high-contrast-button">Toggle high contrast</button>
155-
`;
173+
<p class="DrawerSettingsTitle">Visual Adjustment</p>
174+
<div class="BRcheckbox-group-filters">
175+
`;
176+
FILTERLIST.forEach( (el, i) => {
177+
const checkboxHtml = `
178+
<input type="checkbox" class="BRcheckbox-filters" id="filter${i}">
179+
<label for="filter${i}" class="BRcheckbox-label-filters">${el.label}</label><br>
180+
181+
`;
182+
experimentalHtml = experimentalHtml.concat(checkboxHtml);
183+
})
184+
experimentalHtml = experimentalHtml.concat("</div>");
156185
}
157186

187+
158188
const settingsSection = `
159189
<span>
160190
<span class="DrawerIconWrapper">
@@ -232,4 +262,28 @@ BookReader.prototype.$ = (function (super_) {
232262
}
233263
return $results;
234264
};
235-
})(BookReader.prototype.$);
265+
})(BookReader.prototype.$);
266+
267+
/**
268+
* Dynamically creates styles combining different filters for BookReaders imgs
269+
* based on filters checkbox
270+
*/
271+
const applyFilters = (drawerEl, br) => {
272+
let filterStr = "";
273+
274+
$('.BRcheckbox-filters').each(
275+
(i, el) => {
276+
br.refs.$br.removeClass("filter-applied");
277+
if($(el).is(':checked')){
278+
br.refs.$br.addClass($(el).attr("filter-applied"));
279+
filterStr = filterStr + FILTERLIST[i].filter;
280+
}
281+
}
282+
);
283+
const filtersSheet = $("#filtersStyle")[0] || document.createElement('style');
284+
filtersSheet.id = "filtersStyle";
285+
filtersSheet.innerHTML = `.BRpagecontainer img {
286+
filter: ${filterStr};
287+
-webkit-filter: ${filterStr};}`;
288+
document.body.appendChild(filtersSheet);
289+
}

0 commit comments

Comments
 (0)