*/
setInnerHtml(element, innerHtml) {
element.innerHTML = innerHtml;
- let newScript;
- let script;
const scripts = element.querySelectorAll('script');
for (let i = 0, length = scripts.length; i < length; i++) {
- script = scripts[i];
- newScript = document.createElement('script');
+ const script = scripts[i];
+ const newScript = document.createElement('script');
if (script.src) {
newScript.src = script.src;
}
prefix = 'data-' + prefix;
camelCaseName = (camelCaseName === true);
idToUpperCase = (idToUpperCase === true);
- let attribute, attributes = {}, name, tmp;
+ const attributes = {};
for (let i = 0, length = element.attributes.length; i < length; i++) {
- attribute = element.attributes[i];
+ const attribute = element.attributes[i];
if (attribute.name.indexOf(prefix) === 0) {
- name = attribute.name.replace(new RegExp('^' + prefix), '');
+ let name = attribute.name.replace(new RegExp('^' + prefix), '');
if (camelCaseName) {
- tmp = name.split('-');
+ let tmp = name.split('-');
name = '';
for (let j = 0, innerLength = tmp.length; j < innerLength; j++) {
if (name.length) {
element.style.setProperty('display', 'none', '');
},
/**
- * Shorthand function to show an element previously hidden by using `elHide()`.
+ * Shorthand function to show an element previously hidden by using `hide()`.
*/
show(element) {
element.style.removeProperty('display');
}
}
if (newActiveItem === null) {
- for (let i = 0; i < listItems.length; i++) {
- if (isValidItem(listItems[i])) {
- newActiveItem = listItems[i];
- break;
- }
- }
+ newActiveItem = listItems.find(isValidItem) || null;
}
if (newActiveItem !== null) {
newActiveItem.focus();
button = dropdown;
}
toggle(null, _activeTargetId);
- if (button)
+ if (button) {
button.focus();
+ }
}
}
const UiDropdownSimple = {
* Closes all dropdowns.
*/
closeAll() {
- _dropdowns.forEach((function (dropdown, containerId) {
+ _dropdowns.forEach((dropdown, containerId) => {
if (dropdown.classList.contains('dropdownOpen')) {
dropdown.classList.remove('dropdownOpen');
_menus.get(containerId).classList.remove('dropdownOpen');
notifyCallbacks(containerId, 'close');
}
- }).bind(this));
+ });
},
/**
* Destroys a dropdown identified by given id.
Language = __importStar(Language);
let _busy = false;
let _callback = null;
+ let _didInit = false;
let _message;
- let _notificationElement = null;
+ let _notificationElement;
let _timeout;
function init() {
- if (_notificationElement === null) {
- _notificationElement = document.createElement('div');
- _notificationElement.id = 'systemNotification';
- _message = document.createElement('p');
- _message.addEventListener('click', hide);
- _notificationElement.appendChild(_message);
- document.body.appendChild(_notificationElement);
- }
+ if (_didInit)
+ return;
+ _didInit = true;
+ _notificationElement = document.createElement('div');
+ _notificationElement.id = 'systemNotification';
+ _message = document.createElement('p');
+ _message.addEventListener('click', hide);
+ _notificationElement.appendChild(_message);
+ document.body.appendChild(_notificationElement);
}
/**
* Hides the notification and invokes the callback if provided.
setInnerHtml(element: Element, innerHtml: string): void {
element.innerHTML = innerHtml;
- let newScript: HTMLScriptElement;
- let script: HTMLScriptElement;
const scripts = element.querySelectorAll<HTMLScriptElement>('script');
for (let i = 0, length = scripts.length; i < length; i++) {
- script = scripts[i];
- newScript = document.createElement('script');
+ const script = scripts[i];
+ const newScript = document.createElement('script');
if (script.src) {
newScript.src = script.src;
} else {
* Retrieves all data attributes from target element, optionally allowing for
* a custom prefix that serves two purposes: First it will restrict the results
* for items starting with it and second it will remove that prefix.
- *
+ *
* @deprecated 5.4 Use `element.dataset` instead.
*/
getDataAttributes(element: Element, prefix?: string, camelCaseName?: boolean, idToUpperCase?: boolean): DataAttributes {
camelCaseName = (camelCaseName === true);
idToUpperCase = (idToUpperCase === true);
- let attribute, attributes = {}, name, tmp;
+ const attributes = {};
for (let i = 0, length = element.attributes.length; i < length; i++) {
- attribute = element.attributes[i];
+ const attribute = element.attributes[i];
if (attribute.name.indexOf(prefix) === 0) {
- name = attribute.name.replace(new RegExp('^' + prefix), '');
+ let name = attribute.name.replace(new RegExp('^' + prefix), '');
if (camelCaseName) {
- tmp = name.split('-');
+ let tmp = name.split('-');
name = '';
for (let j = 0, innerLength = tmp.length; j < innerLength; j++) {
if (name.length) {
},
/**
- * Shorthand function to show an element previously hidden by using `elHide()`.
+ * Shorthand function to show an element previously hidden by using `hide()`.
*/
show(element: HTMLElement): void {
element.style.removeProperty('display');
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'End' || event.key === 'Home') {
event.preventDefault();
- const listItems = Array.from<HTMLElement>(activeItem.closest('.dropdownMenu')!.querySelectorAll('li'));
+ const listItems: HTMLElement[] = Array.from(activeItem.closest('.dropdownMenu')!.querySelectorAll('li'));
if (event.key === 'ArrowUp' || event.key === 'End') {
listItems.reverse();
}
}
if (newActiveItem === null) {
- for (let i = 0; i < listItems.length; i++) {
- if (isValidItem(listItems[i])) {
- newActiveItem = listItems[i];
- break;
- }
- }
+ newActiveItem = listItems.find(isValidItem) || null;
}
if (newActiveItem !== null) {
}
toggle(null, _activeTargetId);
- if (button) button.focus();
+ if (button) {
+ button.focus();
+ }
}
}
}
}
- button.dataset.target= containerId;
+ button.dataset.target = containerId;
if (isLazyInitialization) {
setTimeout(() => {
* Closes all dropdowns.
*/
closeAll(): void {
- _dropdowns.forEach((function (dropdown, containerId) {
+ _dropdowns.forEach((dropdown, containerId) => {
if (dropdown.classList.contains('dropdownOpen')) {
dropdown.classList.remove('dropdownOpen');
_menus.get(containerId)!.classList.remove('dropdownOpen');
notifyCallbacks(containerId, 'close');
}
- }).bind(this));
+ });
},
/**
let _busy = false;
let _callback: Callback | null = null;
+let _didInit = false;
let _message: HTMLElement;
-let _notificationElement: HTMLElement | null = null;
+let _notificationElement: HTMLElement;
let _timeout: number;
function init() {
- if (_notificationElement === null) {
- _notificationElement = document.createElement('div');
- _notificationElement.id = 'systemNotification';
+ if (_didInit) return;
+ _didInit = true;
+
+ _notificationElement = document.createElement('div');
+ _notificationElement.id = 'systemNotification';
- _message = document.createElement('p');
- _message.addEventListener('click', hide);
- _notificationElement.appendChild(_message);
+ _message = document.createElement('p');
+ _message.addEventListener('click', hide);
+ _notificationElement.appendChild(_message);
- document.body.appendChild(_notificationElement);
- }
+ document.body.appendChild(_notificationElement);
}
/**
function hide() {
clearTimeout(_timeout);
- _notificationElement!.classList.remove('active');
+ _notificationElement.classList.remove('active');
if (_callback !== null) {
_callback();
_message.className = cssClassName || 'success';
_message.textContent = Language.get(message || 'wcf.global.success');
- _notificationElement!.classList.add('active');
+ _notificationElement.classList.add('active');
_timeout = setTimeout(hide, 2000);
}