forked from MahdiF/loud-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloudlinks-1.0.min.js
1 lines (1 loc) · 1.76 KB
/
loudlinks-1.0.min.js
1
var loudlinks=function(e){var o=(function(){var o=e.createElement("audio"),t=e.createElement("source"),n=e.createElement("source");o.id="loudLinksAudioPlayer",o.preload=!0,t.id="mp3Source",n.id="oggSource",o.appendChild(t),o.appendChild(n),e.body.appendChild(o)}(),e.getElementsByClassName("loud-link-hover")),t=e.getElementsByClassName("loud-link-click"),n=e.getElementById("loudLinksAudioPlayer"),r="sounds/mp3/",i="sounds/ogg/",u=e.getElementById("mp3Source"),c=e.getElementById("oggSource");checkAudioSupport=function(){return!!e.createElement("audio").canPlayType},getAudioSource=function(e){var o=e.getAttribute("data-src"),t=r+o+".mp3",n=i+o+".ogg";u.setAttribute("src",t),c.setAttribute("src",n),c.addEventListener("error",function(){console.log("😶 D'oh! The ♪ ogg file URL is wrong!")},!1),u.addEventListener("error",function(){console.log("😶 D'oh! The ♪ mp3 file URL is wrong!")},!1)},checkAttribute=function(e){var o=e.getAttribute("data-src");return o?!0:!1},playAudio=function(e){checkAttribute(e)&&(getAudioSource(e),n.load(),n.play())},stopAudio=function(){n.pause(),n.currentTime=0},trackHover=function(e){e.addEventListener("mouseover",function(){playAudio(e)},!1),e.addEventListener("mouseout",function(){stopAudio()},!1),e.addEventListener("touchmove",function(){stopAudio()},!1),e.addEventListener("click",function(){stopAudio()},!1),e.addEventListener("dblclick",function(){stopAudio()},!1)},trackClick=function(e){e.addEventListener("click",function(){playAudio(e)},!1)},runTrackers=function(){var e,n=o.length,r=t.length;for(e=0;n>e;e++)trackHover(o[e]);for(e=0;r>e;e++)trackClick(t[e])},checkAudioSupport()?(console.log("Audio works like a charm 👍"),runTrackers()):console.log("Oh man 😩! \nI'm sorry but your browsers doesn't support awesomeness.")}(document);