comparison util.js @ 3:5aa1bf7154b0

Add a simple PEP node viewer and editor.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 22 Dec 2018 02:23:38 +0100
parents d6df73b466f6
children 5e97e1808a35
comparison
equal deleted inserted replaced
2:db033e5eabcb 3:5aa1bf7154b0
1 const NS = {
2 xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
3 disco_items: 'http://jabber.org/protocol/disco#items',
4 disco_info: 'http://jabber.org/protocol/disco#info',
5 dataforms: 'jabber:x:data',
6 pubsub: 'http://jabber.org/protocol/pubsub',
7 pubsub_owner: 'http://jabber.org/protocol/pubsub#owner',
8 avatar_metadata: 'urn:xmpp:avatar:metadata',
9 avatar_data: 'urn:xmpp:avatar:data',
10 nickname: 'http://jabber.org/protocol/nick',
11 };
12
1 function nsResolver(prefix) { 13 function nsResolver(prefix) {
2 return { 14 return NS[prefix] || null;
3 xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
4 pubsub: 'http://jabber.org/protocol/pubsub',
5 avatar_metadata: 'urn:xmpp:avatar:metadata',
6 avatar_data: 'urn:xmpp:avatar:data',
7 nickname: 'http://jabber.org/protocol/nick',
8 }[prefix] || null;
9 } 15 }
10 16
11 function parseXPath(elem, xpath, result) 17 function parseXPath(elem, xpath, result)
12 { 18 {
13 if (result === undefined) 19 if (result === undefined)
15 const value = elem.getRootNode().evaluate(xpath, elem, nsResolver, result, null); 21 const value = elem.getRootNode().evaluate(xpath, elem, nsResolver, result, null);
16 if (result == XPathResult.FIRST_ORDERED_NODE_TYPE) 22 if (result == XPathResult.FIRST_ORDERED_NODE_TYPE)
17 return value.singleNodeValue; 23 return value.singleNodeValue;
18 return value; 24 return value;
19 } 25 }
26
27 function configurePEPField(node, key, value, cb, err_cb) {
28 return $iq({type: 'set'})
29 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
30 .c('configure', {node: node})
31 .c('x', {xmlns: 'jabber:x:data', type: 'submit'})
32 .c('field', {'var': 'FORM_TYPE', type: 'hidden'})
33 .c('value')
34 .t('http://jabber.org/protocol/pubsub#node_config')
35 .up()
36 .up()
37 .c('field', {'var': key})
38 .c('value')
39 .t(value)
40 .up()
41 .up();
42 }