xmppify 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/javascripts/xmpp/index.js +0 -0
  8. data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
  9. data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
  10. data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
  11. data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
  12. data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
  13. data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
  14. data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
  15. data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
  16. data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
  17. data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
  18. data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
  19. data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
  20. data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
  21. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
  22. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
  23. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
  24. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
  25. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
  26. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
  27. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
  28. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
  29. data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
  30. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
  31. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
  32. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
  33. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
  34. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
  35. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
  36. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
  37. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
  38. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
  39. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
  40. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
  41. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
  42. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
  43. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
  44. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
  45. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
  46. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
  47. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
  48. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
  49. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
  50. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
  51. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
  52. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
  53. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
  54. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
  55. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
  56. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
  57. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
  58. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
  59. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
  60. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
  61. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
  62. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
  63. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
  64. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
  65. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
  66. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
  67. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
  68. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
  69. data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
  70. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
  71. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
  72. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
  73. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
  74. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
  75. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
  76. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
  77. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
  78. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
  79. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
  80. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
  81. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
  82. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
  83. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
  84. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
  85. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
  86. data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
  87. data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
  88. data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
  89. data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
  90. data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
  91. data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
  92. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
  93. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
  94. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
  95. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
  96. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
  97. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
  98. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
  99. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
  100. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
  101. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
  102. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
  103. data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
  104. data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
  105. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
  106. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
  107. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
  108. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
  109. data/app/assets/stylesheets/xmpp/index.css +0 -0
  110. data/app/controllers/omniauth_callbacks_controller.rb +15 -0
  111. data/app/controllers/ruby_bosh.rb +221 -0
  112. data/app/models/identity.rb +3 -0
  113. data/app/models/user.rb +40 -0
  114. data/bin/rails +8 -0
  115. data/db/migrate/20140329065635_create_users.rb +10 -0
  116. data/db/migrate/20140329070238_create_identities.rb +11 -0
  117. data/lib/xmppify/version.rb +3 -0
  118. data/lib/xmppify.rb +6 -0
  119. data/xmppify.gemspec +23 -0
  120. metadata +197 -0
