Skip to content

Commit

Permalink
ESY-6582 Tab can include src
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lilja committed Mar 4, 2025
1 parent a739fe2 commit ec0f1b9
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 260 deletions.
4 changes: 4 additions & 0 deletions _includes/example-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Example 1

The src content for **Example 1**
4 changes: 4 additions & 0 deletions _includes/example-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Example 2

The src content for **Example 2**
4 changes: 4 additions & 0 deletions _includes/example-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Example 3

The src content for **Example 3**
25 changes: 0 additions & 25 deletions _includes/example.md

This file was deleted.

126 changes: 77 additions & 49 deletions _includes/tabs.html
Original file line number Diff line number Diff line change
@@ -1,78 +1,106 @@
{%- comment -%}
**Parameters
tab_list(required): An array with items having the attributes title(required), content_text (required),
content_src(optional)
active_tab_index(optional): Index of the tab to be active by default
content_src(optional), mark_with_star (optional)
default_tab_index(optional): Index of the tab to be active by default, starting from 1
{%- endcomment -%}

{% assign tabs = include.tab_list %}
{% assign active_tab_index = include.active_tab_index | default: 1 %}
{% assign max_index = include.tab_list | size | minus:1 %}
{% assign default_tab_index = include.default_tab_index | minus:1 | at_least:0 | at_most:max_index %}

<div id="tabs-container" class="tabs">
<ul>
{% for tab in tabs %}
<li class="tab-title {% if forloop.index == active_tab_index %}active{% endif %}">
<a id="tab-title-{{ forloop.index }}">{{ tab.title }}</a>
<li id="{{ tab.title | replace: ' ', '_' | replace: '.', '' }}"
class="{% if forloop.index0 == default_tab_index %}active{% endif %}">
<a id="{{ forloop.index0 }}">{{ tab.title }}{% if tab.mark_with_star %}*{% endif %}</a>
</li>
{% endfor %}
</ul>
</div>

{% for tab in tabs %}
<p id="tab-content-{{ forloop.index }}" class="tab-content {% unless forloop.index == active_tab_index %}d-none{% endunless %}">
{{ tab.content_text }}
{% if tab.content_src %}
<div id="tab-src-{{ forloop.index }}" class="tab-src {% unless forloop.index == active_tab_index %}d-none{% endunless %}">
{% capture sourced_content %}
{% include {{tab.content_src}} %}
{% endcapture %}
{{ sourced_content | markdownify }}
</div>
{% endif %}
<p id="tab-content-text">
</p>
<div id="tab-content-src">
</div>
{% for tab in tabs %}
{% if tab.content_src %}
<div class="tab-src">
{% capture sourced_content %}
{% include {{tab.content_src}} %}
{% endcapture %}
{{ sourced_content | markdownify }}
</div>
{% endif %}
{% endfor %}

