|
33 | 33 | {{ end }} |
34 | 34 | </select> |
35 | 35 | </div> |
36 | | - <div class="flex items-center gap-2"> |
| 36 | + |
| 37 | + {{/* BinderHub "Run in browser" link - shown conditionally based on current tab's binderId */}} |
| 38 | + <div id="binder-link-container-{{ $id }}" class="flex items-center ml-4"> |
| 39 | + {{/* Link will be shown/hidden by JavaScript based on selected tab */}} |
| 40 | + </div> |
| 41 | + |
| 42 | + <div class="flex items-center gap-2 ml-2"> |
37 | 43 | <button tabindex="1" class="visibility-button text-neutral-400 hover:text-slate-100 bg-slate-600 h-7 w-7 p-1 rounded rounded-mx" |
38 | 44 | title="Toggle visibility" data-codetabs-id="{{ $id }}" onclick="toggleVisibleLinesForCodetabs(this)"> |
39 | 45 | <svg class="visibility-icon-on" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" fill="currentColor"> |
|
61 | 67 | {{ $pid := printf "panel_%s" $tid }} |
62 | 68 | {{ $dataLang := replace (or (index $tab "language") "redis-cli") "C#" "dotnet" }} |
63 | 69 | {{ $dataLang := replace $dataLang "." "-" }} |
| 70 | + {{ $binderId := index $tab "binderId" }} |
64 | 71 |
|
65 | 72 | <div class="panel {{ if ne $i 0 }}panel-hidden{{ end }} w-full mt-0 {{ if not $showFooter}}pb-8{{end}}" |
66 | 73 | id="{{ $pid }}" |
67 | 74 | data-lang="{{ $dataLang }}" |
| 75 | + {{ if $binderId }}data-binder-id="{{ $binderId }}"{{ end }} |
| 76 | + data-codetabs-id="{{ $id }}" |
68 | 77 | role="tabpanel" |
69 | 78 | tabindex="0" |
70 | 79 | aria-labelledby="lang-select-{{ $id }}"> |
|
139 | 148 |
|
140 | 149 | </div> |
141 | 150 | <!-- spellchecker-enable --> |
| 151 | + |
| 152 | +<script> |
| 153 | +(function() { |
| 154 | + // Initialize BinderHub link for this codetabs instance |
| 155 | + const codetabsId = '{{ $id }}'; |
| 156 | + const container = document.getElementById('binder-link-container-' + codetabsId); |
| 157 | + const langSelect = document.getElementById('lang-select-' + codetabsId); |
| 158 | + |
| 159 | + function updateBinderLink() { |
| 160 | + if (!container || !langSelect) return; |
| 161 | + |
| 162 | + // Get the currently selected tab index |
| 163 | + const selectedOption = langSelect.options[langSelect.selectedIndex]; |
| 164 | + const tabIndex = parseInt(selectedOption.getAttribute('data-index')); |
| 165 | + |
| 166 | + // Find the corresponding panel |
| 167 | + const panels = document.querySelectorAll('[data-codetabs-id="' + codetabsId + '"].panel'); |
| 168 | + if (!panels || tabIndex >= panels.length) return; |
| 169 | + |
| 170 | + const currentPanel = panels[tabIndex]; |
| 171 | + const binderId = currentPanel.getAttribute('data-binder-id'); |
| 172 | + |
| 173 | + // Clear existing content |
| 174 | + container.innerHTML = ''; |
| 175 | + |
| 176 | + // If binderId exists, create and show the link |
| 177 | + if (binderId) { |
| 178 | + const binderUrl = 'https://redis.io/binder/v2/gh/redis/binder-launchers/' + |
| 179 | + binderId + |
| 180 | + '?urlpath=%2Fdoc%2Ftree%2Fdemo.ipynb'; |
| 181 | + |
| 182 | + const link = document.createElement('a'); |
| 183 | + link.href = binderUrl; |
| 184 | + link.target = '_blank'; |
| 185 | + link.rel = 'noopener noreferrer'; |
| 186 | + link.className = 'text-xs text-slate-300 hover:text-white hover:underline whitespace-nowrap flex items-center gap-1'; |
| 187 | + link.title = 'Run this example in an interactive Jupyter notebook'; |
| 188 | + |
| 189 | + // Add Binder icon (rocket/play icon) |
| 190 | + link.innerHTML = ` |
| 191 | + <svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"> |
| 192 | + <path d="M8 5v14l11-7z"/> |
| 193 | + </svg> |
| 194 | + <span>Run in browser</span> |
| 195 | + `; |
| 196 | + |
| 197 | + container.appendChild(link); |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + // Initialize on page load |
| 202 | + updateBinderLink(); |
| 203 | + |
| 204 | + // Update when language changes (in addition to existing language change handler) |
| 205 | + if (langSelect) { |
| 206 | + langSelect.addEventListener('change', updateBinderLink); |
| 207 | + } |
| 208 | +})(); |
| 209 | +</script> |
0 commit comments