homepage/layouts/shortcodes/on-off.html
6543 6c9a2fe2e0
add imgping to on-off shortcode
now if a image can be downloadet the service stateis on else off
2019-07-14 00:30:39 +02:00

27 lines
810 B
HTML

{{ $mode := .Get 0 }}{{ $opt := .Get 1 }}
{{ $img_on := ( printf "%s%s" $.Page.Site.BaseURL "img/on-off/switch-on-icon_smal.png" )}}
{{ $img_off := ( printf "%s%s" $.Page.Site.BaseURL "img/on-off/switch-off-icon_smal.png" )}}
{{ if eq $mode "on" }}
<img src="{{ $img_on }}" alt="On">
{{ else if eq $mode "off"}}
<img src="{{ $img_off }}" alt="Off">
{{ else if eq $mode "imgping" }}
{{ with $opt }}
{{ $id := md5 $opt }}
<img id={{ $id }} src="{{ $img_off }}" alt="Off">
<script language="JavaScript">
var imgping = new Image();
imgping.src = '{{ $opt }}';
if(imgping.height>0){
document.getElementById("{{ $id }}").outerHTML ='<img src="{{ $img_on }}" alt="On">';
}
</script>
{{ else }}
Ned URL to image
{{ end }}
{{ else }}
???
{{ end }}