-
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.
- Loading branch information
1 parent
43b83cf
commit bc87d36
Showing
8 changed files
with
89 additions
and
76 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
_prototypes/individual-response--your-household-v15/assets/modules/uac/uac.css
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,18 @@ | ||
.uac__field { | ||
display: inline-block; | ||
position: relative; | ||
} | ||
|
||
.uac__input { | ||
height: 100%; | ||
font-family: monospace; | ||
font-weight: bold; | ||
width: 14.9em !important; | ||
max-width: 14.9em; | ||
font-size: 24px; | ||
letter-spacing: 0.14em; | ||
} | ||
|
||
.uac__security { | ||
display: flex; | ||
} |
34 changes: 34 additions & 0 deletions
34
_prototypes/individual-response--your-household-v15/assets/modules/uac/uac.js
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,34 @@ | ||
export default class UAC { | ||
constructor(context) { | ||
this.input = context; | ||
const groupSize = parseInt(context.getAttribute('data-group-size'), 10); | ||
this.groupingRegex = new RegExp(`.{1,${groupSize}}`, 'g'); | ||
|
||
this.bindEventListeners(); | ||
} | ||
|
||
bindEventListeners() { | ||
this.input.addEventListener('input', this.handleInput.bind(this)); | ||
} | ||
|
||
handleInput() { | ||
const cursorPosition = this.input.selectionStart; | ||
const shouldRepositionCursor = cursorPosition !== this.input.value.length; | ||
|
||
this.input.value = (this.input.value.replace(/\s/g, '').match(this.groupingRegex) || []).join(' '); | ||
|
||
if (shouldRepositionCursor) { | ||
this.input.setSelectionRange(cursorPosition, cursorPosition); | ||
} | ||
} | ||
} | ||
|
||
function runUAC() { | ||
const uacInputs = [...document.querySelectorAll('.js-uac')]; | ||
|
||
if (uacInputs.length) { | ||
uacInputs.forEach(element => new UAC(element)); | ||
} | ||
} | ||
|
||
document.addEventListener('UAC-READY', runUAC); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.