vendor: 4,313 bytes, lines 1-128
1(function webpackUniversalModuleDefinition(root, factory) { 2 if(typeof exports === 'object' && typeof module === 'object') 3 module.exports = factory(); 4 else if(typeof define === 'function' && define.amd) 5 define("Amplitude", [], factory); 6 else if(typeof exports === 'object') 7 exports["Amplitude"] = factory(); 8 else 9 root["Amplitude"] = factory(); 10})(this, function() { 11return /******/ (function(modules) { // webpackBootstrap 12/******/ // The module cache 13/******/ var installedModules = {}; 14/******/ 15/******/ // The require function 16/******/ function __webpack_require__(moduleId) { 17/******/ 18/******/ // Check if module is in cache 19/******/ if(installedModules[moduleId]) { 20/******/ return installedModules[moduleId].exports; 21/******/ } 22/******/ // Create a new module (and put it into the cache) 23/******/ var module = installedModules[moduleId] = { 24/******/ i: moduleId, 25/******/ l: false, 26/******/ exports: {} 27/******/ }; 28/******/ 29/******/ // Execute the module function 30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 31/******/ 32/******/ // Flag the module as loaded 33/******/ module.l = true; 34/******/ 35/******/ // Return the exports of the module 36/******/ return module.exports; 37/******/ } 38/******/ 39/******/ 40/******/ // expose the modules object (__webpack_modules__) 41/******/ __webpack_require__.m = modules; 42/******/ 43/******/ // expose the module cache 44/******/ __webpack_require__.c = installedModules; 45/******/ 46/******/ // identity function for calling harmony imports with the correct context 47/******/ __webpack_require__.i = function(value) { return value; }; 48/******/ 49/******/ // define getter function for harmony exports 50/******/ __webpack_require__.d = function(exports, name, getter) { 51/******/ if(!__webpack_require__.o(exports, name)) { 52/******/ Object.defineProperty(exports, name, { 53/******/ configurable: false, 54/******/ enumerable: true, 55/******/ get: getter 56/******/ }); 57/******/ } 58/******/ }; 59/******/ 60/******/ // getDefaultExport function for compatibility with non-harmony modules 61/******/ __webpack_require__.n = function(module) { 62/******/ var getter = module && module.__esModule ? 63/******/ function getDefault() { return module['default']; } : 64/******/ function getModuleExports() { return module; }; 65/******/ __webpack_require__.d(getter, 'a', getter); 66/******/ return getter; 67/******/ }; 68/******/ 69/******/ // Object.prototype.hasOwnProperty.call 70/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 71/******/ 72/******/ // __webpack_public_path__ 73/******/ __webpack_require__.p = ""; 74/******/ 75/******/ // Load entry module and return exports 76/******/ return __webpack_require__(__webpack_require__.s = 8); 77/******/ }) 78/************************************************************************/ 79/******/ ([ 80/* 0 */ 81/***/ (function(module, exports, __webpack_require__) { 82 83"use strict"; 84 85 86/* 87|------------------------------------------------------------------------------- 88| Module Variables 89|------------------------------------------------------------------------------- 90| These variables make Amplitude run. The config is the most important 91| containing active settings and parameters. 92*/ 93/*-------------------------------------------------------------------------- 94 The config JSON is the global settings for ALL of Amplitude functions. 95 This is global and contains all of the user preferences. The default 96 settings are set, and the user overwrites them when they initialize 97 Amplitude. 98--------------------------------------------------------------------------*/ 99var config = { 100 version: '3.2.0', 101 /* 102 The audio element we will be using to handle all of the audio. This 103 is the javascript version of the HTML5 audio element. 104 */ 105 active_song: new Audio(), 106 107 /* 108 JSON object that contains the active metadata for the song. 109 */ 110 active_metadata: {}, 111 112 /* 113 String to hold the active album name. Used to check and see if the 114 album changed and run the album changed callback. 115 */ 116 active_album: '', 117 118 /* 119 Contains the index of the actively playing song. 120 */ 121 active_index: 0, 122 123 /* 124 Contains the key to the active playlist index. 125 */ 126 active_playlist: '', 127 128 /*
129 Set to true to autoplay the song 130 */ 131 autoplay: false, 132 133 /* 134 Sets the initial playback speed of the song. The values 135 for this can be 1.0, 1.5, 2.0 136 */ 137 playback_speed: 1.0, 138 139 /* 140 The user can pass a JSON object with a key => value store of callbacks 141 to be run at certain events. 142 */ 143 callbacks: {}, 144 145 /* 146 Object containing all of the songs the user has passed to Amplitude 147 to use. 148 */ 149 songs: {}, 150 151 /* 152 Object containing all of the playlists the user created. 153 */ 154 playlists: {}, 155 156 /* 157 Object that will contain shuffled playlists. 158 */ 159 shuffled_playlists: {}, 160 161 /* 162 Object that contains whether the current playlist is in 163 shuffle mode or not. 164 */ 165 shuffled_statuses: {}, 166 167 /* 168 Object that contains the active index in a shuffled playlist. 169 */ 170 shuffled_active_indexes: {}, 171 172 /* 173 When repeat is on, when the song ends the song will replay itself. 174 */ 175 repeat: false, 176 177 /* 178 When shuffled, this gets populated with the songs the user provided 179 in a random order. 180 */ 181 shuffle_list: {}, 182 183 /* 184 When shuffled is turned on this gets set to true so when traversing 185 through songs Amplitude knows whether or not to use the songs object 186 or the shuffle_list. 187 */ 188 shuffle_on: false, 189 190 /* 191 When shuffled, this index is used to let Amplitude know where it's 192 at when traversing. 193 */ 194 shuffle_active_index: 0, 195 196 /* 197 The user can set default album art to be displayed if the song they 198 set doesn't contain album art. 199 */ 200 default_album_art: '', 201 202 /* 203 When set to true, Amplitude will print to the console any errors 204 that it runs into providing helpful feedback to the user. 205 */ 206 debug: false, 207 208 /* 209 The user can set the initial volume to a number between 0 and 1 210 overridding a default of .5. 211 */ 212 volume: .5, 213 214 /* 215 This is set on mute so that when a user un-mutes Amplitude knows 216 what to restore the volume to. 217 */ 218 pre_mute_volume: .5, 219 220 /* 221 This is an integer between 1 and 100 for how much the volume should 222 increase when the user presses a volume up button. 223 */ 224 volume_increment: 5, 225 226 /* 227 This is an integer between 1 and 100 for how much the volume should 228 decrease when the user presses a volume down button. 229 */ 230 volume_decrement: 5, 231 232 /* 233 When using SoundCloud, the user will have to provide their API Client 234 ID 235 */ 236 soundcloud_client: '', 237 238 /* 239 The user can set this to true and Amplitude will use the album art 240 for the song returned from the Soundcloud API 241 */ 242 soundcloud_use_art: false, 243 244 /* 245 Used on config to count how many songs are from soundcloud and 246 compare it to how many are ready for when to move to the rest 247 of the configuration. 248 */ 249 soundcloud_song_count: 0, 250 251 /* 252 Used on config to count how many songs are ready so when we get 253 all of the data from the SoundCloud API that we need this should 254 match the SoundCloud song count meaning we can move to the rest 255 of the config. 256 */ 257 soundcloud_songs_ready: 0, 258 259 /* 260 Flag for if the user is moving the screen. 261 */ 262 is_touch_moving: false, 263 264 /* 265 How much of the song is buffered. 266 */ 267 buffered: 0, 268 269 /* 270 Array of bindings to certain key events. 271 */ 272 bindings: {}, 273 274 /* 275 Determines when a song ends, we should continue to the next 276 song. 277 */ 278 continue_next: true 279}; 280 281module.exports = config; 282 283/***/ }), 284/* 1 */ 285/***/ (function(module, exports, __webpack_require__) { 286 287"use strict"; 288 289 290Object.defineProperty(exports, "__esModule", { 291 value: true 292}); 293 294var _core = __webpack_require__(3); 295 296var _core2 = _interopRequireDefault(_core); 297 298var _visual = __webpack_require__(2); 299 300var _visual2 = _interopRequireDefault(_visual); 301 302function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 303 304var config = __webpack_require__(0); 305 306 307/* 308|---------------------------------------------------------------------------------------------------- 309| HELPER FUNCTIONS 310|---------------------------------------------------------------------------------------------------- 311| For the sake of code clarity, these functions perform helper tasks 312| assisting the logical functions with what they need such as setting 313| the proper song index after an event has occured. 314| 315| METHODS 316| resetConfig() 317| writeDebugMessage( message ) 318| runCallback( callbackName ) 319| changeSong( songIndex ) 320*/ 321var AmplitudeHelpers = function () { 322 /*-------------------------------------------------------------------------- 323 Resets the config to the default state. This is called on initialize 324 to ensure the user's config is what matters. 325 --------------------------------------------------------------------------*/ 326 function resetConfig() { 327 config.active_song = new Audio(); 328 config.active_metadata = {};
329 config.active_album = ''; 330 config.active_index = 0; 331 config.active_playlist = ''; 332 config.autoplay = false; 333 config.playback_speed = 1.0; 334 config.callbacks = {}; 335 config.songs = {}; 336 config.playlists = {}; 337 config.shuffled_playlists = {}; 338 config.shuffled_statuses = {}; 339 config.repeat = false; 340 config.shuffle_list = {}; 341 config.shuffle_on = false; 342 config.shuffle_active_index = 0; 343 config.default_album_art = ''; 344 config.debug = false; 345 config.handle_song_elements = true; 346 config.volume = .5; 347 config.pre_mute_volume = .5; 348 config.volume_increment = 5; 349 config.volume_decrement = 5; 350 config.soundcloud_client = ''; 351 config.soundcloud_use_art = false; 352 config.soundcloud_song_count = 0; 353 config.soundcloud_songs_ready = 0; 354 } 355 356 /*-------------------------------------------------------------------------- 357 Writes out debug message to the console if enabled. 358 @param string message The string that gets printed to 359 alert the user of a debugging error. 360 --------------------------------------------------------------------------*/ 361 function writeDebugMessage(message) { 362 if (config.debug) { 363 console.log(message); 364 } 365 } 366 367 /*-------------------------------------------------------------------------- 368 Runs a user defined callback method 369 @param string callbackName The name of the callback we are going to run. 370 --------------------------------------------------------------------------*/ 371 function runCallback(callbackName) { 372 /* 373 Checks to see if a user defined a callback method for the 374 callback we are running. 375 */ 376 if (config.callbacks[callbackName]) { 377 /* 378 Build the callback function 379 */ 380 var callbackFunction = config.callbacks[callbackName]; 381 382 /* 383 Write a debug message stating the callback we are running 384 */ 385 writeDebugMessage('Running Callback: ' + callbackName); 386 387 /* 388 Run the callback function. 389 */ 390 try { 391 callbackFunction(); 392 } catch (error) { 393 // undocumented way to cancel events 394 if (error.message == "CANCEL EVENT") throw error;else writeDebugMessage('Callback error: ' + error.message); 395 } 396 } 397 } 398 399 /*-------------------------------------------------------------------------- 400 Changes the active song in the config. This happens in multiple 401 scenarios: The user clicks a play button that has an index that is 402 different than what is currently playing, the song ends and the next 403 song begins, etc. 404 @param int songIndex The song index we are changing to 405 --------------------------------------------------------------------------*/ 406 function changeSong(songIndex) { 407 var song = config.songs[songIndex]; 408 409 /* 410 Stops the currently playing song so we can adjust 411 what we need. 412 */ 413 _core2.default.stop(); 414 415 /* 416 FX-TODO: Stop Visualization 417 */ 418 419 /* 420 Set all play buttons to pause while we change 421 the song. 422 */ 423 _visual2.default.setPlayPauseButtonsToPause(); 424 425 /* 426 Since it is a new song, we reset the song sliders. These 427 react to time updates and will eventually be updated but we 428 force update them is if there is a song slider bound to a 429 specific song, they won't update. 430 */ 431 _visual2.default.resetSongSliders(); 432 433 /* 434 Resets the progress bars 435 */ 436 _visual2.default.resetSongPlayedProgressBars(); 437 438 /* 439 Reset all the time place holders accordingly. 440 */ 441 _visual2.default.resetTimes(); 442 443 /* 444 Run a callback if an album is going 445 to change. 446 */ 447 if (checkNewAlbum(song)) { 448 runCallback('album_change'); 449 } 450 451 /* 452 Set the new song information so we can use the 453 active meta data later on. 454 */ 455 setNewSong(song, songIndex); 456 457 /* 458 Display the new visual metadata now that the config has 459 been changed. This will show the new song. 460 */ 461 _visual2.default.displaySongMetadata(); 462 463 /* 464 Sets the active container. This is a class that 465 designers can use on an element that contains the current 466 song's controls to show it's highlighted. 467 */ 468 _visual2.default.setActiveContainer(); 469 470 /* 471 Sets the active song's duration 472 */ 473 _visual2.default.syncSongDuration(); 474 475 /* 476 Run song change callback. 477 */ 478 runCallback('song_change'); 479 } 480 481 /*-------------------------------------------------------------------------- 482 Checks to see if the new song to be played is different than the song 483 that is currently playing. To be true, the user would have selected 484 play on a new song with a new index. To be false, the user would have 485 clicked play/pause on the song that was playing. 486 @param int songIndex The index of the new song to be played. 487 --------------------------------------------------------------------------*/ 488 function checkNewSong(songIndex) { 489 if (songIndex != config.active_index) { 490 return true; 491 } else { 492 return false;
493 } 494 } 495 496 /*-------------------------------------------------------------------------- 497 Checks to see if there is a new album 498 @param string newAlbum Checks to see if the new song will have a new 499 album. 500 --------------------------------------------------------------------------*/ 501 function checkNewAlbum(newAlbum) { 502 if (config.active_album != newAlbum) { 503 return true; 504 } else { 505 return false; 506 } 507 } 508 509 /*-------------------------------------------------------------------------- 510 Checks to see if there is a new playlist 511 @param string playlist The playlist passed in to check against the active 512 playlist. 513 --------------------------------------------------------------------------*/ 514 function checkNewPlaylist(playlist) { 515 if (config.active_playlist != playlist) { 516 return true; 517 } else { 518 return false; 519 } 520 } 521 522 /*-------------------------------------------------------------------------- 523 Sets the new song in the config. Sets the src of the audio object, 524 updates the metadata and sets the active album. 525 @param JSON song The song object of the song we are changing to. 526 @param int index The index of the song in the songs object we are changing. 527 --------------------------------------------------------------------------*/ 528 function setNewSong(song, index) { 529 config.active_song.src = song.url; 530 config.active_metadata = song; 531 config.active_album = song.album; 532 config.active_index = index; 533 } 534 535 /*-------------------------------------------------------------------------- 536 Shuffles individual songs in the config 537 Based off of: http://www.codinghorror.com/blog/2007/12/the-danger-of-naivete.html 538 --------------------------------------------------------------------------*/ 539 function shuffleSongs() { 540 /* 541 Builds a temporary array with the length of the config. 542 */ 543 var shuffleTemp = new Array(config.songs.length); 544 545 /* 546 Set the temporary array equal to the songs array. 547 */ 548 for (var i = 0; i < config.songs.length; i++) { 549 shuffleTemp[i] = config.songs[i]; 550 shuffleTemp[i].original_index = i; 551 } 552 553 /* 554 Iterate ove rthe songs and generate random numbers to 555 swap the indexes of the shuffle array. 556 */ 557 for (var i = config.songs.length - 1; i > 0; i--) { 558 var randNum = Math.floor(Math.random() * config.songs.length + 1); 559 shuffleSwap(shuffleTemp, i, randNum - 1); 560 } 561 562 /* 563 Set the shuffle list to the shuffle temp. 564 */ 565 config.shuffle_list = shuffleTemp; 566 } 567 568 /*-------------------------------------------------------------------------- 569 Shuffle songs in a playlist 570 @param string playlist The playlist we are shuffling. 571 --------------------------------------------------------------------------*/ 572 function shufflePlaylistSongs(playlist) { 573 /* 574 Builds a temporary array with the length of the playlist songs. 575 */ 576 var shuffleTemp = new Array(config.playlists[playlist].length); 577 578 /* 579 Set the temporary array equal to the playlist array. 580 */ 581 for (var i = 0; i < config.playlists[playlist].length; i++) { 582 shuffleTemp[i] = config.songs[config.playlists[playlist][i]]; 583 shuffleTemp[i].original_index = i; 584 } 585 586 /* 587 Iterate ove rthe songs and generate random numbers to 588 swap the indexes of the shuffle array. 589 */ 590 for (var i = config.playlists[playlist].length - 1; i > 0; i--) { 591 var randNum = Math.floor(Math.random() * config.playlists[playlist].length + 1); 592 shuffleSwap(shuffleTemp, i, randNum - 1); 593 } 594 595 /* 596 Set the shuffle list to the shuffle temp. 597 */ 598 config.shuffled_playlists[playlist] = shuffleTemp; 599 } 600 601 /*-------------------------------------------------------------------------- 602 Swaps and randomizes the song shuffle. 603 @param JSON shuffleList The list of songs that is going to 604 be shuffled 605 @param int original The original index of the song in the 606 songs array. 607 @param int random The randomized index that will be the 608 new index of the song in the shuffle array. 609 --------------------------------------------------------------------------*/ 610 function shuffleSwap(shuffleList, original, random) { 611 var temp = shuffleList[original]; 612 shuffleList[original] = shuffleList[random]; 613 shuffleList[random] = temp; 614 } 615 616 /*-------------------------------------------------------------------------- 617 Sets the active playlist 618 @param string playlist The string of the playlist being 619 set to active. 620 --------------------------------------------------------------------------*/ 621 function setActivePlaylist(playlist) { 622 if (config.active_playlist != playlist) { 623 runCallback('playlist_changed'); 624 } 625 626 config.active_playlist = playlist; 627 } 628 629 /*-------------------------------------------------------------------------- 630 Determines if the string passed in is a URL or not 631 @param string url The string we are testing to see if it's a URL. 632 --------------------------------------------------------------------------*/ 633 function isURL(url) { 634 var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; 635 636 return pattern.test(url); 637 } 638 639 /*-------------------------------------------------------------------------- 640 Determines if what is passed in is an integer or not. 641 @param string int The variable we are testing to see is an integer or not. 642 --------------------------------------------------------------------------*/ 643 function isInt(int) { 644 return !isNaN(int) && parseInt(Number(int)) == int && !isNaN(parseInt(int, 10)); 645 } 646 647 /* 648 Returns the public functions 649 */ 650 return { 651 resetConfig: resetConfig, 652 writeDebugMessage: writeDebugMessage, 653 runCallback: runCallback, 654 changeSong: changeSong, 655 checkNewSong: checkNewSong, 656 checkNewAlbum: checkNewAlbum,
vendor: 74,084 bytes, lines 657-2756
657 checkNewPlaylist: checkNewPlaylist, 658 shuffleSongs: shuffleSongs, 659 shufflePlaylistSongs: shufflePlaylistSongs, 660 setActivePlaylist: setActivePlaylist, 661 isURL: isURL, 662 isInt: isInt 663 }; 664}(); 665 666exports.default = AmplitudeHelpers; 667module.exports = exports['default']; 668 669/***/ }), 670/* 2 */ 671/***/ (function(module, exports, __webpack_require__) { 672 673"use strict"; 674 675 676Object.defineProperty(exports, "__esModule", { 677 value: true 678}); 679 680var _config = __webpack_require__(0); 681 682var _config2 = _interopRequireDefault(_config); 683 684var _helpers = __webpack_require__(10); 685 686var _helpers2 = _interopRequireDefault(_helpers); 687 688function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 689 690/* 691|---------------------------------------------------------------------------------------------------- 692| VISUAL SYNC METHODS 693|---------------------------------------------------------------------------------------------------- 694| These methods sync visual displays with what is happening in Amplitude 695| 696| Method Prefix: privateVisualSync 697| 698| METHODS 699| syncCurrentTime( currentTime, completionPercentage ) 700| resetTimes() 701| resetSongSliders() 702| setActiveContainer() 703| displaySongMetadata() 704| syncPlaybackSpeed() 705| syncVolumeSliders() 706| setPlayPauseButtonsToPause() 707| syncMainPlayPause( state ) 708| syncPlaylistPlayPause( playlist, state ) 709| syncSongPlayPause( playlist, song, state ) 710| syncRepeat() 711*/ 712var AmplitudeVisualSync = function () { 713 /*-------------------------------------------------------------------------- 714 Visually displays the current time on the screen. This is called on 715 time update for the current song. 716 @param JSON currentTime An object containing the current time for the 717 song in seconds, minutes, and hours. 718 @param float completionPercentage The percent of the way through the song 719 the user is at. 720 --------------------------------------------------------------------------*/ 721 function syncCurrentTime(currentTime, completionPercentage) { 722 /* 723 Set current hour display. 724 */ 725 _helpers2.default.syncCurrentHours(currentTime.hours); 726 727 /* 728 Set current minute display. 729 */ 730 _helpers2.default.syncCurrentMinutes(currentTime.minutes); 731 732 /* 733 Set current second display. 734 */ 735 _helpers2.default.syncCurrentSeconds(currentTime.seconds); 736 737 /* 738 Set current time display. 739 */ 740 _helpers2.default.syncCurrentTime(currentTime); 741 742 /* 743 Set all song sliders to be to the current percentage 744 of the song played. 745 */ 746 syncMainSliderLocation(completionPercentage); 747 syncPlaylistSliderLocation(_config2.default.active_playlist, completionPercentage); 748 syncSongSliderLocation(_config2.default.active_playlist, _config2.default.active_index, completionPercentage); 749 750 _helpers2.default.syncSongPlayedProgressBar(completionPercentage); 751 } 752 753 /*-------------------------------------------------------------------------- 754 Visually sync all of the times to the initial time of 0. This is so 755 we can keep all the players in sync 756 --------------------------------------------------------------------------*/ 757 function resetTimes() { 758 _helpers2.default.resetCurrentHours(); 759 _helpers2.default.resetCurrentMinutes(); 760 _helpers2.default.resetCurrentSeconds(); 761 _helpers2.default.resetCurrentTime(); 762 } 763 764 /*-------------------------------------------------------------------------- 765 Visually syncs the song sliders back to 0. This usually happens when 766 a song has changed, we ensure that all song sliders get reset. 767 --------------------------------------------------------------------------*/ 768 function resetSongSliders() { 769 var songSliders = document.getElementsByClassName("amplitude-song-slider"); 770 771 /* 772 Iterate over all of the song sliders and set them to 773 0 essentially resetting them. 774 */ 775 for (var i = 0; i < songSliders.length; i++) { 776 songSliders[i].value = 0; 777 } 778 } 779 780 /*-------------------------------------------------------------------------- 781 Sets all of the song buffered progress bars to 0 782 --------------------------------------------------------------------------*/ 783 function resetSongBufferedProgressBars() { 784 /* 785 Gets all of the song buffered progress bars. 786 */ 787 var songBufferedProgressBars = document.getElementsByClassName("amplitude-buffered-progress"); 788 789 /* 790 Iterate over all of the song buffered progress bar and 791 set them to 0 which is like re-setting them. 792 */ 793 for (var i = 0; i < songBufferedProgressBars.length; i++) { 794 songBufferedProgressBars[i].value = 0; 795 } 796 } 797 798 /*-------------------------------------------------------------------------- 799 Sets all of the song played progress bars to 0 800 --------------------------------------------------------------------------*/ 801 function resetSongPlayedProgressBars() { 802 var songPlayedProgressBars = document.getElementsByClassName("amplitude-song-played-progress"); 803 804 for (var i = 0; i < songPlayedProgressBars.length; i++) { 805 songPlayedProgressBars[i].value = 0; 806 } 807 } 808 809 /*-------------------------------------------------------------------------- 810 Applies the class 'amplitude-active-song-container' to the element 811 containing visual information regarding the active song. 812 --------------------------------------------------------------------------*/ 813 function setActiveContainer() { 814 var songContainers = document.getElementsByClassName('amplitude-song-container'); 815 816 /* 817 Removes all of the active song containrs. 818 */ 819 for (var i = 0; i < songContainers.length; i++) { 820 songContainers[i].classList.remove('amplitude-active-song-container'); 821 } 822 823 /* 824 Finds the active index and adds the active song container to the element 825 that represents the song at the index. 826 */ 827 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) { 828 if (document.querySelectorAll('.amplitude-song-container[amplitude-song-index="' + _config2.default.active_index + '"]')) { 829 var songContainers = document.querySelectorAll('.amplitude-song-container[amplitude-song-index="' + _config2.default.active_index + '"]'); 830 831 for (i = 0; i < songContainers.length; i++) { 832 if (!songContainers[i].hasAttribute('amplitude-playlist')) { 833 songContainers[i].classList.add('amplitude-active-song-container'); 834 } 835 } 836 } 837 } else { 838 if (document.querySelectorAll('.amplitude-song-container[amplitude-song-index="' + _config2.default.active_index + '"][amplitude-playlist="' + _config2.default.active_playlist + '"]')) { 839 var songContainers = document.querySelectorAll('.amplitude-song-container[amplitude-song-index="' + _config2.default.active_index + '"][amplitude-playlist="' + _config2.default.active_playlist + '"]'); 840 841 for (i = 0; i < songContainers.length; i++) { 842 songContainers[i].classList.add('amplitude-active-song-container'); 843 } 844 } 845 } 846 } 847 848 /*-------------------------------------------------------------------------- 849 Displays the active song's metadata. This is called after a song has 850 been changed. This method takes the active song and displays the 851 metadata. So once the new active song is set, we update all of the 852 screen elements. 853 --------------------------------------------------------------------------*/ 854 function displaySongMetadata() { 855 /* 856 Define the image meta data keys. These are managed separately 857 since we aren't actually changing the inner HTML of these elements. 858 */ 859 var imageMetaDataKeys = ['cover_art_url', 'station_art_url', 'podcast_episode_cover_art_url']; 860 861 /* 862 These are the ignored keys that we won't be worrying about displaying. 863 Every other key in the song object can be displayed. 864 */ 865 var ignoredKeys = ['url', 'live']; 866 867 /* 868 Get all of the song info elements 869 */ 870 var songInfoElements = document.querySelectorAll('[amplitude-song-info]'); 871 872 /* 873 Iterate over all of the song info elements. We will either 874 set these to the new values, or clear them if the active song 875 doesn't have the info set. 876 */ 877 for (var i = 0; i < songInfoElements.length; i++) { 878 /* 879 Get the info so we can check if the active meta data has the 880 key. 881 */ 882 var info = songInfoElements[i].getAttribute('amplitude-song-info'); 883 884 /* 885 Get the song info element playlist. 886 */ 887 var playlist = songInfoElements[i].getAttribute('amplitude-playlist'); 888 889 /* 890 Get the main song info flag. 891 */ 892 var main = songInfoElements[i].getAttribute('amplitude-main-song-info'); 893 894 /* 895 If the playlists match or the element is a main element, then 896 we set the song info. 897 */ 898 if (_config2.default.active_playlist == playlist || main == 'true') { 899 /* 900 If the active metadata has the key, then we set it, 901 otherwise we clear it. If it's an image element then 902 we default it to the default info if needed. 903 */ 904 if (_config2.default.active_metadata[info] != undefined) { 905 if (imageMetaDataKeys.indexOf(info) >= 0) { 906 songInfoElements[i].setAttribute('src', _config2.default.active_metadata[info]); 907 } else { 908 songInfoElements[i].innerHTML = _config2.default.active_metadata[info]; 909 } 910 } else { 911 /* 912 We look for the default album art because 913 the actual key didn't exist. If the default album 914 art doesn't exist then we set the src attribute 915 to null. 916 */ 917 if (imageMetaDataKeys.indexOf(info) >= 0) { 918 if (_config2.default.default_album_art != '') { 919 songInfoElements[i].setAttribute('src', _config2.default.default_album_art); 920 } else { 921 songInfoElements[i].setAttribute('src', ''); 922 } 923 } else { 924 songInfoElements[i].innerHTML = ''; 925 } 926 } 927 } 928 } 929 } 930 931 function setFirstSongInPlaylist(song, playlist) { 932 /* 933 Define the image meta data keys. These are managed separately 934 since we aren't actually changing the inner HTML of these elements. 935 */ 936 var imageMetaDataKeys = ['cover_art_url', 'station_art_url', 'podcast_episode_cover_art_url']; 937 938 /* 939 These are the ignored keys that we won't be worrying about displaying. 940 Every other key in the song object can be displayed. 941 */ 942 var ignoredKeys = ['url', 'live']; 943 944 /* 945 Get all of the song info elements 946 */ 947 var songInfoElements = document.querySelectorAll('[amplitude-song-info][amplitude-playlist="' + playlist + '"]'); 948 949 /* 950 Iterate over all of the song info elements. We will either 951 set these to the new values, or clear them if the active song 952 doesn't have the info set. 953 */ 954 for (var i = 0; i < songInfoElements.length; i++) { 955 /* 956 Get the info so we can check if the active meta data has the 957 key. 958 */ 959 var info = songInfoElements[i].getAttribute('amplitude-song-info'); 960 961 /* 962 Get the song info element playlist. 963 */ 964 var elementPlaylist = songInfoElements[i].getAttribute('amplitude-playlist'); 965 966 /* 967 If the playlists match or the element is a main element, then 968 we set the song info. 969 */ 970 if (elementPlaylist == playlist) { 971 /* 972 If the active metadata has the key, then we set it, 973 otherwise we clear it. If it's an image element then 974 we default it to the default info if needed. 975 */ 976 if (song[info] != undefined) { 977 if (imageMetaDataKeys.indexOf(info) >= 0) { 978 songInfoElements[i].setAttribute('src', song[info]); 979 } else { 980 songInfoElements[i].innerHTML = song[info]; 981 } 982 } else { 983 /* 984 We look for the default album art because 985 the actual key didn't exist. If the default album 986 art doesn't exist then we set the src attribute 987 to null. 988 */ 989 if (imageMetaDataKeys.indexOf(info) >= 0) { 990 if (song.default_album_art != '') { 991 songInfoElements[i].setAttribute('src', song.default_album_art); 992 } else { 993 songInfoElements[i].setAttribute('src', ''); 994 } 995 } else { 996 songInfoElements[i].innerHTML = ''; 997 } 998 } 999 } 1000 } 1001 } 1002 1003 /*-------------------------------------------------------------------------- 1004 Sets all of the visual playback speed buttons to have the right class 1005 to display the background image that represents the current playback 1006 speed. 1007 --------------------------------------------------------------------------*/ 1008 function syncPlaybackSpeed() { 1009 /* 1010 Gets all of the playback speed classes. 1011 */ 1012 var playbackSpeedClasses = document.getElementsByClassName("amplitude-playback-speed"); 1013 1014 /* 1015 Iterates over all of the playback speed classes 1016 applying the right speed class for visual purposes. 1017 */ 1018 for (var i = 0; i < playbackSpeedClasses.length; i++) { 1019 /* 1020 Removes all of the old playback speed classes. 1021 */ 1022 playbackSpeedClasses[i].classList.remove('amplitude-playback-speed-10'); 1023 playbackSpeedClasses[i].classList.remove('amplitude-playback-speed-15'); 1024 playbackSpeedClasses[i].classList.remove('amplitude-playback-speed-20'); 1025 1026 /* 1027 Switch the current playback speed and apply the appropriate 1028 speed class. 1029 */ 1030 switch (_config2.default.playback_speed) { 1031 case 1: 1032 playbackSpeedClasses[i].classList.add('amplitude-playback-speed-10'); 1033 break; 1034 case 1.5: 1035 playbackSpeedClasses[i].classList.add('amplitude-playback-speed-15'); 1036 break; 1037 case 2: 1038 playbackSpeedClasses[i].classList.add('amplitude-playback-speed-20'); 1039 break; 1040 } 1041 } 1042 } 1043 1044 function syncBufferedProgressBars() { 1045 /* 1046 Gets all of the song buffered progress bars. 1047 */ 1048 var songBufferedProgressBars = document.getElementsByClassName("amplitude-buffered-progress"); 1049 1050 /* 1051 Iterate over all of the song buffered progress bar and 1052 set them to 0 which is like re-setting them. 1053 */ 1054 for (var i = 0; i < songBufferedProgressBars.length; i++) { 1055 songBufferedProgressBars[i].value = parseFloat(parseFloat(_config2.default.buffered) / 100); 1056 } 1057 } 1058 1059 /*-------------------------------------------------------------------------- 1060 Visually syncs the volume sliders so they are all the same if there 1061 are more than one. 1062 --------------------------------------------------------------------------*/ 1063 function syncVolumeSliders() { 1064 var amplitudeVolumeSliders = document.getElementsByClassName("amplitude-volume-slider"); 1065 1066 /* 1067 Iterates over all of the volume sliders for the song, setting the value 1068 to the config value. 1069 */ 1070 for (var i = 0; i < amplitudeVolumeSliders.length; i++) { 1071 amplitudeVolumeSliders[i].value = _config2.default.active_song.volume * 100; 1072 } 1073 } 1074 1075 /*-------------------------------------------------------------------------- 1076 Sets all of the play pause buttons to paused. 1077 --------------------------------------------------------------------------*/ 1078 function setPlayPauseButtonsToPause() { 1079 var playPauseElements = document.querySelectorAll('.amplitude-play-pause'); 1080 1081 for (var i = 0; i < playPauseElements.length; i++) { 1082 _helpers2.default.setElementPause(playPauseElements[i]); 1083 } 1084 } 1085 1086 /*-------------------------------------------------------------------------- 1087 Syncs the main play pause buttons to the state of the active song. 1088 @param string state The state of the player. 1089 --------------------------------------------------------------------------*/ 1090 function syncMainPlayPause(state) { 1091 if (typeof state != "string") state = _config2.default.active_song.paused ? "paused" : "playing"; 1092 /* 1093 Get all play pause buttons. 1094 */ 1095 var playPauseElements = document.querySelectorAll('.amplitude-play-pause[amplitude-main-play-pause="true"]'); 1096 1097 /* 1098 Iterate over all of the play pause elements syncing the 1099 display visually. 1100 */ 1101 for (var i = 0; i < playPauseElements.length; i++) { 1102 /* 1103 Determines what classes we should add and remove 1104 from the elements. 1105 */ 1106 switch (state) { 1107 case 'playing': 1108 _helpers2.default.setElementPlay(playPauseElements[i]); 1109 break; 1110 case 'paused': 1111 _helpers2.default.setElementPause(playPauseElements[i]); 1112 break; 1113 } 1114 } 1115 } 1116 1117 /*-------------------------------------------------------------------------- 1118 Syncs the main playlist play pause buttons to the state of the active song. 1119 @param string playlist The playlist we are setting the play pause state 1120 for. 1121 @param string state Either playing or paused for the state of the 1122 active song. 1123 --------------------------------------------------------------------------*/ 1124 function syncPlaylistPlayPause(playlist, state) { 1125 1126 if (typeof state != "string") state = _config2.default.active_song.paused ? "paused" : "playing"; 1127 /* 1128 Get all of the main playlist play pause elements 1129 */ 1130 var playlistPlayPauseElements = document.querySelectorAll('.amplitude-play-pause[amplitude-playlist-main-play-pause="true"]'); 1131 1132 /* 1133 Iterate over the play pause elements, syncing the state accordingly. 1134 */ 1135 for (var i = 0; i < playlistPlayPauseElements.length; i++) { 1136 /* 1137 If the element has the same playlist attribute as the playlist 1138 passed in and the state is playing, we set the element to 1139 be playing otherwise we set it to pause. Setting to pause 1140 means the element doesn't match the active playlist or the 1141 state is paused. 1142 */ 1143 if (playlistPlayPauseElements[i].getAttribute('amplitude-playlist') == playlist && state == 'playing') { 1144 1145 _helpers2.default.setElementPlay(playlistPlayPauseElements[i]); 1146 } else { 1147 _helpers2.default.setElementPause(playlistPlayPauseElements[i]); 1148 } 1149 } 1150 } 1151 1152 /*-------------------------------------------------------------------------- 1153 Syncs the song play pause buttons to the state of the active song. 1154 @param string playlist The playlist we are setting the play pause state 1155 for. 1156 @param int song The index of the song we are syncing the state for 1157 @param string state Either playing or paused for the state of the 1158 active song. 1159 --------------------------------------------------------------------------*/ 1160 function syncSongPlayPause(playlist, song, state) { 1161 1162 if (typeof state != "string") state = _config2.default.active_song.paused ? "paused" : "playing"; 1163 1164 /* 1165 If the playlist is null or empty, we make sure that any song 1166 that is a part of a playlist is set to paused. 1167 */ 1168 if (playlist == null || playlist == '') { 1169 /* 1170 Get all of the individual song play pause buttons. These have an 1171 amplitude-song-index attribute. Some have amplitude-playlist which 1172 means they are individual songs within a playlist. 1173 */ 1174 var songPlayPauseElements = document.querySelectorAll('.amplitude-play-pause[amplitude-song-index]'); 1175 1176 /* 1177 Iterate over all of the song play pause elements 1178 */ 1179 for (var i = 0; i < songPlayPauseElements.length; i++) { 1180 /* 1181 If the song element has an attribute for amplitude-playlist then 1182 we set it to paused no matter what because the state of the player 1183 is not in a playlist mode. 1184 */ 1185 if (songPlayPauseElements[i].hasAttribute('amplitude-playlist')) { 1186 _helpers2.default.setElementPause(songPlayPauseElements[i]); 1187 } else { 1188 /* 1189 If the state of the song is playing and the song index matches the 1190 index of the song we have, we set the element to playing otherwise 1191 we set the element to paused. 1192 */ 1193 if (state == 'playing' && songPlayPauseElements[i].getAttribute('amplitude-song-index') == song) { 1194 _helpers2.default.setElementPlay(songPlayPauseElements[i]); 1195 } else { 1196 _helpers2.default.setElementPause(songPlayPauseElements[i]); 1197 } 1198 } 1199 } 1200 } else { 1201 /* 1202 Get all of the individual song play pause buttons. These have an 1203 amplitude-song-index attribute. Some have amplitude-playlist which 1204 means they are individual songs within a playlist. 1205 */ 1206 var songPlayPauseElements = document.querySelectorAll('.amplitude-play-pause[amplitude-song-index]'); 1207 1208 /* 1209 Iterate over all of the individual play pause elements. 1210 */ 1211 for (var i = 0; i < songPlayPauseElements.length; i++) { 1212 /* 1213 Since we have an active playlist this time, we want any stand alone 1214 songs to be set to paused since the scope is within a playlist. 1215 We check to see if the element has an amplitude-playlist attribute. 1216 */ 1217 if (songPlayPauseElements[i].hasAttribute('amplitude-playlist')) { 1218 1219 /* 1220 Check to see if the song index matches the index passed in and the 1221 playlist matches the scoped playlist we are looking for and the 1222 state of the player is playing, then we set the element to play. If those 1223 three parameters are not met, set the element to pause. 1224 */ 1225 if (songPlayPauseElements[i].getAttribute('amplitude-song-index') == song && songPlayPauseElements[i].getAttribute('amplitude-playlist') == playlist && state == 'playing') { 1226 _helpers2.default.setElementPlay(songPlayPauseElements[i]); 1227 } else { 1228 _helpers2.default.setElementPause(songPlayPauseElements[i]); 1229 } 1230 } else { 1231 /* 1232 Set any individual songs (songs outside of a playlist scope) to pause 1233 since we are in the scope of a playlist. 1234 */ 1235 _helpers2.default.setElementPause(songPlayPauseElements[i]); 1236 } 1237 } 1238 } 1239 } 1240 1241 /*-------------------------------------------------------------------------- 1242 Syncs repeat for all of the repeat buttons. Users 1243 can apply styles to the 'amplitude-repeat-on' and 1244 'amplitude-repeat-off' classes. They represent the state 1245 of the player. 1246 --------------------------------------------------------------------------*/ 1247 function syncRepeat() { 1248 /* 1249 Gets all of the repeat classes 1250 */ 1251 var repeatClasses = document.getElementsByClassName("amplitude-repeat"); 1252 1253 /* 1254 Iterate over all of the repeat classes. If repeat is on, 1255 then add the 'amplitude-repeat-on' class and remove the 1256 'amplitude-repeat-off' class. If it's off, then do the 1257 opposite. 1258 */ 1259 for (var i = 0; i < repeatClasses.length; i++) { 1260 if (_config2.default.repeat) { 1261 repeatClasses[i].classList.add('amplitude-repeat-on'); 1262 repeatClasses[i].classList.remove('amplitude-repeat-off'); 1263 } else { 1264 repeatClasses[i].classList.remove('amplitude-repeat-on'); 1265 repeatClasses[i].classList.add('amplitude-repeat-off'); 1266 } 1267 } 1268 } 1269 1270 /*-------------------------------------------------------------------------- 1271 Syncs mute for all of the mute buttons. This represents the 1272 state of the player if it's muted or not. 1273 @param string state The muted state of the player. 1274 --------------------------------------------------------------------------*/ 1275 function syncMute(state) { 1276 /* 1277 Get all of the mute buttons. 1278 */ 1279 var muteClasses = document.getElementsByClassName("amplitude-mute"); 1280 1281 /* 1282 Iterate over all of the mute classes. If the state of the player 1283 is not-muted then we add the amplitude-not-muted classe and remove 1284 the amplitude muted class otherwise we do the opposite. 1285 */ 1286 for (var i = 0; i < muteClasses.length; i++) { 1287 if (!state) { 1288 muteClasses[i].classList.add('amplitude-not-muted'); 1289 muteClasses[i].classList.remove('amplitude-muted'); 1290 } else { 1291 muteClasses[i].classList.remove('amplitude-not-muted'); 1292 muteClasses[i].classList.add('amplitude-muted'); 1293 } 1294 } 1295 } 1296 1297 /*-------------------------------------------------------------------------- 1298 Syncs the global shuffle button visual state. 1299 @param bool state The shuffled state of the player. 1300 --------------------------------------------------------------------------*/ 1301 function syncShuffle(state) { 1302 /* 1303 Gets the shuffle buttons. 1304 */ 1305 var shuffleButtons = document.getElementsByClassName("amplitude-shuffle"); 1306 1307 /* 1308 Iterate over all of the shuffle buttons. 1309 */ 1310 for (var i = 0; i < shuffleButtons.length; i++) { 1311 /* 1312 Ensure the shuffle button doesn't belong to a playlist. We have 1313 a separate method for that. 1314 */ 1315 if (shuffleButtons[i].getAttribute('amplitude-playlist') == null) { 1316 /* 1317 If the state of the player is shuffled on, true, then 1318 we add the 'amplitude-shuffle-on' class and remove the 1319 'amplitude-shuffle-off' class. If the player is not shuffled 1320 then we do the opposite. 1321 */ 1322 if (state) { 1323 shuffleButtons[i].classList.add('amplitude-shuffle-on'); 1324 shuffleButtons[i].classList.remove('amplitude-shuffle-off'); 1325 } else { 1326 shuffleButtons[i].classList.add('amplitude-shuffle-off'); 1327 shuffleButtons[i].classList.remove('amplitude-shuffle-on'); 1328 } 1329 } 1330 } 1331 } 1332 1333 /*-------------------------------------------------------------------------- 1334 Syncs the playlist shuffle button visual state. 1335 @param bool state The shuffled state of the player. 1336 @param string playlist The playlist string the shuffle button belongs to. 1337 --------------------------------------------------------------------------*/ 1338 function syncPlaylistShuffle(state, playlist) { 1339 /* 1340 Gets all of the shuffle buttons. 1341 */ 1342 var shuffleButtons = document.getElementsByClassName("amplitude-shuffle"); 1343 1344 /* 1345 Iterate over all of the shuffle buttons 1346 */ 1347 for (var i = 0; i < shuffleButtons.length; i++) { 1348 /* 1349 Ensure that the playlist the shuffle button belongs to matches the 1350 playlist we are syncing the state for. 1351 */ 1352 if (shuffleButtons[i].getAttribute('amplitude-playlist') == playlist) { 1353 /* 1354 If the state of the playlist is shuffled on, true, then 1355 we add the 'amplitude-shuffle-on' class and remove the 1356 'amplitude-shuffle-off' class. If the player is not shuffled 1357 then we do the opposite. 1358 */ 1359 if (state) { 1360 shuffleButtons[i].classList.add('amplitude-shuffle-on'); 1361 shuffleButtons[i].classList.remove('amplitude-shuffle-off'); 1362 } else { 1363 shuffleButtons[i].classList.add('amplitude-shuffle-off'); 1364 shuffleButtons[i].classList.remove('amplitude-shuffle-on'); 1365 } 1366 } 1367 } 1368 } 1369 1370 /*-------------------------------------------------------------------------- 1371 Syncs the main slider location 1372 @param int location The location of the song as a percentage. 1373 --------------------------------------------------------------------------*/ 1374 function syncMainSliderLocation(location) { 1375 /* 1376 Ensure we have a location that's a number 1377 */ 1378 location = !isNaN(location) ? location : 0; 1379 1380 /* 1381 Gets the main song sliders 1382 */ 1383 var mainSongSliders = document.querySelectorAll('.amplitude-song-slider[amplitude-main-song-slider="true"]'); 1384 1385 /* 1386 Iterates over all of the main sliders and sets the value to the 1387 percentage of the song played. 1388 */ 1389 for (var i = 0; i < mainSongSliders.length; i++) { 1390 mainSongSliders[i].value = location; 1391 } 1392 } 1393 1394 /*-------------------------------------------------------------------------- 1395 Syncs playlist song slider locations 1396 @param string playlist The playlist we are setting the song slider for. 1397 @param int location The location of the song as a percentage. 1398 --------------------------------------------------------------------------*/ 1399 function syncPlaylistSliderLocation(playlist, location) { 1400 /* 1401 Ensure we have a location that's a number 1402 */ 1403 location = !isNaN(location) ? location : 0; 1404 1405 /* 1406 Gets the playlist song sliders 1407 */ 1408 var playlistSongSliders = document.querySelectorAll('.amplitude-song-slider[amplitude-playlist-song-slider="true"][amplitude-playlist="' + playlist + '"]'); 1409 1410 /* 1411 Iterates over all of the playlist sliders and sets the value to the 1412 percentage of the song played. 1413 */ 1414 for (var i = 0; i < playlistSongSliders.length; i++) { 1415 playlistSongSliders[i].value = location; 1416 } 1417 } 1418 1419 /*-------------------------------------------------------------------------- 1420 Syncs individual song slider locations 1421 @param string playlist The playlist we are setting the song slider for. 1422 @param int songIndex The index of the song we are adjusting the song slider for. 1423 @param int location The location of the song as a percentage. 1424 --------------------------------------------------------------------------*/ 1425 function syncSongSliderLocation(playlist, songIndex, location) { 1426 /* 1427 Ensure we have a location that's a number 1428 */ 1429 location = !isNaN(location) ? location : 0; 1430 /* 1431 If the playlist is set, we get all of the individual song sliders 1432 that relate to the song and the playlist. 1433 */ 1434 if (playlist != '' && playlist != null) { 1435 /* 1436 Gets the song sliders for the individual songs and the 1437 playlist 1438 */ 1439 var songSliders = document.querySelectorAll('.amplitude-song-slider[amplitude-playlist="' + playlist + '"][amplitude-song-index="' + songIndex + '"]'); 1440 1441 /* 1442 Iterates over all of the playlist sliders and set the value to the 1443 percentage of the song played. 1444 */ 1445 for (var i = 0; i < songSliders.length; i++) { 1446 songSliders[i].value = location; 1447 } 1448 } else { 1449 /* 1450 Get the individual song slider by index 1451 */ 1452 var songSliders = document.querySelectorAll('.amplitude-song-slider[amplitude-song-index="' + songIndex + '"]'); 1453 1454 /* 1455 Iterats over all of the song sliders that have the index of 1456 the song we are sliding. If the song doesn't have a playlist 1457 attribute, we set the location. 1458 */ 1459 for (var i = 0; i < songSliders.length; i++) { 1460 if (!songSliders[i].hasAttribute('amplitude-playlist')) { 1461 if (location != 0) { 1462 songSliders[i].value = location; 1463 } 1464 } 1465 } 1466 } 1467 } 1468 1469 /*-------------------------------------------------------------------------- 1470 Sets the volume slider location 1471 @param int volume The volume from 0 - 1 for song volume. 1472 --------------------------------------------------------------------------*/ 1473 function syncVolumeSliderLocation(volume) { 1474 /* 1475 Gets all of the volume sliders 1476 */ 1477 var volumeSliders = document.querySelectorAll('.amplitude-volume-slider'); 1478 1479 /* 1480 Iterates over all of the sliders and sets their volume 1481 to the volume of the song. 1482 */ 1483 for (var i = 0; i < volumeSliders.length; i++) { 1484 volumeSliders[i].value = volume; 1485 } 1486 } 1487 1488 /*-------------------------------------------------------------------------- 1489 Syncs the song's duration 1490 @param songDuration Object containing information about the duration 1491 of the song 1492 --------------------------------------------------------------------------*/ 1493 function syncSongDuration(currentTime, songDuration) { 1494 /* 1495 Set duration hour display. 1496 */ 1497 _helpers2.default.syncDurationHours(songDuration != undefined && !isNaN(songDuration.hours) ? songDuration.hours : '00'); 1498 1499 /* 1500 Set duration minute display. 1501 */ 1502 _helpers2.default.syncDurationMinutes(songDuration != undefined && !isNaN(songDuration.minutes) ? songDuration.minutes : '00'); 1503 1504 /* 1505 Set duration second display. 1506 */ 1507 _helpers2.default.syncDurationSeconds(songDuration != undefined && !isNaN(songDuration.seconds) ? songDuration.seconds : '00'); 1508 1509 /* 1510 Set duration time display. 1511 */ 1512 _helpers2.default.syncDurationTime(songDuration != undefined ? songDuration : {}); 1513 1514 /* 1515 Set count down time display. 1516 */ 1517 _helpers2.default.syncCountDownTime(currentTime, songDuration); 1518 } 1519 1520 /* 1521 Returns the publically available functions 1522 */ 1523 return { 1524 syncCurrentTime: syncCurrentTime, 1525 resetTimes: resetTimes, 1526 resetSongSliders: resetSongSliders, 1527 resetSongPlayedProgressBars: resetSongPlayedProgressBars, 1528 resetSongBufferedProgressBars: resetSongBufferedProgressBars, 1529 setActiveContainer: setActiveContainer, 1530 displaySongMetadata: displaySongMetadata, 1531 syncPlaybackSpeed: syncPlaybackSpeed, 1532 syncBufferedProgressBars: syncBufferedProgressBars, 1533 syncVolumeSliders: syncVolumeSliders, 1534 setPlayPauseButtonsToPause: setPlayPauseButtonsToPause, 1535 setFirstSongInPlaylist: setFirstSongInPlaylist, 1536 syncMainPlayPause: syncMainPlayPause, 1537 syncPlaylistPlayPause: syncPlaylistPlayPause, 1538 syncSongPlayPause: syncSongPlayPause, 1539 syncRepeat: syncRepeat, 1540 syncMute: syncMute, 1541 syncShuffle: syncShuffle, 1542 syncPlaylistShuffle: syncPlaylistShuffle, 1543 syncMainSliderLocation: syncMainSliderLocation, 1544 syncPlaylistSliderLocation: syncPlaylistSliderLocation, 1545 syncSongSliderLocation: syncSongSliderLocation, 1546 syncVolumeSliderLocation: syncVolumeSliderLocation, 1547 syncSongDuration: syncSongDuration 1548 }; 1549}(); 1550 1551exports.default = AmplitudeVisualSync; 1552module.exports = exports['default']; 1553 1554/***/ }), 1555/* 3 */ 1556/***/ (function(module, exports, __webpack_require__) { 1557 1558"use strict"; 1559 1560 1561Object.defineProperty(exports, "__esModule", { 1562 value: true 1563}); 1564 1565var _config = __webpack_require__(0); 1566 1567var _config2 = _interopRequireDefault(_config); 1568 1569var _helpers = __webpack_require__(1); 1570 1571var _helpers2 = _interopRequireDefault(_helpers); 1572 1573var _visual = __webpack_require__(2); 1574 1575var _visual2 = _interopRequireDefault(_visual); 1576 1577function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1578 1579/* 1580|---------------------------------------------------------------------------------------------------- 1581| CORE FUNCTIONAL METHODS 1582|---------------------------------------------------------------------------------------------------- 1583| Interacts directly with native functions of the Audio element. Logic 1584| leading up to these methods are handled by click handlers which call 1585| helpers and visual synchronizers. These are the core functions of AmplitudeJS. 1586| Every other function that leads to these prepare the information to be 1587| acted upon by these functions. 1588| 1589| METHODS 1590| play() 1591| pause() 1592| stop() 1593| setVolume( volumeLevel ) 1594| setSongLocation( songPercentage ) 1595| disconnectStream() 1596| reconnectStream() 1597| playNow() 1598| setPlaybackSpeed() 1599*/ 1600var AmplitudeCore = function () { 1601 /*-------------------------------------------------------------------------- 1602 Plays the active song. If the current song is live, it reconnects 1603 the stream before playing. 1604 --------------------------------------------------------------------------*/ 1605 function play() { 1606 /* 1607 Run the before play callback 1608 */ 1609 _helpers2.default.runCallback('before_play'); 1610 1611 /* 1612 If the audio is live we re-conenct the stream. 1613 */ 1614 if (_config2.default.active_metadata.live) { 1615 reconnectStream(); 1616 } 1617 1618 /* 1619 Mobile remote sources need to be reconnected on play. I think this is 1620 because mobile browsers are optimized not to load all resources 1621 for speed reasons. We only do this if mobile and the paused button 1622 is not clicked. If the pause button was clicked then we don't reconnect 1623 or the user will lose their place in the stream. 1624 */ 1625 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && !_config2.default.paused) { 1626 reconnectStream(); 1627 } 1628 1629 /* 1630 Play the song and set the playback rate to the playback 1631 speed. 1632 */ 1633 _config2.default.active_song.play(); 1634 _config2.default.active_song.playbackRate = _config2.default.playback_speed; 1635 1636 /* 1637 Run the after play callback 1638 */ 1639 _helpers2.default.runCallback('after_play'); 1640 } 1641 1642 /*-------------------------------------------------------------------------- 1643 Pauses the active song. If it's live, it disconnects the stream. 1644 --------------------------------------------------------------------------*/ 1645 function pause() { 1646 _helpers2.default.runCallback('before_pause'); 1647 /* 1648 Pause the active song. 1649 */ 1650 _config2.default.active_song.pause(); 1651 1652 /* 1653 Flag that pause button was clicked. 1654 */ 1655 _config2.default.paused = true; 1656 1657 if (_config2.default.active_metadata.live) { 1658 disconnectStream(); 1659 } 1660 _helpers2.default.runCallback('after_pause'); 1661 } 1662 1663 /*-------------------------------------------------------------------------- 1664 Stops the active song by setting the current song time to 0. 1665 When the user resumes, it will be from the beginning. 1666 If it's a live stream it disconnects. 1667 --------------------------------------------------------------------------*/ 1668 function stop() { 1669 _helpers2.default.runCallback('before_stop'); 1670 1671 if (_config2.default.active_song.currentTime != 0) { 1672 _config2.default.active_song.currentTime = 0; 1673 } 1674 1675 _config2.default.active_song.pause(); 1676 1677 if (_config2.default.active_metadata.live) { 1678 disconnectStream(); 1679 } 1680 1681 _helpers2.default.runCallback('after_stop'); 1682 } 1683 1684 /*-------------------------------------------------------------------------- 1685 Sets the song volume. 1686 @param int volumeLevel A number between 1 and 100 as a percentage of 1687 min to max for a volume level. 1688 --------------------------------------------------------------------------*/ 1689 function setVolume(volumeLevel) { 1690 _config2.default.active_song.volume = volumeLevel / 100; 1691 } 1692 1693 /*-------------------------------------------------------------------------- 1694 Sets the song percentage. If it's a live song, we ignore this because 1695 we can't skip ahead. This is an issue if you have a playlist with 1696 a live source. 1697 @param int songPercentage A number between 1 and 100 as a percentage of 1698 song completion. 1699 --------------------------------------------------------------------------*/ 1700 function setSongLocation(songPercentage) { 1701 if (!_config2.default.active_metadata.live) { 1702 _config2.default.active_song.currentTime = _config2.default.active_song.duration * (song_percentage / 100); 1703 } 1704 } 1705 1706 /*-------------------------------------------------------------------------- 1707 Skips to a location in a song 1708 @param int seconds An integer containing the seconds to skip to 1709 --------------------------------------------------------------------------*/ 1710 function skipToLocation(seconds) { 1711 /* 1712 When the active song can be played through, we can check to 1713 see if the seconds will work. We only bind the event handler 1714 once and remove it once it's fired. 1715 */ 1716 _config2.default.active_song.addEventListener('canplaythrough', function () { 1717 /* 1718 If the active song duration is greater than or equal to the 1719 amount of seconds the user wants to skip to and the seconds 1720 is greater than 0, we skip to the seconds defined. 1721 */ 1722 if (_config2.default.active_song.duration >= seconds && seconds > 0) { 1723 _config2.default.active_song.currentTime = seconds; 1724 } else { 1725 _helpers2.default.writeDebugMessage('Amplitude can\'t skip to a location greater than the duration of the audio or less than 0'); 1726 } 1727 }, { once: true }); 1728 } 1729 1730 /*-------------------------------------------------------------------------- 1731 Disconnects the live stream 1732 --------------------------------------------------------------------------*/ 1733 function disconnectStream() { 1734 _config2.default.active_song.src = ''; 1735 _config2.default.active_song.load(); 1736 } 1737 1738 /*-------------------------------------------------------------------------- 1739 Reconnects the live stream 1740 --------------------------------------------------------------------------*/ 1741 function reconnectStream() { 1742 _config2.default.active_song.src = _config2.default.active_metadata.url; 1743 _config2.default.active_song.load(); 1744 } 1745 1746 /*-------------------------------------------------------------------------- 1747 When you pass a song object it plays that song right awawy. It sets 1748 the active song in the config to the song you pass in and synchronizes 1749 the visuals. 1750 Public Accessor: Amplitude.playNow( song_json ) 1751 @param song JSON representation of a song. 1752 --------------------------------------------------------------------------*/ 1753 function playNow(song) { 1754 /* 1755 Makes sure the song object has a URL associated with it 1756 or there will be nothing to play. 1757 */ 1758 if (song.url) { 1759 _config2.default.active_song.src = song.url; 1760 _config2.default.active_metadata = song; 1761 _config2.default.active_album = song.album; 1762 } else { 1763 /* 1764 Write error message since the song passed in doesn't 1765 have a URL. 1766 */ 1767 _helpers2.default.writeDebugMessage('The song needs to have a URL!'); 1768 } 1769 1770 /* 1771 Sets the main song control status visual 1772 */ 1773 _visual2.default.syncMainPlayPause('playing'); 1774 1775 /* 1776 Update the song meta data 1777 */ 1778 _visual2.default.displaySongMetadata(); 1779 1780 /* 1781 Reset the song sliders, song progress bar info, and 1782 reset times. This ensures everything stays in sync. 1783 */ 1784 _visual2.default.resetSongSliders(); 1785 1786 _visual2.default.resetSongPlayedProgressBars(); 1787 1788 _visual2.default.resetTimes(); 1789 1790 /* 1791 Plays the song. 1792 */ 1793 play(); 1794 } 1795 1796 /*-------------------------------------------------------------------------- 1797 Sets the playback speed for the song. 1798 @param float playbackSpeed The speed we want the song to play back at. 1799 --------------------------------------------------------------------------*/ 1800 function setPlaybackSpeed(playbackSpeed) { 1801 /* 1802 Set the config playback speed. 1803 */ 1804 _config2.default.playback_speed = playbackSpeed; 1805 1806 /* 1807 Set the active song playback rate. 1808 */ 1809 _config2.default.active_song.playbackRate = _config2.default.playback_speed; 1810 } 1811 1812 /* 1813 Return publically facing functions 1814 */ 1815 return { 1816 play: play, 1817 pause: pause, 1818 stop: stop, 1819 setVolume: setVolume, 1820 setSongLocation: setSongLocation, 1821 skipToLocation: skipToLocation, 1822 disconnectStream: disconnectStream, 1823 reconnectStream: reconnectStream, 1824 playNow: playNow, 1825 setPlaybackSpeed: setPlaybackSpeed 1826 }; 1827}(); 1828 1829exports.default = AmplitudeCore; 1830module.exports = exports['default']; 1831 1832/***/ }), 1833/* 4 */ 1834/***/ (function(module, exports, __webpack_require__) { 1835 1836"use strict"; 1837 1838 1839Object.defineProperty(exports, "__esModule", { 1840 value: true 1841}); 1842 1843var _config = __webpack_require__(0); 1844 1845var _config2 = _interopRequireDefault(_config); 1846 1847var _helpers = __webpack_require__(1); 1848 1849var _helpers2 = _interopRequireDefault(_helpers); 1850 1851var _handlers = __webpack_require__(7); 1852 1853var _handlers2 = _interopRequireDefault(_handlers); 1854 1855function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1856 1857/* 1858|---------------------------------------------------------------------------------------------------- 1859| EVENTS METHODS 1860|---------------------------------------------------------------------------------------------------- 1861| These methods are called when we need to bind events to certain elements. 1862| 1863| METHODS: 1864| initializeEvents() 1865| bindPlay() 1866| bindPause() 1867| bindPlayPause() 1868| bindStop() 1869| bindMute() 1870| bindVolumeUp() 1871| bindVolumeDown() 1872| bindSongSlider() 1873| bindVolumeSlider() 1874| bindNext() 1875| bindPrev() 1876| bindShuffle() 1877| bindRepeat() 1878| bindPlaybackSpeed() 1879| bindSkipTo() 1880| bindProgress() 1881*/ 1882var AmplitudeEvents = function () { 1883 /*-------------------------------------------------------------------------- 1884 Initializes the handlers for the events listened to by Amplitude 1885 --------------------------------------------------------------------------*/ 1886 function initializeEvents() { 1887 /* 1888 Write out debug message 1889 */ 1890 _helpers2.default.writeDebugMessage('Beginning initialization of event handlers..'); 1891 1892 /* 1893 Sets flag that the screen is moving and not a tap 1894 */ 1895 document.addEventListener('touchmove', function () { 1896 _config2.default.is_touch_moving = true; 1897 }); 1898 1899 /* 1900 On touch end if it was a touch move event, set moving to 1901 false 1902 */ 1903 document.addEventListener('touchend', function () { 1904 if (_config2.default.is_touch_moving) { 1905 _config2.default.is_touch_moving = false; 1906 } 1907 }); 1908 1909 /* 1910 On time update for the audio element, update visual displays that 1911 represent the time on either a visualized element or time display. 1912 */ 1913 bindTimeUpdate(); 1914 1915 /* 1916 Binds key down event handlers for matching key codes to functions. 1917 */ 1918 bindKeyDownEventHandlers(); 1919 1920 /* 1921 When the audio element has ended playing, we handle the song 1922 ending. In a single song or multiple modular song instance, 1923 this just synchronizes the visuals for time and song time 1924 visualization, but for a playlist it determines whether 1925 it should play the next song or not. 1926 */ 1927 bindSongEnded(); 1928 1929 /* 1930 Binds progress event so we can see how much of the song is loaded. 1931 */ 1932 bindProgress(); 1933 1934 /* 1935 Binds 'amplitude-play' event handlers 1936 */ 1937 bindPlay(); 1938 1939 /* 1940 Binds 'amplitude-pause' event handlers. 1941 */ 1942 bindPause(); 1943 1944 /* 1945 Binds 'amplitude-play-pause' event handlers. 1946 */ 1947 bindPlayPause(); 1948 1949 /* 1950 Binds 'amplitude-stop' event handlers. 1951 */ 1952 bindStop(); 1953 1954 /* 1955 Binds 'amplitude-mute' event handlers. 1956 */ 1957 bindMute(); 1958 1959 /* 1960 Binds 'amplitude-volume-up' event handlers 1961 */ 1962 bindVolumeUp(); 1963 1964 /* 1965 Binds 'amplitude-volume-down' event handlers 1966 */ 1967 bindVolumeDown(); 1968 1969 /* 1970 Binds 'amplitude-song-slider' event handlers 1971 */ 1972 bindSongSlider(); 1973 1974 /* 1975 Binds 'amplitude-volume-slider' event handlers. 1976 */ 1977 bindVolumeSlider(); 1978 1979 /* 1980 Binds 'amplitude-next' event handlers. 1981 */ 1982 bindNext(); 1983 1984 /* 1985 Binds 'amplitude-prev' event handlers. 1986 */ 1987 bindPrev(); 1988 1989 /* 1990 Binds 'amplitude-shuffle' event handlers. 1991 */ 1992 bindShuffle(); 1993 1994 /* 1995 Binds 'amplitude-repeat' event handlers. 1996 */ 1997 bindRepeat(); 1998 1999 /* 2000 Binds 'amplitude-playback-speed' event handlers. 2001 */ 2002 bindPlaybackSpeed(); 2003 2004 /* 2005 Binds 'amplitude-skip-to' event handlers. 2006 */ 2007 bindSkipTo(); 2008 } 2009 2010 /*-------------------------------------------------------------------------- 2011 On time update for the audio element, update visual displays that 2012 represent the time on either a visualized element or time display. 2013 --------------------------------------------------------------------------*/ 2014 function bindTimeUpdate() { 2015 _config2.default.active_song.removeEventListener('timeupdate', _handlers2.default.updateTime); 2016 _config2.default.active_song.addEventListener('timeupdate', _handlers2.default.updateTime); 2017 2018 // also bind change of duratuion 2019 _config2.default.active_song.removeEventListener('durationchange', _handlers2.default.updateTime); 2020 _config2.default.active_song.addEventListener('durationchange', _handlers2.default.updateTime); 2021 } 2022 2023 /*-------------------------------------------------------------------------- 2024 On keydown, we listen to what key got pressed so we can map the key to 2025 a function. This allows the user to map pause and play, next, etc. to key 2026 presses. 2027 --------------------------------------------------------------------------*/ 2028 function bindKeyDownEventHandlers() { 2029 document.removeEventListener("keydown", _helpers2.default.keydown); 2030 document.addEventListener("keydown", _handlers2.default.keydown); 2031 } 2032 2033 /*-------------------------------------------------------------------------- 2034 When the audio element has ended playing, we handle the song 2035 ending. In a single song or multiple modular song instance, 2036 this just synchronizes the visuals for time and song time 2037 visualization, but for a playlist it determines whether 2038 it should play the next song or not. 2039 --------------------------------------------------------------------------*/ 2040 function bindSongEnded() { 2041 _config2.default.active_song.removeEventListener('ended', _handlers2.default.songEnded); 2042 _config2.default.active_song.addEventListener('ended', _handlers2.default.songEnded); 2043 } 2044 2045 /*-------------------------------------------------------------------------- 2046 As the audio is loaded, the progress event gets fired. We bind into this 2047 to grab the buffered percentage of the song. We can then add more elements 2048 to show the buffered amount. 2049 --------------------------------------------------------------------------*/ 2050 function bindProgress() { 2051 _config2.default.active_song.removeEventListener('progress', _handlers2.default.progess); 2052 _config2.default.active_song.addEventListener('progress', _handlers2.default.progress); 2053 } 2054 2055 /*-------------------------------------------------------------------------- 2056 BINDS: class="amplitude-play" 2057 Binds click and touchend events for amplitude play buttons. 2058 --------------------------------------------------------------------------*/ 2059 function bindPlay() { 2060 /* 2061 Gets all of the elements with the class amplitude-play 2062 */ 2063 var play_classes = document.getElementsByClassName("amplitude-play"); 2064 2065 /* 2066 Iterates over all of the play classes and binds the event interaction 2067 method to the element. If the browser is mobile, then the event is touchend 2068 otherwise it is click. 2069 */ 2070 for (var i = 0; i < play_classes.length; i++) { 2071 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2072 play_classes[i].removeEventListener('touchend', _handlers2.default.play); 2073 play_classes[i].addEventListener('touchend', _handlers2.default.play); 2074 } else { 2075 play_classes[i].removeEventListener('click', _handlers2.default.play); 2076 play_classes[i].addEventListener('click', _handlers2.default.play); 2077 } 2078 } 2079 } 2080 2081 /*-------------------------------------------------------------------------- 2082 BINDS: class="amplitude-pause" 2083 Binds click and touchend events for amplitude pause buttons. 2084 --------------------------------------------------------------------------*/ 2085 function bindPause() { 2086 /* 2087 Gets all of the elements with the class amplitude-pause 2088 */ 2089 var pause_classes = document.getElementsByClassName("amplitude-pause"); 2090 2091 /* 2092 Iterates over all of the pause classes and binds the event interaction 2093 method to the element. If the browser is mobile, then the event is touchend 2094 otherwise it is click. 2095 */ 2096 for (var i = 0; i < pause_classes.length; i++) { 2097 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2098 pause_classes[i].removeEventListener('touchend', _handlers2.default.pause); 2099 pause_classes[i].addEventListener('touchend', _handlers2.default.pause); 2100 } else { 2101 pause_classes[i].removeEventListener('click', _handlers2.default.pause); 2102 pause_classes[i].addEventListener('click', _handlers2.default.pause); 2103 } 2104 } 2105 } 2106 2107 /*-------------------------------------------------------------------------- 2108 BINDS: class="amplitude-play-pause" 2109 Binds click and touchend events for amplitude play pause buttons. 2110 --------------------------------------------------------------------------*/ 2111 function bindPlayPause() { 2112 /* 2113 Gets all of the elements with the class amplitude-play-pause 2114 */ 2115 var play_pause_classes = document.getElementsByClassName("amplitude-play-pause"); 2116 2117 /* 2118 Iterates over all of the play/pause classes and binds the event interaction 2119 method to the element. If the browser is mobile, then the event is touchend 2120 otherwise it is click. 2121 */ 2122 for (var i = 0; i < play_pause_classes.length; i++) { 2123 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2124 play_pause_classes[i].removeEventListener('touchend', _handlers2.default.playPause); 2125 play_pause_classes[i].addEventListener('touchend', _handlers2.default.playPause); 2126 } else { 2127 play_pause_classes[i].removeEventListener('click', _handlers2.default.playPause); 2128 play_pause_classes[i].addEventListener('click', _handlers2.default.playPause); 2129 } 2130 } 2131 } 2132 2133 /*-------------------------------------------------------------------------- 2134 BINDS: class="amplitude-stop" 2135 Binds click and touchend events for amplitude stop buttons 2136 --------------------------------------------------------------------------*/ 2137 function bindStop() { 2138 /* 2139 Gets all of the elements with the class amplitude-stop 2140 */ 2141 var stop_classes = document.getElementsByClassName("amplitude-stop"); 2142 2143 /* 2144 Iterates over all of the stop classes and binds the event interaction 2145 method to the element. If the browser is mobile, then the event is touchend 2146 otherwise it is click. 2147 */ 2148 for (var i = 0; i < stop_classes.length; i++) { 2149 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2150 stop_classes[i].removeEventListener('touchend', _handlers2.default.stop); 2151 stop_classes[i].addEventListener('touchend', _handlers2.default.stop); 2152 } else { 2153 stop_classes[i].removeEventListener('click', _handlers2.default.stop); 2154 stop_classes[i].addEventListener('click', _handlers2.default.stop); 2155 } 2156 } 2157 } 2158 2159 /*-------------------------------------------------------------------------- 2160 BINDS: class="amplitude-mute" 2161 Binds click and touchend events for amplitude mute buttons 2162 --------------------------------------------------------------------------*/ 2163 function bindMute() { 2164 /* 2165 Gets all of the elements with the class amplitue-mute 2166 */ 2167 var mute_classes = document.getElementsByClassName("amplitude-mute"); 2168 2169 /* 2170 Iterates over all of the mute classes and binds the event interaction 2171 method to the element. If the browser is mobile, then the event is touchend 2172 otherwise it is click. 2173 */ 2174 for (var i = 0; i < mute_classes.length; i++) { 2175 /* 2176 WARNING: If iOS, we don't do anything because iOS does not allow the 2177 volume to be adjusted through anything except the buttons on the side of 2178 the device. 2179 */ 2180 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2181 /* 2182 Checks for an iOS device and displays an error message if debugging 2183 is turned on. 2184 */ 2185 if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { 2186 _helpers2.default.writeDebugMessage('iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4'); 2187 } else { 2188 mute_classes[i].removeEventListener('touchend', _handlers2.default.mute); 2189 mute_classes[i].addEventListener('touchend', _handlers2.default.mute); 2190 } 2191 } else { 2192 mute_classes[i].removeEventListener('click', _handlers2.default.mute); 2193 mute_classes[i].addEventListener('click', _handlers2.default.mute); 2194 } 2195 } 2196 } 2197 2198 /*-------------------------------------------------------------------------- 2199 BINDS: class="amplitude-volume-up" 2200 Binds click and touchend events for amplitude volume up buttons 2201 --------------------------------------------------------------------------*/ 2202 function bindVolumeUp() { 2203 /* 2204 Gets all of the elements with the class amplitude-volume-up 2205 */ 2206 var volume_up_classes = document.getElementsByClassName("amplitude-volume-up"); 2207 2208 /* 2209 Iterates over all of the volume up classes and binds the event interaction 2210 methods to the element. If the browser is mobile, then the event is touchend 2211 otherwise it is click. 2212 */ 2213 for (var i = 0; i < volume_up_classes.length; i++) { 2214 /* 2215 WARNING: If iOS, we don't do anything because iOS does not allow the 2216 volume to be adjusted through anything except the buttons on the side of 2217 the device. 2218 */ 2219 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2220 /* 2221 Checks for an iOS device and displays an error message if debugging 2222 is turned on. 2223 */ 2224 if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { 2225 _helpers2.default.writeDebugMessage('iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4'); 2226 } else { 2227 volume_up_classes[i].removeEventListener('touchend', _handlers2.default.volumeUp); 2228 volume_up_classes[i].addEventListener('touchend', _handlers2.default.volumeUp); 2229 } 2230 } else { 2231 volume_up_classes[i].removeEventListener('click', _handlers2.default.volumeUp); 2232 volume_up_classes[i].addEventListener('click', _handlers2.default.volumeUp); 2233 } 2234 } 2235 } 2236 2237 /*-------------------------------------------------------------------------- 2238 BINDS: class="amplitude-volume-down" 2239 Binds click and touchend events for amplitude volume down buttons 2240 --------------------------------------------------------------------------*/ 2241 function bindVolumeDown() { 2242 /* 2243 Gets all of the elements with the class amplitude-volume-down 2244 */ 2245 var volume_down_classes = document.getElementsByClassName("amplitude-volume-down"); 2246 2247 /* 2248 Iterates over all of the volume down classes and binds the event interaction 2249 methods to the element. If the browser is mobile, then the event is touchend 2250 otherwise it is click. 2251 */ 2252 for (var i = 0; i < volume_down_classes.length; i++) { 2253 /* 2254 WARNING: If iOS, we don't do anything because iOS does not allow the 2255 volume to be adjusted through anything except the buttons on the side of 2256 the device. 2257 */ 2258 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2259 /* 2260 Checks for an iOS device and displays an error message if debugging 2261 is turned on. 2262 */ 2263 if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { 2264 _helpers2.default.writeDebugMessage('iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4'); 2265 } else { 2266 volume_down_classes[i].removeEventListener('touchend', _handlers2.default.volumeDown); 2267 volume_down_classes[i].addEventListener('touchend', _handlers2.default.volumeDown); 2268 } 2269 } else { 2270 volume_down_classes[i].removeEventListener('click', _handlers2.default.volumeDown); 2271 volume_down_classes[i].addEventListener('click', _handlers2.default.volumeDown); 2272 } 2273 } 2274 } 2275 2276 /*-------------------------------------------------------------------------- 2277 BINDS: class="amplitude-song-slider" 2278 Binds change and input events for amplitude song slider inputs 2279 --------------------------------------------------------------------------*/ 2280 function bindSongSlider() { 2281 /* 2282 Gets browser so if we need to apply overrides, like we usually 2283 have to do for anything cool in IE, we can do that. 2284 */ 2285 var ua = window.navigator.userAgent; 2286 var msie = ua.indexOf("MSIE "); 2287 2288 /* 2289 Gets all of the elements with the class amplitude-song-slider 2290 */ 2291 var song_sliders = document.getElementsByClassName("amplitude-song-slider"); 2292 2293 /* 2294 Iterates over all of the song slider classes and binds the event interaction 2295 methods to the element. If the browser is IE we listen to the change event 2296 where if it is anything else, it's the input method. 2297 */ 2298 for (var i = 0; i < song_sliders.length; i++) { 2299 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) { 2300 song_sliders[i].removeEventListener('change', _handlers2.default.songSlider); 2301 song_sliders[i].addEventListener('change', _handlers2.default.songSlider); 2302 } else { 2303 song_sliders[i].removeEventListener('input', _handlers2.default.songSlider); 2304 song_sliders[i].addEventListener('input', _handlers2.default.songSlider); 2305 } 2306 } 2307 } 2308 2309 /*-------------------------------------------------------------------------- 2310 BINDS: class="amplitude-volume-slider" 2311 Binds change and input events for amplitude volume slider inputs 2312 --------------------------------------------------------------------------*/ 2313 function bindVolumeSlider() { 2314 /* 2315 Gets browser so if we need to apply overrides, like we usually 2316 have to do for anything cool in IE, we can do that. 2317 */ 2318 var ua = window.navigator.userAgent; 2319 var msie = ua.indexOf("MSIE "); 2320 2321 /* 2322 Gets all of the elements with the class amplitude-volume-slider 2323 */ 2324 var volume_sliders = document.getElementsByClassName("amplitude-volume-slider"); 2325 2326 /* 2327 Iterates over all of the volume slider classes and binds the event interaction 2328 methods to the element. If the browser is IE we listen to the change event 2329 where if it is anything else, it's the input method. 2330 */ 2331 for (var i = 0; i < volume_sliders.length; i++) { 2332 /* 2333 WARNING: If iOS, we don't do anything because iOS does not allow the 2334 volume to be adjusted through anything except the buttons on the side of 2335 the device. 2336 */ 2337 if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { 2338 _helpers2.default.writeDebugMessage('iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4'); 2339 } else { 2340 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) { 2341 volume_sliders[i].removeEventListener('change', _handlers2.default.volumeSlider); 2342 volume_sliders[i].addEventListener('change', _handlers2.default.volumeSlider); 2343 } else { 2344 volume_sliders[i].removeEventListener('input', _handlers2.default.volumeSlider); 2345 volume_sliders[i].addEventListener('input', _handlers2.default.volumeSlider); 2346 } 2347 } 2348 } 2349 } 2350 2351 /*-------------------------------------------------------------------------- 2352 BINDS: class="amplitude-next" 2353 Binds click and touchend events for amplitude next buttons. 2354 --------------------------------------------------------------------------*/ 2355 function bindNext() { 2356 /* 2357 Gets all of the elements with the class amplitude-next 2358 */ 2359 var next_classes = document.getElementsByClassName("amplitude-next"); 2360 2361 /* 2362 Iterates over all of the next classes and binds the event interaction 2363 methods to the element. If the browser is mobile, then the event is touchend 2364 otherwise it is click. 2365 */ 2366 for (var i = 0; i < next_classes.length; i++) { 2367 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2368 next_classes[i].removeEventListener('touchend', _handlers2.default.next); 2369 next_classes[i].addEventListener('touchend', _handlers2.default.next); 2370 } else { 2371 next_classes[i].removeEventListener('click', _handlers2.default.next); 2372 next_classes[i].addEventListener('click', _handlers2.default.next); 2373 } 2374 } 2375 } 2376 2377 /*-------------------------------------------------------------------------- 2378 BINDS: class="amplitude-prev" 2379 Binds click and touchend events for amplitude prev buttons. 2380 --------------------------------------------------------------------------*/ 2381 function bindPrev() { 2382 /* 2383 Gets all of the elements with the class amplitude-prev 2384 */ 2385 var prev_classes = document.getElementsByClassName("amplitude-prev"); 2386 2387 /* 2388 Iterates over all of the prev classes and binds the event interaction 2389 methods to the element. If the browser is mobile, then the event is touchend 2390 otherwise it is click. 2391 */ 2392 for (var i = 0; i < prev_classes.length; i++) { 2393 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2394 prev_classes[i].removeEventListener('touchend', _handlers2.default.prev); 2395 prev_classes[i].addEventListener('touchend', _handlers2.default.prev); 2396 } else { 2397 prev_classes[i].removeEventListener('click', _handlers2.default.prev); 2398 prev_classes[i].addEventListener('click', _handlers2.default.prev); 2399 } 2400 } 2401 } 2402 2403 /*-------------------------------------------------------------------------- 2404 BINDS: class="amplitude-shuffle" 2405 Binds click and touchend events for amplitude shuffle buttons. 2406 --------------------------------------------------------------------------*/ 2407 function bindShuffle() { 2408 /* 2409 Gets all of the elements with the class amplitude-shuffle 2410 */ 2411 var shuffle_classes = document.getElementsByClassName("amplitude-shuffle"); 2412 2413 /* 2414 Iterates over all of the shuffle classes and binds the event interaction 2415 methods to the element. If the browser is mobile, then the event is touchend 2416 otherwise it is click. 2417 */ 2418 for (var i = 0; i < shuffle_classes.length; i++) { 2419 /* 2420 Since we are re-binding everything we remove any classes that signify 2421 a state of the shuffle control. 2422 */ 2423 shuffle_classes[i].classList.remove('amplitude-shuffle-on'); 2424 shuffle_classes[i].classList.add('amplitude-shuffle-off'); 2425 2426 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2427 shuffle_classes[i].removeEventListener('touchend', _handlers2.default.shuffle); 2428 shuffle_classes[i].addEventListener('touchend', _handlers2.default.shuffle); 2429 } else { 2430 shuffle_classes[i].removeEventListener('click', _handlers2.default.shuffle); 2431 shuffle_classes[i].addEventListener('click', _handlers2.default.shuffle); 2432 } 2433 } 2434 } 2435 2436 /*-------------------------------------------------------------------------- 2437 BINDS: class="amplitude-repeat" 2438 Binds click and touchend events for amplitude repeat buttons. 2439 --------------------------------------------------------------------------*/ 2440 function bindRepeat() { 2441 /* 2442 Gets all of the elements with the class amplitude-repeat 2443 */ 2444 var repeat_classes = document.getElementsByClassName("amplitude-repeat"); 2445 2446 /* 2447 Iterates over all of the repeat classes and binds the event interaction 2448 methods to the element. If the browser is mobile, then the event is touchend 2449 otherwise it is click. 2450 */ 2451 for (var i = 0; i < repeat_classes.length; i++) { 2452 /* 2453 Since we are re-binding everything we remove any classes that signify 2454 a state of the repeat control. 2455 */ 2456 repeat_classes[i].classList.remove('amplitude-repeat-on'); 2457 repeat_classes[i].classList.add('amplitude-repeat-off'); 2458 2459 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2460 repeat_classes[i].removeEventListener('touchend', _handlers2.default.repeat); 2461 repeat_classes[i].addEventListener('touchend', _handlers2.default.repeat); 2462 } else { 2463 repeat_classes[i].removeEventListener('click', _handlers2.default.repeat); 2464 repeat_classes[i].addEventListener('click', _handlers2.default.repeat); 2465 } 2466 } 2467 } 2468 2469 /*-------------------------------------------------------------------------- 2470 BINDS: class="amplitude-playback-speed" 2471 Binds click and touchend events for amplitude playback speed buttons. 2472 --------------------------------------------------------------------------*/ 2473 function bindPlaybackSpeed() { 2474 /* 2475 Gets all of the elements with the class amplitude-playback-speed 2476 */ 2477 var playback_speed_classes = document.getElementsByClassName("amplitude-playback-speed"); 2478 2479 /* 2480 Iterates over all of the playback speed classes and binds the event interaction 2481 methods to the element. If the browser is mobile, then the event is touchend 2482 otherwise it is click. 2483 */ 2484 for (var i = 0; i < playback_speed_classes.length; i++) { 2485 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2486 playback_speed_classes[i].removeEventListener('touchend', _handlers2.default.playbackSpeed); 2487 playback_speed_classes[i].addEventListener('touchend', _handlers2.default.playbackSpeed); 2488 } else { 2489 playback_speed_classes[i].removeEventListener('click', _handlers2.default.playbackSpeed); 2490 playback_speed_classes[i].addEventListener('click', _handlers2.default.playbackSpeed); 2491 } 2492 } 2493 } 2494 2495 /*-------------------------------------------------------------------------- 2496 BINDS: class="amplitude-skip-to" 2497 Binds click and touchend events for amplitude skip to buttons. 2498 --------------------------------------------------------------------------*/ 2499 function bindSkipTo() { 2500 /* 2501 Gets all of the skip to elements with the class 'amplitude-skip-to' 2502 */ 2503 var skipToClasses = document.getElementsByClassName("amplitude-skip-to"); 2504 2505 /* 2506 Iterates over all of the skip to classes and binds the event interaction 2507 methods to the element. If the browser is mobile, then the event is touchend 2508 otherwise it's a click. 2509 */ 2510 for (var i = 0; i < skipToClasses.length; i++) { 2511 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 2512 skipToClasses[i].removeEventListener('touchend', _handlers2.default.skipTo); 2513 skipToClasses[i].addEventListener('touchend', _handlers2.default.skipTo); 2514 } else { 2515 skipToClasses[i].removeEventListener('click', _handlers2.default.skipTo); 2516 skipToClasses[i].addEventListener('click', _handlers2.default.skipTo); 2517 } 2518 } 2519 } 2520 2521 return { 2522 initializeEvents: initializeEvents 2523 }; 2524}(); /* 2525 Import the necessary classes and config to use 2526 with the events. 2527 */ 2528exports.default = AmplitudeEvents; 2529module.exports = exports['default']; 2530 2531/***/ }), 2532/* 5 */ 2533/***/ (function(module, exports, __webpack_require__) { 2534 2535"use strict"; 2536 2537 2538Object.defineProperty(exports, "__esModule", { 2539 value: true 2540}); 2541 2542var _config = __webpack_require__(0); 2543 2544var _config2 = _interopRequireDefault(_config); 2545 2546var _visual = __webpack_require__(2); 2547 2548var _visual2 = _interopRequireDefault(_visual); 2549 2550var _core = __webpack_require__(3); 2551 2552var _core2 = _interopRequireDefault(_core); 2553 2554var _helpers = __webpack_require__(1); 2555 2556var _helpers2 = _interopRequireDefault(_helpers); 2557 2558function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 2559 2560/* 2561|------------------------------------------------------------------------------- 2562| EVENT HANDLER HELPER METHODS 2563|------------------------------------------------------------------------------- 2564| These methods help handle interactions whether it's computation or shuffling 2565| songs. 2566| 2567| METHODS 2568| computeCurrentTimes() 2569| computeSongDuration() 2570| computeSongCompletionPercentage() 2571*/ 2572var AmplitudeEventHelpers = function () { 2573 /*-------------------------------------------------------------------------- 2574 Computes the current song time. Breaks down where the song is into 2575 hours, minutes, seconds and formats it to be displayed to the user. 2576 --------------------------------------------------------------------------*/ 2577 function computeCurrentTimes() { 2578 /* 2579 Initialize the current time object that will be returned. 2580 */ 2581 var currentTime = {}; 2582 2583 /* 2584 Computes the current seconds for the song. 2585 */ 2586 var currentSeconds = (Math.floor(_config2.default.active_song.currentTime % 60) < 10 ? '0' : '') + Math.floor(_config2.default.active_song.currentTime % 60); 2587 2588 /* 2589 Computes the current minutes for the song. 2590 */ 2591 var currentMinutes = Math.floor(_config2.default.active_song.currentTime / 60); 2592 2593 /* 2594 Initialize the current hours variable. 2595 */ 2596 var currentHours = '00'; 2597 2598 /* 2599 If the current minutes is less than 10, we add a leading 0. 2600 */ 2601 if (currentMinutes < 10) { 2602 currentMinutes = '0' + currentMinutes; 2603 } 2604 2605 /* 2606 If the user is more than 60 minutes into the song, then 2607 we extract the hours. 2608 */ 2609 if (currentMinutes > 60) { 2610 currentHours = Math.floor(currentMinutes / 60); 2611 currentMinutes = currentMinutes % 60; 2612 2613 /* 2614 If the user is less than 10 hours in, we append the 2615 additional 0 to the hours. 2616 */ 2617 if (currentHours < 10) { 2618 currentHours = '0' + currentHours; 2619 } 2620 2621 /* 2622 If the user is less than 10 minutes in, we append the 2623 additional 0 to the minutes. 2624 */ 2625 if (currentMinutes < 10) { 2626 currentMinutes = '0' + currentMinutes; 2627 } 2628 } 2629 2630 /* 2631 Build a clean current time object and send back the appropriate information. 2632 */ 2633 currentTime.seconds = currentSeconds; 2634 currentTime.minutes = currentMinutes; 2635 currentTime.hours = currentHours; 2636 2637 return currentTime; 2638 } 2639 2640 /*-------------------------------------------------------------------------- 2641 Computes the current song duration. Breaks down where the song is into 2642 hours, minutes, seconds and formats it to be displayed to the user. 2643 --------------------------------------------------------------------------*/ 2644 function computeSongDuration() { 2645 /* 2646 Initialize the song duration object that will be returned. 2647 */ 2648 var songDuration = {}; 2649 2650 /* 2651 Computes the duration of the song's seconds. 2652 */ 2653 var songDurationSeconds = (Math.floor(_config2.default.active_song.duration % 60) < 10 ? '0' : '') + Math.floor(_config2.default.active_song.duration % 60); 2654 2655 /* 2656 Computes the duration of the song's minutes. 2657 */ 2658 var songDurationMinutes = Math.floor(_config2.default.active_song.duration / 60); 2659 2660 /* 2661 Initialize the hours duration variable. 2662 */ 2663 var songDurationHours = '00'; 2664 2665 /* 2666 If the song duration minutes is less than 10, we add a leading 0. 2667 */ 2668 if (songDurationMinutes < 10) { 2669 songDurationMinutes = '0' + songDurationMinutes; 2670 } 2671 2672 /* 2673 If there is more than 60 minutes in the song, then we 2674 extract the hours. 2675 */ 2676 if (songDurationMinutes > 60) { 2677 songDurationHours = Math.floor(songDurationMinutes / 60); 2678 songDurationMinutes = songDurationMinutes % 60; 2679 2680 /* 2681 If the song duration hours is less than 10 we append 2682 the additional 0. 2683 */ 2684 if (songDurationHours < 10) { 2685 songDurationHours = '0' + songDurationHours; 2686 } 2687 2688 /* 2689 If the song duration minutes is less than 10 we append 2690 the additional 0. 2691 */ 2692 if (songDurationMinutes < 10) { 2693 songDurationMinutes = '0' + songDurationMinutes; 2694 } 2695 } 2696 2697 /* 2698 Build a clean song duration object and send back the appropriate information. 2699 */ 2700 songDuration.seconds = songDurationSeconds; 2701 songDuration.minutes = songDurationMinutes; 2702 songDuration.hours = songDurationHours; 2703 2704 return songDuration; 2705 } 2706 2707 /*-------------------------------------------------------------------------- 2708 Computes the song completion percentage. 2709 --------------------------------------------------------------------------*/ 2710 function computeSongCompletionPercentage() { 2711 return _config2.default.active_song.currentTime / _config2.default.active_song.duration * 100; 2712 } 2713 2714 /*-------------------------------------------------------------------------- 2715 Sets the current song's playback speed 2716 @param float speed The float with a base of 1 representing the speed 2717 --------------------------------------------------------------------------*/ 2718 function setPlaybackSpeed(speed) { 2719 _core2.default.setPlaybackSpeed(speed); 2720 } 2721 2722 /*-------------------------------------------------------------------------- 2723 Sets the state of the repeat for the current song. 2724 @param bool repeat A boolean representing whether the repeat should 2725 be on or off 2726 --------------------------------------------------------------------------*/ 2727 function setRepeat(repeat) { 2728 _config2.default.repeat = repeat; 2729 } 2730 2731 /*-------------------------------------------------------------------------- 2732 Sets the main play pause buttons to the current state of the song. 2733 --------------------------------------------------------------------------*/ 2734 function setMainPlayPause() { 2735 /* 2736 Determines what action we should take based on the 2737 state of the song. 2738 */ 2739 if (_config2.default.active_song.paused) { 2740 /* 2741 The song was paused so we sync visually for the song 2742 that is playing and we play the song. 2743 */ 2744 _visual2.default.syncMainPlayPause('playing'); 2745 2746 /* 2747 If there is an active playlist, then 2748 we need to sync that playlist's play pause 2749 button to the state of playing. 2750 */ 2751 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'playing'); 2752 2753 /* 2754 Sync the song play pause buttons 2755 */ 2756 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _c
2756onfig2.default.active_index, 'playing'); 2757 2758 /* 2759 Play the song 2760 */ 2761 _core2.default.play(); 2762 } else { 2763 /* 2764 The song was playing so we sync visually for the song 2765 to be paused and we pause the song. 2766 */ 2767 _visual2.default.syncMainPlayPause('paused'); 2768 2769 /* 2770 If there is an active playlist, then 2771 we need to sync that playlist's play pause 2772 button to the state of paused. 2773 */ 2774 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'paused'); 2775 2776 /* 2777 Sync the song play pause buttons 2778 */ 2779 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _config2.default.active_index, 'paused'); 2780 2781 /* 2782 Pause the song 2783 */ 2784 _core2.default.pause(); 2785 } 2786 } 2787 2788 /*-------------------------------------------------------------------------- 2789 Sets the playlist main play pause buttons to the current state of the song. 2790 @param string playlist The playlist the main play pause button controls 2791 --------------------------------------------------------------------------*/ 2792 function setPlaylistPlayPause(playlist) { 2793 /* 2794 The only thing that can change when you click a playlist 2795 play pause is the playlist. Main play pauses have no change 2796 in song, song play pauses can change playlist and song. 2797 */ 2798 if (_helpers2.default.checkNewPlaylist(playlist)) { 2799 _helpers2.default.setActivePlaylist(playlist); 2800 2801 /* 2802 Play first song in the playlist since we just 2803 switched playlists, we start from the first song. 2804 If the user has shuffle on for the playlist, then 2805 we go from the first song in the shuffle playlist array. 2806 */ 2807 if (_config2.default.shuffled_statuses[playlist]) { 2808 _helpers2.default.changeSong(_config2.default.shuffled_playlists[playlist][0].original_index); 2809 } else { 2810 _helpers2.default.changeSong(_config2.default.playlists[playlist][0]); 2811 } 2812 } 2813 2814 /* 2815 Determines what action we should take based on the 2816 state of the song. 2817 */ 2818 if (_config2.default.active_song.paused) { 2819 /* 2820 The song was paused so we sync visually for the song 2821 that is playing and we play the song. 2822 */ 2823 _visual2.default.syncMainPlayPause('playing'); 2824 2825 /* 2826 If there is an active playlist, then 2827 we need to sync that playlist's play pause 2828 button to the state of playing. 2829 */ 2830 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'playing'); 2831 2832 /* 2833 Sync the song play pause buttons 2834 */ 2835 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _config2.default.active_index, 'playing'); 2836 2837 /* 2838 Play the song 2839 */ 2840 _core2.default.play(); 2841 } else { 2842 /* 2843 The song was playing so we sync visually for the song 2844 to be paused and we pause the song. 2845 */ 2846 _visual2.default.syncMainPlayPause('paused'); 2847 2848 /* 2849 If there is an active playlist, then 2850 we need to sync that playlist's play pause 2851 button to the state of paused. 2852 */ 2853 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'paused'); 2854 2855 /* 2856 Sync the song play pause buttons 2857 */ 2858 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _config2.default.active_index, 'paused'); 2859 2860 /* 2861 Pause the song 2862 */ 2863 _core2.default.pause(); 2864 } 2865 } 2866 2867 /*-------------------------------------------------------------------------- 2868 Sets the song play pause buttons to the current state of the song. 2869 @param string playlist The playlist the song is a part of 2870 @param int songIndex The index of the song being played/paused 2871 --------------------------------------------------------------------------*/ 2872 function setSongPlayPause(playlist, songIndex) { 2873 /* 2874 There can be multiple playlists on the page and there can be 2875 multiple songs on the page AND there can be songs in multiple 2876 playlists, so we have some checking to do. 2877 */ 2878 2879 /* 2880 Check to see if the playlist has changed. If it has, 2881 set the active playlist. 2882 */ 2883 if (_helpers2.default.checkNewPlaylist(playlist)) { 2884 _helpers2.default.setActivePlaylist(playlist); 2885 2886 /* 2887 If there's a new playlist then we reset the 2888 song since the song could be in 2 playlists, 2889 but the user selects another playlist. 2890 */ 2891 _helpers2.default.changeSong(songIndex); 2892 } 2893 2894 /* 2895 Check to see if the song has changed. If it has, 2896 set the active song. If it was in a playlist, the 2897 song wouldn't change here, since we already set the 2898 song when we checked for a playlist. 2899 */ 2900 if (_helpers2.default.checkNewSong(songIndex)) { 2901 /* 2902 The song selected is different, so we change the 2903 song. 2904 */ 2905 _helpers2.default.changeSong(songIndex); 2906 } 2907 2908 /* 2909 Determines what action we should take based on the 2910 state of the song. 2911 */ 2912 if (_config2.default.active_song.paused) { 2913 /* 2914 The song was paused so we sync visually for the song 2915 that is playing and we play the song. 2916 */ 2917 _visual2.default.syncMainPlayPause('playing'); 2918 2919 /* 2920 If there is an active playlist, then 2921 we need to sync that playlist's play pause 2922 button to the state of playing. 2923 */ 2924 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'playing'); 2925 2926 /* 2927 Sync the song play pause buttons 2928 */ 2929 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _c
2929onfig2.default.active_index, 'playing'); 2930 2931 /* 2932 Play the song 2933 */ 2934 _core2.default.play(); 2935 } else { 2936 /* 2937 The song was playing so we sync visually for the song 2938 to be paused and we pause the song. 2939 */ 2940 _visual2.default.syncMainPlayPause('paused'); 2941 2942 /* 2943 If there is an active playlist, then 2944 we need to sync that playlist's play pause 2945 button to the state of paused. 2946 */ 2947 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'paused'); 2948 2949 /* 2950 Sync the song play pause buttons 2951 */ 2952 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _config2.default.active_index, 'paused'); 2953 2954 /* 2955 Pause the song 2956 */ 2957 _core2.default.pause(); 2958 } 2959 } 2960 2961 /*-------------------------------------------------------------------------- 2962 Sets the shuffle state for a playlist 2963 @param string playlist The playlist being shuffled 2964 --------------------------------------------------------------------------*/ 2965 function setShuffle(playlist) { 2966 /* 2967 If the playlist is null, then we are dealing with the global 2968 shuffle status. 2969 */ 2970 if (playlist == null) { 2971 /* 2972 If shuffle is on, we toggle it off. If shuffle is off, we 2973 toggle on. 2974 */ 2975 if (_config2.default.shuffle_on) { 2976 _config2.default.shuffle_on = false; 2977 _config2.default.shuffle_list = {}; 2978 } else { 2979 _config2.default.shuffle_on = true; 2980 _helpers2.default.shuffleSongs(); 2981 } 2982 2983 /* 2984 Visually sync the shuffle statuses 2985 */ 2986 _visual2.default.syncShuffle(_config2.default.shuffle_on); 2987 } else { 2988 /* 2989 If the playlist shuffled is on, we toggle it off. If the 2990 playlist shuffled is off, we toggle it on. 2991 */ 2992 if (_config2.default.shuffled_statuses[playlist]) { 2993 _config2.default.shuffled_statuses[playlist] = false; 2994 _config2.default.shuffled_playlists[playlist] = []; 2995 } else { 2996 _config2.default.shuffled_statuses[playlist] = true; 2997 _helpers2.default.shufflePlaylistSongs(playlist); 2998 } 2999 3000 /* 3001 Visually sync the playlist shuffle statuses. 3002 */ 3003 _visual2.default.syncPlaylistShuffle(_config2.default.shuffled_statuses[playlist], playlist); 3004 } 3005 } 3006 3007 /*-------------------------------------------------------------------------- 3008 Sets the next song when next is clicked 3009 @param songEnded (default false) If the song ended, this is set to true 3010 so we take into effect the repeat setting. 3011 --------------------------------------------------------------------------*/ 3012 function setNext() { 3013 var songEnded = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; 3014 3015 /* 3016 Initializes the next index variable. This will be the 3017 index of the song that is next. 3018 */ 3019 var nextIndex = 0; 3020 /* 3021 Ensure we don't loop in the playlist if config.repeat is not true 3022 */ 3023 var endOfList = false; 3024 3025 /* 3026 If the shuffle is on, we use the shuffled list of 3027 songs to determine our next song. 3028 */ 3029 if (_config2.default.shuffle_on) { 3030 /* 3031 If the active shuffle index + 1 is less than the length, then 3032 we use the next shuffle otherwise we go to the beginning 3033 of the shuffle list. 3034 */ 3035 if (parseInt(_config2.default.shuffle_active_index) + 1 < _config2.default.shuffle_list.length) { 3036 _config2.default.shuffle_active_index = parseInt(_config2.default.shuffle_active_index) + 1; 3037 3038 /* 3039 Set the next index to be the index of the song in the shuffle list. 3040 */ 3041 nextIndex = _config2.default.shuffle_list[parseInt(_config2.default.shuffle_active_index)].original_index; 3042 } else { 3043 _config2.default.shuffle_active_index = 0; 3044 nextIndex = 0; 3045 endOfList = true; 3046 } 3047 } else { 3048 /* 3049 If the active index + 1 is less than the length of the songs, then 3050 we use the next song otherwise we go to the beginning of the 3051 song list. 3052 */ 3053 if (parseInt(_config2.default.active_index) + 1 < _config2.default.songs.length) { 3054 _config2.default.active_index = parseInt(_config2.default.active_index) + 1; 3055 } else { 3056 _config2.default.active_index = 0; 3057 endOfList = true; 3058 } 3059 3060 /* 3061 Sets the next index. 3062 */ 3063 nextIndex = _config2.default.active_index; 3064 } 3065 3066 /* 3067 Stops the active song. 3068 */ 3069 _core2.default.stop(); 3070 3071 /* 3072 Change the song to the index we need. 3073 */ 3074 _helpers2.default.changeSong(nextIndex); 3075 3076 /* 3077 If the song has ended and repeat is on, play the song. 3078 */ 3079 if (!(songEnded && !_config2.default.repeat && endOfList)) { 3080 _core2.default.play(); 3081 } 3082 3083 /* 3084 Syncs the main play pause button, playlist play pause button and 3085 song play pause. 3086 */ 3087 _visual2.default.syncMainPlayPause(); 3088 _visual2.default.syncSongPlayPause(null, nextIndex); 3089 3090 /* 3091 Call after next callback 3092 */ 3093 _helpers2.default.runCallback('after_next'); 3094 } 3095 3096 /*-------------------------------------------------------------------------- 3097 Sets the next song in a playlist 3098 @param string playlist The playlist being shuffled 3099 @param songEnded (default false) If the song ended, this is set to true 3100 so we take into effect the repeat setting. 3101 --------------------------------------------------------------------------*/ 3102 function setNextPlaylist(playlist) { 3103 var songEnded = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3104 3105 /* 3106 Initializes the next index 3107 */ 3108 var nextIndex = 0; 3109 3110 /* 3111 Used to determine whether the playlist looped over 3112 If it did, only play if repeat is allowed, end otherwise 3113 @TODO: Different settings for song loop, in-playlist loop and global loop 3114 */ 3115 var endOfList = false; 3116 /* 3117 If the playlist is shuffled we get the next index of the playlist. 3118 */ 3119 if (_config2.default.shuffled_statuses[playlist]) { 3120 /* 3121 Gets the shuffled playlist's active song index. 3122 */ 3123 var shuffledPlaylistActiveSongIndex = parseInt(_config2.default.shuffled_active_indexes[playlist]); 3124 3125 /* 3126 If the index + 1 is less than the length of the playlist, we increment 3127 the next index otherwise we take the first index of 0. 3128 */ 3129 if (shuffledPlaylistActiveSongIndex + 1 < _config2.default.shuffled_playlists[playlist].length) { 3130 /* 3131 Set the shuffled playlist active song index. 3132 */ 3133 _config2.default.shuffled_active_indexes[playlist] = shuffledPlaylistActiveSongIndex + 1; 3134 /* 3135 Get the index of the song that we will be switching to. 3136 */ 3137 nextIndex = _config2.default.shuffled_playlists[playlist][_config2.default.shuffled_active_indexes[playlist]].original_index; 3138 } else { 3139 /* 3140 Sets the active shuffled playlist active index to 0 and gets the original index of 3141 the song at the shuffled index of 0. 3142 */ 3143 _config2.default.shuffled_active_indexes[playlist] = 0; 3144 nextIndex = _config2.default.shuffled_playlists[playlist][0].original_index; 3145 endOfList = true; 3146 } 3147 } else { 3148 /* 3149 Gets the index of the active song within the scope 3150 of the playlist. 3151 */ 3152 var playlistActiveSongIndex = _config2.default.playlists[playlist].indexOf(parseInt(_config2.default.active_index)); 3153 3154 /* 3155 Checks to see if the next index is still less than the length of the playlist. 3156 If it is, use the next index othwerwise get the first song in the playlist. 3157 */ 3158 if (playlistActiveSongIndex + 1 < _config2.default.playlists[playlist].length) { 3159 _config2.default.active_index = parseInt(_config2.default.playlists[playlist][playlistActiveSongIndex + 1]); 3160 } else { 3161 _config2.default.active_index = parseInt(_config2.default.playlists[playlist][0]); 3162 endOfList = true; 3163 } 3164 3165 /* 3166 Sets the next inex to the active index in the config. 3167 */ 3168 nextIndex = _config2.default.active_index; 3169 } 3170 3171 /* 3172 Stops the active song playing. 3173 */ 3174 3175 _core2.default.stop(); 3176 3177 /* 3178 Changes the song to the next song in the playlist. 3179 */ 3180 _helpers2.default.changeSong(nextIndex); 3181 _helpers2.default.setActivePlaylist(playlist); 3182 3183 /* 3184 If the song has ended and repeat is on, play the song. 3185 */ 3186 if (!(songEnded && !_config2.default.repeat && endOfList)) _core2.default.play(); 3187 3188 /* 3189 Syncs the main play pause button, playlist play pause button and 3190 song play pause. 3191 */ 3192 _visual2.default.syncMainPlayPause(); 3193 _visual2.default.syncPlaylistPlayPause(playlist); 3194 _visual2.default.syncSongPlayPause(playlist, nextIndex); 3195 3196 /* 3197 Call after next callback 3198 */ 3199 _helpers2.default.runCallback('after_next'); 3200 } 3201 3202 /*-------------------------------------------------------------------------- 3203 Sets the previous song 3204 --------------------------------------------------------------------------*/ 3205 function setPrev() { 3206 /* 3207 Initializes the prev index variable. This will be the 3208 index of the song that is next. 3209 */ 3210 var prevIndex = 0; 3211 3212 /* 3213 If the shuffle is on for the individual songs, we get the previous 3214 song. 3215 */ 3216 if (_config2.default.shuffle_on) { 3217 /* 3218 If the previous index is greater than or equal to 0, we use the active 3219 index - 1. 3220 */ 3221 if (parseInt(_config2.default.shuffle_active_index) - 1 >= 0) { 3222 /* 3223 Sets the new active to be 1 less than the current active index. 3224 */ 3225 _config2.default.shuffle_active_index = parseInt(_config2.default.shuffle_active_index) - 1; 3226 3227 /* 3228 Gets the index of the song in the song array for the new index. 3229 */ 3230 prevIndex = _config2.default.shuffle_list[parseInt(_config2.default.shuffle_active_index)].original_index; 3231 } else { 3232 /* 3233 Set the active index and previous index. 3234 */ 3235 _config2.default.shuffle_active_index = _config2.default.shuffle_list.length - 1; 3236 prevIndex = _config2.default.shuffle_list[parseInt(_config2.default.shuffle_list.length) - 1].original_index; 3237 } 3238 } else { 3239 /* 3240 If the active index - 1 is greater than or equal to 0, we subtract 1 from the 3241 active index otherwise we set the active index to the end of the songs array index. 3242 */ 3243 if (parseInt(_config2.default.active_index) - 1 >= 0) { 3244 _config2.default.active_index = parseInt(_config2.default.active_index) - 1; 3245 } else { 3246 _config2.default.active_index = _config2.default.songs.length - 1; 3247 } 3248 3249 /* 3250 Set the previous index. 3251 */ 3252 prevIndex = _config2.default.active_index; 3253 } 3254 3255 /* 3256 Stops the active song. 3257 */ 3258 _core2.default.stop(); 3259 3260 /* 3261 Change the song to the index we need. 3262 */ 3263 _helpers2.default.changeSong(prevIndex); 3264 3265 /* 3266 Play the next song. 3267 */ 3268 _core2.default.play(); 3269 3270 /* 3271 Sync the play/pause buttons to the current state of the player. 3272 */ 3273 _visual2.default.syncMainPlayPause('playing'); 3274 _visual2.default.syncSongPlayPause(null, prevIndex, 'playing'); 3275 3276 /* 3277 Call after prev callback 3278 */ 3279 _helpers2.default.runCallback('after_prev'); 3280 } 3281 3282 /*-------------------------------------------------------------------------- 3283 Sets the previous song in a playlist 3284 @param string The Playlist we are setting the previous for. 3285 --------------------------------------------------------------------------*/ 3286 function setPrevPlaylist(playlist) { 3287 /* 3288 Initializes the prev index variable. This will be the 3289 index of the song that is next. 3290 */ 3291 var prevIndex = 0; 3292 3293 /* 3294 If the shuffle is on for the playlist, we get the previous 3295 song. 3296 */ 3297 if (_config2.default.shuffled_statuses[playlist]) { 3298 /* 3299 Gets the active song index for the shuffled playlist 3300 */ 3301 var shuffledPlaylistActiveSongIndex = parseInt(_config2.default.shuffled_active_indexes[playlist]); 3302 3303 /* 3304 If the shuffled song active index is greater than or equal to 0, 3305 we use the active index - 1. 3306 */ 3307 if (shuffledPlaylistActiveSongIndex - 1 >= 0) { 3308 /* 3309 Sets the active index to the active song index - 1 3310 */
3311 _config2.default.shuffled_active_indexes[playlist] = shuffledPlaylistActiveSongIndex - 1; 3312 3313 /* 3314 Gets the index of the song in the song array for the new index. 3315 */ 3316 prevIndex = _config2.default.shuffled_playlists[playlist][_config2.default.shuffled_active_indexes[playlist]].original_index; 3317 } else { 3318 /* 3319 Set the active index and previous index. 3320 */ 3321 _config2.default.shuffled_active_indexes[playlist] = _config2.default.shuffled_playlists[playlist].length - 1; 3322 prevIndex = _config2.default.shuffled_playlists[playlist][_config2.default.shuffled_playlists[playlist].length - 1].original_index; 3323 } 3324 } else { 3325 /* 3326 Gets the active song index for the playlist 3327 */ 3328 var playlistActiveSongIndex = _config2.default.playlists[playlist].indexOf(parseInt(_config2.default.active_index)); 3329 3330 /* 3331 If the active song index in the playlist - 1 is greater than 3332 or equal to 0, then we use the active song index - 1. 3333 */ 3334 if (playlistActiveSongIndex - 1 >= 0) { 3335 _config2.default.active_index = parseInt(_config2.default.playlists[playlist][playlistActiveSongIndex - 1]); 3336 } else { 3337 _config2.default.active_index = parseInt(_config2.default.playlists[playlist][_config2.default.playlists[playlist].length - 1]); 3338 } 3339 3340 /* 3341 Set the previous index to the active index for use later. 3342 */ 3343 prevIndex = _config2.default.active_index; 3344 } 3345 3346 /* 3347 Stops the active song. 3348 */ 3349 _core2.default.stop(); 3350 3351 /* 3352 Changes the song to the prev song in the playlist. 3353 */ 3354 _helpers2.default.changeSong(prevIndex); 3355 _helpers2.default.setActivePlaylist(playlist); 3356 3357 /* 3358 Plays the song 3359 */ 3360 _core2.default.play(); 3361 3362 /* 3363 Syncs the main play pause button, playlist play pause button and 3364 song play pause. 3365 */ 3366 _visual2.default.syncMainPlayPause('playing'); 3367 _visual2.default.syncPlaylistPlayPause(playlist, 'playing'); 3368 _visual2.default.syncSongPlayPause(playlist, prevIndex, 'playing'); 3369 3370 /* 3371 Call after prev callback 3372 */ 3373 _helpers2.default.runCallback('after_prev'); 3374 } 3375 3376 /*-------------------------------------------------------------------------- 3377 Runs an event on key down 3378 @param int key The key code the event is bound to. 3379 --------------------------------------------------------------------------*/ 3380 function runKeyEvent(key) { 3381 /* 3382 Checks to see if the user bound an event to the code pressed. 3383 */ 3384 if (_config2.default.bindings[key] != undefined) { 3385 /* 3386 Determine which event should be run if bound. 3387 */ 3388 switch (_config2.default.bindings[key]) { 3389 /* 3390 Fires a play pause event. 3391 */ 3392 case 'play_pause': 3393 setSongPlayPause(_config2.default.active_playlist, _config2.default.active_index); 3394 break; 3395 3396 /* 3397 Fires a next event. 3398 */ 3399 case 'next': 3400 /* 3401 Check to see if the current state of the player 3402 is in playlist mode or not playlist mode. 3403 */ 3404 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) { 3405 setNext(); 3406 } else { 3407 setNextPlaylist(_config2.default.active_playlist); 3408 } 3409 break; 3410 3411 /* 3412 Fires a previous event. 3413 */ 3414 case 'prev': 3415 /* 3416 Check to see if the current playlist has been set 3417 or null and set the previous song. 3418 */ 3419 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) { 3420 AmplitudeEventHelpers.setPrev(); 3421 } else { 3422 AmplitudeEventHelpers.setPrevPlaylist(_config2.default.active_playlist); 3423 } 3424 break; 3425 3426 /* 3427 Fires a stop event. 3428 */ 3429 case 'stop': 3430 /* 3431 Sets all of the play/pause buttons to pause 3432 */ 3433 _visual2.default.setPlayPauseButtonsToPause(); 3434 3435 /* 3436 Stops the active song. 3437 */ 3438 _core2.default.stop(); 3439 break; 3440 3441 /* 3442 Fires a shuffle event. 3443 */ 3444 case 'shuffle': 3445 /* 3446 Check to see if the current playlist has been set 3447 or null and set the previous song. 3448 */ 3449 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) { 3450 AmplitudeEventHelpers.setShuffle(null); 3451 } else { 3452 AmplitudeEventHelpers.setShuffle(_config2.default.active_playlist); 3453 } 3454 break; 3455 3456 /* 3457 Fires a repeat event. 3458 */
3459 case 'repeat': 3460 /* 3461 Sets repeat to the opposite of what it was set to 3462 */ 3463 AmplitudeEventHelpers.setRepeat(!_config2.default.repeat); 3464 3465 /* 3466 Visually sync repeat 3467 */ 3468 _visual2.default.syncRepeat(); 3469 break; 3470 } 3471 } 3472 } 3473 3474 /* 3475 Return the publically scoped functions 3476 */ 3477 return { 3478 computeCurrentTimes: computeCurrentTimes, 3479 computeSongDuration: computeSongDuration, 3480 computeSongCompletionPercentage: computeSongCompletionPercentage, 3481 setPlaybackSpeed: setPlaybackSpeed, 3482 setRepeat: setRepeat, 3483 setMainPlayPause: setMainPlayPause, 3484 setPlaylistPlayPause: setPlaylistPlayPause, 3485 setSongPlayPause: setSongPlayPause, 3486 setShuffle: setShuffle, 3487 setNext: setNext, 3488 setNextPlaylist: setNextPlaylist, 3489 setPrev: setPrev, 3490 setPrevPlaylist: setPrevPlaylist, 3491 runKeyEvent: runKeyEvent 3492 }; 3493}(); 3494 3495exports.default = AmplitudeEventHelpers; 3496module.exports = exports['default']; 3497 3498/***/ }), 3499/* 6 */ 3500/***/ (function(module, exports, __webpack_require__) { 3501 3502"use strict"; 3503 3504 3505Object.defineProperty(exports, "__esModule", { 3506 value: true 3507}); 3508 3509var _core = __webpack_require__(3); 3510 3511var _core2 = _interopRequireDefault(_core); 3512 3513var _helpers = __webpack_require__(1); 3514 3515var _helpers2 = _interopRequireDefault(_helpers); 3516 3517var _events = __webpack_require__(4); 3518 3519var _events2 = _interopRequireDefault(_events); 3520 3521var _soundcloud = __webpack_require__(9); 3522 3523var _soundcloud2 = _interopRequireDefault(_soundcloud); 3524 3525var _visual = __webpack_require__(2); 3526 3527var _visual2 = _interopRequireDefault(_visual); 3528 3529function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 3530 3531var config = __webpack_require__(0); 3532 3533/* 3534|---------------------------------------------------------------------------------------------------- 3535| INITIALIZER FOR AMPLITUDE JS 3536|---------------------------------------------------------------------------------------------------- 3537| These methods initialize AmplitudeJS and make sure everything is ready to run 3538| 3539| METHODS 3540| initialize( userConfig ) 3541| countPlaylists( playlists ) 3542| checkValidSongsInPlaylists() 3543| playlistShuffleStatuses() 3544| playlistShuffleLists() 3545| eventHandlers() 3546*/ 3547var AmplitudeInitializer = function () { 3548 3549 /*-------------------------------------------------------------------------- 3550 The main init function. The user will call this through 3551 Amplitude.init({}) and pass in their settings. 3552 Public Accessor: Amplitude.init( user_config_json ); 3553 @param userConfig A JSON object of user defined values that help 3554 configure and initialize AmplitudeJS. 3555 --------------------------------------------------------------------------*/ 3556 function initialize(userConfig) { 3557 var ready = false; 3558 /* 3559 Reset the config on init so we have a clean slate. This is if the 3560 user has to re-init. 3561 */ 3562 _helpers2.default.resetConfig(); 3563 3564 /* 3565 Initialize event handlers on init. This will clear any old 3566 event handlers on the amplitude element and re-bind what is 3567 necessary. 3568 */ 3569 _events2.default.initializeEvents(); 3570 3571 /* 3572 Initializes debugging right away so we can use it for the rest 3573 of the configuration. 3574 */ 3575 config.debug = userConfig.debug != undefined ? userConfig.debug : false; 3576 3577 /* 3578 Checks to see if the user has songs defined. 3579 */ 3580 if (userConfig.songs) { 3581 /* 3582 Checks to see if the user has some songs in the songs array. 3583 */ 3584 if (userConfig.songs.length != 0) { 3585 /* 3586 Copies over the user defined songs. and prepares 3587 Amplitude for the rest of the configuration. 3588 */ 3589 config.songs = userConfig.songs; 3590 /* 3591 Flag amplitude as ready. 3592 */ 3593 ready = true; 3594 } else { 3595 _helpers2.default.writeDebugMessage('Please add some songs, to your songs object!'); 3596 } 3597 } else { 3598 _helpers2.default.writeDebugMessage('Please provide a songs object for AmplitudeJS to run!'); 3599 } 3600 3601 /* 3602 Initializes the audio context. In this method it checks to see if the 3603 user wants to use visualizations or not before proceeding. 3604 AMPFX-TODO: MAKE HANDLED BY AMPLITUDE FX. 3605 */ 3606 //privateHelpInitializeAudioContext(); 3607 3608 /* 3609 Checks if the user has any playlists defined. If they do 3610 we have to initialize the functionality for the playlists. 3611 */ 3612 if (userConfig.playlists && countPlaylists(userConfig.playlists) > 0) { 3613 /* 3614 Copy the playlists over to Amplitude 3615 */ 3616 config.playlists = userConfig.playlists; 3617 3618 /* 3619 Initialize default live settings 3620 */ 3621 initializeDefaultLiveSettings(); 3622 3623 /* 3624 Check to see if the user has valid song indexes in their playlist. 3625 */ 3626 checkValidSongsInPlaylists(); 3627 3628 /* 3629 Initialize the shuffle status of the playlists. 3630 */ 3631 initializePlaylistShuffleStatuses(); 3632 3633 /* 3634 Initialize temporary place holders for shuffle lists. 3635 */ 3636 initializePlaylistShuffleLists(); 3637 3638 /* 3639 Initializes the active shuffled indexes for shuffled playlists. 3640 */ 3641 initializePlaylistShuffleIndexes(); 3642 3643 /* 3644 Initializes the first song in the playlist 3645 */ 3646 initializeFirstSongInPlaylistMetaData(); 3647 } 3648 3649 /* 3650 When the preliminary config is ready, we are ready to proceed. 3651 */ 3652 if (ready) { 3653 /* 3654 Copies over the soundcloud information to the global config 3655 which will determine where we go from there. 3656 */ 3657 config.soundcloud_client = userConfig.soundcloud_client != undefined ? userConfig.soundcloud_client : ''; 3658 3659 /* 3660 Checks if we want to use the art loaded from soundcloud. 3661 */ 3662 config.soundcloud_use_art = userConfig.soundcloud_use_art != undefined ? userConfig.soundcloud_use_art : ''; 3663 3664 /* 3665 If the user provides a soundcloud client then we assume that 3666 there are URLs in their songs that will reference SoundcCloud. 3667 We then copy over the user config they provided to the 3668 temp_user_config so we don't mess up the global or their configs 3669 and load the soundcloud information. 3670 */ 3671 var tempUserConfig = {}; 3672 3673 if (config.soundcloud_client != '') { 3674 tempUserConfig = userConfig; 3675 3676 /* 3677 Load up SoundCloud for use with AmplitudeJS. 3678 */ 3679 _soundcloud2.default.loadSoundCloud(tempUserConfig); 3680 } else { 3681 /* 3682 The user is not using Soundcloud with Amplitude at this point 3683 so we just finish the configuration with the users's preferences. 3684 */ 3685 setConfig(userConfig); 3686 } 3687 } 3688 3689 /* 3690 Debug out what was initialized with AmplitudeJS. 3691 */ 3692 _helpers2.default.writeDebugMessage('Initialized With: '); 3693 _helpers2.default.writeDebugMessage(config); 3694 } 3695 3696 /*-------------------------------------------------------------------------- 3697 Rebinds all of the elements in the display 3698 --------------------------------------------------------------------------*/ 3699 function rebindDisplay() { 3700 _events2.default.initializeEvents(); 3701 } 3702 3703 /*-------------------------------------------------------------------------- 3704 Finishes the initalization of the config. Takes all of the user defined 3705 parameters and makes sure they override the defaults. The important 3706 config information is assigned in the publicInit() function. 3707 This function can be called from 2 different locations: 3708 1. Right away on init after the important settings are defined. 3709 2. After all of the Soundcloud URLs are resolved properly and 3710 soundcloud is configured. We will need the proper URLs from Soundcloud 3711 to stream through Amplitude so we get those right away before we 3712 set the information and the active song 3713 @param JSON userConfig The config provided by the user. 3714 --------------------------------------------------------------------------*/ 3715 function setConfig(userConfig) { 3716 /* 3717 Check to see if the user entered a start song 3718 */ 3719 if (userConfig.start_song != undefined) { 3720 /* 3721 Ensure what has been entered is an integer. 3722 */ 3723 if (_helpers2.default.isInt(userConfig.start_song)) { 3724 _helpers2.default.changeSong(userConfig.start_song); 3725 } else { 3726 _helpers2.default.writeDebugMessage("You must enter an integer index for the start song."); 3727 } 3728 } else { 3729 _helpers2.default.changeSong(0); 3730 } 3731 3732 /* 3733 If the user defined a playback speed, we copy over their 3734 preference here, otherwise we default to normal playback 3735 speed of 1.0. 3736 */ 3737 config.playback_speed = userConfig.playback_speed != undefined ? userConfig.playback_speed : 1.0; 3738 3739 /* 3740 Sets the audio playback speed. 3741 */ 3742 _core2.default.setPlaybackSpeed(config.playback_speed); 3743 3744 /* 3745 If the user wants the song to be pre-loaded for instant 3746 playback, they set it to true. By default it's set to just 3747 load the metadata. 3748 */ 3749 config.active_song.preload = userConfig.preload != undefined ? userConfig.preload : "auto"; 3750 3751 /* 3752 Initializes the user defined callbacks. This should be a JSON 3753 object that contains a key->value store of the callback name 3754 and the name of the function the user needs to call. 3755 */ 3756 config.callbacks = userConfig.callbacks != undefined ? userConfig.callbacks : {}; 3757 3758 /* 3759 Initializes the user defined key bindings. This should be a JSON 3760 object that contains a key->value store of the key event number 3761 pressed and the method to be run. 3762 */ 3763 config.bindings = userConfig.bindings != undefined ? userConfig.bindings : {}; 3764 3765 /* 3766 The user can define a starting volume in a range of 0-100 with 3767 0 being muted and 100 being the loudest. After the config is set 3768 Amplitude sets the active song's volume to the volume defined 3769 by the user. 3770 */ 3771 config.volume = userConfig.volume != undefined ? userConfig.volume : 50; 3772 3773 /* 3774 The user can set the volume increment and decrement values between 1 and 100 3775 for when the volume up or down button is pressed. The default is an increase 3776 or decrease of 5. 3777 */ 3778 config.volume_increment = userConfig.volume_increment != undefined ? userConfig.volume_increment : 5; 3779 3780 config.volume_decrement = userConfig.volume_decrement != undefined ? userConfig.volume_decrement : 5; 3781 3782 /* 3783 Set the volume to what is defined in the config. The user can define this, 3784 so we should set it up that way. 3785 */ 3786 _core2.default.setVolume(config.volume); 3787 3788 /* 3789 Since the user can define a start volume, we want our volume 3790 sliders to sync with the user defined start value. 3791 */ 3792 _visual2.default.syncVolumeSliders(); 3793 3794 /* 3795 If the user defines default album art, this image will display if the active 3796 song doesn't have album art defined. 3797 */ 3798 if (userConfig.default_album_art != undefined) { 3799 config.default_album_art = userConfig.default_album_art; 3800 } else {
3801 config.default_album_art = ''; 3802 } 3803 3804 /* 3805 Set whether the user wants to continue next after a song has played. This 3806 pretty much disables playlist mode. 3807 */ 3808 config.continue_next = userConfig.continue_next; 3809 3810 /* 3811 Syncs all of the visual time elements to 00. 3812 */ 3813 _visual2.default.resetTimes(); 3814 3815 /* 3816 Sets all of the play pause buttons to pause. 3817 */ 3818 _visual2.default.setPlayPauseButtonsToPause(); 3819 3820 /* 3821 If the user has autoplay enabled, then begin playing the song. Everything should 3822 be configured for this to be ready to play. 3823 */ 3824 if (userConfig.autoplay) { 3825 config.active_playlist = null; 3826 /* 3827 Sync the main and song play pause buttons. 3828 */ 3829 _visual2.default.syncMainPlayPause('playing'); 3830 _visual2.default.syncSongPlayPause(null, 0, 'playing'); 3831 3832 /* 3833 Start playing the song 3834 */ 3835 _core2.default.play(); 3836 } 3837 3838 /* 3839 Run after init callback 3840 */ 3841 _helpers2.default.runCallback('after_init'); 3842 } 3843 3844 /*-------------------------------------------------------------------------- 3845 Counts the number of playlists the user has configured. This ensures 3846 that the user has at least 1 playlist so we can validate the songs 3847 defined in the playlist are correct and they didn't enter an invalid 3848 ID. 3849 --------------------------------------------------------------------------*/ 3850 function countPlaylists(playlists) { 3851 /* 3852 Initialize the placeholders to iterate through the playlists 3853 and find out how many we have to account for. 3854 */ 3855 var size = 0, 3856 key; 3857 3858 /* 3859 Iterate over playlists and if the user has the playlist defined, 3860 increment the size of playlists. 3861 */ 3862 for (key in playlists) { 3863 if (playlists.hasOwnProperty(key)) { 3864 size++; 3865 } 3866 } 3867 3868 /* 3869 Debug how many playlists are in the config. 3870 */ 3871 _helpers2.default.writeDebugMessage('You have ' + size + ' playlist(s) in your config'); 3872 3873 /* 3874 Return the number of playlists in the config. 3875 */ 3876 return size; 3877 } 3878 3879 /*-------------------------------------------------------------------------- 3880 Ensures the indexes in the playlists are valid indexes. The song has 3881 to exist in the Amplitude config to be played correctly. 3882 --------------------------------------------------------------------------*/ 3883 function checkValidSongsInPlaylists() { 3884 /* 3885 Iterate over all of the config's playlists 3886 */ 3887 for (var key in config.playlists) { 3888 /* 3889 Checks if the playlist key is accurate. 3890 */ 3891 if (config.playlists.hasOwnProperty(key)) { 3892 /* 3893 Checks if the playlist has songs. 3894 */ 3895 if (config.playlists[key].songs) { 3896 /* 3897 Iterate over all of the songs in the playlist 3898 */ 3899 for (var i = 0; i < config.playlists[key].songs.length; i++) { 3900 /* 3901 Check to see if the index for the song in the playlist 3902 exists in the songs config. 3903 */ 3904 if (!config.songs[config.playlists[key].songs[i]]) { 3905 _helpers2.default.writeDebugMessage('The song index: ' + config.playlists[key].songs[i] + ' in playlist with key: ' + key + ' is not defined in your songs array!'); 3906 } 3907 } 3908 } 3909 } 3910 } 3911 } 3912 3913 /*-------------------------------------------------------------------------- 3914 Initializes the shuffle statuses for each of the playlists. These will 3915 be referenced when we shuffle individual playlists. 3916 --------------------------------------------------------------------------*/ 3917 function initializePlaylistShuffleStatuses() { 3918 /* 3919 Iterate over all of the playlists the user defined adding 3920 the playlist key to the shuffled playlist array and creating 3921 and empty object to house the statuses. 3922 */ 3923 for (var key in config.playlists) { 3924 config.shuffled_statuses[key] = false; 3925 } 3926 } 3927 3928 /*-------------------------------------------------------------------------- 3929 Initializes the shuffled playlist placeholders. These will be set for 3930 playlists that are shuffled and contain the shuffled songs. 3931 --------------------------------------------------------------------------*/ 3932 function initializePlaylistShuffleLists() { 3933 /* 3934 Iterate over all of the playlists the user defined adding 3935 the playlist key to the shuffled playlists array and creating 3936 and empty object to house the shuffled playlists 3937 */ 3938 for (var key in config.playlists) { 3939 config.shuffled_playlists[key] = []; 3940 } 3941 } 3942 3943 /*-------------------------------------------------------------------------- 3944 Initializes the shuffled playlist indexes array. These will be set for 3945 playlists that are shuffled and contain the active shuffled index. 3946 --------------------------------------------------------------------------*/ 3947 function initializePlaylistShuffleIndexes() { 3948 /* 3949 Iterates over all of the playlists adding a key 3950 to the shuffled_active_indexes array that contains 3951 the active shuffled index. 3952 */ 3953 for (var key in config.playlists) { 3954 config.shuffled_active_indexes[key] = 0; 3955 } 3956 } 3957 3958 /*-------------------------------------------------------------------------- 3959 Intializes the display for the first song in the playlist meta data. 3960 --------------------------------------------------------------------------*/ 3961 function initializeFirstSongInPlaylistMetaData() { 3962 /* 3963 Iterates over all of the playlists setting the meta data for the 3964 first song. 3965 */ 3966 for (var key in config.playlists) { 3967 _visual2.default.setFirstSongInPlaylist(config.songs[config.playlists[key][0]], key); 3968 } 3969 } 3970 3971 /*-------------------------------------------------------------------------- 3972 Intializes the default live settings for all of the songs. 3973 --------------------------------------------------------------------------*/ 3974 function initializeDefaultLiveSettings() { 3975 for (var i = 0; i < config.songs.length; i++) { 3976 if (config.songs[i].live == undefined) { 3977 config.songs[i].live = false;
vendor: 5,393 bytes, lines 3978-4170
3978 } 3979 } 3980 } 3981 3982 /* 3983 Returns the publicly accessible methods 3984 */ 3985 return { 3986 initialize: initialize, 3987 setConfig: setConfig, 3988 rebindDisplay: rebindDisplay 3989 }; 3990}(); 3991 3992exports.default = AmplitudeInitializer; 3993module.exports = exports['default']; 3994 3995/***/ }), 3996/* 7 */ 3997/***/ (function(module, exports, __webpack_require__) { 3998 3999"use strict"; 4000 4001 4002Object.defineProperty(exports, "__esModule", { 4003 value: true 4004}); 4005 4006var _config = __webpack_require__(0); 4007 4008var _config2 = _interopRequireDefault(_config); 4009 4010var _helpers = __webpack_require__(5); 4011 4012var _helpers2 = _interopRequireDefault(_helpers); 4013 4014var _visual = __webpack_require__(2); 4015 4016var _visual2 = _interopRequireDefault(_visual); 4017 4018var _core = __webpack_require__(3); 4019 4020var _core2 = _interopRequireDefault(_core); 4021 4022var _helpers3 = __webpack_require__(1); 4023 4024var _helpers4 = _interopRequireDefault(_helpers3); 4025 4026function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 4027 4028/* 4029|------------------------------------------------------------------------------- 4030| EVENT HANDLER FUNCTIONS 4031|------------------------------------------------------------------------------- 4032| These functions handle the events that we bound to each element and 4033| prepare for a function to be called. These kind of act like filters/middleware. 4034| 4035| METHODS 4036| updateTime() 4037| songEnded() 4038| play() 4039| pause() 4040| playPause() 4041| stop() 4042| mute() 4043| volumeUp() 4044| volumeDown() 4045| songSlider() 4046| volumeSlider() 4047| next() 4048| prev() 4049| shuffle() 4050| repeat() 4051| playbackSpeed() 4052| skipTo() 4053*/ 4054exports.default = { 4055 /*-------------------------------------------------------------------------- 4056 HANDLER FOR: timeupdate 4057 When the time updates on the active song, we sync the current time displays 4058 --------------------------------------------------------------------------*/ 4059 updateTime: function updateTime() { 4060 /* 4061 If the current song is not live, then 4062 we can update the time information. Otherwise the 4063 current time updates wouldn't mean much since the time 4064 is infinite. 4065 */ 4066 if (!_config2.default.active_metadata.live) { 4067 /* 4068 Compute the current time 4069 */ 4070 var currentTime = _helpers2.default.computeCurrentTimes(); 4071 4072 /* 4073 Compute the song completion percentage 4074 */ 4075 var songCompletionPercentage = _helpers2.default.computeSongCompletionPercentage(); 4076 4077 /* 4078 Computes the song duration 4079 */ 4080 var songDuration = _helpers2.default.computeSongDuration(); 4081 4082 /* 4083 Sync the current time elements with the current 4084 location of the song and the song duration elements with 4085 the duration of the song. 4086 */ 4087 _visual2.default.syncCurrentTime(currentTime, songCompletionPercentage); 4088 _visual2.default.syncSongDuration(currentTime, songDuration); 4089 4090 /* 4091 Runs the callback defined for the time update. 4092 */ 4093 _helpers4.default.runCallback('time_update'); 4094 } 4095 }, 4096 4097 /*-------------------------------------------------------------------------- 4098 HANDLER FOR: keydown 4099 When the keydown event is fired, we determine which function should be run 4100 based on what was passed in. 4101 --------------------------------------------------------------------------*/ 4102 keydown: function keydown() { 4103 _helpers2.default.runKeyEvent(event.which); 4104 }, 4105 4106 /*-------------------------------------------------------------------------- 4107 HANDLER FOR: ended 4108 When the song has ended, handles what to do next 4109 --------------------------------------------------------------------------*/ 4110 songEnded: function songEnded() { 4111 if (_config2.default.continue_next) { 4112 /* 4113 If the active playlist is not set, we set the 4114 next song that's in the songs array. 4115 */ 4116 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) { 4117 _helpers2.default.setNext(true); 4118 } else { 4119 /* 4120 Set the next song in the playlist 4121 */ 4122 _helpers2.default.setNextPlaylist(_config2.default.active_playlist, true); 4123 } 4124 } else { 4125 if (!_config2.default.is_touch_moving) { 4126 /* 4127 Sets all of the play/pause buttons to pause 4128 */ 4129 _visual2.default.setPlayPauseButtonsToPause(); 4130 4131 /* 4132 Stops the active song. 4133 */ 4134 _core2.default.stop(); 4135 } 4136 } 4137 }, 4138 4139 /*-------------------------------------------------------------------------- 4140 HANDLER FOR: progress 4141 As the song is buffered, we can display the buffered percentage in 4142 a progress bar. 4143 --------------------------------------------------------------------------*/ 4144 progress: function progress() { 4145 /* 4146 Help from: http://jsbin.com/badimipi/1/edit?html,js,output 4147 */ 4148 if (_config2.default.active_song.buffered.length - 1 >= 0) { 4149 var bufferedEnd = _config2.default.active_song.buffered.end(_config2.default.active_song.buffered.length - 1); 4150 var duration = _config2.default.active_song.duration; 4151 4152 _config2.default.buffered = bufferedEnd / duration * 100; 4153 } 4154 4155 /* 4156 Sync the buffered progress bars. 4157 */ 4158 _visual2.default.syncBufferedProgressBars(); 4159 }, 4160 4161 /*-------------------------------------------------------------------------- 4162 HANDLER FOR: 'amplitude-play' 4163 Handles an event on a play button in Amplitude. 4164 --------------------------------------------------------------------------*/ 4165 play: function play() { 4166 if (!_config2.default.is_touch_moving) { 4167 /* 4168 Gets the attribute for song index so we can check if 4169 there is a need to change the song. In some scenarios 4170 there might be multiple play classes on the page. In that
4171 case it is possible the user could click a different play 4172 class and change the song. 4173 */ 4174 var playButtonSongIndex = this.getAttribute('amplitude-song-index'); 4175 var playButtonPlaylistIndex = this.getAttribute('amplitude-playlist'); 4176 4177 if (playButtonPlaylistIndex == null && playButtonSongIndex == null) { 4178 _helpers2.default.setSongPlayPause(_config2.default.active_playlist, _config2.default.active_index); 4179 } 4180 4181 /* 4182 */ 4183 if (playButtonPlaylistIndex != null && playButtonPlaylistIndex != '') { 4184 if (_helpers4.default.checkNewPlaylist(playButtonPlaylistIndex)) { 4185 _helpers4.default.setActivePlaylist(playButtonPlaylistIndex); 4186 4187 if (playButtonSongIndex != null) { 4188 _helpers4.default.changeSong(playButtonSongIndex); 4189 _helpers2.default.setPlaylistPlayPause(playButtonPlaylistIndex); 4190 } else { 4191 _helpers4.default.changeSong(_config2.default.playlists[playButtonPlaylistIndex][0]); 4192 _helpers2.default.setPlaylistPlayPause(playButtonPlaylistIndex); 4193 } 4194 } else { 4195 if (playButtonSongIndex != null) { 4196 _helpers4.default.changeSong(playButtonSongIndex); 4197 _helpers2.default.setPlaylistPlayPause(playButtonPlaylistIndex); 4198 } else { 4199 _helpers4.default.changeSong(_config2.default.active_index); 4200 _helpers2.default.setPlaylistPlayPause(playButtonPlaylistIndex); 4201 } 4202 } 4203 } 4204 4205 /* 4206 */ 4207 if ((playButtonPlaylistIndex == null || playButtonPlaylistIndex == '') && playButtonSongIndex != null && playButtonSongIndex != '') { 4208 4209 if (_helpers4.default.checkNewSong(playButtonSongIndex) || _config2.default.active_playlist != playButtonPlaylistIndex) { 4210 _helpers4.default.changeSong(playButtonSongIndex); 4211 } 4212 4213 _helpers2.default.setSongPlayPause(playButtonPlaylistIndex, playButtonSongIndex); 4214 } 4215 4216 /* 4217 Start the visualizations for the song. 4218 AMPFX-TODO: MAKE HANDLED BY AMPLITUDE FX 4219 */ 4220 //privateStartVisualization(); 4221 } 4222 }, 4223 4224 /*-------------------------------------------------------------------------- 4225 HANDLER FOR: 'amplitude-pause' 4226 --------------------------------------------------------------------------*/ 4227 pause: function pause() { 4228 if (!_config2.default.is_touch_moving) { 4229 var pauseButtonSongIndex = this.getAttribute('amplitude-song-index'); 4230 var pauseButtonPlaylistIndex = this.getAttribute('amplitude-playlist'); 4231 4232 if (pauseButtonSongIndex == null && pauseButtonPlaylistIndex == null) { 4233 _helpers2.default.setSongPlayPause(_config2.default.active_playlist, _config2.default.active_index); 4234 _core2.default.pause(); 4235 } 4236 4237 if (pauseButtonPlaylistIndex != null || pauseButtonPlaylistIndex != '' && _config2.default.active_playlist == pauseButtonPlaylistIndex) { 4238 /* 4239 The song was playing so we sync visually for the song 4240 to be paused and we pause the song. 4241 */ 4242 _visual2.default.syncMainPlayPause('paused'); 4243 4244 /* 4245 If there is an active playlist, then 4246 we need to sync that playlist's play pause 4247 button to the state of paused. 4248 */ 4249 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'paused'); 4250 4251 /* 4252 Sync the song play pause buttons 4253 */ 4254 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _config2.default.active_index, 'paused'); 4255 4256 _core2.default.pause(); 4257 } 4258 4259 if ((pauseButtonPlaylistIndex == null || pauseButtonPlaylistIndex == '') && pauseButtonSongIndex == _config2.default.active_index) { 4260 /* 4261 The song was playing so we sync visually for the song 4262 to be paused and we pause the song. 4263 */ 4264 _visual2.default.syncMainPlayPause('paused'); 4265 4266 /* 4267 If there is an active playlist, then 4268 we need to sync that playlist's play pause 4269 button to the state of paused. 4270 */ 4271 _visual2.default.syncPlaylistPlayPause(_config2.default.active_playlist, 'paused'); 4272 4273 /* 4274 Sync the song play pause buttons 4275 */ 4276 _visual2.default.syncSongPlayPause(_config2.default.active_playlist, _config2.default.active_index, 'paused'); 4277 4278 _core2.default.pause(); 4279 } 4280 } 4281 }, 4282 4283 /*-------------------------------------------------------------------------- 4284 HANDLER FOR: 'amplitude-play-pause' 4285 Handles an event on a play pause button. 4286 --------------------------------------------------------------------------*/ 4287 playPause: function playPause() { 4288 if (!_config2.default.is_touch_moving) { 4289 /* 4290 Checks to see if the element has an attribute for amplitude-main-play-pause 4291 and syncs accordingly 4292 */ 4293 if (this.getAttribute('amplitude-main-play-pause') != null) { 4294 _helpers2.default.setMainPlayPause(); 4295 4296 /* 4297 Syncs playlist main play pause buttons 4298 */ 4299 } else if (this.getAttribute('amplitude-playlist-main-play-pause') != null) { 4300 var playlist = this.getAttribute('amplitude-playlist'); 4301 4302 _helpers2.default.setPlaylistPlayPause(playlist); 4303 4304 /* 4305 Syncs amplitude individual song buttons 4306 */ 4307 } else { 4308 var playlist = this.getAttribute('amplitude-playlist'); 4309 var songIndex = this.getAttribute('amplitude-song-index'); 4310 4311 _helpers2.default.setSongPlayPause(playlist, songIndex); 4312 } 4313 } 4314 }, 4315 4316 /*-------------------------------------------------------------------------- 4317 HANDLER FOR: 'amplitude-stop' 4318 Handles an event on a stop element. 4319 AMP-FX TODO: Before stopping, make sure that AmplitudeFX visualization 4320 is stopped as well. 4321 --------------------------------------------------------------------------*/ 4322 stop: function stop() { 4323 if (!_config2.default.is_touch_moving) { 4324 /* 4325 Sets all of the play/pause buttons to pause 4326 */ 4327 _visual2.default.setPlayPauseButtonsToPause(); 4328 4329 /* 4330 Stops the active song. 4331 */ 4332 _core2.default.stop(); 4333 } 4334 }, 4335 4336 /*-------------------------------------------------------------------------- 4337 HANDLER FOR: 'amplitude-mute' 4338 Handles an event on a mute element. 4339 --------------------------------------------------------------------------*/ 4340 mute: function mute() { 4341 if (!_config2.default.is_touch_moving) { 4342 /* 4343 If the current volume in the config is 0, we set the volume to the 4344 pre_mute level. This means that the audio is already muted and 4345 needs to be restored to the pre_mute level. 4346 Otherwise, we set pre_mute volume to the current volume 4347 and set the config volume to 0, muting the audio. 4348 */ 4349 if (_config2.default.volume == 0) { 4350 _config2.default.volume = _config2.default.pre_mute_volume; 4351 _visual2.default.syncMute(false); 4352 } else { 4353 _config2.default.pre_mute_volume = _config2.default.volume; 4354 _config2.default.volume = 0; 4355 _visual2.default.syncMute(true); 4356 } 4357 4358 /* 4359 Calls the core function to set the volume to the computed value 4360 based on the user's intent. 4361 */ 4362 _core2.default.setVolume(_config2.default.volume); 4363 4364 /*
4365 Syncs the volume sliders so the visuals align up with the functionality. 4366 If the volume is at 0, then the sliders should represent that so the user 4367 has the right starting point. 4368 */ 4369 _visual2.default.syncVolumeSliders(_config2.default.volume); 4370 } 4371 }, 4372 4373 /*-------------------------------------------------------------------------- 4374 HANDLER FOR: 'amplitude-volume-up' 4375 Handles a click on a volume up element. 4376 --------------------------------------------------------------------------*/ 4377 volumeUp: function volumeUp() { 4378 if (!_config2.default.is_touch_moving) { 4379 /* 4380 The volume range is from 0 to 1 for an audio element. We make this 4381 a base of 100 for ease of working with. 4382 If the new value is less than 100, we use the new calculated 4383 value which gets converted to the proper unit for the audio element. 4384 If the new value is greater than 100, we set the volume to 1 which 4385 is the max for the audio element. 4386 */ 4387 if (_config2.default.volume + _config2.default.volume_increment <= 100) { 4388 _config2.default.volume = _config2.default.volume + _config2.default.volume_increment; 4389 } else { 4390 _config2.default.volume = 100; 4391 } 4392 4393 /* 4394 Calls the core function to set the volume to the computed value 4395 based on the user's intent. 4396 */ 4397 _core2.default.setVolume(_config2.default.volume); 4398 4399 /* 4400 Syncs the volume sliders so the visuals align up with the functionality. 4401 If the volume is at 0, then the sliders should represent that so the user 4402 has the right starting point. 4403 */ 4404 _visual2.default.syncVolumeSliders(_config2.default.volume); 4405 } 4406 }, 4407 4408 /*-------------------------------------------------------------------------- 4409 HANDLER FOR: 'amplitude-volume-down' 4410 Handles a click on a volume down element. 4411 --------------------------------------------------------------------------*/ 4412 volumeDown: function volumeDown() { 4413 if (!_config2.default.is_touch_moving) { 4414 /* 4415 The volume range is from 0 to 1 for an audio element. We make this 4416 a base of 100 for ease of working with. 4417 If the new value is less than 100, we use the new calculated 4418 value which gets converted to the proper unit for the audio element. 4419 If the new value is greater than 100, we set the volume to 1 which 4420 is the max for the audio element. 4421 */ 4422 if (_config2.default.volume - _config2.default.volume_increment > 0) { 4423 _config2.default.volume = _config2.default.volume - _config2.default.volume_increment; 4424 } else { 4425 _config2.default.volume = 0; 4426 } 4427 4428 /* 4429 Calls the core function to set the volume to the computed value 4430 based on the user's intent. 4431 */ 4432 _core2.default.setVolume(_config2.default.volume); 4433 4434 /* 4435 Syncs the volume sliders so the visuals align up with the functionality. 4436 If the volume is at 0, then the sliders should represent that so the user 4437 has the right starting point. 4438 */ 4439 _visual2.default.syncVolumeSliders(_config2.default.volume); 4440 } 4441 }, 4442 4443 /*-------------------------------------------------------------------------- 4444 HANDLER FOR: 'amplitude-song-slider' 4445 Handles a change on the song slider 4446 --------------------------------------------------------------------------*/ 4447 songSlider: function songSlider() { 4448 /* 4449 Gets the percentage of the song we will be setting the location for. 4450 */ 4451 var locationPercentage = this.value; 4452 4453 /* 4454 Checks to see if the element has an attribute for amplitude-main-play-pause 4455 and syncs accordingly 4456 */ 4457 if (this.getAttribute('amplitude-main-song-slider') != null) { 4458 /* 4459 If the active song is not live, set the current time 4460 */ 4461 if (!_config2.default.active_metadata.live) { 4462 var currentTime = _config2.default.active_song.duration * (locationPercentage / 100); 4463 4464 if (isFinite(currentTime)) { 4465 _config2.default.active_song.currentTime = currentTime; 4466 } 4467 } 4468 4469 _visual2.default.syncMainSliderLocation(locationPercentage); 4470 4471 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null) { 4472 _visual2.default.syncPlaylistSliderLocation(_config2.default.active_playlist, locationPercentage); 4473 } 4474 } 4475 4476 /* 4477 Syncs playlist main play pause buttons 4478 */ 4479 if (this.getAttribute('amplitude-playlist-song-slider') != null) { 4480 var playlist = this.getAttribute('amplitude-playlist'); 4481 4482 /* 4483 We don't want to song slide a playlist that's not the 4484 active placylist. 4485 */ 4486 if (_config2.default.active_playlist == playlist) { 4487 /* 4488 If the active song is not live, set the current time 4489 */ 4490 if (!_config2.default.active_metadata.live) { 4491 _config2.default.active_song.currentTime = _config2.default.active_song.duration * (locationPercentage / 100); 4492 } 4493 _visual2.default.syncMainSliderLocation(locationPercentage); 4494 _visual2.default.syncPlaylistSliderLocation(playlist, locationPercentage); 4495 } 4496 } 4497 4498 /* 4499 Syncs amplitude individual song buttons 4500 */ 4501 if (this.getAttribute('amplitude-playlist-song-slider') == null && this.getAttribute('amplitude-main-song-slider') == null) { 4502 4503 var playlist = this.getAttribute('amplitude-playlist'); 4504 var songIndex = this.getAttribute('amplitude-song-index'); 4505 4506 if (_config2.default.active_index == songIndex) { 4507 /* 4508 If the active song is not live, set the current time 4509 */ 4510 if (!_config2.default.active_metadata.live) { 4511 _config2.default.active_song.currentTime = _config2.default.active_song.duration * (locationPercentage / 100); 4512 } 4513 4514 _visual2.default.syncMainSliderLocation(); 4515 4516 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && _config2.default.active_playlist == playlist) { 4517 _visual2.default.syncPlaylistSliderLocation(playlist, location); 4518 } 4519 4520 _visual2.default.syncSongSliderLocation(playlist, songIndex, location); 4521 } 4522 } 4523 }, 4524 4525 /*-------------------------------------------------------------------------- 4526 HANDLER FOR: 'amplitude-volume-slider' 4527 Handles a change on the volume slider 4528 --------------------------------------------------------------------------*/ 4529 volumeSlider: function volumeSlider() { 4530 /* 4531 Calls the core function to set the volume to the computed value 4532 based on the user's intent. 4533 */ 4534 _core2.default.setVolume(this.value); 4535 4536 /* 4537 Sync the volume slider locations 4538 */ 4539 _visual2.default.syncVolumeSliderLocation(this.value); 4540 }, 4541 4542 /*-------------------------------------------------------------------------- 4543 HANDLER FOR: 'amplitude-next' 4544 Handles an event on the next button 4545 --------------------------------------------------------------------------*/ 4546 next: function next() { 4547 if (!_config2.default.is_touch_moving) { 4548 /* 4549 Checks to see if the button is a playlist next button or 4550 if it's a global playlist button. 4551 */ 4552 if (this.getAttribute('amplitude-playlist') == '' || this.getAttribute('amplitude-playlist') == null) { 4553 4554 /* 4555 Check to see if the current state of the player 4556 is in playlist mode or not playlist mode. 4557 */ 4558 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) { 4559 _helpers2.default.setNext(); 4560 } else { 4561 _helpers2.default.setNextPlaylist(_config2.default.active_playlist); 4562 } 4563 } else { 4564 /* 4565 Gets the playlist of the next button. 4566 */ 4567 var playlist = this.getAttribute('amplitude-playlist'); 4568 4569 /* 4570 Sets the next playlist 4571 */ 4572 _helpers2.default.setNextPlaylist(playlist); 4573 } 4574 } 4575 }, 4576 4577 /*-------------------------------------------------------------------------- 4578 HANDLER FOR: 'amplitude-prev' 4579 Handles an event on the previous button 4580 --------------------------------------------------------------------------*/ 4581 prev: function prev() { 4582 if (!_config2.default.is_touch_moving) { 4583 /* 4584 Checks to see if the previous button is a playlist previous 4585 button or if it's a global playlist button. 4586 */ 4587 if (this.getAttribute('amplitude-playlist') == '' || this.getAttribute('amplitude-playlist') == null) { 4588 4589 /* 4590 Check to see if the current playlist has been set 4591 or null and set the previous song. 4592 */ 4593 if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null) {
vendor: 13,756 bytes, lines 4594-4968
4594 _helpers2.default.setPrev(); 4595 } else { 4596 _helpers2.default.setPrevPlaylist(_config2.default.active_playlist); 4597 } 4598 } else { 4599 /* 4600 Gets the playlist of the previous button. 4601 */ 4602 var playlist = this.getAttribute('amplitude-playlist'); 4603 4604 /* 4605 Sets the previous playlist 4606 */ 4607 _helpers2.default.setPrevPlaylist(playlist); 4608 } 4609 } 4610 }, 4611 4612 /*-------------------------------------------------------------------------- 4613 HANDLER FOR: 'amplitude-shuffle' 4614 Handles an event on the shuffle button 4615 --------------------------------------------------------------------------*/ 4616 shuffle: function shuffle() { 4617 if (!_config2.default.is_touch_moving) { 4618 /* 4619 Check to see if the shuffle button belongs to a playlist 4620 */ 4621 if (this.getAttribute('amplitude-playlist') == '' || this.getAttribute('amplitude-playlist') == null) { 4622 /* 4623 Sets the shuffle button to null 4624 */ 4625 _helpers2.default.setShuffle(null); 4626 } else { 4627 /* 4628 Gets the playlist attribute of the shuffle button and 4629 set shuffle to on for the playlist. 4630 */ 4631 var playlist = this.getAttribute('amplitude-playlist'); 4632 _helpers2.default.setShuffle(playlist); 4633 } 4634 } 4635 }, 4636 4637 /*-------------------------------------------------------------------------- 4638 HANDLER FOR: 'amplitude-repeat' 4639 Handles an event on the repeat button 4640 --------------------------------------------------------------------------*/ 4641 repeat: function repeat() { 4642 if (!_config2.default.is_touch_moving) { 4643 /* 4644 Sets repeat to the opposite of what it was set to 4645 */ 4646 _helpers2.default.setRepeat(!_config2.default.repeat); 4647 4648 /* 4649 Visually sync repeat 4650 */ 4651 _visual2.default.syncRepeat(); 4652 } 4653 }, 4654 4655 /*-------------------------------------------------------------------------- 4656 HANDLER FOR: 'amplitude-playback-speed' 4657 Handles an event on the playback speed button 4658 --------------------------------------------------------------------------*/ 4659 playbackSpeed: function playbackSpeed() { 4660 if (!_config2.default.is_touch_moving) { 4661 /* 4662 We increment the speed by .5 everytime we click 4663 the button to change the playback speed. Once we are 4664 actively playing back at 2, we start back at 1 which 4665 is normal speed. 4666 */ 4667 switch (_config2.default.playback_speed) { 4668 case 1: 4669 _helpers2.default.setPlaybackSpeed(1.5); 4670 break; 4671 case 1.5: 4672 _helpers2.default.setPlaybackSpeed(2); 4673 break; 4674 case 2: 4675 _helpers2.default.setPlaybackSpeed(1); 4676 break; 4677 } 4678 4679 /* 4680 Visually sync the playback speed. 4681 */ 4682 _visual2.default.syncPlaybackSpeed(); 4683 } 4684 }, 4685 4686 /*-------------------------------------------------------------------------- 4687 HANDLER FOR: 'amplitude-skip-to' 4688 Handles an event on a skip to button. 4689 --------------------------------------------------------------------------*/ 4690 skipTo: function skipTo() { 4691 if (!_config2.default.is_touch_moving) { 4692 /* 4693 Determines if the skip to button is in the scope of a playlist. 4694 */ 4695 if (this.hasAttribute('amplitude-playlist')) { 4696 var playlist = this.getAttribute('amplitude-playlist'); 4697 4698 if (_helpers4.default.checkNewPlaylist(playlist)) { 4699 _helpers4.default.setActivePlaylist(playlist); 4700 } 4701 /* 4702 Gets the location, playlist and song index that is being skipped 4703 to. 4704 */ 4705 var seconds = parseInt(this.getAttribute('amplitude-location')); 4706 var songIndex = parseInt(this.getAttribute('amplitude-song-index')); 4707 4708 /* 4709 Changes the song to where it's being skipped and then 4710 play the song. 4711 */ 4712 _helpers4.default.changeSong(songIndex); 4713 _core2.default.play(); 4714 4715 _visual2.default.syncMainPlayPause('playing'); 4716 _visual2.default.syncPlaylistPlayPause(playlist, 'playing'); 4717 _visual2.default.syncSongPlayPause(playlist, songIndex, 'playing'); 4718 4719 /* 4720 Skip to the location in the song. 4721 */ 4722 _core2.default.skipToLocation(seconds); 4723 } else { 4724 /* 4725 Gets the location and song index that is being skipped 4726 to. 4727 */ 4728 var seconds = parseInt(this.getAttribute('amplitude-location')); 4729 var songIndex = parseInt(this.getAttribute('amplitude-song-index')); 4730 4731 /* 4732 Changes the song to where it's being skipped and then 4733 play the song. 4734 */ 4735 _helpers4.default.changeSong(songIndex); 4736 _core2.default.play(); 4737 4738 _visual2.default.syncMainPlayPause('playing'); 4739 _visual2.default.syncSongPlayPause(null, songIndex, 'playing'); 4740 4741 /* 4742 Skip to the location in the song. 4743 */ 4744 _core2.default.skipToLocation(seconds); 4745 } 4746 } 4747 } 4748}; 4749module.exports = exports['default']; 4750 4751/***/ }), 4752/* 8 */ 4753/***/ (function(module, exports, __webpack_require__) { 4754 4755"use strict"; 4756 4757 4758Object.defineProperty(exports, "__esModule", { 4759 value: true 4760}); 4761 4762var _init = __webpack_require__(6); 4763 4764var _init2 = _interopRequireDefault(_init); 4765 4766var _core = __webpack_require__(3); 4767 4768var _core2 = _interopRequireDefault(_core); 4769 4770var _helpers = __webpack_require__(1); 4771 4772var _helpers2 = _interopRequireDefault(_helpers); 4773 4774var _events = __webpack_require__(4); 4775 4776var _events2 = _interopRequireDefault(_events); 4777 4778var _helpers3 = __webpack_require__(5); 4779 4780var _helpers4 = _interopRequireDefault(_helpers3); 4781 4782var _visual = __webpack_require__(2); 4783 4784var _visual2 = _interopRequireDefault(_visual); 4785 4786var _config = __webpack_require__(0); 4787 4788var _config2 = _interopRequireDefault(_config); 4789 4790function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 4791 4792function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /* 4793 Amplitude.js 4794 Version: 3.2.0 4795 Author: Dan Pastori 4796 Company: 521 Dimensions 4797 */ 4798 4799 4800/* 4801 Amplitude should just be an interface to the public functions. 4802 Everything else should be handled by other objects 4803*/ 4804 4805var Amplitude = function () { 4806 var _ref; 4807 4808 /*-------------------------------------------------------------------------- 4809 The main init function. The user will call this through 4810 Amplitude.init({}) and pass in their settings. 4811 Public Accessor: Amplitude.init( user_config_json ); 4812 @param user_config A JSON object of user defined values that help 4813 configure and initialize AmplitudeJS. 4814 --------------------------------------------------------------------------*/ 4815 function init(userConfig) { 4816 _init2.default.initialize(userConfig); 4817 } 4818 4819 /*-------------------------------------------------------------------------- 4820 Binds new elements that were added to the page. 4821 --------------------------------------------------------------------------*/ 4822 function bindNewElements() { 4823 _init2.default.rebindDisplay(); 4824 } 4825 4826 /*-------------------------------------------------------------------------- 4827 Returns the active playlist 4828 --------------------------------------------------------------------------*/ 4829 function getActivePlaylist() { 4830 return _config2.default.active_playlist; 4831 } 4832 4833 /*-------------------------------------------------------------------------- 4834 Returns the current playback speed 4835 --------------------------------------------------------------------------*/ 4836 function getPlaybackSpeed() { 4837 return _config2.default.playback_speed; 4838 } 4839 4840 /*-------------------------------------------------------------------------- 4841 Gets the repeat state of the player. 4842 --------------------------------------------------------------------------*/ 4843 function getRepeat() { 4844 return _config2.default.repeat; 4845 } 4846 4847 /*-------------------------------------------------------------------------- 4848 Returns the shuffle state of the player. 4849 --------------------------------------------------------------------------*/ 4850 function getShuffle() { 4851 return _config2.default.shuffle_on; 4852 } 4853 4854 /*-------------------------------------------------------------------------- 4855 Returns the shuffle state of the playlist. 4856 @param playlist The key representing the playlist ID to see if it's shuffled 4857 or not. 4858 --------------------------------------------------------------------------*/ 4859 function getShufflePlaylist(playlist) { 4860 return _config2.default.shuffled_statuses[playlist]; 4861 } 4862 4863 /*-------------------------------------------------------------------------- 4864 Gets the default album art for the player 4865 --------------------------------------------------------------------------*/ 4866 function getDefaultAlbumArt() { 4867 return _config2.default.default_album_art; 4868 } 4869 4870 /*-------------------------------------------------------------------------- 4871 Sets the default album art for the player 4872 @param url A string representing the URL of the new default album art. 4873 --------------------------------------------------------------------------*/ 4874 function setDefaultAlbumArt(url) { 4875 _config2.default.default_album_art = url; 4876 } 4877 4878 /*-------------------------------------------------------------------------- 4879 Allows the user to get the percentage of the song played. 4880 Public Accessor: Amplitude.getSongPlayedPercentage(); 4881 --------------------------------------------------------------------------*/ 4882 function getSongPlayedPercentage() { 4883 /* 4884 Returns the percentage of the song played. 4885 */ 4886 return _config2.default.active_song.currentTime / _config2.default.active_song.duration * 100; 4887 } 4888 4889 /*-------------------------------------------------------------------------- 4890 Allows the user to set how far into the song they want to be. This is 4891 helpful for implementing custom range sliders. Only works on the current song. 4892 Public Accessor: Amplitude.setSongPlayedPercentage( float ); 4893 @param Float percentage The percentage of the song played 4894 --------------------------------------------------------------------------*/ 4895 function setSongPlayedPercentage(percentage) { 4896 /* 4897 Ensures the percentage is a number and is between 0 and 100. 4898 */ 4899 if (typeof percentage == 'number' && percentage > 0 && percentage < 100) { 4900 /* 4901 Sets the current time of the song to the percentage. 4902 */ 4903 _config2.default.active_song.currentTime = _config2.default.active_song.duration * (percentage / 100); 4904 } 4905 } 4906 4907 /*-------------------------------------------------------------------------- 4908 Allows the user to turn on debugging. 4909 Public Accessor: Amplitude.setDebug( bool ); 4910 @param BOOL state Turns debugging on and off. 4911 --------------------------------------------------------------------------*/ 4912 function setDebug(state) { 4913 /* 4914 Sets the global config debug on or off. 4915 */ 4916 _config2.default.debug = state; 4917 } 4918 4919 /*-------------------------------------------------------------------------- 4920 Returns the active song meta data for the user to do what is 4921 needed. 4922 Public Accessor: Amplitude.getActiveSongMetadata(); 4923 @returns JSON Object with the active song information 4924 --------------------------------------------------------------------------*/ 4925 function getActiveSongMetadata() { 4926 return _config2.default.active_metadata; 4927 } 4928 4929 /*-------------------------------------------------------------------------- 4930 Returns a song in the songs array at that index 4931 Public Accessor: Amplitude.getSongByIndex( song_index ) 4932 @param int index The integer for the index of the 4933 song in the songs array. 4934 @returns JSON representation for the song at a specific index. 4935 --------------------------------------------------------------------------*/ 4936 function getSongByIndex(index) { 4937 return _config2.default.songs[index]; 4938 } 4939 4940 /*-------------------------------------------------------------------------- 4941 Returns a song at a playlist index 4942 Public Accessor: Amplitude.getSongAtPlaylistIndex( playlist, index 4943 @param int index The integer for the index of the 4944 song in the playlist. 4945 @param string playlist The key of the playlist we are getting the song 4946 at the index for 4947 @returns JSON representation for the song at a specific index. 4948 --------------------------------------------------------------------------*/ 4949 function getSongAtPlaylistIndex(playlist, index) { 4950 var songIndex = _config2.default.playlists[playlist][index]; 4951 4952 return _config2.default.songs[songIndex]; 4953 } 4954 4955 /*-------------------------------------------------------------------------- 4956 Adds a song to the end of the config array. This will allow Amplitude 4957 to play the song in a playlist type setting. 4958 Public Accessor: Amplitude.addSong( song_json ) 4959 @param song JSON representation of a song. 4960 @returns int New index of the song. 4961 --------------------------------------------------------------------------*/ 4962 function addSong(song) { 4963 _config2.default.songs.push(song); 4964 return _config2.default.songs.length - 1; 4965 } 4966 4967 /*-------------------------------------------------------------------------- 4968 When you pass a song object it plays that song right awawy. It set
4968s 4969 the active song in the config to the song you pass in and synchronizes 4970 the visuals. 4971 Public Accessor: Amplitude.playNow( song ) 4972 @param song JSON representation of a song. 4973 --------------------------------------------------------------------------*/ 4974 function playNow(song) { 4975 _core2.default.playNow(song); 4976 } 4977 4978 /* 4979 TODO: Implement Add Song To Playlist Functionality 4980 */ 4981 function addSongToPlaylist(song, playlist) {} 4982 4983 /*-------------------------------------------------------------------------- 4984 Allows the user to play whatever the active song is directly 4985 through Javascript. Normally ALL of Amplitude functions that access 4986 the core features are called through event handlers. 4987 Public Accessor: Amplitude.play(); 4988 --------------------------------------------------------------------------*/ 4989 function play() { 4990 _core2.default.play(); 4991 } 4992 4993 /*-------------------------------------------------------------------------- 4994 Allows the user to pause whatever the active song is directly 4995 through Javascript. Normally ALL of Amplitude functions that access 4996 the core features are called through event handlers. 4997 Public Accessor: Amplitude.pause(); 4998 --------------------------------------------------------------------------*/ 4999 function pause() { 5000 _core2.default.pause(); 5001 } 5002 5003 /*-------------------------------------------------------------------------- 5004 Returns the audio object used to play the audio 5005 Public Accessor: Amplitude.getAudio(); 5006 --------------------------------------------------------------------------*/ 5007 function getAudio() { 5008 return _config2.default.active_song; 5009 } 5010 5011 /*-------------------------------------------------------------------------- 5012 Plays the next song either in the playlist or globally. 5013 Public Accessor: Amplitude.next( playlist ); 5014 @param string playlist The playlist key 5015 --------------------------------------------------------------------------*/ 5016 function next() { 5017 var playlist = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; 5018 5019 /* 5020 If the playlist is empty or null, then we check the active 5021 playlist 5022 */ 5023 if (playlist == '' || playlist == null) { 5024 /* 5025 If the active playlist is null, then we set the next global 5026 song or we set the next in the playlist. 5027 */ 5028 if (_config2.default.active_playlist == null || _config2.default.active_playlist == '') { 5029 _helpers4.default.setNext(); 5030 } else { 5031 _helpers4.default.setNextPlaylist(_config2.default.active_playlist); 5032 } 5033 } else { 5034 /* 5035 Set the next in the playlist for the key provided. 5036 */ 5037 _helpers4.default.setNextPlaylist(playlist); 5038 } 5039 } 5040 5041 /*-------------------------------------------------------------------------- 5042 Plays the prev song either in the playlist or globally. 5043 Public Accessor: Amplitude.prev( playlist ); 5044 @param string playlist The playlist key 5045 --------------------------------------------------------------------------*/ 5046 function prev() { 5047 var playlist = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; 5048 5049 /* 5050 If the playlist is empty or null, then we check the active 5051 playlist 5052 */ 5053 if (playlist == '' || playlist == null) { 5054 /* 5055 If the active playlist is null, then we set the prev global 5056 song or we set the prev in the playlist. 5057 */ 5058 if (_config2.default.active_playlist == null || _config2.default.active_playlist == '') { 5059 _helpers4.default.setPrev(); 5060 } else { 5061 _helpers4.default.setPrevPlaylist(_config2.default.active_playlist); 5062 } 5063 } else { 5064 /* 5065 Set the prev in the playlist for the key provided. 5066 */ 5067 _helpers4.default.setPrevPlaylist(playlist); 5068 } 5069 } 5070 5071 /*-------------------------------------------------------------------------- 5072 Gets all of the songs in the songs array 5073 Public Accessor: Amplitude.getSongs( ); 5074 --------------------------------------------------------------------------*/ 5075 function getSongs() { 5076 return _config2.default.songs; 5077 } 5078 5079 /*-------------------------------------------------------------------------- 5080 Gets all of the songs in a playlist 5081 Public Accessor: Amplitude.getSongsInPlaylist( playlist ); 5082 @param string playlist The playlist key 5083 --------------------------------------------------------------------------*/ 5084 function getSongsInPlaylist(playlist) { 5085 var songsArray = []; 5086 5087 for (var i = 0; i < _config2.default.playlist[playlist].length; i++) { 5088 songsArray.push(_config2.default.songs[i]); 5089 } 5090 5091 return songsArray; 5092 } 5093 5094 /*-------------------------------------------------------------------------- 5095 Get current state of songs. If shuffled, this will return the shuffled 5096 songs. 5097 Public Accessor: Amplitude.getSongsState(); 5098 --------------------------------------------------------------------------*/ 5099 function getSongsState() { 5100 if (_config2.default.shuffle_on) { 5101 return _config2.default.shuffle_list; 5102 } else { 5103 return _config2.default.songs; 5104 } 5105 } 5106 5107 /*-------------------------------------------------------------------------- 5108 Get current state of songs in playlist. If shuffled, this will return the 5109 shuffled songs. 5110 Public Accessor: Amplitude.getSongsStatePlaylist( playlist ); 5111 @param string playlist The playlist key 5112 --------------------------------------------------------------------------*/ 5113 function getSongsStatePlaylist(playlist) { 5114 var songsArray = []; 5115 5116 if (_config2.default.shuffled_status[playlist]) { 5117 5118 for (var i = 0; i < _config2.default.shuffled_playlists[playlist].length; i++) { 5119 songsArray.push(_config2.default.songs[i]); 5120 } 5121 } else { 5122 5123 for (var i = 0; i < _config2.default.playlist[playlist].length; i++) { 5124 songsArray.push(_config2.default.songs[i]); 5125 } 5126 } 5127 5128 return songsArray; 5129 } 5130 5131 /*-------------------------------------------------------------------------- 5132 Gets the active index of the player 5133 Public Accessor: Amplitude.getActiveIndex() 5134 --------------------------------------------------------------------------*/ 5135 function getActiveIndex() { 5136 return parseInt(_config2.default.active_index); 5137 } 5138 5139 /*-------------------------------------------------------------------------- 5140 Gets the active index with respect to the state of the player whether it is 5141 shuffled or not. 5142 Public Accessor: Amplitude.getActiveIndexState() 5143 --------------------------------------------------------------------------*/ 5144 function getActiveIndexState() { 5145 if (_config2.default.shuffle_on) { 5146 return parseInt(_config2.default.shuffle_active_index); 5147 } else { 5148 return parseInt(_config2.default.active_index); 5149 } 5150 } 5151 5152 /*-------------------------------------------------------------------------- 5153 Get the version of AmplitudeJS 5154 Public Accessor: Amplitude.getVersion() 5155 --------------------------------------------------------------------------*/ 5156 function getVersion() { 5157 return _config2.default.version; 5158 } 5159 5160 /*-------------------------------------------------------------------------- 5161 Get the buffered amount for the current song 5162 Public Accessor: Amplitude.getBuffered() 5163 --------------------------------------------------------------------------*/ 5164 function getBuffered() { 5165 return _config2.default.buffered; 5166 } 5167 5168 /*-------------------------------------------------------------------------- 5169 Skip to a certain location in a selected song. 5170 Public Accessor: Amplitude.getBuffered() 5171 --------------------------------------------------------------------------*/ 5172 function skipTo(seconds, songIndex) { 5173 var playlist = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; 5174 5175 if (playlist != null) { 5176 if (_helpers2.default.checkNewPlaylist(playlist)) { 5177 _helpers2.default.setActivePlaylist(playlist); 5178 } 5179 } 5180 5181 seconds = parseInt(seconds); 5182 5183 /* 5184 Changes the song to where it's being skipped and then 5185 play the song. 5186 */ 5187 _helpers2.default.changeSong(songIndex); 5188 _core2.default.play(); 5189 5190 _visual2.default.syncMainPlayPause('playing'); 5191 5192 if (playlist != null) { 5193 _visual2.default.syncPlaylistPlayPause(playlist, 'playing'); 5194 } 5195 5196 _visual2.default.syncSongPlayPause(playlist, songIndex, 'playing'); 5197 5198 /* 5199 Skip to the location in the song. 5200 */ 5201 _core2.default.skipToLocation(seconds); 5202 } 5203 5204 /* 5205 Returns all of the publically accesible methods. 5206 */ 5207 return _ref = { 5208 init: init, 5209 bindNewElements: bindNewElements, 5210 getActivePlaylist: getActivePlaylist, 5211 getPlaybackSpeed: getPlaybackSpeed, 5212 getRepeat: getRepeat, 5213 getShuffle: getShuffle, 5214 getShufflePlaylist: getShufflePlaylist, 5215 getDefaultAlbumArt: getDefaultAlbumArt, 5216 setDefaultAlbumArt: setDefaultAlbumArt, 5217 getSongPlayedPercentage: getSongPlayedPercentage, 5218 setSongPlayedPercentage: setSongPlayedPercentage, 5219 setDebug: setDebug, 5220 getActiveSongMetadata: getActiveSongMetadata,
vendor: 13,827 bytes, lines 5221-5591
5221 getSongByIndex: getSongByIndex, 5222 getSongAtPlaylistIndex: getSongAtPlaylistIndex, 5223 addSong: addSong, 5224 playNow: playNow, 5225 play: play, 5226 pause: pause 5227 }, _defineProperty(_ref, 'addSong', addSong), _defineProperty(_ref, 'audio', getAudio), _defineProperty(_ref, 'next', next), _defineProperty(_ref, 'prev', prev), _defineProperty(_ref, 'getSongs', getSongs), _defineProperty(_ref, 'getSongsInPlaylist', getSongsInPlaylist), _defineProperty(_ref, 'getSongsState', getSongsState), _defineProperty(_ref, 'getSongsStatePlaylist', getSongsStatePlaylist), _defineProperty(_ref, 'getActiveIndex', getActiveIndex), _defineProperty(_ref, 'getActiveIndexState', getActiveIndexState), _defineProperty(_ref, 'getVersion', getVersion), _defineProperty(_ref, 'getBuffered', getBuffered), _defineProperty(_ref, 'skipTo', skipTo), _ref; 5228}(); 5229 5230exports.default = Amplitude; 5231module.exports = exports['default']; 5232 5233/***/ }), 5234/* 9 */ 5235/***/ (function(module, exports, __webpack_require__) { 5236 5237"use strict"; 5238 5239 5240Object.defineProperty(exports, "__esModule", { 5241 value: true 5242}); 5243 5244var _config = __webpack_require__(0); 5245 5246var _config2 = _interopRequireDefault(_config); 5247 5248var _helpers = __webpack_require__(1); 5249 5250var _helpers2 = _interopRequireDefault(_helpers); 5251 5252var _init = __webpack_require__(6); 5253 5254var _init2 = _interopRequireDefault(_init); 5255 5256function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 5257 5258/* 5259|---------------------------------------------------------------------------------------------------- 5260| SOUNDCLOUD 5261|---------------------------------------------------------------------------------------------------- 5262| These helpers wrap around the basic methods of the Soundcloud API 5263| and get the information we need from SoundCloud to make the songs 5264| streamable through Amplitude 5265*/ 5266var AmplitudeSoundcloud = function () { 5267 /* 5268 Defines the temp user config 5269 */ 5270 var tempUserConfig = {}; 5271 5272 /*-------------------------------------------------------------------------- 5273 Loads the soundcloud SDK for use with Amplitude so the user doesn't have 5274 to load it themselves. 5275 With help from: http://stackoverflow.com/questions/950087/include-a-javascript-file-in-another-javascript-file 5276 --------------------------------------------------------------------------*/ 5277 function loadSoundCloud(userConfig) { 5278 tempUserConfig = userConfig; 5279 5280 var head = document.getElementsByTagName('head')[0]; 5281 var script = document.createElement('script'); 5282 5283 script.type = 'text/javascript'; 5284 /* 5285 URL to the remote soundcloud SDK 5286 */ 5287 script.src = 'https://connect.soundcloud.com/sdk.js'; 5288 script.onreadystatechange = initSoundcloud; 5289 script.onload = initSoundcloud; 5290 5291 head.appendChild(script); 5292 } 5293 5294 /*-------------------------------------------------------------------------- 5295 Initializes soundcloud with the key provided. 5296 --------------------------------------------------------------------------*/ 5297 function initSoundcloud() { 5298 /* 5299 Calls the SoundCloud initialize function 5300 from their API and sends it the client_id 5301 that the user passed in. 5302 */ 5303 SC.initialize({ 5304 client_id: _config2.default.soundcloud_client 5305 }); 5306 5307 /* 5308 Gets the streamable URLs to run through Amplitue. This is 5309 VERY important since Amplitude can't stream the copy and pasted 5310 link from the SoundCloud page, but can resolve the streaming 5311 URLs from the link. 5312 */ 5313 getStreamableURLs(); 5314 } 5315 5316 /*-------------------------------------------------------------------------- 5317 Gets the streamable URL from the URL provided for 5318 all of the soundcloud links. This will loop through 5319 and set all of the information for the soundcloud 5320 urls. 5321 --------------------------------------------------------------------------*/ 5322 function getStreamableURLs() { 5323 var soundcloud_regex = /^https?:\/\/(soundcloud.com|snd.sc)\/(.*)$/; 5324 5325 for (var i = 0; i < _config2.default.songs.length; i++) { 5326 /* 5327 If the URL matches soundcloud, we grab 5328 that url and get the streamable link 5329 if there is one. 5330 */ 5331 if (_config2.default.songs[i].url.match(soundcloud_regex)) { 5332 _config2.default.soundcloud_song_count++; 5333 resolveStreamable(_config2.default.songs[i].url, i); 5334 } 5335 } 5336 } 5337 5338 /*-------------------------------------------------------------------------- 5339 Due to Soundcloud SDK being asynchronous, we need to scope the 5340 index of the song in another function. The privateGetSoundcloudStreamableURLs 5341 function does the actual iteration and scoping. 5342 --------------------------------------------------------------------------*/ 5343 function resolveStreamable(url, index) { 5344 SC.get('/resolve/?url=' + url, function (sound) { 5345 /* 5346 If streamable we get the url and bind the client ID to the end 5347 so Amplitude can just stream the song normally. We then overwrite 5348 the url the user provided with the streamable URL. 5349 */ 5350 if (sound.streamable) { 5351 _config2.default.songs[index].url = sound.stream_url + '?client_id=' + _config2.default.soundcloud_client; 5352 5353 /* 5354 If the user want's to use soundcloud art, we overwrite the 5355 cover_art_url with the soundcloud artwork url. 5356 */ 5357 if (_config2.default.soundcloud_use_art) { 5358 _config2.default.songs[index].cover_art_url = sound.artwork_url; 5359 } 5360 5361 /* 5362 Grab the extra metadata from soundcloud and bind it to the 5363 song. The user can get this through the public function: 5364 getActiveSongMetadata 5365 */ 5366 _config2.default.songs[index].soundcloud_data = sound; 5367 } else { 5368 /* 5369 If not streamable, then we print a message to the user stating 5370 that the song with name X and artist X is not streamable. This 5371 gets printed ONLY if they have debug turned on. 5372 */ 5373 _helpers2.default.writeDebugMessage(_config2.default.songs[index].name + ' by ' + _config2.default.songs[index].artist + ' is not streamable by the Soundcloud API'); 5374 } 5375 /* 5376 Increments the song ready counter. 5377 */ 5378 _config2.default.soundcloud_songs_ready++; 5379 5380 /* 5381 When all songs are accounted for, then amplitude is ready 5382 to rock and we set the rest of the config. 5383 */ 5384 if (_config2.default.soundcloud_songs_ready == _config2.default.soundcloud_song_count) { 5385 _init2.default.setConfig(tempUserConfig); 5386 } 5387 }); 5388 } 5389 5390 /* 5391 Returns the publically accessible methods 5392 */ 5393 return { 5394 loadSoundCloud: loadSoundCloud 5395 }; 5396}(); 5397 5398exports.default = AmplitudeSoundcloud; 5399module.exports = exports['default']; 5400 5401/***/ }), 5402/* 10 */ 5403/***/ (function(module, exports, __webpack_require__) { 5404 5405"use strict"; 5406 5407 5408Object.defineProperty(exports, "__esModule", { 5409 value: true 5410}); 5411 5412var _config = __webpack_require__(0); 5413 5414var _config2 = _interopRequireDefault(_config); 5415 5416function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 5417 5418/* 5419|------------------------------------------------------------------------------- 5420| VISUAL SYNC HELPER METHODS 5421|------------------------------------------------------------------------------- 5422| These methods help sync visual displays. They essentially make the visual sync 5423| methods smaller and more maintainable. 5424| 5425| METHODS 5426| syncCurrentHours( hours ) 5427| resetCurrentHours() 5428| syncCurrentMinutes( minutes ) 5429| resetCurrentMinutes() 5430| syncCurrentSeconds( seconds ) 5431| resetCurrentSeconds() 5432| syncCurrentTime( currentTime ) 5433| syncCurrentHours( hours ) 5434| syncCurrentMinutes( minutes ) 5435| syncCurrentSeconds( seconds ) 5436| syncCurrentTime( time ) 5437| resetCurrentTime() 5438| setElementPlay( element ) 5439| setElementPause( element ) 5440*/ 5441var AmplitudeVisualSyncHelpers = function () { 5442 /*-------------------------------------------------------------------------- 5443 Updates any elements that display the current hour for the song. 5444 @param int hours An integer conaining how many hours into 5445 the song. 5446 --------------------------------------------------------------------------*/ 5447 function syncCurrentHours(hours) { 5448 /* 5449 Gets all of the song hour selectors. 5450 */ 5451 if (_config2.default.active_playlist != null && _config2.default.active_playlist != '') { 5452 var hourSelectors = ['.amplitude-current-hours[amplitude-main-current-hours="true"]', '.amplitude-current-hours[amplitude-playlist-current-hours="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]', '.amplitude-current-hours[amplitude-song-index="' + _config2.default.active_index + '"]']; 5453 } else { 5454 var hourSelectors = ['.amplitude-current-hours[amplitude-main-current-hours="true"]', '.amplitude-current-hours[amplitude-song-index="' + _config2.default.active_index + '"]']; 5455 } 5456 5457 /* 5458 Ensures that there are some hour selectors. 5459 */ 5460 if (document.querySelectorAll(hourSelectors.join()).length > 0) { 5461 /* 5462 Get all of the hour selectors 5463 */ 5464 var currentHourSelectors = document.querySelectorAll(hourSelectors.join()); 5465 5466 /* 5467 Set the current hour selector's inner html to hours passed in. 5468 */ 5469 for (var i = 0; i < currentHourSelectors.length; i++) { 5470 /* 5471 If the selector is a main selector, we set the hours. 5472 */ 5473 if (currentHourSelectors[i].getAttribute('amplitude-main-current-hours') == 'true') { 5474 currentHourSelectors[i].innerHTML = hours; 5475 } else { 5476 /* 5477 If the active playlist is not null or empty 5478 and the attribute of the playlist is equal to the 5479 active playlist, then we set the inner html. 5480 */ 5481 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && currentHourSelectors[i].getAttribute('amplitude-playlist') == _config2.default.active_playlist) { 5482 currentHourSelectors[i].innerHTML = hours; 5483 /* 5484 If the active playlist is not set and the selector 5485 does not have a playlist then we set the hours. This 5486 means that the current selector is an individual song 5487 selector. 5488 */ 5489 } else if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null && !currentHourSelectors[i].hasAttribute('amplitude-playlist')) { 5490 currentHourSelectors[i].innerHTML = hours; 5491 /* 5492 If nothing else matches, set the selector's inner HTML to '00' 5493 */ 5494 } else { 5495 currentHourSelectors[i].innerHTML = '00'; 5496 } 5497 } 5498 } 5499 } 5500 } 5501 5502 /*-------------------------------------------------------------------------- 5503 Resets the current hours displays to 00 5504 --------------------------------------------------------------------------*/ 5505 function resetCurrentHours() { 5506 /* 5507 Gets the hour display elements 5508 */ 5509 var hourSelectors = document.querySelectorAll('.amplitude-current-hours'); 5510 5511 /* 5512 Iterates over all of the hour selectors and sets the inner HTML 5513 to 00. 5514 */ 5515 for (var i = 0; i < hourSelectors.length; i++) { 5516 hourSelectors[i].innerHTML = '00'; 5517 } 5518 } 5519 5520 /*-------------------------------------------------------------------------- 5521 Updates any elements that display the current minutes for the song. 5522 @param int minutes An integer conaining how many minutes into 5523 the song. 5524 --------------------------------------------------------------------------*/ 5525 function syncCurrentMinutes(minutes) { 5526 /* 5527 Gets all of the song minute selectors. 5528 */ 5529 if (_config2.default.active_playlist != null && _config2.default.active_playlist != '') { 5530 var minuteSelectors = ['.amplitude-current-minutes[amplitude-main-current-minutes="true"]', '.amplitude-current-minutes[amplitude-playlist-current-minutes="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]', '.amplitude-current-minutes[amplitude-song-index="' + _config2.default.active_index + '"]']; 5531 } else { 5532 var minuteSelectors = ['.amplitude-current-minutes[amplitude-main-current-minutes="true"]', '.amplitude-current-minutes[amplitude-song-index="' + _config2.default.active_index + '"]']; 5533 } 5534 5535 var currentMinuteSelectors = document.querySelectorAll(minuteSelectors.join()); 5536 5537 /* 5538 Set the current minute selector's inner html to minutes passed in. 5539 */ 5540 for (var i = 0, l = currentMinuteSelectors.length; i < l; i++) { 5541 /* 5542 If the selector is a main selector, we set the seconds. 5543 */ 5544 if (currentMinuteSelectors[i].getAttribute('amplitude-main-current-minutes') == 'true') { 5545 currentMinuteSelectors[i].innerHTML = minutes; 5546 } else { 5547 /* 5548 If the active playlist is not null or empty 5549 and the attribute of the playlist is equal to the 5550 active playlist, then we set the inner html. 5551 */ 5552 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && currentMinuteSelectors[i].getAttribute('amplitude-playlist') == _config2.default.active_playlist) { 5553 currentMinuteSelectors[i].innerHTML = minutes; 5554 /* 5555 If the active playlist is not set and the selector 5556 does not have a playlist then we set the minutes. This 5557 means that the current selector is an individual song 5558 selector. 5559 */ 5560 } else if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null && !currentMinuteSelectors[i].hasAttribute('amplitude-playlist')) { 5561 currentMinuteSelectors[i].innerHTML = minutes; 5562 /* 5563 If nothing else matches, set the selector's inner HTML to '00' 5564 */ 5565 } else { 5566 currentMinuteSelectors[i].innerHTML = '00'; 5567 } 5568 } 5569 } 5570 } 5571 5572 /*-------------------------------------------------------------------------- 5573 Resets the current minutes displays to 00 5574 --------------------------------------------------------------------------*/ 5575 function resetCurrentMinutes() { 5576 /* 5577 Gets the minutes display elements 5578 */ 5579 var minuteSelectors = document.querySelectorAll('.amplitude-current-minutes'); 5580 5581 /* 5582 Iterates over all of the minute selectors and sets the inner HTML 5583 to 00. 5584 */ 5585 for (var i = 0; i < minuteSelectors.length; i++) { 5586 minuteSelectors[i].innerHTML = '00'; 5587 } 5588 } 5589 5590 /*-------------------------------------------------------------------------- 5591 Updates any elements that display the current seconds for the song.
5592 @param int minutes An integer conaining how many seconds into 5593 the song. 5594 --------------------------------------------------------------------------*/ 5595 function syncCurrentSeconds(seconds) { 5596 /* 5597 Gets all of the song second selectors. If the active playlist 5598 is not null, then we get the playlist selectors. 5599 */ 5600 if (_config2.default.active_playlist != null && _config2.default.active_playlist != '') { 5601 var secondSelectors = ['.amplitude-current-seconds[amplitude-main-current-seconds="true"]', '.amplitude-current-seconds[amplitude-playlist-current-seconds="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]', '.amplitude-current-seconds[amplitude-song-index="' + _config2.default.active_index + '"]']; 5602 } else { 5603 var secondSelectors = ['.amplitude-current-seconds[amplitude-main-current-seconds="true"]', '.amplitude-current-seconds[amplitude-song-index="' + _config2.default.active_index + '"]']; 5604 } 5605 5606 /* 5607 Get all of the second selectors 5608 */ 5609 var currentSecondSelectors = document.querySelectorAll(secondSelectors.join()); 5610 5611 /* 5612 Iterate over all of the second selectors. 5613 */ 5614 for (var i = 0, l = currentSecondSelectors.length; i < l; i++) { 5615 /* 5616 If the selector is a main selector, we set the seconds. 5617 */ 5618 if (currentSecondSelectors[i].getAttribute('amplitude-main-current-seconds') == 'true') { 5619 currentSecondSelectors[i].innerHTML = seconds; 5620 } else { 5621 /* 5622 If the active playlist is not null or empty 5623 and the attribute of the playlist is equal to the 5624 active playlist, then we set the inner html. 5625 */ 5626 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && currentSecondSelectors[i].getAttribute('amplitude-playlist') == _config2.default.active_playlist) { 5627 currentSecondSelectors[i].innerHTML = seconds; 5628 /* 5629 If the active playlist is not set and the selector 5630 does not have a playlist then we set the seconds. This 5631 means that the current selector is an individual song 5632 selector. 5633 */ 5634 } else if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null && !currentSecondSelectors[i].hasAttribute('amplitude-playlist')) { 5635 currentSecondSelectors[i].innerHTML = seconds; 5636 /* 5637 If nothing else matches, set the selector's inner HTML to '00' 5638 */ 5639 } else { 5640 currentSecondSelectors[i].innerHTML = '00'; 5641 } 5642 } 5643 } 5644 } 5645 5646 /*-------------------------------------------------------------------------- 5647 Resets the current seconds displays to 00 5648 --------------------------------------------------------------------------*/ 5649 function resetCurrentSeconds() { 5650 /* 5651 Gets the seconds display elements 5652 */ 5653 var secondSelectors = document.querySelectorAll('.amplitude-current-seconds'); 5654 5655 /* 5656 Iterates over all of the seconds selectors and sets the inner HTML 5657 to 00. 5658 */ 5659 for (var i = 0; i < secondSelectors.length; i++) { 5660 secondSelectors[i].innerHTML = '00'; 5661 } 5662 } 5663 5664 /*-------------------------------------------------------------------------- 5665 Updates any elements that display the current time for the song. This 5666 is a computed field that will be commonly used. 5667 @param JSON currentTime A json object conaining the parts for the 5668 current time for the song. 5669 --------------------------------------------------------------------------*/ 5670 function syncCurrentTime(currentTime) { 5671 /* 5672 Gets all of the song time selectors. 5673 */ 5674 var timeSelectors = ['.amplitude-current-time[amplitude-main-current-time="true"]', '.amplitude-current-time[amplitude-playlist-main-current-time="' + _config2.default.active_playlist + '"]', '.amplitude-current-time[amplitude-song-index="' + _config2.default.active_index + '"]']; 5675 5676 /* 5677 Get all of the time selectors. 5678 */ 5679 var currentTimeSelectors = document.querySelectorAll(timeSelectors.join()); 5680 5681 /* 5682 Set the time selector's inner html to the current time for the song. The current 5683 time is computed by joining minutes and seconds. 5684 */ 5685 for (var i = 0, l = currentTimeSelectors.length; i < l; i++) { 5686 currentTimeSelectors[i].innerHTML = currentTime.minutes + ':' + currentTime.seconds; 5687 } 5688 } 5689 5690 /*-------------------------------------------------------------------------- 5691 Resets the current time displays to 00:00 5692 --------------------------------------------------------------------------*/ 5693 function resetCurrentTime() { 5694 /* 5695 Gets the time selector display elements 5696 */ 5697 var timeSelectors = document.querySelectorAll('.amplitude-current-time'); 5698 5699 /* 5700 Iterates over all of the time selectors and sets the inner HTML 5701 to 00. 5702 */ 5703 for (var i = 0; i < timeSelectors.length; i++) { 5704 timeSelectors[i].innerHTML = '00:00'; 5705 } 5706 } 5707 5708 /*-------------------------------------------------------------------------- 5709 Syncs the song played progress bars. These are HTML5 progress elements. 5710 --------------------------------------------------------------------------*/ 5711 function syncSongPlayedProgressBar(songPlayedPercentage) { 5712 syncMainSongPlayedProgressBars(songPlayedPercentage); 5713 syncPlaylistSongPlayedProgressBars(songPlayedPercentage); 5714 syncIndividualSongPlayedProgressBars(songPlayedPercentage); 5715 } 5716 5717 /*-------------------------------------------------------------------------- 5718 Sync how much has been played with a progress bar. This is the main progress 5719 bar. 5720 @param float songPlayedPercentage The percent of the song completed. 5721 --------------------------------------------------------------------------*/ 5722 function syncMainSongPlayedProgressBars(songPlayedPercentage) { 5723 /* 5724 Ensure that the song completion percentage is a number 5725 */ 5726 if (!isNaN(songPlayedPercentage)) { 5727 /* 5728 Get all of the song progress bars 5729 */ 5730 var songPlayedProgressBars = document.querySelectorAll('.amplitude-song-played-progress[amplitude-main-song-played-progress="true"]'); 5731 5732 for (var i = 0; i < songPlayedProgressBars.length; i++) { 5733 var max = songPlayedProgressBars[i].max; 5734 5735 songPlayedProgressBars[i].value = songPlayedPercentage / 100 * max; 5736 } 5737 } 5738 } 5739 5740 /*-------------------------------------------------------------------------- 5741 Sync how much has been played with a progress bar. This is the playlist progress 5742 bar. 5743 @param float songPlayedPercentage The percent of the song completed. 5744 --------------------------------------------------------------------------*/ 5745 function syncPlaylistSongPlayedProgressBars(songPlayedPercentage) { 5746 /* 5747 Ensure that the song completion percentage is a number 5748 */ 5749 if (!isNaN(songPlayedPercentage)) { 5750 /* 5751 Get all of the song progress bars 5752 */ 5753 var songPlayedProgressBars = document.querySelectorAll('.amplitude-song-played-progress[amplitude-playlist-song-played-progress="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]'); 5754 5755 for (var i = 0; i < songPlayedProgressBars.length; i++) { 5756 var max = songPlayedProgressBars[i].max; 5757 5758 songPlayedProgressBars[i].value = songPlayedPercentage / 100 * max; 5759 } 5760 } 5761 } 5762 5763 /*-------------------------------------------------------------------------- 5764 Sync how much has been played with a progress bar. This is for an individual 5765 song. 5766 @param float songPlayedPercentage The percent of the song completed. 5767 --------------------------------------------------------------------------*/ 5768 function syncIndividualSongPlayedProgressBars(songPlayedPercentage) { 5769 /* 5770 Ensure that the song completion percentage is a number 5771 */ 5772 if (!isNaN(songPlayedPercentage)) { 5773 /* 5774 If the active playlist is not null, we get the individual song 5775 played progress for the playlist. 5776 */ 5777 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null) { 5778 /* 5779 Get all of the song progress bars 5780 */ 5781 var songPlayedProgressBars = document.querySelectorAll('.amplitude-song-played-progress[amplitude-playlist="' + _config2.default.active_playlist + '"][amplitude-song-index="' + _config2.default.active_index + '"]'); 5782 5783 for (var i = 0; i < songPlayedProgressBars.length; i++) { 5784 var max = songPlayedProgressBars[i].max; 5785 5786 songPlayedProgressBars[i].value = songPlayedPercentage / 100 * max; 5787 } 5788 } else { 5789 /* 5790 Get all of the song progress bars 5791 */ 5792 var songPlayedProgressBars = document.querySelectorAll('.amplitude-song-played-progress[amplitude-song-index="' + _config2.default.active_index + '"]'); 5793 5794 for (var i = 0; i < songPlayedProgressBars.length; i++) { 5795 var max = songPlayedProgressBars[i].max; 5796 5797 songPlayedProgressBars[i].value = songPlayedPercentage / 100 * max; 5798 } 5799 } 5800 } 5801 } 5802 5803 /*-------------------------------------------------------------------------- 5804 Sets an element to be playing by removing the 'amplitude-paused' class 5805 and adding the 'amplitude-playing' class 5806 @param element element The element getting the playing class added. 5807 --------------------------------------------------------------------------*/ 5808 function setElementPlay(element) { 5809 element.classList.add('amplitude-playing'); 5810 element.classList.remove('amplitude-paused'); 5811 } 5812 5813 /*-------------------------------------------------------------------------- 5814 Sets an element to be paused by adding the 'amplitude-paused' class 5815 and removing the 'amplitude-playing' class 5816 @param element element The element getting the paused class added. 5817 --------------------------------------------------------------------------*/ 5818 function setElementPause(element) { 5819 element.classList.remove('amplitude-playing'); 5820 element.classList.add('amplitude-paused'); 5821 } 5822 5823 /*-------------------------------------------------------------------------- 5824 Updates any elements that display the duration hour for the song. 5825 @param int hours An integer conaining how many hours are in the song 5826 --------------------------------------------------------------------------*/ 5827 function syncDurationHours(hours) { 5828 /* 5829 Gets all of the song hour selectors. 5830 */ 5831 if (_config2.default.active_playlist != null && _config2.default.active_playlist != '') { 5832 var hourSelectors = ['.amplitude-duration-hours[amplitude-main-duration-hours="true"]', '.amplitude-duration-hours[amplitude-playlist-duration-hours="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]', '.amplitude-duration-hours[amplitude-song-index="' + _config2.default.active_index + '"]']; 5833 } else { 5834 var hourSelectors = ['.amplitude-duration-hours[amplitude-main-duration-hours="true"]', '.amplitude-duration-hours[amplitude-song-index="' + _config2.default.active_index + '"]']; 5835 } 5836 5837 /* 5838 Ensures that there are some hour selectors. 5839 */ 5840 if (document.querySelectorAll(hourSelectors.join()).length > 0) { 5841 /* 5842 Get all of the hour selectors 5843 */ 5844 var durationHourSelectors = document.querySelectorAll(hourSelectors.join()); 5845 5846 /* 5847 Set the duration hour selector's inner html to hours passed in. 5848 */ 5849 for (var i = 0; i < durationHourSelectors.length; i++) { 5850 /* 5851 If the selector is a main selector, we set the hours. 5852 */ 5853 if (durationHourSelectors[i].getAttribute('amplitude-main-duration-hours') == 'true') { 5854 durationHourSelectors[i].innerHTML = hours; 5855 } else { 5856 /* 5857 If the active playlist is not null or empty 5858 and the attribute of the playlist is equal to the 5859 active playlist, then we set the inner html. 5860 */ 5861 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && durationHourSelectors[i].getAttribute('amplitude-playlist') == _config2.default.active_playlist) { 5862 durationHourSelectors[i].innerHTML = hours; 5863 /* 5864 If the active playlist is not set and the selector 5865 does not have a playlist then we set the hours. This 5866 means that the duration selector is an individual song 5867 selector. 5868 */ 5869 } else if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null && !durationHourSelectors[i].hasAttribute('amplitude-playlist')) { 5870 durationHourSelectors[i].innerHTML = hours; 5871 /* 5872 If nothing else matches, set the selector's inner HTML to '00' 5873 */ 5874 } else { 5875 durationHourSelectors[i].innerHTML = '00'; 5876 } 5877 } 5878 } 5879 } 5880 } 5881 5882 /*-------------------------------------------------------------------------- 5883 Updates any elements that display the duration minutes for the song. 5884 @param int minutes An integer conaining how many minutes into 5885 the song. 5886 --------------------------------------------------------------------------*/ 5887 function syncDurationMinutes(minutes) { 5888 /* 5889 Gets all of the song minute selectors. 5890 */ 5891 if (_config2.default.active_playlist != null && _config2.default.active_playlist != '') { 5892 var minuteSelectors = ['.amplitude-duration-minutes[amplitude-main-duration-minutes="true"]', '.amplitude-duration-minutes[amplitude-playlist-duration-minutes="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]', '.amplitude-duration-minutes[amplitude-song-index="' + _config2.default.active_index + '"]']; 5893 } else { 5894 var minuteSelectors = ['.amplitude-duration-minutes[amplitude-main-duration-minutes="true"]', '.amplitude-duration-minutes[amplitude-song-index="' + _config2.default.active_index + '"]']; 5895 } 5896 5897 /* 5898 Get all of the minute selectors 5899 */ 5900 var durationMinuteSelectors = document.querySelectorAll(minuteSelectors.join()); 5901 5902 /* 5903 Set the duration minute selector's inner html to minutes passed in. 5904 */ 5905 for (var i = 0; i < durationMinuteSelectors.length; i++) { 5906 /* 5907 If the selector is a main selector, we set the seconds. 5908 */ 5909 if (durationMinuteSelectors[i].getAttribute('amplitude-main-duration-minutes') == 'true') { 5910 durationMinuteSelectors[i].innerHTML = minutes; 5911 } else { 5912 /* 5913 If the active playlist is not null or empty 5914 and the attribute of the playlist is equal to the 5915 active playlist, then we set the inner html. 5916 */ 5917 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && durationMinuteSelectors[i].getAttribute('amplitude-playlist') == _config2.default.active_playlist) { 5918 durationMinuteSelectors[i].innerHTML = minutes; 5919 /* 5920 If the active playlist is not set and the selector 5921 does not have a playlist then we set the minutes. This 5922 means that the duration selector is an individual song 5923 selector. 5924 */ 5925 } else if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null && !durationMinuteSelectors[i].hasAttribute('amplitude-playlist')) { 5926 durationMinuteSelectors[i].innerHTML = minutes; 5927 /* 5928 If nothing else matches, set the selector's inner HTML to '00' 5929 */ 5930 } else { 5931 durationMinuteSelectors[i].innerHTML = '00'; 5932 } 5933 } 5934 } 5935 } 5936 5937 /*-------------------------------------------------------------------------- 5938 Updates any elements that display the duration seconds for the song.
5939 @param int minutes An integer conaining how many seconds into 5940 the song. 5941 --------------------------------------------------------------------------*/ 5942 function syncDurationSeconds(seconds) { 5943 /* 5944 Gets all of the song second selectors. If the active playlist 5945 is not null, then we get the playlist selectors. 5946 */ 5947 if (_config2.default.active_playlist != null && _config2.default.active_playlist != '') { 5948 var secondSelectors = ['.amplitude-duration-seconds[amplitude-main-duration-seconds="true"]', '.amplitude-duration-seconds[amplitude-playlist-duration-seconds="true"][amplitude-playlist="' + _config2.default.active_playlist + '"]', '.amplitude-duration-seconds[amplitude-song-index="' + _config2.default.active_index + '"]']; 5949 } else { 5950 var secondSelectors = ['.amplitude-duration-seconds[amplitude-main-duration-seconds="true"]', '.amplitude-duration-seconds[amplitude-song-index="' + _config2.default.active_index + '"]']; 5951 } 5952 5953 /* 5954 Get all of the second selectors 5955 */ 5956 var durationSecondSelectors = document.querySelectorAll(secondSelectors.join()); 5957 5958 /* 5959 Iterate over all of the second selectors. 5960 */ 5961 for (var i = 0; i < durationSecondSelectors.length; i++) { 5962 /* 5963 If the selector is a main selector, we set the seconds. 5964 */ 5965 if (durationSecondSelectors[i].getAttribute('amplitude-main-duration-seconds') == 'true') { 5966 durationSecondSelectors[i].innerHTML = seconds; 5967 } else { 5968 /* 5969 If the active playlist is not null or empty 5970 and the attribute of the playlist is equal to the 5971 active playlist, then we set the inner html. 5972 */ 5973 if (_config2.default.active_playlist != '' && _config2.default.active_playlist != null && durationSecondSelectors[i].getAttribute('amplitude-playlist') == _config2.default.active_playlist) { 5974 durationSecondSelectors[i].innerHTML = seconds; 5975 /* 5976 If the active playlist is not set and the selector 5977 does not have a playlist then we set the seconds. This 5978 means that the duration selector is an individual song 5979 selector. 5980 */ 5981 } else if (_config2.default.active_playlist == '' || _config2.default.active_playlist == null && !durationSecondSelectors[i].hasAttribute('amplitude-playlist')) { 5982 durationSecondSelectors[i].innerHTML = seconds; 5983 /* 5984 If nothing else matches, set the selector's inner HTML to '00' 5985 */ 5986 } else { 5987 durationSecondSelectors[i].innerHTML = '00'; 5988 } 5989 } 5990 } 5991 } 5992 5993 /*-------------------------------------------------------------------------- 5994 Updates any elements that display the duration time for the song. This 5995 is a computed field that will be commonly used. 5996 @param JSON durationTime A json object conaining the parts for the 5997 duration time for the song. 5998 --------------------------------------------------------------------------*/ 5999 function syncDurationTime(durationTime) { 6000 /* 6001 Gets all of the song time selectors. 6002 */ 6003 var timeSelectors = ['.amplitude-duration-time[amplitude-main-duration-time="true"]', '.amplitude-duration-time[amplitude-playlist-main-duration-time="' + _config2.default.active_playlist + '"]', '.amplitude-duration-time[amplitude-song-index="' + _config2.default.active_index + '"]']; 6004 6005 /* 6006 Get all of the time selectors. 6007 */ 6008 var durationTimeSelectors = document.querySelectorAll(timeSelectors.join()); 6009 6010 /* 6011 Set the time selector's inner html to the duration time for the song. The duration 6012 time is computed by joining minutes and seconds. 6013 */ 6014 for (var i = 0; i < durationTimeSelectors.length; i++) { 6015 if (!isNaN(durationTime.minutes) && !isNaN(durationTime.seconds)) { 6016 durationTimeSelectors[i].innerHTML = durationTime.minutes + ':' + durationTime.seconds; 6017 } else { 6018 durationTimeSelectors[i].innerHTML = '00:00'; 6019 } 6020 } 6021 } 6022 6023 /*-------------------------------------------------------------------------- 6024 Updates the elements that show how much time is remaining in the song. 6025 @param JSON currentTime A json object containing the parts for the current 6026 time for the song. 6027 @param JSON durationTime A json object conaining the parts for the 6028 duration time for the song. 6029 --------------------------------------------------------------------------*/ 6030 function syncCountDownTime(currentTime, songDuration) { 6031 /* 6032 Initialize time remaining. 6033 */ 6034 var timeRemaining = '00:00'; 6035 6036 /* 6037 Ensure that all values are defined. 6038 */ 6039 if (currentTime != undefined && songDuration != undefined) { 6040 /* 6041 Initialize the total current seconds and total duration seconds 6042 */ 6043 var totalCurrentSeconds = parseInt(currentTime.seconds) + parseInt(currentTime.minutes) * 60 + parseInt(currentTime.hours) * 60 * 60; 6044 var totalDurationSeconds = parseInt(songDuration.seconds) + parseInt(songDuration.minutes) * 60 + parseInt(songDuration.hours) * 60 * 60; 6045 6046 /* 6047 If the two variables are numbers we continue the computing. 6048 */ 6049 if (!isNaN(totalCurrentSeconds) && !isNaN(totalDurationSeconds)) { 6050 /* 6051 Find the total remaining seconds. 6052 */ 6053 var timeRemainingTotalSeconds = totalDurationSeconds - totalCurrentSeconds; 6054 6055 /* 6056 Find how many seconds are remaining. 6057 */ 6058 var timeRemainingSeconds = (Math.floor(timeRemainingTotalSeconds % 60) < 10 ? '0' : '') + Math.floor(timeRemainingTotalSeconds % 60); 6059 6060 /* 6061 Find how many minutes are remaining. 6062 */ 6063 var timeRemainingMinutes = (Math.floor(timeRemainingTotalSeconds / 60) < 10 ? '0' : '') + Math.floor(timeRemainingTotalSeconds / 60); 6064 6065 /* 6066 Build the time remaining. 6067 */ 6068 timeRemaining = timeRemainingMinutes + ':' + timeRemainingSeconds; 6069 } 6070 } 6071 6072 /* 6073 Gets all of the song time selectors. 6074 */ 6075 var timeSelectors = ['.amplitude-time-remaining[amplitude-main-time-remaining="true"]', '.amplitude-time-remaining[amplitude-playlist-main-time-remaining="' + _config2.default.active_playlist + '"]', '.amplitude-time-remaining[amplitude-song-index="' + _config2.default.active_index + '"]']; 6076 6077 /* 6078 Get all of the time selectors. 6079 */ 6080 var timeRemainingSelectors = document.querySelectorAll(timeSelectors.join()); 6081 6082 /* 6083 Set the time selector's inner html to the duration time for the song. The duration 6084 time is computed by joining minutes and seconds. 6085 */ 6086 for (var i = 0; i < timeRemainingSelectors.length; i++) { 6087 timeRemainingSelectors[i].innerHTML = timeRemaining; 6088 } 6089 } 6090 6091 /* 6092 Return the publically available functions. 6093 */ 6094 return { 6095 syncCurrentHours: syncCurrentHours, 6096 syncCurrentMinutes: syncCurrentMinutes, 6097 syncCurrentSeconds: syncCurrentSeconds, 6098 syncCurrentTime: syncCurrentTime, 6099 resetCurrentHours: resetCurrentHours, 6100 resetCurrentMinutes: resetCurrentMinutes, 6101 resetCurrentSeconds: resetCurrentSeconds, 6102 resetCurrentTime: resetCurrentTime, 6103 syncSongPlayedProgressBar: syncSongPlayedProgressBar, 6104 setElementPlay: setElementPlay, 6105 setElementPause: setElementPause, 6106 syncDurationHours: syncDurationHours, 6107 syncDurationMinutes: syncDurationMinutes, 6108 syncDurationSeconds: syncDurationSeconds, 6109 syncDurationTime: syncDurationTime, 6110 syncCountDownTime: syncCountDownTime 6111 }; 6112}(); 6113 6114exports.default = AmplitudeVisualSyncHelpers; 6115module.exports = exports['default']; 6116 6117/***/ }) 6118/******/ ]); 6119});
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.