Mercurial > xmpp-account-manager
annotate util.js @ 63:ee1df80a1715 default tip
Nicer-looking input form
author | mathieui |
---|---|
date | Sun, 24 May 2020 14:19:29 +0200 |
parents | 6d861d881b96 |
children |
rev | line source |
---|---|
60
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
1 // SPDX-License-Identifier: AGPL-3.0-only |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
2 /* |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
3 * Copyright © 2018-2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
4 * Copyright © 2020 Mathieu Pasquet <mathieui@mathieui.net> |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
5 * |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
6 * Released under GNU AGPL v3 only, read the file 'LICENSE' for more information. |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
7 */ |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
8 |
48
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
9 'use strict'; |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
10 |
3
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
11 const NS = { |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
12 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
|
13 roster: 'jabber:iq:roster', |
3
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
14 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
|
15 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
|
16 dataforms: 'jabber:x:data', |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 }; |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
26 |
1
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 function nsResolver(prefix) { |
3
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
28 return NS[prefix] || null; |
1
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 } |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 function parseXPath(elem, xpath, result) |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 { |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 if (result === undefined) |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 return value.singleNodeValue; |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 return value; |
d6df73b466f6
Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 } |
3
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
40 |
25
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
41 function parseXPathText(elem, xpath) |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
42 { |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
43 const value = parseXPath(elem, xpath); |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
44 if (value === null) |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
45 return null; |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
46 return value.textContent; |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
47 } |
d9da5c3e305d
Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
48 |
3
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
49 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
|
50 return $iq({type: 'set'}) |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
51 .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
|
52 .c('configure', {node: node}) |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
53 .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
|
54 .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
|
55 .c('value') |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
56 .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
|
57 .up() |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
58 .up() |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
59 .c('field', {'var': key}) |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
60 .c('value') |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
61 .t(value) |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
62 .up() |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
63 .up(); |
5aa1bf7154b0
Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
64 } |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
65 |
30
9ba4f8cc32f1
Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
66 function parseErrorIq(iq) { |
9ba4f8cc32f1
Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
67 // 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
|
68 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
|
69 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
|
70 return null; |
9ba4f8cc32f1
Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
71 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
|
72 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
|
73 return null; |
9ba4f8cc32f1
Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
74 const text = error.lastChild; |
32
b15e1581c3d4
Allow iq error to not have a <text/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
75 if (text === condition) |
b15e1581c3d4
Allow iq error to not have a <text/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
76 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
|
77 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
|
78 return null; |
32
b15e1581c3d4
Allow iq error to not have a <text/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
79 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
|
80 } |
9ba4f8cc32f1
Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
81 |
52
2f45bee88b47
Add pubsub#access_model retrieval for the avatar node.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
48
diff
changeset
|
82 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
|
83 { |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
84 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
|
85 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
|
86 .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
|
87 .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
|
88 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
|
89 }); |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
90 } |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
91 |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
92 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
|
93 { |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
94 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
|
95 if (fields === null) |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
96 return reject('no fields'); |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
97 let access_model = null; |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
98 while (true) { |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
99 const field = fields.iterateNext(); |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
100 if (field === null) |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
101 break; |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 access_model = value.textContent; |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
106 } |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
107 } |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
108 return resolve(access_model); |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
109 } |
021185105e2f
Move the node configuration retrieval to a util promise.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
32
diff
changeset
|
110 |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
111 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
|
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 = 'spinner.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; |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
117 } |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
118 |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 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
|
123 spinner.title = ''; |
15
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
124 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
|
125 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
|
126 spinner.hidden = true; |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
127 }, 1000); |
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 |
30
9ba4f8cc32f1
Display the returned error in the title of the spinner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
130 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
|
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.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
|
134 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
|
135 spinner.hidden = false; |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
136 } |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
137 |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 spinner.hidden = true; |
3eed9fe0bd7c
End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4
diff
changeset
|
142 } |