Last active
March 6, 2024 23:51
-
-
Save carlosesteven/0a089920493dfbc0c167892c7af855c5 to your computer and use it in GitHub Desktop.
Implementation of carousel in php/html. It receives 2 parameters: time and links (links must be encoded in base64 and separated by ,). Example: path/grafana-carousel.php?time=...&links=...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function formatLinks($inputString) { | |
$linksArray = explode(",", $inputString); | |
foreach ($linksArray as &$link) { | |
$link = trim($link); | |
$link = '"' . $link . '"'; | |
} | |
$formattedLinks = implode(", ", $linksArray); | |
return $formattedLinks; | |
} | |
if ( $_GET && isset($_GET["time"]) && isset($_GET["links"])) | |
{ | |
$time = $_GET["time"] * 1000; | |
$links = formatLinks( | |
base64_decode( | |
$_GET["links"] | |
) | |
); | |
}else{ | |
echo "Error: no se anexarón los parametros (time o links) en la petición."; | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Carousel Dinamico Grafana</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<style type="text/css"> | |
body, html { | |
margin: 0; | |
padding: 0; | |
height: 100%; | |
overflow: hidden; | |
background: #FFFFFF; | |
} | |
.content { | |
position: absolute; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
top: 0px; | |
} | |
</style> | |
</head> | |
<body> | |
<iframe | |
class="content" | |
id="iframe1" | |
src="" | |
width="100%" | |
height="100%" | |
frameborder="0"></iframe> | |
<iframe | |
class="content" | |
id="iframe2" | |
src="" | |
width="100%" | |
height="100%" | |
frameborder="0"></iframe> | |
<script type="text/javascript"> | |
const TIMEOUT = <?php echo $time; ?>; | |
const dashboards_list = [<?php echo $links; ?>]; | |
const iframe_1 = document.getElementById("iframe1"); | |
const iframe_2 = document.getElementById("iframe2"); | |
var index = 0; | |
iframe_1.src = dashboards_list[index]; | |
iframe_1.style.zIndex = 1; | |
iframe_2.style.zIndex = 0; | |
function load_next_url() { | |
index = (index + 1) % dashboards_list.length; | |
select_bottom().src = dashboards_list[index]; | |
setTimeout(load_next_url, TIMEOUT); | |
setTimeout(change_order, 3000); | |
} | |
function select_bottom() { | |
if ( | |
parseInt(iframe_1.style.zIndex, 10) > | |
parseInt(iframe_2.style.zIndex, 10) | |
) { | |
return iframe_2; | |
} else { | |
return iframe_1; | |
} | |
} | |
function change_order() { | |
if ( | |
parseInt(iframe_1.style.zIndex, 10) > | |
parseInt(iframe_2.style.zIndex, 10) | |
) { | |
iframe_1.style.zIndex = 0; | |
iframe_2.style.zIndex = 1; | |
} else { | |
iframe_1.style.zIndex = 1; | |
iframe_2.style.zIndex = 0; | |
} | |
} | |
setTimeout(load_next_url, TIMEOUT); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment