Skip to content

Commit decf0f3

Browse files
DOC-5804 added binder link to example tabs
1 parent b4ddd1c commit decf0f3

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

layouts/partials/tabbed-clients-example.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848
{{ if hasPrefix $language "java" }}{{ $language = "java"}}{{ end }}
4949
{{ $params := dict "language" $language "contentPath" $examplePath "options" $options }}
5050
{{ $content := partial "tabs/source.html" $params }}
51-
{{ $tabs = $tabs | append (dict "title" $client "language" $client "quickstartSlug" $quickstartSlug "content" $content "sourceUrl" (index $example "sourceUrl")) }}
51+
52+
{{/* Extract binderId if it exists */}}
53+
{{ $binderId := index $example "binderId" }}
54+
55+
{{ $tabs = $tabs | append (dict "title" $client "language" $client "quickstartSlug" $quickstartSlug "content" $content "sourceUrl" (index $example "sourceUrl") "binderId" $binderId) }}
5256
{{ end }}
5357
{{ end }}
5458

layouts/partials/tabs/wrapper.html

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
{{ end }}
3434
</select>
3535
</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">
3743
<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"
3844
title="Toggle visibility" data-codetabs-id="{{ $id }}" onclick="toggleVisibleLinesForCodetabs(this)">
3945
<svg class="visibility-icon-on" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" fill="currentColor">
@@ -61,10 +67,13 @@
6167
{{ $pid := printf "panel_%s" $tid }}
6268
{{ $dataLang := replace (or (index $tab "language") "redis-cli") "C#" "dotnet" }}
6369
{{ $dataLang := replace $dataLang "." "-" }}
70+
{{ $binderId := index $tab "binderId" }}
6471

6572
<div class="panel {{ if ne $i 0 }}panel-hidden{{ end }} w-full mt-0 {{ if not $showFooter}}pb-8{{end}}"
6673
id="{{ $pid }}"
6774
data-lang="{{ $dataLang }}"
75+
{{ if $binderId }}data-binder-id="{{ $binderId }}"{{ end }}
76+
data-codetabs-id="{{ $id }}"
6877
role="tabpanel"
6978
tabindex="0"
7079
aria-labelledby="lang-select-{{ $id }}">
@@ -139,3 +148,62 @@
139148

140149
</div>
141150
<!-- 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

Comments
 (0)