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