forked from google/docsy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabpane.html
172 lines (144 loc) · 6.07 KB
/
tabpane.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{{/* Check parameter types */ -}}
{{ $tpPersistAttrName := "data-td-tp-persist" -}}
{{ with .Get "langEqualsHeader" -}}
{{ if ne ( printf "%T" . ) "bool" -}}
{{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "langEqualsHeader" (printf "%T" .) $.Position -}}
{{ end -}}
{{ end -}}
{{ with .Get "text" -}}
{{ if ne ( printf "%T" . ) "bool" -}}
{{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "text" (printf "%T" .) $.Position -}}
{{ end -}}
{{ end -}}
{{ $_persistLang := .Get "persistLang" -}}
{{ if and (ne $_persistLang nil) (ne $_persistLang "") -}}
{{ if ne ( printf "%T" $_persistLang ) "bool" -}}
{{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "persistLang" (printf "%T" $_persistLang) $.Position -}}
{{ else -}}
{{ warnf "Shortcode %q parameter `persistLang` is deprecated, use `persist` instead: %s" $.Name $.Position -}}
{{ end -}}
{{ end -}}
{{ $_persist := .Get "persist" -}}
{{ with $_persist -}}
{{ $matched := findRE "^(header|lang|disabled)$" . -}}
{{ if not $matched -}}
{{ errorf "Shortcode %q: parameter %q should be one of 'header', 'lang', or 'disabled'; but got %s. Error position: %s" $.Name "persist" $_persist $.Position -}}
{{ end -}}
{{ end -}}
{{ with .Get "right" -}}
{{ if ne ( printf "%T" . ) "bool" -}}
{{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "right" (printf "%T" .) $.Position -}}
{{ end -}}
{{ end -}}
{{/* Set values given defined within tabpane */ -}}
{{ $langPane := default "" ($.Get "lang") -}}
{{ $hloptionsPane := default "" ($.Get "highlight") -}}
{{ $textPane := default false ($.Get "text") -}}
{{ $langEqualsHeader := default false ($.Get "langEqualsHeader") -}}
{{ $deprecatedPersistLang := $_persistLang | default true -}}
{{ $persistKeyKind := $_persist | default (cond (eq $langPane "") "lang" "header") -}}
{{ $persistTab := and $deprecatedPersistLang (ne $persistKeyKind "disabled") -}}
{{ $rightPane := default false ($.Get "right") -}}
{{ $activeSet := false -}}
{{/* Scratchpad gets populated through call to .Inner */ -}}
{{ .Inner -}}
{{ $duplicate := false -}}
{{ $duplicateKey := "" -}}
{{ $persistKeyList := slice -}}
{{ $tabPaneOrdinal := .Ordinal -}}
{{/* Nav tabs */ -}}
<ul class="nav nav-tabs{{ if $rightPane }} justify-content-end{{ end }}" id="tabs-{{- $tabPaneOrdinal -}}" role="tablist">
{{ range $index, $element := $.Scratch.Get "tabs" -}}
{{ $disabled := false -}}
{{ with $element.disabled -}}
{{ $disabled = . -}}
{{ end -}}
{{ $lang := $langPane -}}
{{ if $langEqualsHeader -}}
{{ $lang = $element.header -}}
{{ end -}}
{{ with $element.language -}}
{{ $lang = . -}}
{{ end -}}
{{ $persistKey := "" -}}
{{ if eq $persistKeyKind "lang" -}}
{{ $persistKey = $lang -}}
{{ else if eq $persistKeyKind "header" -}}
{{ $persistKey = $element.header -}}
{{ end -}}
{{ $persistKey = $persistKey | lower -}}
{{/* Check for duplicate tab-persistence keys */ -}}
{{ if and $persistTab $persistKey -}}
{{ if in $persistKey $persistKeyList -}}
{{ $duplicate = true -}}
{{ $duplicateKey = $persistKey -}}
{{ $persistTab = false -}}
{{ else -}}
{{ $persistKeyList = $persistKeyList | append $persistKey -}}
{{ end -}}
{{ end -}}
{{ $rightpush := false -}}
{{ with $element.rightpush -}}
{{ $rightpush = . -}}
{{ end -}}
<li class="nav-item{{ if $rightpush }} ms-auto{{ end -}}">
{{/* Generate the IDs for the <a> and the <div> elements */ -}}
{{ $tabid := printf "tabs-%02v-%v-tab" $tabPaneOrdinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $tabPaneOrdinal $index | anchorize -}}
<button class="nav-link
{{- if and ( not $activeSet ) ( not $disabled ) }} active{{ end -}}
{{ if $disabled }} disabled{{ end -}}"
id="{{ $tabid }}" data-bs-toggle="tab" data-bs-target="#{{ $entryid }}" role="tab"
{{ if and $persistTab $persistKey -}}
{{ printf "%s=%q " $tpPersistAttrName $persistKey | safeHTMLAttr -}}
{{ end -}}
aria-controls="{{- $entryid -}}" aria-selected="{{- cond ( and ( not $activeSet ) ( not $disabled ) ) "true" "false" -}}">
{{ index . "header" | markdownify }}
</button>
</li>
{{- if not $disabled -}}
{{ $activeSet = true -}}
{{ end -}}
{{ end }}
</ul>
{{ if $duplicate -}}
{{ warnf "Shortcode %q: duplicate tab-persistence key %q detected, disabling persistance to avoid multiple tab display. Position: %s" $.Name $duplicateKey $.Position -}}
{{ end -}}
{{ $activeSet = false -}}
{{/* Tab panes */ -}}
<div class="tab-content" id="tabs-{{ $tabPaneOrdinal }}-content">
{{- range $index, $element := $.Scratch.Get "tabs" -}}
{{ $lang := $langPane -}}
{{ if $langEqualsHeader -}}
{{ $lang = $element.header -}}
{{ end -}}
{{ with $element.language -}}
{{ $lang = . -}}
{{ end -}}
{{ $disabled := false -}}
{{ with $element.disabled -}}
{{ $disabled = . -}}
{{ end -}}
{{ $hloptions := $hloptionsPane -}}
{{ with $element.highlight -}}
{{ $hloptions = . -}}
{{ end -}}
{{ $text := $textPane -}}
{{ with $element.text -}}
{{ $text = . }}
{{ end -}}
{{ $tabid := printf "tabs-%02v-%v-tab" $tabPaneOrdinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $tabPaneOrdinal $index | anchorize }}
<div class="{{ if $text }}tab-body {{end}}tab-pane fade{{ if and ( not $activeSet ) ( not $disabled ) }} show active{{ end }}"
id="{{ $entryid }}" role="tabpanel" aria-labelled-by="{{ $tabid }}" tabindex="{{ $tabPaneOrdinal }}">
{{ if $text -}}
{{ index . "content" -}}
{{ else -}}
{{ highlight (trim (index . "content") "\r\n") $lang $hloptions -}}
{{ end }}
</div>
{{- if not $disabled -}}
{{ $activeSet = true -}}
{{ end -}}
{{ end }}
</div>