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

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-09-20 01:59:07 +02:00
---
---
2018-10-22 04:00:14 +02:00
var hash = window.location.hash;
2018-09-13 03:31:49 +02:00
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var options = {};
var instances = M.Sidenav.init(elems, options);
2017-03-12 03:02:54 +01:00
2018-10-22 04:00:14 +02:00
if (hash)
$('a[href=' + hash +']').click();
else
$('a[href=#tabMain]').click();
});
2017-03-12 21:38:18 +01:00
2018-09-13 03:31:49 +02:00
$(document).ready(function(){
$('.sidenav').sidenav();
2020-11-15 03:26:34 +01:00
$('.collapsible').collapsible();
2018-10-20 20:47:44 +02:00
let currentPage = document.location.hash.replace('#tab', '').replace(/[\s+_]/g, '-').toLowerCase();
if (currentPage === 'main') currentPage = 'awesome-wm-widgets';
2021-04-13 03:39:49 +02:00
ga('set', 'page', currentPage);
2018-10-20 20:47:44 +02:00
ga('send', 'pageview');
2020-11-15 03:26:34 +01:00
$('li.tab > a').click(function(event){
event.preventDefault();//stop browser to take action for clicked anchor
2018-10-20 20:47:44 +02:00
let currentPage = $(this).text().trim().replace(/\s+/g, '-').toLowerCase();
2018-10-20 19:29:26 +02:00
ga('set', 'page', currentPage);
ga('send', 'pageview');
//find actived navigation and remove 'active' css
2020-12-18 02:28:30 +01:00
let actived_nav = $('li.active');
actived_nav.removeClass('active');
//add 'active' css into clicked navigation
$(this).parents('li').addClass('active');
//hide displaying tab content
2021-04-13 03:39:49 +02:00
$('.widget.active').each(function(){$(this).removeClass('active fade-in').addClass('hide')})
//show target tab content
2018-10-22 04:00:14 +02:00
let target_tab_selector = $(this).attr('href');
2018-09-16 04:08:49 +02:00
$(target_tab_selector).removeClass('hide');
2018-09-16 03:19:46 +02:00
$(target_tab_selector).addClass('active fade-in');
});
});
particlesJS.load('particles-js', 'assets/js/particlesjs-config.json', function() {
console.log('callback - particles.js config loaded');
2018-09-13 03:31:49 +02:00
});
2018-09-17 04:36:57 +02:00
2018-09-20 01:59:07 +02:00
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("assets/js/service-worker.js").catch(function(e) {
console.log("Error registering service worker" + e);
});
}