Skip to content

Commit

Permalink
TASK: Clean up, fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesAlias committed Sep 26, 2024
1 parent a0667d1 commit acf2729
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 81 deletions.
24 changes: 10 additions & 14 deletions Resources/Private/Fusion/Integration/Controller/Backend/New.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,17 @@ Sandstorm.NeosTwoFactorAuthentication.BackendController.new = Sandstorm.NeosTwoF
}
</p>

<div class="neos-two-factor__secret__overflow-indicator--left">
<i>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/>
</svg>
</i>
<div class="neos-two-factor__secret__overflow-indicator--left" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/>
</svg>
</div>
<div class="neos-two-factor__secret__overflow-indicator--right">
<i>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/>
</svg>
</i>
<div class="neos-two-factor__secret__overflow-indicator--right" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/>
</svg>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,36 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Page.SetupSecondFactorPage) < pr
}
</p>

<div class="neos-two-factor__secret__overflow-indicator--left">
<i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/></svg></i>
<div class="neos-two-factor__secret__overflow-indicator--left" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/>
</svg>
</div>
<div class="neos-two-factor__secret__overflow-indicator--right">
<i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/></svg></i>
<div class="neos-two-factor__secret__overflow-indicator--right" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/>
</svg>
</div>
</div>

<div class="neos-two-factor__dialog__actions neos-actions">
<button type="button" class="neos-two-factor__secret__copy__button neos-button neos-login-btn">
<span class="neos-two-factor__secret__copy__button__icon">
<i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i>
<i>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
<path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/>
</svg>
</i>
</span>
<span class="neos-two-factor__secret__copy__button__icon neos-two-factor__hidden">
<i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg></i>
<i>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/>
</svg>
</i>
</span>
{I18n.id('form.secret.copy').package('Sandstorm.NeosTwoFactorAuthentication')}
</button>
Expand Down
31 changes: 27 additions & 4 deletions Resources/Public/Styles/Login.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}

.neos-two-factor__secret-wrapper {
/* specificity hack */
display: flex !important;
}

Expand Down Expand Up @@ -46,12 +47,19 @@
}

.neos-two-factor__secret__copy__button {
/* specificity hack */
display: flex !important;
gap: 8px;
align-items: center;
justify-content: center;
}

.neos-two-factor__secret__copy__button span,
.neos-two-factor__secret__copy__button span i {
display: flex;
align-items: center;
}

.neos-two-factor__secret__copy__button svg {
height: 16px;
width: 16px;
Expand All @@ -61,6 +69,7 @@
}

.neos-two-factor__hidden {
/* specificity hack */
display: none !important;
}

Expand All @@ -69,14 +78,28 @@
display: block;
width: 100%;
overflow: hidden;

font-size: 14px;
line-height: 1.6em;
}

.neos-two-factor__secret div,
.neos-two-factor__secret p,
.neos-two-factor__secret svg {
box-sizing: content-box;
margin: 0 !important;
padding: 0 !important;
}

.neos-two-factor__secret p {
overflow: scroll;

color: #0f0f0f;
font-family: monospace;
letter-spacing: 2px;
}

.neos-two-factor__secret span:nth-child(3n) {
margin-right: 4px;
}

