1$(function() { 2 var device = window.getComputedStyle(document.querySelector('body'), ':before').getPropertyValue('content').replace(/"/g, ''); 3 var podcastPlayer = new window.podcastPlayer(device); 4 if ($(".abril-player-podcast").length > 0) { 5 podcastPlayer.init(); 6 } 7}); 8 9(function(window) { 10 'use strict'; 11 var podcastPlayer = function(device){ 12 this.device = device || 'desktop'; 13 this.click_event = device === 'mobile' ? 'touchstart' : 'click'; 14 }; 15 16 podcastPlayer.prototype = { 17 init: function() { 18 19 var player_title = document.getElementById('player-title'); 20 21 if (this.device === 'mobile' && player_title.innerHTML.length > 53){ 22 player_title.textContent = player_title.textContent.substring(0,53)+'...'; 23 } 24 25 var audio = document.getElementById('audio-podcast'); 26 var brand = document.querySelector("html").className; 27 var player_title = document.getElementById('player-title').innerHTML; 28 29 audio.addEventListener('play', playEvent , false); 30 audio.addEventListener('timeupdate', updateCurrentTime , false); 31 startUpdateProgressBar(); 32 33 var player_category = document.getElementById('article-category'); 34 35 var total_played = document.getElementById('total-played'); 36 var progress_bar = document.getElementById('progress-bar'); 37 38 progress_bar.addEventListener('mousedown', stopUpdateProgressBar , false); 39 progress_bar.addEventListener(this.click_event, seek , false); 40 41 var btn_play = document.getElementById('play'); 42 btn_play.addEventListener(this.click_event, play , false); 43 44 var btn_pause = document.getElementById('pause'); 45 btn_pause.addEventListener(this.click_event, pause , false); 46 47 var btn_mute = document.getElementById('mute-unmute'); 48 btn_mute.addEventListener(this.click_event, muteUnmute , false); 49 50 var btn_goback = document.getElementById('goback-10'); 51 btn_goback.addEventListener(this.click_event, goback , false); 52 53 var btn_skip = document.getElementById('skip-10'); 54 btn_skip.addEventListener(this.click_event, skip , false); 55 56 var player_spotify = document.getElementById('player-spotify'); 57 player_spotify.onclick = function() { 58 gaSend(brand, 'podcasts-platforms', brand, 'podcasts-spotify'); 59 } 60 61 function playEvent(e){ 62 document.getElementById('current-time').textContent = secToStr( audio.currentTime ) ; 63 progress_bar.value = audio.currentTime; 64 } 65 66 function updateCurrentTime(){ 67 document.getElementById('current-time').textContent = secToStr( audio.currentTime); 68 document.getElementById('total-time').textContent = secToStr( audio.duration - audio.currentTime ); 69 if (audio.ended) { 70 gaSend(brand, 'podcasts-eng', 'podcasts-eng-'+player_category.textContent+': '+player_title,'podcasts-eng-100'); 71 } 72 } 73 74 function updateProgressBar(){ 75 progress_bar.value = audio.currentTime; 76 total_played.style.width = (audio.currentTime / audio.duration * 100) + "%"; 77 } 78 79 function stopUpdateProgressBar(){ 80 audio.removeEventListener('timeupdate', updateProgressBar , false); 81 } 82 83 function startUpdateProgressBar(){ 84 audio.addEventListener('timeupdate', updateProgressBar , false); 85 } 86 87 function seek(e){ 88 audio.currentTime = progress_bar.value; 89 startUpdateProgressBar(); 90 gaSend(brand, 'podcasts-player', brand,'podcasts-player-seekbar'); 91 } 92 93 function play(e){ 94 e.preventDefault(); 95 audio.play(); 96 btn_play.style.display = "none"; 97 btn_pause.style.display = "inline-block"; 98 gaSend(brand, 'podcasts-player', brand,'podcasts-player-play'); 99 if (!audio.played.length) { 100 gaSend(brand, 'podcasts-eng','podcasts-eng-'+player_category.innerHTML+': '+player_title,'podcasts-eng-0'); 101 gaSend(brand, 'podcasts-platforms', brand, 'podcasts-native'); 102 } 103 104 window.addEventListener('beforeunload', gaSendClose, false); 105 } 106 107 function pause(e){ 108 e.preventDefault(); 109 audio.pause(); 110 btn_pause.style.display = "none"; 111 btn_play.style.display = "inline-block"; 112 gaSend(brand, 'podcasts-player', brand,'podcasts-player-pause'); 113 114 window.removeEventListener('beforeunload', gaSendClose, false); 115 } 116 117 function muteUnmute(e){ 118 e.preventDefault(); 119 audio.muted = !audio.muted; 120 var muted_state = audio.muted ? 'mute' : 'unmute'; 121 btn_mute.classList.toggle("muted"); 122 gaSend(brand, 'podcasts-player', brand,'podcasts-player-'+muted_state); 123 } 124 125 function goback(e){ 126 e.preventDefault(); 127 stopUpdateProgressBar(); 128 audio.currentTime = audio.currentTime - 10;
129 startUpdateProgressBar(); 130 gaSend(brand, 'podcasts-player', brand,'podcasts-player-rewind'); 131 } 132 133 function skip(e){ 134 e.preventDefault(); 135 stopUpdateProgressBar(); 136 audio.currentTime = audio.currentTime + 10; 137 startUpdateProgressBar(); 138 gaSend(brand, 'podcasts-player', brand,'podcasts-player-forward'); 139 } 140 141 function secToStr( sec_num ) { 142 sec_num = Math.floor( sec_num ); 143 var horas = Math.floor(sec_num / 3600); 144 var minutos = Math.floor((sec_num - (horas * 3600)) / 60); 145 var segundos = sec_num - (horas * 3600) - (minutos * 60); 146 if (horas < 10) {horas = "0"+horas;} 147 if (minutos < 10) {minutos = "0"+minutos;} 148 if (segundos < 10) {segundos = "0"+segundos;} 149 var tempo = minutos+':'+segundos; 150 return tempo; 151 } 152 153 function gaSend( brand, category, action, label ) { 154 if ( typeOfMethodCompare() !== typeof "undefined" ) { 155 156 gaSendEvent({ 157 "brand": brand, 158 "category": category, 159 "action": action, 160 "label": label 161 }); 162 163 } 164 } 165 166 function gaSendClose( e ) { 167 e.preventDefault(); 168 gaSend(brand, 'podcasts-eng','podcasts-eng-'+player_category.innerHTML+': '+player_title,'podcasts-eng-' + Math.round( audio.currentTime / audio.duration * 100 ) ); 169 e.returnValue = ''; 170 return true; 171 } 172 } 173 } 174 window.podcastPlayer = podcastPlayer; 175})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.