Skip to content

Commit

Permalink
Fix: Prevent using localization API before initialization
Browse files Browse the repository at this point in the history
It could happen that the window.Typo3Neos.I18n.translate has been used before the initialization
flag was set. This change prevents this.

fix #26
  • Loading branch information
markusguenther committed Aug 18, 2023
1 parent 822131e commit ee96c92
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
45 changes: 29 additions & 16 deletions Resources/Private/Javascript/Main.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import { UserModule, UserMenu } from './Components'
import { isNil } from './Helper'
import {UserModule, UserMenu} from './Components'
import {isNil} from './Helper'

document.addEventListener('DOMContentLoaded', function () {
const userModuleContainer = document.querySelector(
'.neos-module-administration-users'
)
if (!isNil(userModuleContainer)) {
Array.from(userModuleContainer.querySelectorAll('.neos-table')).forEach(
(_userModule) => {
if (!isNil(_userModule)) {
new UserModule(_userModule)
const initialize = () => {
const userModuleContainer = document.querySelector(
'.neos-module-administration-users'
)
if (!isNil(userModuleContainer)) {
Array.from(userModuleContainer.querySelectorAll('.neos-table')).forEach(
(_userModule) => {
if (!isNil(_userModule)) {
new UserModule(_userModule)
}
}
}
)
}

const userMenuContainer = document.querySelector(
'#neos-top-bar .neos-user-menu'
)
if (!isNil(userMenuContainer)) {
new UserMenu(userMenuContainer)
}
}

const userMenuContainer = document.querySelector(
'#neos-top-bar .neos-user-menu'
)
if (!isNil(userMenuContainer)) {
new UserMenu(userMenuContainer)
if (window.Typo3Neos.I18n.initialized) {
initialize()
} else {
const interval = setInterval(() => {
if (window.Typo3Neos.I18n.initialized) {
clearInterval(interval)
initialize()
}
}, 50)
}
})
6 changes: 3 additions & 3 deletions Resources/Private/Javascript/Templates/ImpersonateButton.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {isNil} from "../Helper"

const impersonateIcon = '<i class="fas fa-random icon-white"></i>'
const localizedTooltip = !isNil(window.Typo3Neos) ?
window.Typo3Neos.I18n.translate('tooltip.impersonateUserButton', 'Login as this user', 'Unikka.LoginAs') :
'Login as this user';

const ImpersonateButton = (identifier, disabled) => {
const localizedTooltip = !isNil(window.Typo3Neos) ?
window.Typo3Neos.I18n.translate('tooltip.impersonateUserButton', 'Login as this user', 'Unikka.LoginAs') :
'Login as this user';
const attributesObject = {
'data-neos-toggle': 'tooltip',
'title': localizedTooltip,
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Javascript/Main.js

Large diffs are not rendered by default.

0 comments on commit ee96c92

Please sign in to comment.