.neos-two-factor__secret .neos-two-factor__secret__number {
Expand All @@ -88,7 +111,7 @@
position: absolute;
top: 0;
width: 10em;
height: 100%;
height: 1.6em;

display: flex;
align-items: center;
Expand All @@ -98,9 +121,9 @@

.neos-two-factor__secret__overflow-indicator--left svg,
.neos-two-factor__secret__overflow-indicator--right svg {
height: 18px;
height: 1.2em;

fill: #1a1a1a;
fill: #3f3f3f;
}

.neos-two-factor__secret__overflow-indicator--left {
Expand Down
134 changes: 77 additions & 57 deletions Resources/Public/index.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,83 @@
// Progressively enhance the secret form element on load
window.addEventListener('load', function () {
document.querySelectorAll('.neos-two-factor__secret-wrapper')
.forEach(function (secretFormElement) {
const secretInput = secretFormElement.querySelector('input#secret')
const secretDialog = secretFormElement.querySelector('dialog')
const showSecretButton = secretFormElement.querySelector('.neos-two-factor__secret__show__button')
const secretDialogCloseButton = secretDialog.querySelector('.neos-two-factor__secret__close__button')

showSecretButton.onclick = function () {
secretDialog.showModal()
}

secretDialogCloseButton.onclick = function () {
secretDialog.close()
}

const secretDisplay = secretDialog.querySelector('.neos-two-factor__secret')
const allChars = Array.from(secretDisplay.querySelectorAll('span'))
const firstChar = allChars[0]
const lastChar = allChars[allChars.length - 1]
const overflowIndicatorLeft = secretDialog.querySelector('.neos-two-factor__secret__overflow-indicator--left')
const overflowIndicatorRight = secretDialog.querySelector('.neos-two-factor__secret__overflow-indicator--right')

const intersectionObserverFirstChar = new IntersectionObserver(function (entries) {
if (entries[0].isIntersecting) {
overflowIndicatorLeft.classList.add('neos-two-factor__hidden')
} else {
overflowIndicatorLeft.classList.remove('neos-two-factor__hidden')
}
.forEach(progressivelyEnhanceSecretFormElement)
})

function progressivelyEnhanceSecretFormElement(secretFormElement) {
// Collect inner elements (scoped to the secretFormElement)
const secretInput = secretFormElement.querySelector('input#secret')
const secretDialog = secretFormElement.querySelector('dialog')
const showSecretButton = secretFormElement.querySelector('.neos-two-factor__secret__show__button')
const secretDialogCloseButton = secretDialog.querySelector('.neos-two-factor__secret__close__button')
const secretDisplay = secretDialog.querySelector('.neos-two-factor__secret')

// Init secret modal buttons
showSecretButton.onclick = function () {
secretDialog.showModal()
}

secretDialogCloseButton.onclick = function () {
secretDialog.close()
}

// Init overflow indicators
// Each character are wrapped in a span element (so we can have different styles for numbers and letters)
const allCharElements = Array.from(secretDisplay.querySelectorAll('span'))
const firstCharElement = allCharElements[0]
const lastCharElement = allCharElements[allCharElements.length - 1]

const overflowIndicatorLeft = secretDialog.querySelector('.neos-two-factor__secret__overflow-indicator--left')
const overflowIndicatorRight = secretDialog.querySelector('.neos-two-factor__secret__overflow-indicator--right')

const intersectionObserverOptions = {
threshold: 0.9
}

const firstCharIntersectionObserver = new IntersectionObserver(function (entries) {
// Hide or show indicator when first character is visible or not visible respectively
if (entries[0].isIntersecting) {
overflowIndicatorLeft.classList.add('neos-two-factor__hidden')
} else {
overflowIndicatorLeft.classList.remove('neos-two-factor__hidden')
}
}, intersectionObserverOptions)

const lastCharIntersectionObserver = new IntersectionObserver(function (entries) {
// Hide or show indicator when last character is visible or not visible respectively
if (entries[0].isIntersecting) {
overflowIndicatorRight.classList.add('neos-two-factor__hidden')
} else {
overflowIndicatorRight.classList.remove('neos-two-factor__hidden')
}
}, intersectionObserverOptions)

firstCharIntersectionObserver.observe(firstCharElement)
lastCharIntersectionObserver.observe(lastCharElement)

// Init copy secret button
const copySecretButton = secretFormElement.querySelector('.neos-two-factor__secret__copy__button')
copySecretButton.onclick = async function () {
try {
// Copy secret to clipboard
await navigator.clipboard.writeText(secretInput.value)
// Disable button and show success indicator
copySecretButton.setAttribute('disabled', 'disabled')
copySecretButton.querySelectorAll('span').forEach(element => {
element.classList.toggle('neos-two-factor__hidden')
})

const intersectionObserverLastChar = new IntersectionObserver(function (entries) {
if (entries[0].isIntersecting) {
overflowIndicatorRight.classList.add('neos-two-factor__hidden')
} else {
overflowIndicatorRight.classList.remove('neos-two-factor__hidden')
}
// Wait for 1 second
await new Promise(function (resolve) {
setTimeout(resolve, 1000)
})

intersectionObserverFirstChar.observe(firstChar)
intersectionObserverLastChar.observe(lastChar)

const copySecretButton = secretFormElement.querySelector('.neos-two-factor__secret__copy__button')
copySecretButton.onclick = function () {

navigator.clipboard.writeText(secretInput.value)
.then(function () {
copySecretButton.querySelectorAll('span').forEach(element => {
element.classList.toggle('neos-two-factor__hidden')
})

return new Promise(function (resolve) {
setTimeout(resolve, 1000)
})
})
.then(function () {
copySecretButton.querySelectorAll('span').forEach(element => {
element.classList.toggle('neos-two-factor__hidden')
})
})
}
})
})
} finally {
// Re-enable button and hide success indicator
copySecretButton.removeAttribute('disabled')
copySecretButton.querySelectorAll('span').forEach(element => {
element.classList.toggle('neos-two-factor__hidden')
})
}
}
}

0 comments on commit acf2729

Please sign in to comment.