let ws = window.wavesurfer; var GLOBAL_ACTIONS = { // eslint-disable-line play: function() { window.wavesurfer.playPause(); }, back: function() { window.wavesurfer.skipBackward(); }, forth: function() { window.wavesurfer.skipForward(); }, 'toggle-mute': function() { window.wavesurfer.toggleMute(); } }; // Bind actions to buttons and keypresses document.addEventListener('DOMContentLoaded', function() { document.addEventListener('keydown', function(e) { let map = { 32: 'play', // space 37: 'back', // left 39: 'forth' // right }; let action = map[e.keyCode]; if (action in GLOBAL_ACTIONS) { if (document == e.target || document.body == e.target || e.target.attributes["data-action"]) { e.preventDefault(); } GLOBAL_ACTIONS[action](e); } }); [].forEach.call(document.querySelectorAll('[data-action]'), function(el) { el.addEventListener('click', function(e) { let action = e.currentTarget.dataset.action; if (action in GLOBAL_ACTIONS) { e.preventDefault(); GLOBAL_ACTIONS[action](e); } }); }); }); // Misc document.addEventListener('DOMContentLoaded', function() { // Web Audio not supported if (!window.AudioContext && !window.webkitAudioContext) { let demo = document.querySelector('#demo'); if (demo) { demo.innerHTML = ''; } } // Navbar links let ul = document.querySelector('.nav-pills'); if ( !ul ) { return; } let pills = ul.querySelectorAll('li'); let active = pills[0]; if (location.search) { let first = location.search.split('&')[0]; let link = ul.querySelector('a[href="' + first + '"]'); if (link) { active = link.parentNode; } } active && active.classList.add('active'); });