1/* 2 Initial text holds what should be set for the title of the song in the player. 3*/ 4var initialText = []; 5 6(function(){ 7 /* 8 Configure the player views based on the config 9 provided by the user. 10 */ 11 configurePlayerViews(); 12 13 /* 14 Initialize Amplitude 15 */ 16 initializeAmplitude(); 17 18 /* 19 Sets the initial text so we can truncate as needed. 20 */ 21 setInitialText(); 22 23 /* 24 Add ellipses to the text box 25 */ 26 ellipsizeTextBox(); 27 28 /* 29 Bind Song Downloads 30 */ 31 bindPlayerDownloads(); 32 33 /* 34 Show all players on the page 35 */ 36 showPlayers(); 37})(); 38 39/* 40 When the document is loaded, make sure the text box has ellipses where 41 necessary. 42*/ 43document.addEventListener("DOMContentLoaded", function(event) { 44 ellipsizeTextBox(); 45}); 46 47/* 48 When the window is resized, make sure the text box has ellipses where 49 necessary. 50*/ 51window.onresize = function(){ 52 ellipsizeTextBox(); 53} 54 55/* 56 Sets the initial text variable 57*/ 58function setInitialText(){ 59 /* 60 Gets the audio item names from the players. 61 */ 62 var audioItemNames = document.getElementsByClassName('player-audio-item-name'); 63 64 /* 65 Set the initial text variables 66 */ 67 for( var i = 0; i < audioItemNames.length; i++ ){ 68 initialText[i] = audioItemNames[i].innerHTML; 69 } 70} 71 72/* 73 Truncates the string accordingly with ellipses if needed 74*/ 75function ellipsizeTextBox() { 76 /* 77 Gets all of the player name fields 78 */ 79 var audioItemNames = document.getElementsByClassName('player-audio-item-name'); 80 81 /* 82 Iterates over the player name fields and sets the inner html to 83 a truncated string with ellipses 84 */ 85 for( var i = 0; i < audioItemNames.length; i++ ){ 86 /* 87 Sets the inner HTML to the initial text. 88 */ 89 audioItemNames[i].innerHTML = initialText[i]; 90 91 /* 92 Splits the names by spaces 93 */
94 var wordArray = audioItemNames[i].innerHTML.split(' '); 95 96 /* 97 As long as the scroll height is greater than the offset height (+2 for firefox bug) 98 we keep adding a word to the HTML 99 */ 100 while( audioItemNames[i].scrollHeight > audioItemNames[i].offsetHeight + 2 ) { 101 wordArray.pop(); 102 audioItemNames[i].innerHTML = wordArray.join(' ') + '...'; 103 } 104 } 105} 106 107/* 108 Initializes Amplitude.js 109*/ 110function initializeAmplitude(){ 111 /* 112 Builds the array of songs used by the player. 113 */ 114 var songs = buildSongsArray(); 115 116 /* 117 Initialize AmplitudeJS and configure source media files 118 */ 119 Amplitude.init({ 120 "songs": songs, 121 "continue_next": false 122 }); 123} 124 125/* 126 Builds an array of songs 127*/ 128function buildSongsArray(){ 129 /* 130 Initializes the songs array. 131 */ 132 var songsArray = []; 133 134 /* 135 Builds the songs array with the URLs provided 136 */ 137 for( var i = 0; i < players.length; i++ ){ 138 songsArray[i] = { 139 'url': players[i].url 140 } 141 } 142 143 /* 144 Returns the songs array. 145 */ 146 return songsArray; 147} 148 149/* 150 Configures the views for the player 151*/ 152function configurePlayerViews(){ 153 for( var i = 0; i < players.length; i++ ){ 154 var playerElement = document.getElementById('player-'+ ( i + 1 ) ); 155 156 /* 157 Gets the audio item names 158 */ 159 var audioItemNames = playerElement.getElementsByClassName('player-audio-item-name'); 160 161 /* 162 Sets the line height to 24 px so we can do ellipses. 163 */ 164 for( var k = 0; k < audioItemNames.length; k++ ){ 165 audioItemNames[k].style.lineHeight = '24px'; 166 } 167 168 /* 169 Get the player speed icons and download icons 170 */ 171 var speedIcons = playerElement.getElementsByClassName('player-speed'); 172 var downloadIcons = playerElement.getElementsByClassName('player-download-link'); 173 174 /* 175 Determine if the player should show the speed icon or not. 176 */ 177 if( !players[i].show_speed_icon ){ 178 for( var k = 0; k < speedIcons.length; k++ ){ 179 speedIcons[k].style.display = "none"; 180 } 181 } 182 183 /* 184 Determine if the player should show the download icon or not 185 */ 186 if( !players[i].show_download_icon ){ 187 for( var k = 0; k < downloadIcons.length; k++ ){ 188 downloadIcons[k].style.display = "none"; 189 } 190 } 191 192 /* 193 Determine if we should show the episode image or not. 194 */ 195 if( !players[i].show_episode_image ){ 196 playerElement.classList.add('hide-episode-image'); 197 } 198 199 /* 200 Apply the appropriate class to the player to show or hide the icons. 201 */ 202 if( players[i].show_speed_icon && players[i].show_download_icon ){ 203 playerElement.classList.add('show-all-icons'); 204 }else if( players[i].show_speed_icon && !players[i].show_download_icon ){ 205 playerElement.classList.add('show-speed-icons'); 206 }else if( !players[i].show_speed_icon && players[i].show_download_icon ){ 207 playerElement.classList.add('show-download-icons'); 208 }else{ 209 playerElement.classList.add('show-no-function-icons'); 210 } 211 } 212} 213 214/* 215 Bind the download links for each song 216*/ 217function bindPlayerDownloads(){ 218 /* 219 Gets all download links 220 */ 221 var playerDownloadLinks = document.getElementsByClassName('player-download-link'); 222 223 /* 224 Set the download URL for each link. 225 */ 226 for( var i = 0; i < playerDownloadLinks.length; i++ ){ 227 var songIndex = playerDownloadLinks[i].getAttribute('amplitude-song-index'); 228 var song = Amplitude.getSongByIndex( songIndex ); 229 230 playerDownloadLinks[i].setAttribute( 'href', song.url ); 231 } 232} 233 234/* 235 Show each player element. 236*/ 237function showPlayers(){ 238 var playerElements = document.getElementsByClassName("player"); 239 240 for( var i = 0; i < players.length; i++ ){ 241 playerElements[i].style.display = "block"; 242 } 243}
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.