Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion assets/scss/homepage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,11 @@
display: block;
}

& h4#{&}__title {
& p#{&}__title {
margin-top: 0;
font-size: 1.125em;
font-family: bca6d3310b5c9dae1dae416e8abc8405,helvetica,arial,sans-serif;
line-height: 1.2;
}

p:last-child {
Expand Down
4 changes: 2 additions & 2 deletions layouts/shortcodes/blocks/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{ $modifiedSvg := replaceRE `(<svg)(.*?>)` "$1 aria-hidden=\"true\"$2" $svgContent 1 }}
{{ $modifiedSvg | safeHTML }}
</div>
<h4 class="homepage-card__title">{{ .Title }}</h4>
<p class="homepage-card__title">{{ .Title }}</p>
{{ if $description }}
<p class="homepage-card__text">{{ $description }}</p>
{{ else }}
Expand All @@ -56,7 +56,7 @@ <h4 class="homepage-card__title">{{ .Title }}</h4>
{{ end }}
</div>
{{ end }}
<h4 class="homepage-card__title">{{ $title }}</h4>
<p class="homepage-card__title">{{ $title }}</p>

{{ if eq .Page.File.Ext "md" }}
{{ .Inner | .Page.RenderString }}
Expand Down
240 changes: 130 additions & 110 deletions static/js/prism-accessibility.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,134 @@
// (C) 2023 GoodData Corporation

