X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=blobdiff_plain;f=js%2Fadhoc.js;h=51932499f7a099ac94a96f8daa20d78f4509d1c9;hp=02be46c6342512080f728e4c18c5a8261c54321f;hb=3a1e752b5d9120ffd6def0a5e17e2cf536209854;hpb=61e5961e4a4db4362a2ac0d59da5929671b583cc diff --git a/js/adhoc.js b/js/adhoc.js index 02be46c..5193249 100644 --- a/js/adhoc.js +++ b/js/adhoc.js @@ -1,132 +1,155 @@ +// adhocweb +// Copyright (c) 2010-2013 Florian Zeitz +// +// This project is MIT licensed. +// Please see the COPYING file for more information. + +/* + * 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 = { - status: { +function Adhoc(view, readycb) { + this.status = { sessionid: null, cmdNode: null, - queryJID: null - }, + queryJID: null, + readycb: readycb, + view: view + }; +} + +Adhoc.prototype = { + constructor: Adhoc, - addNote: function (elem, text, type) { + addNote: function (text, type) { if (!type) { type = "info"; } text = text.replace(/\n/g, "
"); - $(elem).append("

" + text + "

"); + $(this.status.view).append("

" + text + "

"); }, - addForm: function (elem, x) { - var form = $("
"); + addForm: function (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(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")) { - $("