/** * @license * Copyright The Closure Library Authors. * SPDX-License-Identifier: Apache-2.0 */ /** * @fileoverview DHTML prompt to replace javascript's prompt(). * * @see ../demos/prompt.html */ /** * Creates an object that represents a prompt (used in place of javascript's * prompt). The html structure of the prompt is the same as the layout for * dialog.js except for the addition of a text box which is placed inside the * "Content area" and has the default class-name 'modal-dialog-userInput' * * String is treated as plain text and it will be HTML-escaped. * Cancel. The function should expect a single argument which represents * what the user entered into the prompt. If the user presses cancel, the * value of the argument will be null. * the text box when the prompt appears. * z-index issue by using a an iframe instead of a div for bg element. * Component} for semantics. * @extends {Dialog} */ export class Prompt extends Dialog { /** * Creates an object that represents a prompt (used in place of javascript's * prompt). The html structure of the prompt is the same as the layout for * dialog.js except for the addition of a text box which is placed inside the * "Content area" and has the default class-name 'modal-dialog-userInput' * * @param {string} promptTitle The title of the prompt. * @param {string|!SafeHtml} promptBody The body of the prompt. * String is treated as plain text and it will be HTML-escaped. * @param {?Function} callback The function to call when the user selects Ok or * Cancel. The function should expect a single argument which represents * what the user entered into the prompt. If the user presses cancel, the * value of the argument will be null. * @param {string=} opt_defaultValue Optional default value that should be in * the text box when the prompt appears. * @param {string=} opt_class Optional prefix for the classes. * @param {boolean=} opt_useIframeForIE For IE, workaround windowed controls * z-index issue by using a an iframe instead of a div for bg element. * @param {DomHelper=} opt_domHelper Optional DOM helper; see {@link * Component} for semantics. */ constructor(promptTitle: string, promptBody: string | SafeHtml, callback: Function | null, opt_defaultValue?: string | undefined, opt_class?: string | undefined, opt_useIframeForIE?: boolean | undefined, opt_domHelper?: DomHelper | undefined); /** * Callback function which is invoked with the response to the prompt * @type {?Function} * @private */ private callback_; /** * Default value to display in prompt window * @type {string} * @private */ private defaultValue_; /** * Element in which user enters response (HTML text box) * @type {?HTMLInputElement|?HTMLTextAreaElement} * @private */ private userInputEl_; /** * Tracks whether the prompt is in the process of closing to prevent multiple * calls to the callback when the user presses enter. * @type {boolean} * @private */ private isClosing_; /** * Number of rows in the user input element. * The default is 1 which means use an element. * @type {number} * @private */ private rows_; /** * Number of cols in the user input element. * The default is 0 which means use browser default. * @type {number} * @private */ private cols_; /** * The input decorator function. * @type {?function(?Element)} * @private */ private inputDecoratorFn_; /** * A validation function that takes a string and returns true if the string is * accepted, false otherwise. * @type {function(string):boolean} * @private */ private validationFn_; /** * The id of the input element. * @type {string} * @private */ private inputElementId_; /** * Sets the validation function that takes a string and returns true if the * string is accepted, false otherwise. * @param {function(string): boolean} fn The validation function to use on user * input. */ setValidationFunction(fn: (arg0: string) => boolean): void; /** * @return {?HTMLInputElement|?HTMLTextAreaElement} The user input element. May * be null if the Prompt has not been rendered. */ getInputElement(): (HTMLInputElement | (HTMLTextAreaElement | null)) | null; /** * Sets an input decorator function. This function will be called in * #enterDocument and will be passed the input element. This is useful for * attaching handlers to the input element for specific change events, * for example. * @param {function(?Element)} inputDecoratorFn A function to call on the input * element on #enterDocument. */ setInputDecoratorFn(inputDecoratorFn: (arg0: Element | null) => any): void; /** * Set the number of rows in the user input element. * A values of 1 means use an `` element. If the prompt is already * rendered then you cannot change from `` to `