mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 14:11:02 +01:00
Add customisations for confirm box.
Can change the text of the accept and reject buttons. Now returns undefined if the user clicks off it
This commit is contained in:
parent
8d628cf0ed
commit
082d939f7d
@ -670,18 +670,22 @@ class App {
|
|||||||
*
|
*
|
||||||
* @param {string} title - The title of the box
|
* @param {string} title - The title of the box
|
||||||
* @param {string} body - The question (HTML supported)
|
* @param {string} body - The question (HTML supported)
|
||||||
|
* @param {string} accept - The text of the accept button
|
||||||
|
* @param {string} reject - The text of the reject button
|
||||||
* @param {function} callback - A function accepting one boolean argument which handles the
|
* @param {function} callback - A function accepting one boolean argument which handles the
|
||||||
* response e.g. function(answer) {...}
|
* response e.g. function(answer) {...}
|
||||||
* @param {Object} [scope=this] - The object to bind to the callback function
|
* @param {Object} [scope=this] - The object to bind to the callback function
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
|
* // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
|
||||||
* this.confirm("Question", "Would you like a cookie?", function(answer) {console.log(answer);});
|
* this.confirm("Question", "Would you like a cookie?", "Yes", "No", function(answer) {console.log(answer);});
|
||||||
*/
|
*/
|
||||||
confirm(title, body, callback, scope) {
|
confirm(title, body, accept, reject, callback, scope) {
|
||||||
scope = scope || this;
|
scope = scope || this;
|
||||||
document.getElementById("confirm-title").innerHTML = title;
|
document.getElementById("confirm-title").innerHTML = title;
|
||||||
document.getElementById("confirm-body").innerHTML = body;
|
document.getElementById("confirm-body").innerHTML = body;
|
||||||
|
document.getElementById("confirm-yes").innerText = accept;
|
||||||
|
document.getElementById("confirm-no").innerText = reject;
|
||||||
document.getElementById("confirm-modal").style.display = "block";
|
document.getElementById("confirm-modal").style.display = "block";
|
||||||
|
|
||||||
this.confirmClosed = false;
|
this.confirmClosed = false;
|
||||||
@ -694,9 +698,14 @@ class App {
|
|||||||
callback.bind(scope)(true);
|
callback.bind(scope)(true);
|
||||||
$("#confirm-modal").modal("hide");
|
$("#confirm-modal").modal("hide");
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
.one("hide.bs.modal", function(e) {
|
.one("click", "#confirm-no", function() {
|
||||||
if (!this.confirmClosed)
|
this.confirmClosed = true;
|
||||||
callback.bind(scope)(false);
|
callback.bind(scope)(false);
|
||||||
|
}.bind(this))
|
||||||
|
.one("hide.bs.modal", function(e) {
|
||||||
|
if (!this.confirmClosed) {
|
||||||
|
callback.bind(scope)(undefined);
|
||||||
|
}
|
||||||
this.confirmClosed = true;
|
this.confirmClosed = true;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user