-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to prevent sleep on Chrome (#68)
* Create Options js class to simplify setting cookies-based options * Add option to prevent sleep on Chrome
- Loading branch information
Showing
3 changed files
with
117 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Cookies from "./js.cookie.js"; | ||
|
||
export class BooleanOption { | ||
constructor(checkbox, callable, defaultValue) { | ||
this.checkbox = checkbox; | ||
this.callable = callable; | ||
this.defaultValue = defaultValue || false; | ||
} | ||
|
||
get() { | ||
return this.checkbox.is(':checked') | ||
} | ||
|
||
set(value) { | ||
this.checkbox.attr('checked', value); | ||
this.checkbox.prop('checked', value); | ||
} | ||
|
||
call(value) { | ||
this.callable(value) | ||
} | ||
|
||
selector() { | ||
return this.checkbox | ||
} | ||
|
||
default() { | ||
return this.defaultValue | ||
} | ||
} | ||
|
||
export class Options { | ||
constructor(options) { | ||
this.options = options | ||
for (let [name, option] of options) { | ||
option.selector().change(function () { | ||
const value = option.get(); | ||
Cookies.set(name, value, {SameSite: "Strict"}) | ||
option.call(value) | ||
}) | ||
let value = Cookies.get(name) | ||
if (value === undefined) { | ||
value = option.default() | ||
Cookies.set(name, value, {SameSite: "Strict"}) | ||
} | ||
option.set(value) | ||
option.call(value) | ||
} | ||
} | ||
|
||
get(name) { | ||
return this.options.get(name).get() | ||
} | ||
set(name, value) { | ||
this.options.get(name).set(value) | ||
} | ||
|
||
call(name, value) { | ||
this.options.get(name).call(value) | ||
} | ||
|
||
selector(name) { | ||
return this.options.get(name).selector() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters