forked from MahdiF/loud-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloudlinks-1.0.min.js
More file actions
1 lines (1 loc) · 1.82 KB
/
Copy pathloudlinks-1.0.min.js
File metadata and controls
1 lines (1 loc) · 1.82 KB
1
var loudlinks=function(){var e=(function(){var e=document.createElement("audio");e.id="loudLinksAudioPlayer",e.preload=!0;var o=document.createElement("source"),t=document.createElement("source");o.id="mp3Source",t.id="oggSource",e.appendChild(o),e.appendChild(t),document.body.appendChild(e)}(),document.getElementsByClassName("loud-link-hover")),o=document.getElementsByClassName("loud-link-click"),t=document.getElementById("loudLinksAudioPlayer"),n="sounds/mp3/",r="sounds/ogg/",u=document.getElementById("mp3Source"),c=document.getElementById("oggSource");checkAudioSupport=function(){return!!document.createElement("audio").canPlayType},getAudioSource=function(e){var o=e.getAttribute("data-src"),t=n+o+".mp3",i=r+o+".ogg";u.setAttribute("src",t),c.setAttribute("src",i),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),t.load(),t.play())},stopAudio=function(){t.pause(),t.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(){for(var t=0;t<e.length;t++)trackHover(e[t]);for(var t=0;t<o.length;t++)trackClick(o[t])},checkAudioSupport()?(console.log("Audio works like a charm 👍"),runTrackers()):console.log("Oh man 😩! \nI'm sorry but your browsers doesn't support awesomeness.")}();