summaryrefslogtreecommitdiff
path: root/source/features/limit-commit-title-length.tsx
diff options
context:
space:
mode:
authorGravatar Federico Brigante <github@bfred.it> 2020-01-07 00:19:09 +0700
committerGravatar GitHub <noreply@github.com> 2020-01-07 00:19:09 +0700
commit7f1f2c52d8deeb0fddb7a7322af7dd090ac19461 (patch)
tree6d5aba6a51777875918a609e4fdf2534870169be /source/features/limit-commit-title-length.tsx
parentdac2a0302aad5462c3a6b896fc66b18391c73d12 (diff)
downloadrefined-github-7f1f2c52d8deeb0fddb7a7322af7dd090ac19461.tar.gz
refined-github-7f1f2c52d8deeb0fddb7a7322af7dd090ac19461.tar.zst
refined-github-7f1f2c52d8deeb0fddb7a7322af7dd090ac19461.zip
Keep features working after clicking the browser’s Back button (#2639)
Diffstat (limited to 'source/features/limit-commit-title-length.tsx')
-rw-r--r--source/features/limit-commit-title-length.tsx30
1 files changed, 15 insertions, 15 deletions
diff --git a/source/features/limit-commit-title-length.tsx b/source/features/limit-commit-title-length.tsx
index 81d60111..ac94fc09 100644
--- a/source/features/limit-commit-title-length.tsx
+++ b/source/features/limit-commit-title-length.tsx
@@ -1,28 +1,28 @@
import './limit-commit-title-length.css';
import select from 'select-dom';
+import delegate, {DelegateEvent} from 'delegate-it';
import features from '../libs/features';
import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open';
-function init(): void {
- const inputField = select<HTMLInputElement>([
- '#commit-summary-input', // Commit title on edit file page
- '#merge_title_field' // PR merge message field
- ]);
+const fieldSelector = [
+ '#commit-summary-input', // Commit title on edit file page
+ '#merge_title_field' // PR merge message field
+].join();
- // The input field doesn't exist on PR merge page if you don't have access to that repo
- if (!inputField) {
- return;
- }
+function validateInput({delegateTarget: inputField}: DelegateEvent<InputEvent, HTMLInputElement>): void {
+ inputField.setCustomValidity(inputField.value.length > 72 ? `The title should be maximum 72 characters, but is ${inputField.value.length}` : '');
+}
- inputField.addEventListener('input', () => {
- inputField.setCustomValidity(inputField.value.length > 72 ? `The title should be maximum 72 characters, but is ${inputField.value.length}` : '');
- });
+function triggerValidation(): void {
+ select(fieldSelector)!.dispatchEvent(new Event('input'));
+}
+
+function init(): void {
+ delegate(fieldSelector, 'input', validateInput);
// For PR merges, GitHub restores any saved commit messages on page load
// Triggering input event for these fields immediately validates the form
- onPrMergePanelOpen(() => {
- inputField.dispatchEvent(new Event('input'));
- });
+ onPrMergePanelOpen(triggerValidation);
}
features.add({