X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=blobdiff_plain;f=js%2Fmain.js;h=955ceb9f5d9a0795529b5f9a9d577e134789b73c;hp=6bd32412743739166210a6cc07f5d3c9e3df1a29;hb=c61edf2757c92c0460b9e0581771f7a9b06ed1ba;hpb=e5d4fe480e02907b80e91d9ed42854700c5866c1 diff --git a/js/main.js b/js/main.js index 6bd3241..955ceb9 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,15 @@ var BOSH_SERVICE = 'http://localhost:5280/http-bind/'; -var show_log = false; +var show_log = true; Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands"); var localJID = null; var connection = null; -var sessionid = null; -var cmdNode = null; -var queryJID = null; +var adhoc_status = { + sessionid: null, + cmdNode: null, + queryJID: null +}; function log(msg) { var entry = $('
').append(document.createTextNode(msg)); @@ -40,8 +42,8 @@ function onConnect(status) { } } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); - queryJID = connection.domain; - $('#queryJID').val(queryJID); + adhoc_status.queryJID = connection.domain; + $('#queryJID').val(adhoc_status.queryJID); $('#query').show(); checkFeatures(); } @@ -64,7 +66,7 @@ function addForm(elem, x) { $("").text($(x).find("title").text()).appendTo(fieldset); if ($(x).find("instructions").length > 0) $("

").text($(x).find("instructions").text()).appendTo(fieldset); - $(x).find("field").each(function(){ + $(x).find("field").each(function() { var item = null; var type = $(this).attr("type"); if($(this).attr("label")) { @@ -95,15 +97,15 @@ function addForm(elem, x) { break; case "list-multi": item = $(""); - $(this).find("option").each(function(){ - $("

"); $(result).find("item").each(function(index, e) { @@ -259,16 +262,21 @@ function getCommandNodes() { } function checkFeatures() { - featureIQ = $iq({ type: "get", to: queryJID, id: "features1" }).c("query", {xmlns: Strophe.NS.DISCO_INFO}); - connection.sendIQ(featureIQ, function(result) { - if ($(result).find("feature[var='" + Strophe.NS.ADHOC + "']").length > 0) { - $('#output').append("

This entitiy does support AdHoc commands

"); - } else { - $('#output').append("

This entitiy does NOT support AdHoc commands

"); - } - }); + featureIQ = $iq({ type: "get", to: adhoc_status.queryJID, id: "features1" }).c("query", {xmlns: Strophe.NS.DISCO_INFO}); $('#output').empty(); - getCommandNodes(); + connection.sendIQ(featureIQ, + function(result) { /* Callback */ + if ($(result).find("feature[var='" + Strophe.NS.ADHOC + "']").length > 0) { + $('#output').append("

This entitiy does support AdHoc commands

"); + getCommandNodes(); + } else { + $('#output').append("

This entitiy does NOT support AdHoc commands

"); + } + }, + function(result) { /* Errback */ + $('#output').append("

Couldn't get list of supported features

"); + } + ); } function showConnect() { @@ -328,15 +336,14 @@ $(document).ready(function () { }); $('#queryForm').bind('submit', function (event) { - queryJID = $('#queryJID').val(); + adhoc_status.queryJID = $('#queryJID').val(); checkFeatures(); event.preventDefault(); }); }); -onunload = function() { +window.onunload = window.onbeforeunload = function() { if (connection) { connection.disconnect(); } } -