function modifySliderToIncludeNav() {
var slider = jQuery("div.paginated-slider div.flexslider.content-slider");
slider.removeClass("content-slider");
slider.addClass("new-slider");
}
function populateTabsSlider() {
//empty the list
var ul = jQuery("div.tabs-slider ul.slides");
ul.empty();
//grab content from tabs
var tabNames = jQuery("div.custom-tabs ul.nav-tabs span");
// var tabContents = jQuery("div.custom-tabs .tab-pane");
var tabImages = jQuery("div.custom-tabs .tab-pane div.custom-tabs-image img");
var tabTexts = jQuery("div.custom-tabs .tab-pane div.custom-tabs-text p");
// //create clones for first and last elements
// create elements for slider content
for (i = 0; i < tabNames.length; i++) {
var sliderItem = constructSliderItemFromTab(
tabNames.eq(i),
tabImages.eq(i),
tabTexts.eq(i)
);
if (i == 0) {
sliderItem.addClass("flex-active-slide");
}
ul.append(sliderItem);
}
function constructCloneFromTab(index) {
var clone = constructSliderItemFromTab(
tabNames.eq(index),
tabImages.eq(index),
tabTexts.eq(index)
);
clone.addClass("clone");
return clone;
}
function constructSliderItemFromTab(tabName, tabImage, tabText) {
var sliderContent = jQuery('
');
var imgUrl = tabImage.attr("src");
// use this when lazyloading is enabled
// var imgUrl = tabImage.data("src");
sliderContent.append(
''
);
// add text content
sliderContent.append(
jQuery(
'"
)
);
sliderContent.append(
jQuery(
'' +
tabText.html() +
"
"
)
);
var sliderListItem = jQuery("" + sliderContent[0].outerHTML + "");
return sliderListItem;
}
}
function standardizeSlideHeights() {
if (jQuery(document).width() < 768) {
jQuery("style.slide-heights").html(
"div.testimonials-slider.new-slider li > div.tabs-slider-content { height: auto;}"
);
var sliderUl = jQuery(
"div.tabs-slider div.testimonials-slider.new-slider ul.slides"
);
jQuery("style.slide-heights").html(
"div.testimonials-slider.new-slider li > div.tabs-slider-content { height: " +
sliderUl.height() +
"px;}"
);
}
}
function createNewSlider() {
modifySliderToIncludeNav();
jQuery(".new-slider").each(function () {
var slider = jQuery(this),
autoplay = slider.attr("data-autoplay") === "yes" ? true : false;
// this is pretty hacky
// i'd like a better way to modify properties of the slider
// than a different class for each property value
var animation = "slide";
var parentNode = slider.parent().parent();
if (parentNode.hasClass("slider-animation-slide")) {
animation = "slide";
} else if (parentNode.hasClass("slider-animation-fade")) {
animation = "fade";
}
slider.flexslider({
animation: animation, //String: Select your animation type, "fade" or "slide"
slideshow: autoplay, //Boolean: Animate slider automatically
slideshowSpeed: 11050, //Integer: Set the speed of the slideshow cycling, in milliseconds
animationDuration: 500, //Integer: Set the speed of animations, in milliseconds
smoothHeight: true,
directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false)
controlNav: true, //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
pauseOnHover: true,
start: function () {
return null;
},
});
});
}
function addTabBackground() {
var height = jQuery(".custom-tabs ul.nav.nav-tabs").outerHeight();
var backgroundDiv = jQuery('');
backgroundDiv.css("height", height);
var rowContainer = jQuery("div.spb-row-container.custom-tabs");
rowContainer.append(backgroundDiv);
}
// this fixes a Swift bug where Swift tabs don't respect hyphens in tab names
// the hyphen exists in the tab content's id but is stripped from the url in the tab button
// this code strips the hyphen in the tab content's id to match
function removeHyphensFromTabIds() {
var tabIds = jQuery("div.tab-content div.tab-pane");
tabIds.each(function (index) {
var pane = jQuery(this);
pane.attr("id", pane.attr("id").replace("-", ""));
});
}
function setCarouselPagination() {
alert("pagination!");
jQuery("#sf-option-params").attr("data-carousel-pagination", "true");
}
function togglePagination() {
var owlControls = jQuery("div.owl-controls");
for (i = 0; i < owlControls.length; i++) {
var owlControl = owlControls.eq(i);
var owlPages = owlControl.find("div.owl-page");
if (owlPages.length <= 1) {
owlControl.css("display", "none");
} else {
owlControl.css("display", "block");
}
}
}
document.addEventListener("DOMContentLoaded", function (event) {
console.time("tabs-slider");
populateTabsSlider();
addTabBackground();
jQuery(window).resize(togglePagination);
jQuery(window).resize(standardizeSlideHeights);
togglePagination();
createNewSlider();
removeHyphensFromTabIds();
var jQueryTime = console.timeEnd("tabs-slider");
});