@@ -0,0 +1,443 @@
1
+ # Copyright (c) Markus Kohlhase, 2011
2
+
3
+ # a little helper
4
+ helper =
5
+
6
+ fill: (src, target, klass) -> for f in src
7
+ target.push if f instanceof klass then f else new klass f
8
+
9
+ createHtmlFieldCouple: (f) ->
10
+ div = $ "<div>"
11
+ id = "Strophe.x.Field-#{ f.type }-#{f.var}"
12
+ div
13
+ .append("<label for='#{id}'>#{f.label or ''}</label>")
14
+ .append( $(f.toHTML()).attr("id", id ) )
15
+ .append("<br />")
16
+ div.children()
17
+
18
+ getHtmlFields: (html) ->
19
+ html = $ html
20
+ [html.find("input")..., html.find("select")..., html.find("textarea")...]
21
+
22
+ class Form
23
+
24
+ @_types: ["form","submit","cancel","result"]
25
+
26
+ constructor: (opt) ->
27
+
28
+ @fields = []
29
+ @items = []
30
+ @reported = []
31
+
32
+ if opt
33
+ @type = opt.type if opt.type in Form._types
34
+ @title = opt.title
35
+ @instructions = opt.instructions
36
+
37
+ helper.fill = (src, target, klass) -> for f in src
38
+ target.push if f instanceof klass then f else new klass f
39
+
40
+ if opt.fields
41
+ helper.fill opt.fields, @fields, Field if opt.fields
42
+ else if opt.items
43
+ helper.fill opt.items, @items, Item if opt.items
44
+ for i in @items
45
+ for f in i.fields
46
+ @reported.push f.var if not (f.var in @reported)
47
+
48
+ type: "form"
49
+ title: null
50
+ instructions: null
51
+
52
+ toXML: =>
53
+
54
+ xml = ($build "x", { xmlns: "jabber:x:data", @type })
55
+
56
+ xml.c("title").t(@title.toString()).up() if @title
57
+ xml.c("instructions").t(@instructions.toString()).up() if @instructions
58
+
59
+ if @fields.length > 0
60
+ for f in @fields
61
+ xml.cnode(f.toXML()).up()
62
+
63
+ else if @items.length > 0
64
+ xml.c("reported")
65
+
66
+ for r in @reported
67
+ xml.c("field",{var: r}).up()
68
+ xml.up()
69
+
70
+ for i in @items
71
+ xml.cnode(i.toXML()).up()
72
+
73
+ xml.tree()
74
+
75
+ toJSON: =>
76
+ json = {@type}
77
+ json.title = @title if @title
78
+ json.instructions = @instructions if @instructions
79
+
80
+ if @fields.length > 0
81
+ json.fields = []
82
+ for f in @fields
83
+ json.fields.push f.toJSON()
84
+ else if @items.length > 0
85
+ json.items = []
86
+ json.reported = @reported
87
+ json.items.push i.toJSON() for i in @items
88
+
89
+ json
90
+
91
+
92
+ toHTML: =>
93
+
94
+ form = $("<form data-type='#{@type}'>")
95
+ form.append("<h1>#{@title}</h1>") if @title
96
+ form.append("<p>#{@instructions}</p>") if @instructions
97
+
98
+ if @fields.length > 0
99
+ (helper.createHtmlFieldCouple f).appendTo form for f in @fields
100
+
101
+ else if @items.length > 0
102
+ ($ i.toHTML()).appendTo form for i in @items
103
+
104
+ form[0]
105
+
106
+ @fromXML: (xml) ->
107
+ xml = $ xml
108
+ f = new Form
109
+ type: xml.attr "type"
110
+
111
+ title = xml.find "title"
112
+ if title.length is 1
113
+ f.title = title.text()
114
+
115
+ instr = xml.find "instructions"
116
+ if instr.length is 1
117
+ f.instructions = instr.text()
118
+
119
+ fields = xml.find "field"
120
+ items = xml.find "item"
121
+
122
+ if items.length > 0
123
+ f.items = ( Item.fromXML i for i in items)
124
+
125
+ else if fields.length > 0
126
+ f.fields = ( Field.fromXML j for j in fields)
127
+
128
+ reported = xml.find "reported"
129
+ if reported.length is 1
130
+ fields = reported.find "field"
131
+ f.reported = ( ($ r).attr("var") for r in fields)
132
+ f
133
+
134
+ @fromHTML: (html) ->
135
+ html = $ html
136
+
137
+
138
+ f = new Form
139
+ type: html.attr "data-type"
140
+
141
+ title = html.find("h1").text()
142
+ f.title = title if title
143
+
144
+ instructions = html.find("p").text()
145
+ f.instructions = instructions if instructions
146
+
147
+ items = html.find "fieldset"
148
+ fields = helper.getHtmlFields html
149
+
150
+ if items.length > 0
151
+ f.items = ( Item.fromHTML i for i in items)
152
+
153
+ for item in f.items
154
+ for field in item.fields
155
+ f.reported.push field.var if not (field.var in f.reported)
156
+
157
+ else if fields.length > 0
158
+ f.fields = ( Field.fromHTML j for j in fields )
159
+
160
+ f
161
+
162
+
163
+ class Field
164
+
165
+ @_types: ["boolean","fixed","hidden","jid-multi","jid-single","list-multi",
166
+ "list-single", "text-multi", "text-private", "text-single"]
167
+
168
+ @_multiTypes = ["list-multi", "jid-multi", "text-multi", "hidden"]
169
+
170
+ constructor: (opt) ->
171
+
172
+ @options = []
173
+ @values = []
174
+
175
+ if opt
176
+ @type = opt.type.toString() if opt.type in Field._types
177
+ @desc = opt.desc.toString() if opt.desc
178
+ @label = opt.label.toString() if opt.label
179
+ @var = opt.var?.toString() or "_no_var_was_defined_"
180
+ @required = opt.required is true or opt.required is "true"
181
+ @addOptions opt.options if opt.options
182
+ opt.values = [ opt.value ] if opt.value
183
+ @addValues opt.values if opt.values
184
+
185
+ type: "text-single"
186
+ desc: null
187
+ label: null
188
+ var: "_no_var_was_defined_"
189
+ required: false
190
+
191
+ addValue: (val) => @addValues [val]
192
+
193
+ addValues: (vals) =>
194
+ multi = @type in Field._multiTypes
195
+ if multi or ( not multi and vals.length is 1 )
196
+ @values = [@values..., (v.toString() for v in vals)...]
197
+ @
198
+
199
+ addOption: (opt) => @addOptions [opt]
200
+
201
+ addOptions: (opts) =>
202
+ if @type is "list-single" or @type is "list-multi"
203
+ if typeof opts[0] isnt "object"
204
+ opts = (new Option { value: o.toString() } for o in opts)
205
+ helper.fill opts, @options, Option
206
+ @
207
+
208
+ toJSON: =>
209
+ json = { @type, @var, @required }
210
+ json.desc = @desc if @desc
211
+ json.label = @label if @label
212
+ json.values = @values if @values
213
+
214
+ if @options
215
+ json.options = []
216
+ for o in @options
217
+ json.options.push o.toJSON()
218
+ json
219
+
220
+ toXML: =>
221
+ attrs = {@type, @var}
222
+ attrs.label = @label if @label
223
+
224
+ xml = ($build "field", attrs )
225
+
226
+ xml.c("desc").t(@desc).up() if @desc
227
+ xml.c("required").up() if @required
228
+
229
+ if @values
230
+ for v in @values
231
+ xml.c("value").t(v.toString()).up()
232
+
233
+ if @options
234
+ for o in @options
235
+ xml.cnode(o.toXML()).up()
236
+ xml.tree()
237
+
238
+ toHTML: =>
239
+
240
+ switch @type.toLowerCase()
241
+
242
+
243
+ when 'list-single', 'list-multi'
244
+
245
+ el = ($ "<select>")
246
+ el.attr 'multiple', 'multiple' if @type is 'list-multi'
247
+
248
+ if @options.length > 0
249
+ for opt in @options when opt
250
+ o = $ opt.toHTML()
251
+ for k in @values
252
+ o.attr 'selected', 'selected' if k.toString() is opt.value.toString()
253
+ o.appendTo el
254
+
255
+ when 'text-multi', 'jid-multi'
256
+ el = $ "<textarea>"
257
+ txt = (line for line in @values).join '\n'
258
+ el.text txt if txt
259
+
260
+ when 'text-single', 'boolean','text-private', 'hidden', 'fixed', 'jid-single'
261
+
262
+ el = $ "<input>"
263
+ el.val @values[0] if @values
264
+
265
+ switch @type.toLowerCase()
266
+
267
+ when 'text-single'
268
+ el.attr 'type', 'text'
269
+ el.attr 'placeholder', @desc
270
+
271
+ when 'boolean'
272
+ el.attr 'type', 'checkbox'
273
+ val = @values[0]?.toString?()
274
+ el.attr('checked','checked') if val and ( val is "true" or val is "1" )
275
+
276
+ when 'text-private'
277
+ el.attr 'type', 'password'
278
+
279
+ when 'hidden'
280
+ el.attr 'type', 'hidden'
281
+
282
+ when 'fixed'
283
+ el.attr('type','text').attr('readonly','readonly')
284
+
285
+ when 'jid-single'
286
+ el.attr 'type', 'email'
287
+
288
+ else
289
+ el = $ "<input type='text'>"
290
+
291
+ el.attr('name', @var )
292
+ el.attr('required', @required ) if @required
293
+ el[0]
294
+
295
+ @fromXML: (xml) ->
296
+ xml = $ xml
297
+ new Field
298
+ type: xml.attr "type"
299
+ var: xml.attr "var"
300
+ label: xml.attr "label"
301
+ desc: xml.find("desc").text()
302
+ required: (xml.find("required").length is 1)
303
+ values: ( ($ v).text() for v in xml.find "value" )
304
+ options: ( Option.fromXML o for o in xml.find "option" )
305
+
306
+ @_htmlElementToFieldType: (el) ->
307
+
308
+ el = $ el
309
+
310
+ switch el[0].nodeName.toLowerCase()
311
+
312
+ when "textarea"
313
+ type = "text-multi" # or jid-multi
314
+
315
+ when "select"
316
+
317
+ if el.attr("multiple") is "multiple"
318
+ type = "list-multi"
319
+ else
320
+ type = "list-single"
321
+
322
+ when "input"
323
+ switch el.attr "type"
324
+ when "checkbox"
325
+ type = "boolean"
326
+ when "email"
327
+ type = "jid-single"
328
+ when "hidden"
329
+ type = "hidden"
330
+ when "password"
331
+ type = "text-private"
332
+ when "text"
333
+ r = el.attr("readonly") is "readonly"
334
+ if r
335
+ type = "fixed"
336
+ else
337
+ type = "text-single"
338
+ type
339
+
340
+ @fromHTML: (html) ->
341
+
342
+ html = $ html
343
+ type = Field._htmlElementToFieldType html
344
+
345
+ f = new Field
346
+ type:type
347
+ var: html.attr "name"
348
+ required: (html.attr("required") is "required")
349
+
350
+ switch type
351
+ when "list-multi","list-single"
352
+ f.values = ( ($ el).val() for el in html.find "option:selected" )
353
+ f.options= ( Option.fromHTML el for el in html.find "option" )
354
+ when "text-multi","jid-multi"
355
+ txt = html.text()
356
+ f.values = txt.split('\n') if txt.trim() isnt ""
357
+ when 'text-single', 'boolean','text-private', 'hidden', 'fixed', 'jid-single'
358
+ f.values = [ html.val() ] if html.val().trim() isnt ""
359
+
360
+ f
361
+
362
+ class Option
363
+
364
+ constructor: (opt) ->
365
+ if opt
366
+ @label = opt.label.toString() if opt.label
367
+ @value = opt.value.toString() if opt.value
368
+
369
+ label: ""
370
+ value: ""
371
+
372
+ toXML: => ($build "option", { label: @label })
373
+ .c("value")
374
+ .t(@value.toString())
375
+ .tree()
376
+
377
+ toJSON: => { @label, @value }
378
+
379
+ toHTML: => ($ "<option>").attr('value', @value ).text( @label or @value )[0]
380
+
381
+ @fromXML: (xml) ->
382
+ new Option { label: ($ xml).attr("label"), value: ($ xml).text() }
383
+
384
+ @fromHTML: (html) ->
385
+ new Option { value: ($ html).attr("value"), label: ($ html).text() }
386
+
387
+ class Item
388
+
389
+ constructor: (opts) ->
390
+
391
+ @fields = []
392
+ helper.fill opts.fields, @fields, Field if opts?.fields
393
+
394
+ toXML: =>
395
+ xml = $build "item"
396
+ for f in @fields
397
+ xml.cnode( f.toXML() ).up()
398
+ xml.tree()
399
+
400
+ toJSON: =>
401
+ json = {}
402
+ if @fields
403
+ json.fields = []
404
+ for f in @fields
405
+ json.fields.push f.toJSON()
406
+ json
407
+
408
+ toHTML: =>
409
+ fieldset = $ "<fieldset>"
410
+ (helper.createHtmlFieldCouple f).appendTo fieldset for f in @fields
411
+ fieldset[0]
412
+
413
+ @fromXML: (xml) ->
414
+ xml = $ xml
415
+ fields = xml.find "field"
416
+ new Item
417
+ fields: ( Field.fromXML f for f in fields)
418
+
419
+ @fromHTML: (html) ->
420
+ new Item fields: ( Field.fromHTML f for f in helper.getHtmlFields(html))
421
+
422
+ Strophe.x =
423
+ Form: Form
424
+ Field: Field
425
+ Option:Option
426
+ Item:Item
427
+
428
+ $form = (opt) -> new Strophe.x.Form opt
429
+ $field = (opt) -> new Strophe.x.Field opt
430
+ $opt = (opt) -> new Strophe.x.Option opt
431
+ $item = (opts) -> new Strophe.x.Item opts
432
+
433
+ Strophe.addConnectionPlugin 'x',
434
+
435
+ init : (conn) ->
436
+ Strophe.addNamespace 'DATA', 'jabber:x:data'
437
+ conn.disco.addFeature Strophe.NS.DATA if conn.disco
438
+
439
+ parseFromResult: (result) ->
440
+ if result.nodeName.toLowerCase() is "x"
441
+ Form.fromXML result
442
+ else
443
+ Form.fromXML ($ result).find("x")?[0]