-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add types for
mediawiki.confirmCloseWindow
- Loading branch information
Adrien LESÉNÉCHAL
committed
Mar 8, 2024
1 parent
773af71
commit dffd1ac
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
interface Options { | ||
/** | ||
* Optional jQuery event namespace, to allow loosely coupled | ||
* external code to release your trigger. For example, the VisualEditor extension can use this | ||
* remove the trigger registered by mediawiki.action.edit, without strong runtime coupling. | ||
*/ | ||
namespace?: string; | ||
|
||
/** | ||
* @returns {boolean} Whether to show the dialog to the user. | ||
*/ | ||
test?(): boolean; | ||
} | ||
|
||
interface ConfirmCloseWindow { | ||
/** | ||
* Remove the event listener and don't show an alert anymore, if the user wants to leave | ||
* the page. | ||
*/ | ||
release(): void; | ||
|
||
/** | ||
* Trigger the module's function manually. | ||
* | ||
* Check, if options.test() returns true and show an alert to the user if he/she want | ||
* to leave this page. Returns false, if options.test() returns false or the user | ||
* cancelled the alert window (~don't leave the page), true otherwise. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
trigger(): boolean; | ||
} | ||
|
||
declare global { | ||
namespace mw { | ||
/** | ||
* Prevent the closing of a window with a confirm message (the onbeforeunload event seems to | ||
* work in most browsers.) | ||
* | ||
* This supersedes any previous onbeforeunload handler. If there was a handler before, it is | ||
* restored when you execute the returned release() function. | ||
* | ||
* ```js | ||
* var allowCloseWindow = mw.confirmCloseWindow(); | ||
* // ... do stuff that can't be interrupted ... | ||
* allowCloseWindow.release(); | ||
* ``` | ||
* | ||
* The second function returned is a trigger function to trigger the check and an alert | ||
* window manually, e.g.: | ||
* | ||
* ```js | ||
* var allowCloseWindow = mw.confirmCloseWindow(); | ||
* // ... do stuff that can't be interrupted ... | ||
* if ( allowCloseWindow.trigger() ) { | ||
* // don't do anything (e.g. destroy the input field) | ||
* } else { | ||
* // do whatever you wanted to do | ||
* } | ||
* ``` | ||
* | ||
* @param {Options} [options] | ||
* @returns {ConfirmCloseWindow} An object of functions to work with this module | ||
*/ | ||
function confirmCloseWindow(options?: Options): ConfirmCloseWindow; | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters