Mercurial > prosody-modules
comparison mod_invites_page/static/invite.js @ 5719:18bae78282a6
mod_invites_page: Move the JS script to its own file
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 16 Nov 2023 16:16:55 +0100 |
parents | |
children | 40558231ab7d |
comparison
equal
deleted
inserted
replaced
5718:8cd617c0b701 | 5719:18bae78282a6 |
---|---|
1 (function () { | |
2 // If QR lib loaded ok, show QR button on desktop devices | |
3 if(window.QRCode) { | |
4 new QRCode(document.getElementById("qr-invite-page"), document.location.href); | |
5 document.getElementById('qr-button-container').classList.remove("d-none"); | |
6 } | |
7 | |
8 // Detect current platform and show/hide appropriate clients | |
9 if(window.platform) { | |
10 var platform_friendly = null; | |
11 var platform_classname = null; | |
12 | |
13 switch(platform.os.family) { | |
14 case "Ubuntu": | |
15 case "Linux": | |
16 case "Fedora": | |
17 case "Red Hat": | |
18 case "SuSE": | |
19 platform_friendly = platform.os.family + " (Linux)"; | |
20 platform_classname = "linux"; | |
21 break; | |
22 case "Windows Phone": | |
23 platform_friendly = "Windows Phone"; | |
24 platform_classname = "windows-phone"; | |
25 break; | |
26 default: | |
27 if(platform.os.family.startsWith("Windows")) { | |
28 platform_friendly = "Windows"; | |
29 platform_classname = "windows"; | |
30 } else { | |
31 platform_friendly = platform.os.family; | |
32 platform_classname = platform_friendly.toLowerCase(); | |
33 } | |
34 } | |
35 | |
36 if(platform_friendly && platform_classname) { | |
37 if(document.querySelectorAll('.client-card .client-platform-badge-'+platform_classname).length == 0) { | |
38 // No clients recognised for this platform, do nothing | |
39 return; | |
40 } | |
41 // Hide clients not for this platform | |
42 const client_cards = document.getElementsByClassName('client-card'); | |
43 for (let card of client_cards) { | |
44 if (card.classList.contains('app-platform-'+platform_classname)) | |
45 card.classList.add('supported-platform'); | |
46 else if (!card.classList.contains('app-platform-web')) | |
47 card.hidden = true; | |
48 const badges = card.querySelectorAll('.client-platform-badge'); | |
49 for (let badge of badges) { | |
50 if (badge.classList.contains('client-platform-badge-'+platform_classname)) { | |
51 badge.classList.add("badge-success"); | |
52 badge.classList.remove("badge-info"); | |
53 } else { | |
54 badge.classList.add("badge-secondary"); | |
55 badge.classList.remove("badge-info"); | |
56 } | |
57 } | |
58 } | |
59 const show_all_clients_button_container = document.getElementById('show-all-clients-button-container'); | |
60 show_all_clients_button_container.querySelector('.platform-name').innerHTML = platform_friendly; | |
61 show_all_clients_button_container.classList.remove("d-none"); | |
62 document.getElementById('show-all-clients-button').addEventListener('click', function (e) { | |
63 for (let card of client_cards) | |
64 card.hidden = false; | |
65 show_all_clients_button_container.hidden = true; | |
66 e.preventDefaults(); | |
67 }); | |
68 } | |
69 } | |
70 })(); |