From: Florian Zeitz Date: Sun, 18 Dec 2011 02:23:05 +0000 (+0100) Subject: Rework HTML form building X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=commitdiff_plain;h=9f26ed9cdd3330b0fb922e1475d3175caa46d528 Rework HTML form building --- diff --git a/index.html b/index.html index 5390947..acf79d3 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@ - + + adHocWeb diff --git a/js/adhoc.js b/js/adhoc.js index 02be46c..3f2ae2b 100644 --- a/js/adhoc.js +++ b/js/adhoc.js @@ -1,3 +1,26 @@ +/* + * Implementation of ECMA Script 5 like bind from: + * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind + */ +if (!Function.prototype.bind) { + Function.prototype.bind = function (oThis) { + if (typeof this !== "function") { + /* closest thing possible to the ECMAScript 5 internal IsCallable function */ + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + var fSlice = Array.prototype.slice, + aArgs = fSlice.call(arguments, 1), + fToBind = this, + fNOP = function () {}, + fBound = function () { + return fToBind.apply(this instanceof fNOP ? this : oThis || window, Args.concat(fSlice.call(arguments))); + }; + fNOP.prototype = this.prototype; + fBound.prototype = new fNOP(); + return fBound; + }; +} + Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands"); var Adhoc = { @@ -16,117 +39,106 @@ var Adhoc = { }, addForm: function (elem, x) { + var self = this; var form = $("
"); form.submit(function(event) { - Adhoc.executeCommand("execute", Adhoc.serializeToDataform('form'), - function(e) { Adhoc.displayResult(elem, e) }); + self.executeCommand("execute", self.serializeToDataform('form'), + function(e) { self.displayResult(elem, e) }); event.preventDefault(); }); var fieldset = $("
"); form.append(fieldset); - if ($(x).find("title").length > 0) - $("").text($(x).find("title").text()).appendTo(fieldset); - if ($(x).find("instructions").length > 0) - $("

").text($(x).find("instructions").text()).appendTo(fieldset); + $(x).find("title").each(function() { $("").text($(this).text()).appendTo(fieldset); }); + $(x).find("instructions").each(function() { $("

").text($(this).text()).appendTo(fieldset); }); $(x).find("field").each(function() { - var item = null; - var type = $(this).attr("type"); - if($(this).attr("label")) { - $("