forked from LiveCarta/LiveCartaWP
107 lines
3.6 KiB
JavaScript
107 lines
3.6 KiB
JavaScript
window.addEventListener('DOMContentLoaded', function(){
|
|
|
|
// home page scripts start
|
|
function startTopBlockAnimations(){
|
|
const lines = [
|
|
'customized learning experiences.',
|
|
'online publishing.',
|
|
'customized teaching experiences.'
|
|
];
|
|
let currentTextNum = 0;
|
|
const element = document.getElementById('animatedText');
|
|
|
|
function clearCurrent(){
|
|
element.innerText = element.innerText.slice(0, -1);
|
|
if (element.innerText.length > 0 ) {
|
|
setTimeout(function(){
|
|
clearCurrent();
|
|
}, 30);
|
|
} else {
|
|
currentTextNum++;
|
|
if (currentTextNum > lines.length - 1) {
|
|
currentTextNum = 0;
|
|
}
|
|
setTimeout(function(){
|
|
addNext();
|
|
}, 1000);
|
|
}
|
|
}
|
|
|
|
function addNext(){
|
|
if (!element) return;
|
|
element.innerText = lines[currentTextNum].substr(0, element.innerText.length + 1);
|
|
if (element.innerText.length === lines[currentTextNum].length ) {
|
|
setTimeout(function(){
|
|
clearCurrent();
|
|
}, 1000);
|
|
} else {
|
|
setTimeout(function(){
|
|
addNext();
|
|
}, 30);
|
|
}
|
|
}
|
|
|
|
setTimeout(function(){
|
|
addNext();
|
|
}, 1000);
|
|
|
|
function promoTopNext(){
|
|
if (document.querySelectorAll('.promo-backs').length){
|
|
setTimeout(function(){
|
|
let currents = document.querySelectorAll('.promo-bg.current');
|
|
currents.forEach(item => {
|
|
item.classList.remove('current');
|
|
if (item.nextElementSibling){
|
|
item.nextElementSibling.classList.add('current');
|
|
} else {
|
|
item.closest('.promo-backs').find('.promo-bg:first-child').classList.add('current');
|
|
}
|
|
});
|
|
promoTopNext();
|
|
}, 5000);
|
|
}
|
|
}
|
|
promoTopNext();
|
|
}
|
|
|
|
if (this.document.querySelector('.promo-top')) {
|
|
startTopBlockAnimations();
|
|
}
|
|
// home page scripts end
|
|
|
|
// sliders
|
|
|
|
document.querySelectorAll('.splide').forEach(slider => {
|
|
new Splide( slider, {
|
|
type: 'loop',
|
|
perPage: 3,
|
|
perMove: 1,
|
|
rewind : true,
|
|
pagination: false,
|
|
gap: 10,
|
|
breakpoints: {
|
|
1000: { perPage: 2 },
|
|
768 : { perPage: 1, gap: 0 },
|
|
}
|
|
} ).mount();
|
|
});
|
|
|
|
// blog page
|
|
|
|
document.body.addEventListener('click', function(event){
|
|
var catClass = '';
|
|
if (event.target.closest('.category-select')) {
|
|
event.preventDefault();
|
|
let elem = event.target.closest('.category-select');
|
|
document.querySelector('.category-select.selected').classList.remove('selected');
|
|
elem.classList.add('selected');
|
|
document.querySelector('.bp-list').classList.remove('cat-publishing');
|
|
document.querySelector('.bp-list').classList.remove('cat-teaching');
|
|
document.querySelector('.bp-list').classList.remove('cat-learning');
|
|
document.querySelector('.bp-list').classList.remove('cat-all');
|
|
catClass = elem.dataset.cat;
|
|
document.querySelector('.bp-list').classList.add(catClass);
|
|
return false;
|
|
}
|
|
});
|
|
}); |