Mercurial > hg > fapweb
changeset 858:fa12a996e86b
ESC handling for message boxes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Nov 2014 10:29:40 +0200 |
parents | 70a8d52a8d00 |
children | 16cbfb3e7cd4 |
files | ajax.js |
diffstat | 1 files changed, 37 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ajax.js Wed Nov 26 10:02:41 2014 +0200 +++ b/ajax.js Wed Nov 26 10:29:40 2014 +0200 @@ -3,17 +3,39 @@ // Common JavaScript / AJAX code // (C) Copyright 2012-2014 Tecnic Software productions (TNSP) // +var jsMessageBoxCancelCB = null, jsMessageBoxCBData = null, jsMessageBoxOKCB = null; + +function jsHandleMessageBoxKeys(ev) +{ + ev = ev || window.event; + var key = ev.keyCode ? ev.keyCode : ev.which; + if (key == 27) + { + jsCloseMessageBox(jsMessageBoxCancelCB, jsMessageBoxCBData); + return false; + } + else + return true; +} function jsCloseMessageBox(callback, cb_data) { var nitem = document.getElementById("messageBox"); - if (nitem && nitem.style.display != "none") + if (nitem) { - nitem.style.display = "none"; - - if (callback && typeof(callback) === "function") - callback(cb_data); + document.onkeydown = null; + jsMessageBoxCancelCB = null; + jsMessageBoxCBData = null; + jsMessageBoxOKCB = null; + + if (nitem.style.display != "none") + { + nitem.style.display = "none"; + + if (callback && typeof(callback) === "function") + callback(cb_data); + } } } @@ -28,6 +50,11 @@ "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+ "</div></div>"; + document.onkeydown = jsHandleMessageBoxKeys; + jsMessageBoxCancelCB = null; + jsMessageBoxCBData = null; + jsMessageBoxOKCB = null; + var elem = document.getElementById("msgBoxConfirmClose"); elem.onclick = function () { jsCloseMessageBox(0, 0); } @@ -53,6 +80,11 @@ "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+ "</div></div>"; + document.onkeydown = jsHandleMessageBoxKeys; + jsMessageBoxOKCB = cb_ok; + jsMessageBoxCancelCB = cb_cancel; + jsMessageBoxCBData = cb_data; + var elem = document.getElementById("msgBoxConfirmCancel"); elem.onclick = function () { jsCloseMessageBox(cb_cancel, cb_data); }