From: Florian Zeitz Date: Tue, 7 Sep 2010 23:06:02 +0000 (+0200) Subject: Event handling changes X-Git-Url: https://git.babelmonkeys.de/?a=commitdiff_plain;h=eab81f9e4afd38c8390745449865185e9637c830;p=adhocweb.git Event handling changes * Use event.preventDefault() instead of just return false * remove superfluous returns * Add around commands for usability --- diff --git a/js/main.js b/js/main.js index 9f802b5..4cff25c 100644 --- a/js/main.js +++ b/js/main.js @@ -55,7 +55,7 @@ function addNote(elem, text, type) { function addForm(elem, x) { var form = $("
"); - form.submit(function(){return false;}); + form.submit(function(event){event.preventDefault();}); var fieldset = $("
"); form.append(fieldset); if ($(x).find("title").length > 0) @@ -209,7 +209,7 @@ function displayResult(result) { } } -function runCommand() { +function runCommand(event) { cmdNode = $(this).attr("id"); // Save node of executed command (in global var) var execIQ = $iq({ type: "set", to: queryJID, id: connection.getUniqueId() }) .c("command", { xmlns: Strophe.NS.ADHOC, node: cmdNode, action: "execute" }); @@ -217,6 +217,7 @@ function runCommand() { sessionid = $(result).find("command").attr("sessionid"); displayResult(result); }); + event.preventDefault(); } function getCommandNodes() { @@ -224,7 +225,8 @@ function getCommandNodes() { connection.sendIQ(nodesIQ, function(result) { $('#output').append("
    "); $(result).find("item").each(function(index, e) { - item = $("
  • " + $(e).attr("name") + "
  • ").bind("click", runCommand); + link = $("
    " + $(e).attr("name") + "").click(runCommand) + item = $("
  • ").append(link); $("#items").append(item); }); }); @@ -254,7 +256,6 @@ function showConnect() { jid.show(); $('label').show(); $('#output').empty(); - return false; } function showDisconnect() { @@ -266,7 +267,6 @@ function showDisconnect() { pass.hide(); jid.hide(); $('#cred label').hide(); - return false; } $(document).ready(function () { @@ -281,7 +281,7 @@ $(document).ready(function () { $("#log").toggle(); }); - $('#cred').bind('submit', function () { + $('#cred').bind('submit', function (event) { var button = $('#connect').get(0); var jid = $('#jid'); var pass = $('#pass'); @@ -296,13 +296,13 @@ $(document).ready(function () { } else { connection.disconnect(); } - return false; + event.preventDefault(); }); - $('#queryForm').bind('submit', function () { + $('#queryForm').bind('submit', function (event) { queryJID = $('#queryJID').val(); checkFeatures(); - return false; + event.preventDefault(); }); });