Skip to content

Commit 79f52cf

Browse files
authored
Merge pull request #168 from valters-tomsons/download-icon-from-ua
Set download button icon depending on browser's user agent
2 parents 1d6abd0 + 7ccea82 commit 79f52cf

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

public_html/index.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,31 @@
8484
<div class="build-btn-button">
8585
<div class="build-ico-button">
8686
<div class="build-ico-os">
87-
<img alt="Windows" src="img/icons/list/os-windows-11.png" style='height: 100%; width: 100%; object-fit: contain'/>
88-
<img alt="Linux" src="img/icons/list/os-linux-na.png" style='height: 100%; width: 100%; object-fit: contain; display:none;'/>
89-
<img alt="macOS" src="img/icons/list/os-macos.png" style='height: 100%; width: 100%; object-fit: contain; display:none;'/>
90-
<img alt="FreeBSD" src="img/icons/list/os-bsd.png" style='height: 100%; width: 100%; object-fit: contain; display:none;'/>
87+
<?php
88+
89+
$os_icons = [
90+
'Windows' => 'img/icons/list/os-windows-11.png',
91+
'Linux' => 'img/icons/list/os-linux-na.png',
92+
'macOS' => 'img/icons/list/os-macos.png',
93+
'FreeBSD' => 'img/icons/list/os-bsd.png',
94+
];
95+
96+
$os_name = $os_icon = null;
97+
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
98+
99+
if (str_contains($ua, 'FreeBSD')) { $os_name = 'FreeBSD'; $os_icon = $os_icons['FreeBSD']; }
100+
elseif (str_contains($ua, 'Windows')) { $os_name = 'Windows'; $os_icon = $os_icons['Windows']; }
101+
elseif (str_contains($ua, 'Mac OS X')) { $os_name = 'macOS'; $os_icon = $os_icons['macOS']; }
102+
elseif (str_contains($ua, 'Linux') && !str_contains($ua, 'Android')) { $os_name = 'Linux'; $os_icon = $os_icons['Linux']; }
103+
?>
104+
105+
<?php if ($os_icon !== null): ?>
106+
<img alt="<?= $os_name ?>" src="<?= $os_icon ?>" style='height: 100%; width: 100%; object-fit: contain'/>
107+
<?php else: ?>
108+
<?php $first = true; foreach ($os_icons as $name => $icon): ?>
109+
<img alt="<?= $name ?>" src="<?= $icon ?>" style='height: 100%; width: 100%; object-fit: contain<?= $first ? '' : '; display:none' ?>'/>
110+
<?php $first = false; endforeach; ?>
111+
<?php endif; ?>
91112
</div>
92113
</div>
93114
<a href="/download">

public_html/lib/js/inc-anim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ $(document).ready(function () {
5454
];
5555

5656
cyclers.forEach(function ({ selector, interval }) {
57+
if ($(`${selector} img`).length <= 1) return;
5758
$(`${selector} img:gt(0)`).hide();
5859
setInterval(function () {
5960
$(`${selector} :first-child`).fadeOut(200)
6061
.next().fadeIn(200).end().appendTo(selector);
6162
}, interval);
6263
});
63-
6464
});
6565
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6666
// Theme menu fade-out and fade-in animations

0 commit comments

Comments
 (0)