hugo-blog/themes/eddie/assets/js/script.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-08-16 20:42:05 +00:00
// Passive event listeners
jQuery.event.special.touchstart = {
setup: function (_, ns, handle) {
this.addEventListener("touchstart", handle, {
passive: !ns.includes("noPreventDefault")
});
}
};
jQuery.event.special.touchmove = {
setup: function (_, ns, handle) {
this.addEventListener("touchmove", handle, {
passive: !ns.includes("noPreventDefault")
});
}
};
// Preloader js
function preloader() {
$('.preloader').delay(100).fadeOut(10);
}
$(preloader);
$(document).on("turbolinks:load", preloader);
(function ($) {
'use strict';
// tab
$('.tab-content').find('.tab-pane').each(function (idx, item) {
var navTabs = $(this).closest('.code-tabs').find('.nav-tabs'),
title = $(this).attr('title');
navTabs.append('<li class="nav-item"><a class="nav-link" href="#">' + title + '</a></li>');
});
$('.code-tabs ul.nav-tabs').each(function () {
$(this).find("li:first").addClass('active');
})
$('.code-tabs .tab-content').each(function () {
$(this).find("div:first").addClass('active');
});
$('.nav-tabs a').click(function (e) {
e.preventDefault();
var tab = $(this).parent(),
tabIndex = tab.index(),
tabPanel = $(this).closest('.code-tabs'),
tabPane = tabPanel.find('.tab-pane').eq(tabIndex);
tabPanel.find('.active').removeClass('active');
tab.addClass('active');
tabPane.addClass('active');
});
// Accordions
$('.collapse').on('shown.bs.collapse', function () {
$(this).parent().find('.ti-plus').removeClass('ti-plus').addClass('ti-minus');
}).on('hidden.bs.collapse', function () {
$(this).parent().find('.ti-minus').removeClass('ti-minus').addClass('ti-plus');
});
})(jQuery);