This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
forked from cameroncondry/cbc-kitten-scientists
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(limited): Discrete component for
limited
- Loading branch information
1 parent
d435b17
commit 04eaf18
Showing
7 changed files
with
65 additions
and
59 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SettingLimited } from "../../options/Settings"; | ||
import { mustExist } from "../../tools/Maybe"; | ||
import { UserScript } from "../../UserScript"; | ||
|
||
export class LimitedButton { | ||
readonly host: UserScript; | ||
readonly setting: SettingLimited; | ||
readonly element: JQuery<HTMLElement>; | ||
|
||
constructor( | ||
host: UserScript, | ||
id: string, | ||
setting: SettingLimited, | ||
handler: { onLimitedCheck: () => void; onLimitedUnCheck: () => void } | ||
) { | ||
const element = $("<label/>", { | ||
for: `toggle-limited-${id}`, | ||
text: host.engine.i18n("ui.limit"), | ||
}); | ||
|
||
const input = $("<input/>", { | ||
id: `toggle-limited-${id}`, | ||
type: "checkbox", | ||
}); | ||
|
||
input.on("change", () => { | ||
if (input.is(":checked") && setting.limited === false) { | ||
setting.limited = true; | ||
host.updateOptions(); | ||
handler.onLimitedCheck(); | ||
} else if (!input.is(":checked") && setting.limited === true) { | ||
setting.limited = false; | ||
host.updateOptions(); | ||
handler.onLimitedUnCheck(); | ||
} | ||
}); | ||
|
||
setting.$limited = this; | ||
|
||
this.element = element; | ||
this.host = host; | ||
this.setting = setting; | ||
} | ||
|
||
refreshUi() { | ||
mustExist(this.element).prop("checked", this.setting.limited); | ||
} | ||
} |