add imgping to on-off shortcode

now if a image can be downloadet the service stateis on else off
This commit is contained in:
6543 2019-07-14 00:30:39 +02:00
parent 1ace323411
commit 6c9a2fe2e0
Signed by: 6543
GPG Key ID: A1CA74D27FD13271

View File

@ -1,8 +1,26 @@
{{ $mode := .Get 0 }}
{{ $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="{{ .Page.Site.BaseURL }}img/on-off/switch-on-icon_smal.png" alt="On">
<img src="{{ $img_on }}" alt="On">
{{ else if eq $mode "off"}}
<img src="{{ .Page.Site.BaseURL }}img/on-off/switch-off-icon_smal.png" alt="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}}
{{ end }}