annotate util.js @ 52:2f45bee88b47

Add pubsub#access_model retrieval for the avatar node.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 23 May 2020 21:24:34 +0200
parents 021185105e2f
children 6d861d881b96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
1 'use strict';
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
2
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
3 const NS = {
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
4 xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
5 roster: 'jabber:iq:roster',
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
6 disco_items: 'http://jabber.org/protocol/disco#items',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
7 disco_info: 'http://jabber.org/protocol/disco#info',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
8 dataforms: 'jabber:x:data',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
9 pubsub: 'http://jabber.org/protocol/pubsub',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
10 pubsub_owner: 'http://jabber.org/protocol/pubsub#owner',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
11 avatar_metadata: 'urn:xmpp:avatar:metadata',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
12 avatar_data: 'urn:xmpp:avatar:data',
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
13 nickname: 'http://jabber.org/protocol/nick',
25
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
14 vcard4: 'urn:ietf:params:xml:ns:vcard-4.0',
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 15
diff changeset
15 mam: 'urn:xmpp:mam:2',
24
6c620e9f7d2c Add support for retrieving all MAM messages, and for downloading it in a XEP-0227-like format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 19
diff changeset
16 forward: 'urn:xmpp:forward:0',
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
17 };
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
18
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 function nsResolver(prefix) {
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
20 return NS[prefix] || null;
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 }
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 function parseXPath(elem, xpath, result)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 if (result === undefined)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 result = XPathResult.FIRST_ORDERED_NODE_TYPE;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 const value = elem.getRootNode().evaluate(xpath, elem, nsResolver, result, null);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 if (result == XPathResult.FIRST_ORDERED_NODE_TYPE)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 return value.singleNodeValue;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 return value;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 }
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
32
25
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
33 function parseXPathText(elem, xpath)
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
34 {
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
35 const value = parseXPath(elem, xpath);
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
36 if (value === null)
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
37 return null;
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
38 return value.textContent;
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
39 }
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
40
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
41 function configurePEPField(node, key, value, cb, err_cb) {
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
42 return $iq({type: 'set'})
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
43 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
44 .c('configure', {node: node})
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
45 .c('x', {xmlns: 'jabber:x:data', type: 'submit'})
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
46 .c('field', {'var': 'FORM_TYPE', type: 'hidden'})
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
47 .c('value')
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
48 .t('http://jabber.org/protocol/pubsub#node_config')
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
49 .up()
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
50 .up()
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
51 .c('field', {'var': key})
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
52 .c('value')
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
53 .t(value)
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
54 .up()
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
55 .up();
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
56 }
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
57
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
58 function parseErrorIq(iq) {
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
59 // TODO: actually check that it is the first one.
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
60 const error = iq.firstChild;
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
61 if (error.namespaceURI !== 'jabber:client' || error.localName !== 'error')
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
62 return null;
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
63 const condition = error.firstChild;
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
64 if (condition.namespaceURI !== 'urn:ietf:params:xml:ns:xmpp-stanzas')
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
65 return null;
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
66 const text = error.lastChild;
32
b15e1581c3d4 Allow iq error to not have a <text/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
67 if (text === condition)
b15e1581c3d4 Allow iq error to not have a <text/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
68 return condition.localName;
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
69 if (text.namespaceURI !== 'urn:ietf:params:xml:ns:xmpp-stanzas' || text.localName !== 'text')
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
70 return null;
32
b15e1581c3d4 Allow iq error to not have a <text/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
71 return condition.localName + ': ' + text.textContent;
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
72 }
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
73
52
2f45bee88b47 Add pubsub#access_model retrieval for the avatar node.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 48
diff changeset
74 function retrieveConfiguration(connection, node)
48
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
75 {
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
76 return new Promise((resolve, reject) => {
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
77 const iq = $iq({type: 'get'})
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
78 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
52
2f45bee88b47 Add pubsub#access_model retrieval for the avatar node.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 48
diff changeset
79 .c('configure', {node: node});
48
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
80 connection.sendIQ(iq, onNodeConfigure.bind(null, resolve, reject), reject);
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
81 });
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
82 }
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
83
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
84 function onNodeConfigure(resolve, reject, result_iq)
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
85 {
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
86 const fields = parseXPath(result_iq, './pubsub_owner:pubsub/pubsub_owner:configure/dataforms:x/dataforms:field', XPathResult.UNORDERED_NODE_ITERATOR_TYPE);
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
87 if (fields === null)
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
88 return reject('no fields');
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
89 let access_model = null;
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
90 while (true) {
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
91 const field = fields.iterateNext();
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
92 if (field === null)
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
93 break;
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
94 const var_ = field.getAttributeNS(null, 'var');
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
95 if (var_ === 'pubsub#access_model') {
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
96 const value = parseXPath(field, './dataforms:value');
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
97 access_model = value.textContent;
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
98 }
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
99 }
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
100 return resolve(access_model);
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
101 }
021185105e2f Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
102
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
103 function displaySpinner(spinner) {
19
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
104 if ('timeoutid' in spinner.dataset)
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
105 clearTimeout(spinner.dataset.timeoutid);
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
106 spinner.src = 'spinner.svg';
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
107 spinner.title = '';
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
108 spinner.hidden = false;
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
109 }
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
110
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
111 function spinnerOk(spinner) {
19
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
112 if ('timeoutid' in spinner.dataset)
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
113 clearTimeout(spinner.dataset.timeoutid);
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
114 spinner.src = 'ok.svg';
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
115 spinner.title = '';
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
116 spinner.hidden = false;
19
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
117 spinner.dataset.timeoutid = setTimeout(function () {
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
118 spinner.hidden = true;
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
119 }, 1000);
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
120 }
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
121
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
122 function spinnerError(spinner, title) {
19
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
123 if ('timeoutid' in spinner.dataset)
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
124 clearTimeout(spinner.dataset.timeoutid);
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
125 spinner.src = 'error.svg';
30
9ba4f8cc32f1 Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
126 spinner.title = title ? title : '';
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
127 spinner.hidden = false;
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
128 }
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
129
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
130 function hideSpinner(spinner) {
19
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
131 if ('timeoutid' in spinner.dataset)
bde4f0bbfe69 Clear a spinner’s timeout on change if it had been set previously.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
132 clearTimeout(spinner.dataset.timeoutid);
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
133 spinner.hidden = true;
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
134 }