Skip to content

Commit 4f04ef8

Browse files
committed
feat: standardizes the summary message
The number of characters that can be inserted varies depending on the total number of the header
1 parent 2a6bf41 commit 4f04ef8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

assets/script/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,34 @@ scope.querySelector('form').onreset = function() {
132132
behavior: 'smooth'
133133
});
134134

135+
};
136+
137+
138+
summary.querySelector('form').summary.onblur = function() { // Standardize the message
139+
140+
this.value = this.value.trim();
141+
142+
this.value =
143+
this.value.slice(0, 1).toLocaleLowerCase() // Don't capitalize the first letter
144+
+
145+
this.value.slice(1).split('.').filter(e => e).join('.'); // No dot (.) at the end
146+
147+
};
148+
summary.querySelector('form').summary.onfocus = function() {
149+
150+
let typeSize = type.querySelector('form').type.value.length;
151+
let scopeSize = scope.querySelector('form').scope.value.trim().length;
152+
let ornamentSize = (scopeSize ? ' ()!: ' : '!: ').length;
153+
154+
let maxLength = 50 - typeSize - scopeSize - ornamentSize;
155+
156+
this.maxLength = maxLength;
157+
158+
summary.querySelector('form > div > label > small').innerHTML = this.value.length +' / '+ this.maxLength + '<sub>50 - '+ (50 - this.maxLength) +'</sub>';
159+
160+
};
161+
summary.querySelector('form').summary.oninput = function() {
162+
163+
summary.querySelector('form > div > label > small').innerHTML = this.value.length +' / '+ this.maxLength + '<sub>50 - '+ (50 - this.maxLength) +'</sub>';
164+
135165
};

0 commit comments

Comments
 (0)