xmppify 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/xmpp/index.js +0 -0
- data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
- data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
- data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
- data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
- data/app/assets/stylesheets/xmpp/index.css +0 -0
- data/app/controllers/omniauth_callbacks_controller.rb +15 -0
- data/app/controllers/ruby_bosh.rb +221 -0
- data/app/models/identity.rb +3 -0
- data/app/models/user.rb +40 -0
- data/bin/rails +8 -0
- data/db/migrate/20140329065635_create_users.rb +10 -0
- data/db/migrate/20140329070238_create_identities.rb +11 -0
- data/lib/xmppify/version.rb +3 -0
- data/lib/xmppify.rb +6 -0
- data/xmppify.gemspec +23 -0
- metadata +197 -0
@@ -0,0 +1,854 @@
|
|
1
|
+
// Generated by CoffeeScript 1.3.3
|
2
|
+
var $field, $form, $item, $opt, Field, Form, Item, Option, helper,
|
3
|
+
__slice = [].slice,
|
4
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
5
|
+
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
6
|
+
|
7
|
+
helper = {
|
8
|
+
fill: function(src, target, klass) {
|
9
|
+
var f, _i, _len, _results;
|
10
|
+
_results = [];
|
11
|
+
for (_i = 0, _len = src.length; _i < _len; _i++) {
|
12
|
+
f = src[_i];
|
13
|
+
_results.push(target.push(f instanceof klass ? f : new klass(f)));
|
14
|
+
}
|
15
|
+
return _results;
|
16
|
+
},
|
17
|
+
createHtmlFieldCouple: function(f) {
|
18
|
+
var div, id;
|
19
|
+
div = $("<div>");
|
20
|
+
id = "Strophe.x.Field-" + f.type + "-" + f["var"];
|
21
|
+
div.append("<label for='" + id + "'>" + (f.label || '') + "</label>").append($(f.toHTML()).attr("id", id)).append("<br />");
|
22
|
+
return div.children();
|
23
|
+
},
|
24
|
+
getHtmlFields: function(html) {
|
25
|
+
html = $(html);
|
26
|
+
return __slice.call(html.find("input")).concat(__slice.call(html.find("select")), __slice.call(html.find("textarea")));
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
Form = (function() {
|
31
|
+
|
32
|
+
Form._types = ["form", "submit", "cancel", "result"];
|
33
|
+
|
34
|
+
function Form(opt) {
|
35
|
+
this.toHTML = __bind(this.toHTML, this);
|
36
|
+
|
37
|
+
this.toJSON = __bind(this.toJSON, this);
|
38
|
+
|
39
|
+
this.toXML = __bind(this.toXML, this);
|
40
|
+
|
41
|
+
var f, i, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3;
|
42
|
+
this.fields = [];
|
43
|
+
this.items = [];
|
44
|
+
this.reported = [];
|
45
|
+
if (opt) {
|
46
|
+
if (_ref = opt.type, __indexOf.call(Form._types, _ref) >= 0) {
|
47
|
+
this.type = opt.type;
|
48
|
+
}
|
49
|
+
this.title = opt.title;
|
50
|
+
this.instructions = opt.instructions;
|
51
|
+
helper.fill = function(src, target, klass) {
|
52
|
+
var f, _i, _len, _results;
|
53
|
+
_results = [];
|
54
|
+
for (_i = 0, _len = src.length; _i < _len; _i++) {
|
55
|
+
f = src[_i];
|
56
|
+
_results.push(target.push(f instanceof klass ? f : new klass(f)));
|
57
|
+
}
|
58
|
+
return _results;
|
59
|
+
};
|
60
|
+
if (opt.fields) {
|
61
|
+
if (opt.fields) {
|
62
|
+
helper.fill(opt.fields, this.fields, Field);
|
63
|
+
}
|
64
|
+
} else if (opt.items) {
|
65
|
+
if (opt.items) {
|
66
|
+
helper.fill(opt.items, this.items, Item);
|
67
|
+
}
|
68
|
+
_ref1 = this.items;
|
69
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
70
|
+
i = _ref1[_i];
|
71
|
+
_ref2 = i.fields;
|
72
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
73
|
+
f = _ref2[_j];
|
74
|
+
if (!(_ref3 = f["var"], __indexOf.call(this.reported, _ref3) >= 0)) {
|
75
|
+
this.reported.push(f["var"]);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
Form.prototype.type = "form";
|
84
|
+
|
85
|
+
Form.prototype.title = null;
|
86
|
+
|
87
|
+
Form.prototype.instructions = null;
|
88
|
+
|
89
|
+
Form.prototype.toXML = function() {
|
90
|
+
var f, i, r, xml, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
91
|
+
xml = $build("x", {
|
92
|
+
xmlns: "jabber:x:data",
|
93
|
+
type: this.type
|
94
|
+
});
|
95
|
+
if (this.title) {
|
96
|
+
xml.c("title").t(this.title.toString()).up();
|
97
|
+
}
|
98
|
+
if (this.instructions) {
|
99
|
+
xml.c("instructions").t(this.instructions.toString()).up();
|
100
|
+
}
|
101
|
+
if (this.fields.length > 0) {
|
102
|
+
_ref = this.fields;
|
103
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
104
|
+
f = _ref[_i];
|
105
|
+
xml.cnode(f.toXML()).up();
|
106
|
+
}
|
107
|
+
} else if (this.items.length > 0) {
|
108
|
+
xml.c("reported");
|
109
|
+
_ref1 = this.reported;
|
110
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
111
|
+
r = _ref1[_j];
|
112
|
+
xml.c("field", {
|
113
|
+
"var": r
|
114
|
+
}).up();
|
115
|
+
}
|
116
|
+
xml.up();
|
117
|
+
_ref2 = this.items;
|
118
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
119
|
+
i = _ref2[_k];
|
120
|
+
xml.cnode(i.toXML()).up();
|
121
|
+
}
|
122
|
+
}
|
123
|
+
return xml.tree();
|
124
|
+
};
|
125
|
+
|
126
|
+
Form.prototype.toJSON = function() {
|
127
|
+
var f, i, json, _i, _j, _len, _len1, _ref, _ref1;
|
128
|
+
json = {
|
129
|
+
type: this.type
|
130
|
+
};
|
131
|
+
if (this.title) {
|
132
|
+
json.title = this.title;
|
133
|
+
}
|
134
|
+
if (this.instructions) {
|
135
|
+
json.instructions = this.instructions;
|
136
|
+
}
|
137
|
+
if (this.fields.length > 0) {
|
138
|
+
json.fields = [];
|
139
|
+
_ref = this.fields;
|
140
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
141
|
+
f = _ref[_i];
|
142
|
+
json.fields.push(f.toJSON());
|
143
|
+
}
|
144
|
+
} else if (this.items.length > 0) {
|
145
|
+
json.items = [];
|
146
|
+
json.reported = this.reported;
|
147
|
+
_ref1 = this.items;
|
148
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
149
|
+
i = _ref1[_j];
|
150
|
+
json.items.push(i.toJSON());
|
151
|
+
}
|
152
|
+
}
|
153
|
+
return json;
|
154
|
+
};
|
155
|
+
|
156
|
+
Form.prototype.toHTML = function() {
|
157
|
+
var f, form, i, _i, _j, _len, _len1, _ref, _ref1;
|
158
|
+
form = $("<form data-type='" + this.type + "'>");
|
159
|
+
if (this.title) {
|
160
|
+
form.append("<h1>" + this.title + "</h1>");
|
161
|
+
}
|
162
|
+
if (this.instructions) {
|
163
|
+
form.append("<p>" + this.instructions + "</p>");
|
164
|
+
}
|
165
|
+
if (this.fields.length > 0) {
|
166
|
+
_ref = this.fields;
|
167
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
168
|
+
f = _ref[_i];
|
169
|
+
(helper.createHtmlFieldCouple(f)).appendTo(form);
|
170
|
+
}
|
171
|
+
} else if (this.items.length > 0) {
|
172
|
+
_ref1 = this.items;
|
173
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
174
|
+
i = _ref1[_j];
|
175
|
+
($(i.toHTML())).appendTo(form);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
return form[0];
|
179
|
+
};
|
180
|
+
|
181
|
+
Form.fromXML = function(xml) {
|
182
|
+
var f, fields, i, instr, items, j, r, reported, title;
|
183
|
+
xml = $(xml);
|
184
|
+
f = new Form({
|
185
|
+
type: xml.attr("type")
|
186
|
+
});
|
187
|
+
title = xml.find("title");
|
188
|
+
if (title.length === 1) {
|
189
|
+
f.title = title.text();
|
190
|
+
}
|
191
|
+
instr = xml.find("instructions");
|
192
|
+
if (instr.length === 1) {
|
193
|
+
f.instructions = instr.text();
|
194
|
+
}
|
195
|
+
fields = xml.find("field");
|
196
|
+
items = xml.find("item");
|
197
|
+
if (items.length > 0) {
|
198
|
+
f.items = (function() {
|
199
|
+
var _i, _len, _results;
|
200
|
+
_results = [];
|
201
|
+
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
202
|
+
i = items[_i];
|
203
|
+
_results.push(Item.fromXML(i));
|
204
|
+
}
|
205
|
+
return _results;
|
206
|
+
})();
|
207
|
+
} else if (fields.length > 0) {
|
208
|
+
f.fields = (function() {
|
209
|
+
var _i, _len, _results;
|
210
|
+
_results = [];
|
211
|
+
for (_i = 0, _len = fields.length; _i < _len; _i++) {
|
212
|
+
j = fields[_i];
|
213
|
+
_results.push(Field.fromXML(j));
|
214
|
+
}
|
215
|
+
return _results;
|
216
|
+
})();
|
217
|
+
}
|
218
|
+
reported = xml.find("reported");
|
219
|
+
if (reported.length === 1) {
|
220
|
+
fields = reported.find("field");
|
221
|
+
f.reported = (function() {
|
222
|
+
var _i, _len, _results;
|
223
|
+
_results = [];
|
224
|
+
for (_i = 0, _len = fields.length; _i < _len; _i++) {
|
225
|
+
r = fields[_i];
|
226
|
+
_results.push(($(r)).attr("var"));
|
227
|
+
}
|
228
|
+
return _results;
|
229
|
+
})();
|
230
|
+
}
|
231
|
+
return f;
|
232
|
+
};
|
233
|
+
|
234
|
+
Form.fromHTML = function(html) {
|
235
|
+
var f, field, fields, i, instructions, item, items, j, title, _i, _j, _len, _len1, _ref, _ref1, _ref2;
|
236
|
+
html = $(html);
|
237
|
+
f = new Form({
|
238
|
+
type: html.attr("data-type")
|
239
|
+
});
|
240
|
+
title = html.find("h1").text();
|
241
|
+
if (title) {
|
242
|
+
f.title = title;
|
243
|
+
}
|
244
|
+
instructions = html.find("p").text();
|
245
|
+
if (instructions) {
|
246
|
+
f.instructions = instructions;
|
247
|
+
}
|
248
|
+
items = html.find("fieldset");
|
249
|
+
fields = helper.getHtmlFields(html);
|
250
|
+
if (items.length > 0) {
|
251
|
+
f.items = (function() {
|
252
|
+
var _i, _len, _results;
|
253
|
+
_results = [];
|
254
|
+
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
255
|
+
i = items[_i];
|
256
|
+
_results.push(Item.fromHTML(i));
|
257
|
+
}
|
258
|
+
return _results;
|
259
|
+
})();
|
260
|
+
_ref = f.items;
|
261
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
262
|
+
item = _ref[_i];
|
263
|
+
_ref1 = item.fields;
|
264
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
265
|
+
field = _ref1[_j];
|
266
|
+
if (!(_ref2 = field["var"], __indexOf.call(f.reported, _ref2) >= 0)) {
|
267
|
+
f.reported.push(field["var"]);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
} else if (fields.length > 0) {
|
272
|
+
f.fields = (function() {
|
273
|
+
var _k, _len2, _results;
|
274
|
+
_results = [];
|
275
|
+
for (_k = 0, _len2 = fields.length; _k < _len2; _k++) {
|
276
|
+
j = fields[_k];
|
277
|
+
_results.push(Field.fromHTML(j));
|
278
|
+
}
|
279
|
+
return _results;
|
280
|
+
})();
|
281
|
+
}
|
282
|
+
return f;
|
283
|
+
};
|
284
|
+
|
285
|
+
return Form;
|
286
|
+
|
287
|
+
})();
|
288
|
+
|
289
|
+
Field = (function() {
|
290
|
+
|
291
|
+
Field._types = ["boolean", "fixed", "hidden", "jid-multi", "jid-single", "list-multi", "list-single", "text-multi", "text-private", "text-single"];
|
292
|
+
|
293
|
+
Field._multiTypes = ["list-multi", "jid-multi", "text-multi", "hidden"];
|
294
|
+
|
295
|
+
function Field(opt) {
|
296
|
+
this.toHTML = __bind(this.toHTML, this);
|
297
|
+
|
298
|
+
this.toXML = __bind(this.toXML, this);
|
299
|
+
|
300
|
+
this.toJSON = __bind(this.toJSON, this);
|
301
|
+
|
302
|
+
this.addOptions = __bind(this.addOptions, this);
|
303
|
+
|
304
|
+
this.addOption = __bind(this.addOption, this);
|
305
|
+
|
306
|
+
this.addValues = __bind(this.addValues, this);
|
307
|
+
|
308
|
+
this.addValue = __bind(this.addValue, this);
|
309
|
+
|
310
|
+
var _ref, _ref1;
|
311
|
+
this.options = [];
|
312
|
+
this.values = [];
|
313
|
+
if (opt) {
|
314
|
+
if (_ref = opt.type, __indexOf.call(Field._types, _ref) >= 0) {
|
315
|
+
this.type = opt.type.toString();
|
316
|
+
}
|
317
|
+
if (opt.desc) {
|
318
|
+
this.desc = opt.desc.toString();
|
319
|
+
}
|
320
|
+
if (opt.label) {
|
321
|
+
this.label = opt.label.toString();
|
322
|
+
}
|
323
|
+
this["var"] = ((_ref1 = opt["var"]) != null ? _ref1.toString() : void 0) || "_no_var_was_defined_";
|
324
|
+
this.required = opt.required === true || opt.required === "true";
|
325
|
+
if (opt.options) {
|
326
|
+
this.addOptions(opt.options);
|
327
|
+
}
|
328
|
+
if (opt.value) {
|
329
|
+
opt.values = [opt.value];
|
330
|
+
}
|
331
|
+
if (opt.values) {
|
332
|
+
this.addValues(opt.values);
|
333
|
+
}
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
Field.prototype.type = "text-single";
|
338
|
+
|
339
|
+
Field.prototype.desc = null;
|
340
|
+
|
341
|
+
Field.prototype.label = null;
|
342
|
+
|
343
|
+
Field.prototype["var"] = "_no_var_was_defined_";
|
344
|
+
|
345
|
+
Field.prototype.required = false;
|
346
|
+
|
347
|
+
Field.prototype.addValue = function(val) {
|
348
|
+
return this.addValues([val]);
|
349
|
+
};
|
350
|
+
|
351
|
+
Field.prototype.addValues = function(vals) {
|
352
|
+
var multi, v, _ref;
|
353
|
+
multi = (_ref = this.type, __indexOf.call(Field._multiTypes, _ref) >= 0);
|
354
|
+
if (multi || (!multi && vals.length === 1)) {
|
355
|
+
this.values = __slice.call(this.values).concat(__slice.call((function() {
|
356
|
+
var _i, _len, _results;
|
357
|
+
_results = [];
|
358
|
+
for (_i = 0, _len = vals.length; _i < _len; _i++) {
|
359
|
+
v = vals[_i];
|
360
|
+
_results.push(v.toString());
|
361
|
+
}
|
362
|
+
return _results;
|
363
|
+
})()));
|
364
|
+
}
|
365
|
+
return this;
|
366
|
+
};
|
367
|
+
|
368
|
+
Field.prototype.addOption = function(opt) {
|
369
|
+
return this.addOptions([opt]);
|
370
|
+
};
|
371
|
+
|
372
|
+
Field.prototype.addOptions = function(opts) {
|
373
|
+
var o;
|
374
|
+
if (this.type === "list-single" || this.type === "list-multi") {
|
375
|
+
if (typeof opts[0] !== "object") {
|
376
|
+
opts = (function() {
|
377
|
+
var _i, _len, _results;
|
378
|
+
_results = [];
|
379
|
+
for (_i = 0, _len = opts.length; _i < _len; _i++) {
|
380
|
+
o = opts[_i];
|
381
|
+
_results.push(new Option({
|
382
|
+
value: o.toString()
|
383
|
+
}));
|
384
|
+
}
|
385
|
+
return _results;
|
386
|
+
})();
|
387
|
+
}
|
388
|
+
helper.fill(opts, this.options, Option);
|
389
|
+
}
|
390
|
+
return this;
|
391
|
+
};
|
392
|
+
|
393
|
+
Field.prototype.toJSON = function() {
|
394
|
+
var json, o, _i, _len, _ref;
|
395
|
+
json = {
|
396
|
+
type: this.type,
|
397
|
+
"var": this["var"],
|
398
|
+
required: this.required
|
399
|
+
};
|
400
|
+
if (this.desc) {
|
401
|
+
json.desc = this.desc;
|
402
|
+
}
|
403
|
+
if (this.label) {
|
404
|
+
json.label = this.label;
|
405
|
+
}
|
406
|
+
if (this.values) {
|
407
|
+
json.values = this.values;
|
408
|
+
}
|
409
|
+
if (this.options) {
|
410
|
+
json.options = [];
|
411
|
+
_ref = this.options;
|
412
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
413
|
+
o = _ref[_i];
|
414
|
+
json.options.push(o.toJSON());
|
415
|
+
}
|
416
|
+
}
|
417
|
+
return json;
|
418
|
+
};
|
419
|
+
|
420
|
+
Field.prototype.toXML = function() {
|
421
|
+
var attrs, o, v, xml, _i, _j, _len, _len1, _ref, _ref1;
|
422
|
+
attrs = {
|
423
|
+
type: this.type,
|
424
|
+
"var": this["var"]
|
425
|
+
};
|
426
|
+
if (this.label) {
|
427
|
+
attrs.label = this.label;
|
428
|
+
}
|
429
|
+
xml = $build("field", attrs);
|
430
|
+
if (this.desc) {
|
431
|
+
xml.c("desc").t(this.desc).up();
|
432
|
+
}
|
433
|
+
if (this.required) {
|
434
|
+
xml.c("required").up();
|
435
|
+
}
|
436
|
+
if (this.values) {
|
437
|
+
_ref = this.values;
|
438
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
439
|
+
v = _ref[_i];
|
440
|
+
xml.c("value").t(v.toString()).up();
|
441
|
+
}
|
442
|
+
}
|
443
|
+
if (this.options) {
|
444
|
+
_ref1 = this.options;
|
445
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
446
|
+
o = _ref1[_j];
|
447
|
+
xml.cnode(o.toXML()).up();
|
448
|
+
}
|
449
|
+
}
|
450
|
+
return xml.tree();
|
451
|
+
};
|
452
|
+
|
453
|
+
Field.prototype.toHTML = function() {
|
454
|
+
var el, k, line, o, opt, txt, val, _i, _j, _len, _len1, _ref, _ref1, _ref2;
|
455
|
+
switch (this.type.toLowerCase()) {
|
456
|
+
case 'list-single':
|
457
|
+
case 'list-multi':
|
458
|
+
el = $("<select>");
|
459
|
+
if (this.type === 'list-multi') {
|
460
|
+
el.attr('multiple', 'multiple');
|
461
|
+
}
|
462
|
+
if (this.options.length > 0) {
|
463
|
+
_ref = this.options;
|
464
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
465
|
+
opt = _ref[_i];
|
466
|
+
if (!(opt)) {
|
467
|
+
continue;
|
468
|
+
}
|
469
|
+
o = $(opt.toHTML());
|
470
|
+
_ref1 = this.values;
|
471
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
472
|
+
k = _ref1[_j];
|
473
|
+
if (k.toString() === opt.value.toString()) {
|
474
|
+
o.attr('selected', 'selected');
|
475
|
+
}
|
476
|
+
}
|
477
|
+
o.appendTo(el);
|
478
|
+
}
|
479
|
+
}
|
480
|
+
break;
|
481
|
+
case 'text-multi':
|
482
|
+
case 'jid-multi':
|
483
|
+
el = $("<textarea>");
|
484
|
+
txt = ((function() {
|
485
|
+
var _k, _len2, _ref2, _results;
|
486
|
+
_ref2 = this.values;
|
487
|
+
_results = [];
|
488
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
489
|
+
line = _ref2[_k];
|
490
|
+
_results.push(line);
|
491
|
+
}
|
492
|
+
return _results;
|
493
|
+
}).call(this)).join('\n');
|
494
|
+
if (txt) {
|
495
|
+
el.text(txt);
|
496
|
+
}
|
497
|
+
break;
|
498
|
+
case 'text-single':
|
499
|
+
case 'boolean':
|
500
|
+
case 'text-private':
|
501
|
+
case 'hidden':
|
502
|
+
case 'fixed':
|
503
|
+
case 'jid-single':
|
504
|
+
el = $("<input>");
|
505
|
+
if (this.values) {
|
506
|
+
el.val(this.values[0]);
|
507
|
+
}
|
508
|
+
switch (this.type.toLowerCase()) {
|
509
|
+
case 'text-single':
|
510
|
+
el.attr('type', 'text');
|
511
|
+
el.attr('placeholder', this.desc);
|
512
|
+
break;
|
513
|
+
case 'boolean':
|
514
|
+
el.attr('type', 'checkbox');
|
515
|
+
val = (_ref2 = this.values[0]) != null ? typeof _ref2.toString === "function" ? _ref2.toString() : void 0 : void 0;
|
516
|
+
if (val && (val === "true" || val === "1")) {
|
517
|
+
el.attr('checked', 'checked');
|
518
|
+
}
|
519
|
+
break;
|
520
|
+
case 'text-private':
|
521
|
+
el.attr('type', 'password');
|
522
|
+
break;
|
523
|
+
case 'hidden':
|
524
|
+
el.attr('type', 'hidden');
|
525
|
+
break;
|
526
|
+
case 'fixed':
|
527
|
+
el.attr('type', 'text').attr('readonly', 'readonly');
|
528
|
+
break;
|
529
|
+
case 'jid-single':
|
530
|
+
el.attr('type', 'email');
|
531
|
+
}
|
532
|
+
break;
|
533
|
+
default:
|
534
|
+
el = $("<input type='text'>");
|
535
|
+
}
|
536
|
+
el.attr('name', this["var"]);
|
537
|
+
if (this.required) {
|
538
|
+
el.attr('required', this.required);
|
539
|
+
}
|
540
|
+
return el[0];
|
541
|
+
};
|
542
|
+
|
543
|
+
Field.fromXML = function(xml) {
|
544
|
+
var o, v;
|
545
|
+
xml = $(xml);
|
546
|
+
return new Field({
|
547
|
+
type: xml.attr("type"),
|
548
|
+
"var": xml.attr("var"),
|
549
|
+
label: xml.attr("label"),
|
550
|
+
desc: xml.find("desc").text(),
|
551
|
+
required: xml.find("required").length === 1,
|
552
|
+
values: (function() {
|
553
|
+
var _i, _len, _ref, _results;
|
554
|
+
_ref = xml.find("value");
|
555
|
+
_results = [];
|
556
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
557
|
+
v = _ref[_i];
|
558
|
+
_results.push(($(v)).text());
|
559
|
+
}
|
560
|
+
return _results;
|
561
|
+
})(),
|
562
|
+
options: (function() {
|
563
|
+
var _i, _len, _ref, _results;
|
564
|
+
_ref = xml.find("option");
|
565
|
+
_results = [];
|
566
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
567
|
+
o = _ref[_i];
|
568
|
+
_results.push(Option.fromXML(o));
|
569
|
+
}
|
570
|
+
return _results;
|
571
|
+
})()
|
572
|
+
});
|
573
|
+
};
|
574
|
+
|
575
|
+
Field._htmlElementToFieldType = function(el) {
|
576
|
+
var r, type;
|
577
|
+
el = $(el);
|
578
|
+
switch (el[0].nodeName.toLowerCase()) {
|
579
|
+
case "textarea":
|
580
|
+
type = "text-multi";
|
581
|
+
break;
|
582
|
+
case "select":
|
583
|
+
if (el.attr("multiple") === "multiple") {
|
584
|
+
type = "list-multi";
|
585
|
+
} else {
|
586
|
+
type = "list-single";
|
587
|
+
}
|
588
|
+
break;
|
589
|
+
case "input":
|
590
|
+
switch (el.attr("type")) {
|
591
|
+
case "checkbox":
|
592
|
+
type = "boolean";
|
593
|
+
break;
|
594
|
+
case "email":
|
595
|
+
type = "jid-single";
|
596
|
+
break;
|
597
|
+
case "hidden":
|
598
|
+
type = "hidden";
|
599
|
+
break;
|
600
|
+
case "password":
|
601
|
+
type = "text-private";
|
602
|
+
break;
|
603
|
+
case "text":
|
604
|
+
r = el.attr("readonly") === "readonly";
|
605
|
+
if (r) {
|
606
|
+
type = "fixed";
|
607
|
+
} else {
|
608
|
+
type = "text-single";
|
609
|
+
}
|
610
|
+
}
|
611
|
+
}
|
612
|
+
return type;
|
613
|
+
};
|
614
|
+
|
615
|
+
Field.fromHTML = function(html) {
|
616
|
+
var el, f, txt, type;
|
617
|
+
html = $(html);
|
618
|
+
type = Field._htmlElementToFieldType(html);
|
619
|
+
f = new Field({
|
620
|
+
type: type,
|
621
|
+
"var": html.attr("name"),
|
622
|
+
required: html.attr("required") === "required"
|
623
|
+
});
|
624
|
+
switch (type) {
|
625
|
+
case "list-multi":
|
626
|
+
case "list-single":
|
627
|
+
f.values = (function() {
|
628
|
+
var _i, _len, _ref, _results;
|
629
|
+
_ref = html.find("option:selected");
|
630
|
+
_results = [];
|
631
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
632
|
+
el = _ref[_i];
|
633
|
+
_results.push(($(el)).val());
|
634
|
+
}
|
635
|
+
return _results;
|
636
|
+
})();
|
637
|
+
f.options = (function() {
|
638
|
+
var _i, _len, _ref, _results;
|
639
|
+
_ref = html.find("option");
|
640
|
+
_results = [];
|
641
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
642
|
+
el = _ref[_i];
|
643
|
+
_results.push(Option.fromHTML(el));
|
644
|
+
}
|
645
|
+
return _results;
|
646
|
+
})();
|
647
|
+
break;
|
648
|
+
case "text-multi":
|
649
|
+
case "jid-multi":
|
650
|
+
txt = html.text();
|
651
|
+
if (txt.trim() !== "") {
|
652
|
+
f.values = txt.split('\n');
|
653
|
+
}
|
654
|
+
break;
|
655
|
+
case 'text-single':
|
656
|
+
case 'boolean':
|
657
|
+
case 'text-private':
|
658
|
+
case 'hidden':
|
659
|
+
case 'fixed':
|
660
|
+
case 'jid-single':
|
661
|
+
if (html.val().trim() !== "") {
|
662
|
+
f.values = [html.val()];
|
663
|
+
}
|
664
|
+
}
|
665
|
+
return f;
|
666
|
+
};
|
667
|
+
|
668
|
+
return Field;
|
669
|
+
|
670
|
+
})();
|
671
|
+
|
672
|
+
Option = (function() {
|
673
|
+
|
674
|
+
function Option(opt) {
|
675
|
+
this.toHTML = __bind(this.toHTML, this);
|
676
|
+
|
677
|
+
this.toJSON = __bind(this.toJSON, this);
|
678
|
+
|
679
|
+
this.toXML = __bind(this.toXML, this);
|
680
|
+
if (opt) {
|
681
|
+
if (opt.label) {
|
682
|
+
this.label = opt.label.toString();
|
683
|
+
}
|
684
|
+
if (opt.value) {
|
685
|
+
this.value = opt.value.toString();
|
686
|
+
}
|
687
|
+
}
|
688
|
+
}
|
689
|
+
|
690
|
+
Option.prototype.label = "";
|
691
|
+
|
692
|
+
Option.prototype.value = "";
|
693
|
+
|
694
|
+
Option.prototype.toXML = function() {
|
695
|
+
return ($build("option", {
|
696
|
+
label: this.label
|
697
|
+
})).c("value").t(this.value.toString()).tree();
|
698
|
+
};
|
699
|
+
|
700
|
+
Option.prototype.toJSON = function() {
|
701
|
+
return {
|
702
|
+
label: this.label,
|
703
|
+
value: this.value
|
704
|
+
};
|
705
|
+
};
|
706
|
+
|
707
|
+
Option.prototype.toHTML = function() {
|
708
|
+
return ($("<option>")).attr('value', this.value).text(this.label || this.value)[0];
|
709
|
+
};
|
710
|
+
|
711
|
+
Option.fromXML = function(xml) {
|
712
|
+
return new Option({
|
713
|
+
label: ($(xml)).attr("label"),
|
714
|
+
value: ($(xml)).text()
|
715
|
+
});
|
716
|
+
};
|
717
|
+
|
718
|
+
Option.fromHTML = function(html) {
|
719
|
+
return new Option({
|
720
|
+
value: ($(html)).attr("value"),
|
721
|
+
label: ($(html)).text()
|
722
|
+
});
|
723
|
+
};
|
724
|
+
|
725
|
+
return Option;
|
726
|
+
|
727
|
+
})();
|
728
|
+
|
729
|
+
Item = (function() {
|
730
|
+
|
731
|
+
function Item(opts) {
|
732
|
+
this.toHTML = __bind(this.toHTML, this);
|
733
|
+
|
734
|
+
this.toJSON = __bind(this.toJSON, this);
|
735
|
+
|
736
|
+
this.toXML = __bind(this.toXML, this);
|
737
|
+
this.fields = [];
|
738
|
+
if (opts != null ? opts.fields : void 0) {
|
739
|
+
helper.fill(opts.fields, this.fields, Field);
|
740
|
+
}
|
741
|
+
}
|
742
|
+
|
743
|
+
Item.prototype.toXML = function() {
|
744
|
+
var f, xml, _i, _len, _ref;
|
745
|
+
xml = $build("item");
|
746
|
+
_ref = this.fields;
|
747
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
748
|
+
f = _ref[_i];
|
749
|
+
xml.cnode(f.toXML()).up();
|
750
|
+
}
|
751
|
+
return xml.tree();
|
752
|
+
};
|
753
|
+
|
754
|
+
Item.prototype.toJSON = function() {
|
755
|
+
var f, json, _i, _len, _ref;
|
756
|
+
json = {};
|
757
|
+
if (this.fields) {
|
758
|
+
json.fields = [];
|
759
|
+
_ref = this.fields;
|
760
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
761
|
+
f = _ref[_i];
|
762
|
+
json.fields.push(f.toJSON());
|
763
|
+
}
|
764
|
+
}
|
765
|
+
return json;
|
766
|
+
};
|
767
|
+
|
768
|
+
Item.prototype.toHTML = function() {
|
769
|
+
var f, fieldset, _i, _len, _ref;
|
770
|
+
fieldset = $("<fieldset>");
|
771
|
+
_ref = this.fields;
|
772
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
773
|
+
f = _ref[_i];
|
774
|
+
(helper.createHtmlFieldCouple(f)).appendTo(fieldset);
|
775
|
+
}
|
776
|
+
return fieldset[0];
|
777
|
+
};
|
778
|
+
|
779
|
+
Item.fromXML = function(xml) {
|
780
|
+
var f, fields;
|
781
|
+
xml = $(xml);
|
782
|
+
fields = xml.find("field");
|
783
|
+
return new Item({
|
784
|
+
fields: (function() {
|
785
|
+
var _i, _len, _results;
|
786
|
+
_results = [];
|
787
|
+
for (_i = 0, _len = fields.length; _i < _len; _i++) {
|
788
|
+
f = fields[_i];
|
789
|
+
_results.push(Field.fromXML(f));
|
790
|
+
}
|
791
|
+
return _results;
|
792
|
+
})()
|
793
|
+
});
|
794
|
+
};
|
795
|
+
|
796
|
+
Item.fromHTML = function(html) {
|
797
|
+
var f;
|
798
|
+
return new Item({
|
799
|
+
fields: (function() {
|
800
|
+
var _i, _len, _ref, _results;
|
801
|
+
_ref = helper.getHtmlFields(html);
|
802
|
+
_results = [];
|
803
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
804
|
+
f = _ref[_i];
|
805
|
+
_results.push(Field.fromHTML(f));
|
806
|
+
}
|
807
|
+
return _results;
|
808
|
+
})()
|
809
|
+
});
|
810
|
+
};
|
811
|
+
|
812
|
+
return Item;
|
813
|
+
|
814
|
+
})();
|
815
|
+
|
816
|
+
Strophe.x = {
|
817
|
+
Form: Form,
|
818
|
+
Field: Field,
|
819
|
+
Option: Option,
|
820
|
+
Item: Item
|
821
|
+
};
|
822
|
+
|
823
|
+
$form = function(opt) {
|
824
|
+
return new Strophe.x.Form(opt);
|
825
|
+
};
|
826
|
+
|
827
|
+
$field = function(opt) {
|
828
|
+
return new Strophe.x.Field(opt);
|
829
|
+
};
|
830
|
+
|
831
|
+
$opt = function(opt) {
|
832
|
+
return new Strophe.x.Option(opt);
|
833
|
+
};
|
834
|
+
|
835
|
+
$item = function(opts) {
|
836
|
+
return new Strophe.x.Item(opts);
|
837
|
+
};
|
838
|
+
|
839
|
+
Strophe.addConnectionPlugin('x', {
|
840
|
+
init: function(conn) {
|
841
|
+
Strophe.addNamespace('DATA', 'jabber:x:data');
|
842
|
+
if (conn.disco) {
|
843
|
+
return conn.disco.addFeature(Strophe.NS.DATA);
|
844
|
+
}
|
845
|
+
},
|
846
|
+
parseFromResult: function(result) {
|
847
|
+
var _ref;
|
848
|
+
if (result.nodeName.toLowerCase() === "x") {
|
849
|
+
return Form.fromXML(result);
|
850
|
+
} else {
|
851
|
+
return Form.fromXML((_ref = ($(result)).find("x")) != null ? _ref[0] : void 0);
|
852
|
+
}
|
853
|
+
}
|
854
|
+
});
|