awesome-wm-widgets/assets/js/init.js

65 lines
2.0 KiB
JavaScript

---
---
var hash = window.location.hash;
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var options = {};
var instances = M.Sidenav.init(elems, options);
if (hash)
$('a[href=' + hash +']').click();
else
$('a[href=#tabMain]').click();
});
$(document).ready(function(){
$('.sidenav').sidenav();
let currentPage = document.location.hash.replace('#tab', '').replace(/[\s+_]/g, '-').toLowerCase();
if (currentPage === 'main') currentPage = 'awesome-wm-widgets';
ga('set', 'page', currentPage);1
ga('send', 'pageview');
$('.sidenav > li > a').click(function(event){
event.preventDefault();//stop browser to take action for clicked anchor
let currentPage = $(this).text().trim().replace(/\s+/g, '-').toLowerCase();
ga('set', 'page', currentPage);
ga('send', 'pageview');
location.hash = event.target.hash;
//get displaying tab content jQuery selector
let active_tab_selector = $('.sidenav > li.active > a').attr('href');
//find actived navigation and remove 'active' css
let actived_nav = $('.sidenav > li.active');
actived_nav.removeClass('active');
//add 'active' css into clicked navigation
$(this).parents('li').addClass('active');
//hide displaying tab content
$(active_tab_selector).removeClass('active fade-in');
$(active_tab_selector).addClass('hide ');
//show target tab content
let target_tab_selector = $(this).attr('href');
$(target_tab_selector).removeClass('hide');
$(target_tab_selector).addClass('active fade-in');
});
});
particlesJS.load('particles-js', 'assets/js/particlesjs-config.json', function() {
console.log('callback - particles.js config loaded');
});
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("assets/js/service-worker.js").catch(function(e) {
console.log("Error registering service worker" + e);
});
}