hugo-theme-relearn/layouts/partials/topbar-button.html

49 lines
1.9 KiB
HTML
Raw Normal View History

2023-09-11 22:10:03 +00:00
{{- $page := .page }}
{{- $class := .class | default "" }}
{{- $href := (trim .href " ") | default "" }}
{{- $target := .target | default "" }}
{{- $type := .type | default "" }}
{{- $isDisabled := not $href }}
{{- $isButton := false }}
{{- if or (not $href) (strings.HasPrefix $href "javascript:") }}
{{- $isButton = true }}
{{- $href = substr $href (len "javascript:") }}
{{- if not $type }}
{{- $type = "button" }}
{{- end }}
{{- else if and (eq (len $target) 0) (or (strings.HasPrefix $href "http://") (strings.HasPrefix $href "https://") ) }}
{{- $target = "_blank" }}
{{- if isset $page.Site.Params "externallinktarget" }}
{{- $target = $page.Site.Params.externalLinkTarget }}
{{- end }}
{{- end }}
{{- $title := (trim .title " ") | default "" }}
{{- $icon := (trim .icon " ") | default "" }}
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- $content := .content }}
<div class="topbar-button {{ $class }}">
2023-09-11 22:10:03 +00:00
{{- if $isDisabled }}
<span class="topbar-button-control">
2023-09-11 22:10:03 +00:00
{{- else if $isButton }}
<button class="topbar-button-control"{{ if $href }} onclick="{{ $href | safeJS }}"{{ end }}{{ if gt (len $type) 0 }} type="{{ $type }}"{{ end }} title="{{ $title }}">
2023-09-11 22:10:03 +00:00
{{- else }}
<a class="topbar-button-control"{{ if $href }} href="{{ $href }}"{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}{{ end }} title="{{ $title }}">
2023-09-11 22:10:03 +00:00
{{- end }}
<i class="{{ $icon }}"></i>
2023-09-11 22:10:03 +00:00
{{- if $isDisabled }}
</span>
2023-09-11 22:10:03 +00:00
{{- else if $isButton }}
</button>
2023-09-11 22:10:03 +00:00
{{- else }}
</a>
{{- end }}
{{- if $content }}
<div class="topbar-button-flyout">
<div class="topbar-button-flyout-wrapper">
{{- $content }}
</div>
</div>
2023-09-11 22:10:03 +00:00
{{- end }}
</div>