<script>
$("#tabs-container ul li a").click(function () {
const tabTitles = $(".tab-title");
for (let index = 0; index < tabTitles.length; index++) {
const tab = tabTitles[index];
tab.classList.remove("active");
var defaultIndex = {{ default_tab_index | jsonify }};
const allTabs = {{ tabs | jsonify }};
const compiledTabTextContents = allTabs?.map(tab => tab.content_text);
const compiledTabSrcContents = $(".tab-src");
</script>

<script>
$(document).ready(function () {
let tabSrcContents = [];
for (let index = 0; index < compiledTabSrcContents.length; index++) {
tabSrcContents[index] = compiledTabSrcContents[index].innerHTML;
}
$(".tab-src").remove();

$("#tabs-container ul li a").click(function () {
const tabTitles = $("#tabs-container ul li");
for (let index = 0; index < tabTitles.length; index++) {
tabTitles[index].classList.remove("active");
}

$(this).parent().addClass("active");
const tabContentId = $(this).attr("id").replace("tab-title-", "tab-content-");
const tabSrcId = $(this).attr("id").replace("tab-title-", "tab-src-");
$(this).parent().addClass("active");
populateTabContent(this.id);
});

let tabContents = $(".tab-content");

for (let index = 0; index < tabContents.length; index++) {
const tabContent = tabContents[index];
function populateTabContent(index) {
if (compiledTabTextContents && compiledTabTextContents[index]) {
$("#tab-content-text").html(compiledTabTextContents[index]);
} else {
$("#tab-content-text").html("");
}

switch (tabContent.id) {
case tabContentId:
tabContent.classList.remove("d-none");
break;
default:
if (!tabContent.classList.contains("d-none"))
tabContent.classList.add("d-none");
break;
if (compiledTabSrcContents && compiledTabSrcContents[index]) {
$("#tab-content-src").html(compiledTabSrcContents[index]);
}
else {
$("#tab-content-src").html("");
}
}
let tabSrcs = $(".tab-src");

for (let index = 0; index < tabSrcs.length; index++) {
const tabSrc = tabSrcs[index];

switch (tabSrc.id) {
case tabSrcId:
tabSrc.classList.remove("d-none");
break;
default:
if (!tabSrc.classList.contains("d-none"))
tabSrc.classList.add("d-none");
break;
function setActiveTabOnLoad() {
const hash = window.location.hash;

if (hash) {
const hashParts = hash.split("-").reverse();
const tabTitles = $("#tabs-container ul li");
for (let index = 0; index < tabTitles.length; index++) {
const tabTitleParts = tabTitles[index].id.split("_").reverse();

if (hashParts[0] === tabTitleParts[0]) {
defaultIndex = index;
}
}
}

const tabTitles = $("#tabs-container ul li");
for (let index = 0; index < tabTitles.length; index++) {

if (index === defaultIndex) {
tabTitles[index].classList.add("active");
} else {
tabTitles[index].classList.remove("active");
}
}
}

setActiveTabOnLoad();
populateTabContent(defaultIndex);
});
</script>
32 changes: 0 additions & 32 deletions _sass/accordion-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,5 @@
display: block;
}
}

&:hover {
background-color: $apricot;
}
}

.accordion-body {
padding: 0;
}

table {
border: 1px solid rgba(153, 153, 153, 0.5);
border-radius: 0.25rem;

th {
font-size: 0.875rem;
}

tbody {
font-size: 0.875rem;

tr:nth-child(odd) {
background-color: #F9F8F6;
}

tr {
&:hover {
background-color: $apricot;
transition: .5s;
}
}
}
}
}
6 changes: 0 additions & 6 deletions _sass/card.scss

This file was deleted.

127 changes: 0 additions & 127 deletions _sass/front-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ $front-page-max-width: $breakpoint-lg;
}

@media screen and (min-width: $breakpoint-xxl) {
margin-bottom: 8rem;

.front-page-intro-cards {
left: 0;
Expand Down Expand Up @@ -244,130 +243,4 @@ $front-page-max-width: $breakpoint-lg;

}
}

.front-page-demoshop {
display: flex;
flex-direction: column;
align-items: center;
padding: $front-page-padding;
padding-top: 4rem;
margin-bottom: 4rem;
width: 100%;
height: 22.5rem;
background-color: $dark-brown;
text-decoration: none;
border-radius: 1rem;

&:after {
display: none;
content: none;
}

.front-page-demoshop-text {
display: flex;
flex-direction: column;
margin-bottom: 2rem;
max-width: $front-page-max-width;
width: 100%;

.h2 {
color: $white;
}

.demoshop-text-description {
color: $white;
width: 40%;
min-height: 4.5rem;
font-size: 1rem;

}

}

@media screen and (max-width: $breakpoint-md) {
padding-top: 3rem;
height: 18rem;

.front-page-demoshop-text {
.demoshop-text-description {
width: 100%;
min-height: 2.25rem;
}
}

}

.front-page-demoshop-link {
display: flex;
position: relative;
color: $white;
text-decoration: none;
background-color: $medium-brown;
align-items: center;
height: 4.625rem;
border-radius: 2px;
box-shadow: 1px 2px 10px rgba(0, 0, 0, 0.15);
max-width: $front-page-max-width;
width: 100%;
cursor: pointer;

a::after{
content: '';
}

&:hover,
&:focus {
background-color: $white;
color: $brown;

.h3 {
color: $brown;
}
}

.demoshop-link-img {
display: flex;
align-items: center;
position: absolute;
bottom: -1rem;
right: 3%;
pointer-events: none;

.demoshop-link-img-web {
width: 26.5rem;
height: 15.125rem;
border-radius: 2px;
box-shadow: 1px 2px 10px rgba(0, 0, 0, 0.15);
}

.demoshop-link-img-mobile {
height: 15.125rem;
border-radius: 2px;
box-shadow: 1px 2px 10px rgba(0, 0, 0, 0.15);
margin-right: 1rem;
}
}

.h3 {
color: $white;
padding-right: 1rem;
padding-left: 1.5rem;
margin: 0;
}
}

@media screen and (min-width: $breakpoint-xxl) {
.front-page-demoshop-text {
margin-bottom: 1rem;
}

.front-page-demoshop-link {
.demoshop-link-img {
bottom: -2rem;
}
}
}
}


}
Loading

0 comments on commit ec0f1b9

Please sign in to comment.