diff --git a/client/dcwebui.js b/client/dcwebui.js index ccc25c4..b85b116 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -243,8 +243,7 @@ var userMenu = function(u, ev) { usermenu.show(); // - ev.preventDefault(); - return false; + return noprop(ev); }; var userlist = { @@ -525,6 +524,20 @@ var tab_free = function(id) { } }; +var noprop = function(ev) { + if (ev.preventDefault) { + ev.preventDefault(); + } + + if (ev.stopPropagation) { + ev.stopPropagation(); + } else { + ev.cancelBubble = true; // oldIE + } + + return false; +} + var tab_addHandlers = function() { var tabitems = $(".tabitem"); for (var i = 0; i < tabitems.length; i++) { @@ -533,13 +546,7 @@ var tab_addHandlers = function() { tabitems[i].onclick = function(ev) { tab_set( this.getAttribute('data-tab') ); - // 360nobubble - if (ev.stopPropagation) { - ev.stopPropagation(); - } else { - ev.cancelBubble = true; // oldIE - } - return false; + return noprop(ev); }; } @@ -550,13 +557,7 @@ var tab_addHandlers = function() { tabclosers[i].onclick = function(ev) { tab_free( this.getAttribute('data-tab') ); - // 360nobubble - if (ev.stopPropagation) { - ev.stopPropagation(); - } else { - ev.cancelBubble = true; // oldIE - } - return false; + return noprop(ev); }; } }; @@ -949,26 +950,21 @@ window.onload = function() { $("#form-none").onsubmit = function(ev) { submit(); - // don't submit form - ev.preventDefault(); - return false; + return noprop(ev); // don't submit form }; $("#chatbox").onkeydown = function(ev) { if (ev.keyCode === 9 /* Tab */) { tabcompletion_start( ev.shiftKey ? -1 : 1 ); - ev.preventDefault(); - return false; + return noprop(ev); } else if (ev.keyCode == 38 /* ArrowUp */ && ev.ctrlKey) { scrollback_move(-1); - ev.preventDefault(); - return false; + return noprop(ev); } else if (ev.keyCode == 40 /* ArrowDown */ && ev.ctrlKey) { scrollback_move(1); - ev.preventDefault(); - return false; + return noprop(ev); } else { tabcompletion_inactive(); @@ -987,9 +983,7 @@ window.onload = function() { $("#menubutton").onclick = function(ev) { menu.toggle(); - ev.preventDefault(); - ev.stopPropagation(); - return false; + return noprop(ev); }; window.onclick = function() {