# HG changeset patch # User Matti Hamalainen # Date 1416990580 -7200 # Node ID fa12a996e86b1f840f440873838a0f15a5d174e0 # Parent 70a8d52a8d0094043fadad3cbac0f5210d8cd76f ESC handling for message boxes. diff -r 70a8d52a8d00 -r fa12a996e86b ajax.js --- 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 @@ ""+ ""; + document.onkeydown = jsHandleMessageBoxKeys; + jsMessageBoxCancelCB = null; + jsMessageBoxCBData = null; + jsMessageBoxOKCB = null; + var elem = document.getElementById("msgBoxConfirmClose"); elem.onclick = function () { jsCloseMessageBox(0, 0); } @@ -53,6 +80,11 @@ ""+ ""; + 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); }