sass-site/source/assets/js/components/sass-syntax-switcher.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-01-09 20:10:02 +01:00
$(function () {
$('.code-example').each(function () {
2023-01-09 21:15:35 +01:00
const figure = $(this);
2023-01-06 22:40:29 +01:00
figure.tabs({
active: 0,
2023-01-09 20:10:02 +01:00
beforeActivate: function (event, ui) {
2023-01-06 22:40:29 +01:00
// If multiple panels are visible, the CSS tab shouldn't be clickable.
2023-06-15 19:47:55 +02:00
return !(
ui.newPanel.hasClass('css') && allPanels.filter(':visible').length > 1
);
2023-01-06 22:40:29 +01:00
},
2023-01-09 20:10:02 +01:00
activate: function (event, ui) {
2023-01-06 22:40:29 +01:00
if (ui.newPanel.hasClass('css')) {
figure.addClass('ui-tabs-panel-css-is-active');
} else {
figure.removeClass('ui-tabs-panel-css-is-active');
}
allPanels.removeClass('ui-tabs-panel-previously-active');
2023-01-09 20:10:02 +01:00
ui.oldPanel
.addClass('ui-tabs-panel-inactive')
.addClass('ui-tabs-panel-previously-active');
2023-01-06 22:40:29 +01:00
ui.newPanel.removeClass('ui-tabs-panel-inactive');
allPanels.css('display', '');
2023-01-09 20:10:02 +01:00
},
2023-01-06 22:40:29 +01:00
});
2023-01-09 21:15:35 +01:00
const allPanels = figure.find('.ui-tabs-panel');
2023-01-06 22:40:29 +01:00
allPanels.css('display', '');
});
// Switch ALL the tabs (Sass/SCSS) together
2023-01-09 21:15:35 +01:00
let noRecursion = false;
const jqA = $('a.ui-tabs-anchor'),
jqASass = jqA.filter(":contains('Sass')").on('click', function () {
2023-01-09 20:10:02 +01:00
if (!noRecursion) {
2023-01-06 22:40:29 +01:00
noRecursion = true;
2023-01-09 21:15:35 +01:00
jqASass.not(this).trigger('click');
2023-01-06 22:40:29 +01:00
noRecursion = false;
}
}),
2023-01-09 21:15:35 +01:00
jqASCSS = jqA.filter(":contains('SCSS')").on('click', function () {
2023-01-09 20:10:02 +01:00
if (!noRecursion) {
2023-01-06 22:40:29 +01:00
noRecursion = true;
2023-01-09 21:15:35 +01:00
jqASCSS.not(this).trigger('click');
2023-01-06 22:40:29 +01:00
noRecursion = false;
}
2023-01-09 20:10:02 +01:00
});
2023-01-06 22:40:29 +01:00
});