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.
refactor(max): Discrete max component
- Loading branch information
1 parent
3ca7f9a
commit 86fc660
Showing
11 changed files
with
68 additions
and
65 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
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,52 @@ | ||
import { SettingMax } from "../../options/Settings"; | ||
import { UserScript } from "../../UserScript"; | ||
import { SettingsSectionUi } from "../SettingsSectionUi"; | ||
|
||
export class MaxButton { | ||
readonly host: UserScript; | ||
readonly setting: SettingMax; | ||
readonly element: JQuery<HTMLElement>; | ||
|
||
constructor( | ||
host: UserScript, | ||
id: string, | ||
label: string, | ||
setting: SettingMax, | ||
handler: { onClick?: () => void } = {} | ||
) { | ||
const element = $("<div/>", { | ||
id: `set-${id}-max`, | ||
}).addClass("ks-max-button"); | ||
|
||
element.on("click", () => { | ||
const value = SettingsSectionUi.promptLimit( | ||
host.engine.i18n("ui.max.set", [label]), | ||
setting.max.toString() | ||
); | ||
|
||
if (value !== null) { | ||
const limit = SettingsSectionUi.renderLimit(value, host); | ||
host.updateOptions(() => (setting.max = value)); | ||
element[0].title = limit; | ||
element[0].innerText = host.engine.i18n("ui.max", [limit]); | ||
} | ||
|
||
if (handler.onClick) { | ||
handler.onClick(); | ||
} | ||
}); | ||
|
||
setting.$max = this; | ||
|
||
this.element = element; | ||
this.host = host; | ||
this.setting = setting; | ||
} | ||
|
||
refreshUi() { | ||
this.element[0].title = this.setting.max.toFixed(); | ||
this.element.text( | ||
this.host.engine.i18n("ui.max", [SettingsSectionUi.renderLimit(this.setting.max, this.host)]) | ||
); | ||
} | ||
} |