About this:
If you have alot of content or categorized content you may want to give people to option to search what they are looking for. With tese searchable tabs you can offer that functionality. For example try searching: Rackham
The standard Lorem Ipsum passage, used since the 1500s
“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
Section 1.10.32 of “de Finibus Bonorum et Malorum”, written by Cicero in 45 BC
“Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?”
Section 1.10.33 of “de Finibus Bonorum et Malorum”, written by Cicero in 45 BC
“At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.”
1914 translation by H. Rackham:
“On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.”
The standard Lorem Ipsum passage, used since the 1500s
“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
Section 1.10.32 of “de Finibus Bonorum et Malorum”, written by Cicero in 45 BC
“Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?”
Section 1.10.33 of “de Finibus Bonorum et Malorum”, written by Cicero in 45 BC
“At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.”
The HTML
You can build the tabs with the Tab element in your UX Builder. For the search field you can use the below HTML in an HTML element in your UX Builder. Place it somewhere convenient for your users, preferable above the tabs element.
<input type="text" id="search" placeholder="Search...">
<button id="search-button" class="button primary">Search</button>
The Script
Now for the searchbar to work you will need this script. Copy and paste the script into your Footer scripts. Flatsome > Advanced > Global Settings > Footer scripts.
The script will check the content of the tabs for the existence and sets the tab with the first result as active. It also highlights the search term.
<script>
const searchInput = document.getElementById('search');
const searchButton = document.getElementById('search-button');
const tabTitles = document.querySelectorAll('.tab');
const tabContent = document.querySelector('.tab-panels');
searchButton.addEventListener('click', () => {
const searchTerm = searchInput.value; // Store the original search term
const searchTermLower = searchTerm.toLowerCase(); // Convert to lowercase for case-insensitive search
const tabs = tabContent.querySelectorAll('.panel');
let activeTabIndex = -1; // Initialize to an invalid index
tabs.forEach((tab, i) => {
const paragraphs = tab.querySelectorAll('p, h1, h2, h3, h4, h5, h6, em, strong, b, span');
let found = false;
paragraphs.forEach(paragraph => {
const originalContent = paragraph.innerHTML;
const paragraphText = paragraph.textContent.toLowerCase(); // Convert text to lowercase for case-insensitive search
if (paragraphText.includes(searchTermLower)) {
const regex = new RegExp(searchTerm, 'gi');
const highlightedText = originalContent.replace(regex, match => {
return `<span class="highlighted">${match}</span>`;
});
paragraph.innerHTML = highlightedText;
found = true;
}
});
if (found) {
tab.classList.add('active');
if (activeTabIndex === -1) {
activeTabIndex = i; // Set the first matching tab as active
}
} else {
tab.classList.remove('active');
}
});
if (activeTabIndex !== -1) {
// Activate the first matching tab
tabTitles.forEach((title, i) => {
if (i === activeTabIndex) {
title.classList.add('active');
} else {
title.classList.remove('active');
}
});
tabs.forEach((tab, i) => {
if (i === activeTabIndex) {
tab.classList.add('active');
} else {
tab.classList.remove('active');
}
});
}
});
</script>
The CSS
Not much. Just to make sure the necessary things are visible. You can add it to Flatsome > Advanced > Custom CSS > All Screens. You can change the color of the highlighted text by changing the color of .highlighted
.
.active {
display: block !important;
}
.panel {
display: none;
}
.highlighted{
background-color: yellow;
}
Stay Connected
Flatsome is the perfect theme for your shop, company websites or client websites. It has all the tools needed to create super fast responsive websites with amazing user experience.
Starting a project?
Looking to start a website project for a new Flatsome website or webshop? Already got a Flatsome site but looking to redesign it?
Got a question?
Want to ask a question of request more information on what we do within Flatsome? Shoot us a message or feedback.