/**
* Simple notification overlay.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module Ui/Notification (alias)
- * @module WoltLabSuite/Core/Ui/Notification
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module Ui/Notification (alias)
+ * @module WoltLabSuite/Core/Ui/Notification
*/
-define(['Language'], function (Language) {
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+ __setModuleDefault(result, mod);
+ return result;
+};
+define(["require", "exports", "../Language"], function (require, exports, Language) {
"use strict";
- var _busy = false;
- var _callback = null;
- var _message = null;
- var _notificationElement = null;
- var _timeout = null;
- var _callbackHide = null;
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.show = void 0;
+ Language = __importStar(Language);
+ let _busy = false;
+ let _callback = null;
+ let _message;
+ let _notificationElement = null;
+ 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);
+ }
+ }
+ /**
+ * Hides the notification and invokes the callback if provided.
+ */
+ function hide() {
+ clearTimeout(_timeout);
+ _notificationElement.classList.remove('active');
+ if (_callback !== null) {
+ _callback();
+ }
+ _busy = false;
+ }
/**
- * @exports WoltLabSuite/Core/Ui/Notification
+ * Displays a notification.
*/
- var UiNotification = {
- /**
- * Shows a notification.
- *
- * @param {string} message message
- * @param {function=} callback callback function to be executed once notification is being hidden
- * @param {string=} cssClassName alternate CSS class name, defaults to 'success'
- */
- show: function (message, callback, cssClassName) {
- if (_busy) {
- return;
- }
- this._init();
- _callback = (typeof callback === 'function') ? callback : null;
- _message.className = cssClassName || 'success';
- _message.textContent = Language.get(message || 'wcf.global.success');
- _busy = true;
- _notificationElement.classList.add('active');
- _timeout = setTimeout(_callbackHide, 2000);
- },
- /**
- * Initializes the UI elements.
- */
- _init: function () {
- if (_notificationElement === null) {
- _callbackHide = this._hide.bind(this);
- _notificationElement = elCreate('div');
- _notificationElement.id = 'systemNotification';
- _message = elCreate('p');
- _message.addEventListener(WCF_CLICK_EVENT, _callbackHide);
- _notificationElement.appendChild(_message);
- document.body.appendChild(_notificationElement);
- }
- },
- /**
- * Hides the notification and invokes the callback if provided.
- */
- _hide: function () {
- clearTimeout(_timeout);
- _notificationElement.classList.remove('active');
- if (_callback !== null) {
- _callback();
- }
- _busy = false;
+ function show(message, callback, cssClassName) {
+ if (_busy) {
+ return;
}
- };
- return UiNotification;
+ _busy = true;
+ init();
+ _callback = (typeof callback === 'function') ? callback : null;
+ _message.className = cssClassName || 'success';
+ _message.textContent = Language.get(message || 'wcf.global.success');
+ _notificationElement.classList.add('active');
+ _timeout = setTimeout(hide, 2000);
+ }
+ exports.show = show;
});
+++ /dev/null
-/**
- * Simple notification overlay.
- *
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module Ui/Notification (alias)
- * @module WoltLabSuite/Core/Ui/Notification
- */
-define(['Language'], function (Language) {
- "use strict";
- var _busy = false;
- var _callback = null;
- var _message = null;
- var _notificationElement = null;
- var _timeout = null;
- var _callbackHide = null;
- /**
- * @exports WoltLabSuite/Core/Ui/Notification
- */
- var UiNotification = {
- /**
- * Shows a notification.
- *
- * @param {string} message message
- * @param {function=} callback callback function to be executed once notification is being hidden
- * @param {string=} cssClassName alternate CSS class name, defaults to 'success'
- */
- show: function (message, callback, cssClassName) {
- if (_busy) {
- return;
- }
- this._init();
- _callback = (typeof callback === 'function') ? callback : null;
- _message.className = cssClassName || 'success';
- _message.textContent = Language.get(message || 'wcf.global.success');
- _busy = true;
- _notificationElement.classList.add('active');
- _timeout = setTimeout(_callbackHide, 2000);
- },
- /**
- * Initializes the UI elements.
- */
- _init: function () {
- if (_notificationElement === null) {
- _callbackHide = this._hide.bind(this);
- _notificationElement = elCreate('div');
- _notificationElement.id = 'systemNotification';
- _message = elCreate('p');
- _message.addEventListener(WCF_CLICK_EVENT, _callbackHide);
- _notificationElement.appendChild(_message);
- document.body.appendChild(_notificationElement);
- }
- },
- /**
- * Hides the notification and invokes the callback if provided.
- */
- _hide: function () {
- clearTimeout(_timeout);
- _notificationElement.classList.remove('active');
- if (_callback !== null) {
- _callback();
- }
- _busy = false;
- }
- };
- return UiNotification;
-});
--- /dev/null
+/**
+ * Simple notification overlay.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module Ui/Notification (alias)
+ * @module WoltLabSuite/Core/Ui/Notification
+ */
+
+import * as Language from '../Language';
+
+type Callback = () => void;
+
+let _busy = false;
+let _callback: Callback | null = null;
+let _message: HTMLElement;
+let _notificationElement: HTMLElement | null = null;
+let _timeout: number;
+
+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);
+ }
+}
+
+/**
+ * Hides the notification and invokes the callback if provided.
+ */
+function hide() {
+ clearTimeout(_timeout);
+
+ _notificationElement!.classList.remove('active');
+
+ if (_callback !== null) {
+ _callback();
+ }
+
+ _busy = false;
+}
+
+/**
+ * Displays a notification.
+ */
+export function show(message: string, callback?: Callback, cssClassName?: string): void {
+ if (_busy) {
+ return;
+ }
+ _busy = true;
+
+ init();
+
+ _callback = (typeof callback === 'function') ? callback : null;
+ _message.className = cssClassName || 'success';
+ _message.textContent = Language.get(message || 'wcf.global.success');
+
+ _notificationElement!.classList.add('active');
+ _timeout = setTimeout(hide, 2000);
+}