UNPKG

jodit

Version:

Jodit is awesome and usefully wysiwyg editor with filebrowser

68 lines (59 loc) 1.74 kB
/*! * Jodit Editor (https://xdsoft.net/jodit/) * Released under MIT see LICENSE.txt in the project root for license information. * Copyright (c) 2013-2020 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ import { Dialog } from './dialog'; import { asArray, isFunction } from '../../core/helpers/'; import { Dom } from '../../core/dom'; import { Button } from '../../core/ui'; /** * Show `alert` dialog. Work without Jodit object * * @method Alert * @param {string} msg Message * @param {string|function} [title] Title or callback * @param {function} [callback] callback * @param {string} [className] * @example * ```javascript * Jodit.Alert("File was uploaded"); * Jodit.Alert("File was uploaded", "Message"); * Jodit.Alert("File was uploaded", function() { * $('form').hide(); * }); * Jodit.Alert("File wasn't uploaded", "Error", function() { * $('form').hide(); * }); * ``` */ export const Alert = ( msg: string | HTMLElement, title?: string | (() => void | false), callback?: string | ((dialog: Dialog) => void | false), className: string = 'jodit-dialog_alert' ): Dialog => { if (isFunction(title)) { callback = title; title = undefined; } const dialog = new Dialog(), container = dialog.c.div(className), okButton = Button(dialog, 'ok', 'Ok'); asArray(msg).forEach(oneMessage => { container.appendChild( Dom.isNode(oneMessage, dialog.ow) ? oneMessage : dialog.c.fromHTML(oneMessage) ); }); okButton.onAction(() => { if (!callback || !isFunction(callback) || callback(dialog) !== false) { dialog.close(); } }); dialog.setFooter([okButton]); dialog.open(container, (title as string) || ' ', true, true); okButton.focus(); return dialog; };