(function ($) {
$(document).ready(function () {
// Set initial ARIA attributes and variables
var $codeBlock = $('.code-toolbar');
var $codeBlockToolBar = $('.toolbar');
var $codeBlockContent = $('pre');
var $accordionOptions = $('.accordion-options');
var $defaultThreshold = 200;

$codeBlock.attr('aria-expanded', 'false');

// Find all copy buttons
$('.copy-to-clipboard-button').each(function() {
var button = $(this);

// Add ARIA attributes for better accessibility
button.attr('aria-label', 'Copy code to clipboard');
});

// Expand buttons and expand code block options
$codeBlockToolBar.each(function() {
var nearestCodeBlock = $(this).closest($codeBlock);
var nearestCodeBlockContent = nearestCodeBlock.find($codeBlockContent);
var nearestAccordionOptions = nearestCodeBlock.closest($accordionOptions);
var threshold = nearestAccordionOptions.data('threshold') ? nearestAccordionOptions.data('threshold') : $defaultThreshold;

var expandButton = $('<button class="expand-button">Expand</button>');
if (nearestCodeBlockContent.outerHeight(true) > threshold && !nearestAccordionOptions.hasClass('accordion-options--not-collapsible')) {
$(this).prepend(expandButton);
nearestCodeBlock.css('max-height', threshold + 'px');
nearestCodeBlock.addClass('overflowing');
expandButton.attr('aria-label', 'Expand code block');
expandButton.wrap('<div class="toolbar-item"></div>');
}
});

var $expandButton = $('.expand-button');

$expandButton.on('click', function() {
var nearestCodeBlock = $(this).closest($codeBlock);
var nearestCodeBlockContent = $(this).closest($codeBlock).find($codeBlockContent);
var nearestAccordionOptions = nearestCodeBlock.closest($accordionOptions);
var threshold = nearestAccordionOptions.data('threshold') ? nearestAccordionOptions.data('threshold') : $defaultThreshold;

// Toggle expanded state
nearestCodeBlock.toggleClass('expanded');
nearestCodeBlock.attr('aria-expanded', nearestCodeBlock.hasClass('expanded'));
$(this).attr('aria-expanded', nearestCodeBlock.hasClass('expanded'));
$(this).attr('aria-label', nearestCodeBlock.hasClass('expanded') ? 'Collapse code block' : 'Expand code block');
$(this).text(nearestCodeBlock.hasClass('expanded') ? 'Collapse' : 'Expand');
$(this).toggleClass('expand-button--expanded');

// Adjust max-height based on expanded state
if (nearestCodeBlock.hasClass('expanded')) {
nearestCodeBlock.css('max-height', nearestCodeBlockContent.outerHeight(true) + 'px');
} else {
nearestCodeBlock.css('max-height', threshold + 'px');
$('html, body').animate({
scrollTop: nearestCodeBlock.offset().top - 300
}, 300);
nearestCodeBlockContent.animate({
scrollLeft: 0
}, 300);
}
});

// Add global escape key handler for code blocks
$(document).on('keydown', function(e) {
if (e.key === 'Escape') {
// Find any focused copy buttons and blur them
$('.copy-to-clipboard-button:focus').blur();
}
});

// Accessibility for buttons
$codeBlockToolBar.find('button').each(function() {
var button = $(this);

button.attr('tabindex', '0');

button.on('keydown', function(e) {
// Allow Escape key to dismiss the button
if (e.key === 'Escape') {
button.blur();
e.preventDefault();
}

// Allow Enter or Space to activate the button
if (e.key === 'Enter' || e.key === ' ') {
button.click();
e.preventDefault();
}
});
});

// Make the toolbar stay visible when tabbing into it
$('div.code-toolbar > .toolbar').each(function() {
var toolbar = $(this);

toolbar.on('focusin', function() {
toolbar.css('opacity', '1');
});

toolbar.on('focusout', function(e) {
// Only hide if focus moved outside the toolbar
if (!$.contains(toolbar[0], e.relatedTarget)) {
toolbar.css('opacity', '');
}
});
});
$(document).ready(function () {
// Set initial ARIA attributes and variables
var $codeBlock = $(".code-toolbar");
var $codeBlockToolBar = $(".toolbar");
var $codeBlockContent = $("pre");
var $accordionOptions = $(".accordion-options");
var $defaultThreshold = 200;

$codeBlock.attr("aria-expanded", "false");

// Expand buttons and expand code block options
$codeBlockToolBar.each(function () {
var nearestCodeBlock = $(this).closest($codeBlock);
var nearestCodeBlockContent = nearestCodeBlock.find($codeBlockContent);
var nearestAccordionOptions = nearestCodeBlock.closest($accordionOptions);
var threshold = nearestAccordionOptions.data("threshold")
? nearestAccordionOptions.data("threshold")
: $defaultThreshold;

var expandButton = $('<button class="expand-button">Expand</button>');
if (
nearestCodeBlockContent.outerHeight(true) > threshold &&
!nearestAccordionOptions.hasClass("accordion-options--not-collapsible")
) {
$(this).prepend(expandButton);
nearestCodeBlock.css("max-height", threshold + "px");
nearestCodeBlock.addClass("overflowing");
expandButton.attr("aria-label", "Expand code block");
expandButton.wrap('<div class="toolbar-item"></div>');
}
});

var $expandButton = $(".expand-button");

$expandButton.on("click", function () {
var nearestCodeBlock = $(this).closest($codeBlock);
var nearestCodeBlockContent = $(this)
.closest($codeBlock)
.find($codeBlockContent);
var nearestAccordionOptions = nearestCodeBlock.closest($accordionOptions);
var threshold = nearestAccordionOptions.data("threshold")
? nearestAccordionOptions.data("threshold")
: $defaultThreshold;

// Toggle expanded state
nearestCodeBlock.toggleClass("expanded");
nearestCodeBlock.attr(
"aria-expanded",
nearestCodeBlock.hasClass("expanded"),
);
$(this).attr("aria-expanded", nearestCodeBlock.hasClass("expanded"));
$(this).attr(
"aria-label",
nearestCodeBlock.hasClass("expanded")
? "Collapse code block"
: "Expand code block",
);
$(this).text(
nearestCodeBlock.hasClass("expanded") ? "Collapse" : "Expand",
);
$(this).toggleClass("expand-button--expanded");

// Adjust max-height based on expanded state
if (nearestCodeBlock.hasClass("expanded")) {
nearestCodeBlock.css(
"max-height",
nearestCodeBlockContent.outerHeight(true) + "px",
);
} else {
nearestCodeBlock.css("max-height", threshold + "px");
$("html, body").animate(
{
scrollTop: nearestCodeBlock.offset().top - 300,
},
300,
);
nearestCodeBlockContent.animate(
{
scrollLeft: 0,
},
300,
);
}
});

// Add global escape key handler for code blocks
$(document).on("keydown", function (e) {
if (e.key === "Escape") {
// Find any focused copy buttons and blur them
$(".copy-to-clipboard-button:focus").blur();
}
});

// Accessibility for buttons
$codeBlockToolBar.find("button").each(function () {
var button = $(this);

button.attr("tabindex", "0");

button.on("keydown", function (e) {
// Allow Escape key to dismiss the button
if (e.key === "Escape") {
button.blur();
e.preventDefault();
}

// Allow Enter or Space to activate the button
if (e.key === "Enter" || e.key === " ") {
button.click();
e.preventDefault();
}
});
});

// Make the toolbar stay visible when tabbing into it
$("div.code-toolbar > .toolbar").each(function () {
var toolbar = $(this);

toolbar.on("focusin", function () {
toolbar.css("opacity", "1");
});

toolbar.on("focusout", function (e) {
// Only hide if focus moved outside the toolbar
if (!$.contains(toolbar[0], e.relatedTarget)) {
toolbar.css("opacity", "");
}
});
});
})(jQuery);
});
})(jQuery);
Loading