All files / src/visual containerElements.js

100% Statements 16/16
78.57% Branches 11/14
100% Functions 2/2
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                      31x                     210x             210x 12x             210x 180x             180x           180x 3x 1x           30x       30x                 30x               30x 1x           31x            
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Handles all of the container elements.
 *
 * @param visual/ContainerElements
 */
let ContainerElements = (function() {
  /**
   * Applies the class 'amplitude-active-song-container' to the element
   * containing visual information regarding the active song.
   *
   * @access public
   */
  function setActive() {
    /*
      Gets all of the song container elements.
    */
    let songContainers = document.getElementsByClassName(
      "amplitude-song-container"
    );
 
    /*
			Removes all of the active song containrs.
		*/
    for (let i = 0; i < songContainers.length; i++) {
      songContainers[i].classList.remove("amplitude-active-song-container");
    }
 
    /*
			Finds the active index and adds the active song container to the element
			that represents the song at the index.
		*/
    if (config.active_playlist == "" || config.active_playlist == null) {
      Eif (
        document.querySelectorAll(
          '.amplitude-song-container[data-amplitude-song-index="' +
            config.active_index +
            '"]'
        )
      ) {
        let songContainers = document.querySelectorAll(
          '.amplitude-song-container[data-amplitude-song-index="' +
            config.active_index +
            '"]'
        );
 
        for (let i = 0; i < songContainers.length; i++) {
          if (!songContainers[i].hasAttribute("data-amplitude-playlist")) {
            songContainers[i].classList.add("amplitude-active-song-container");
          }
        }
      }
    } else {
      let activePlaylistIndex =
        config.active_playlist != null && config.active_playlist != ""
          ? config.playlists[config.active_playlist].active_index
          : null;
 
      Eif (
        document.querySelectorAll(
          '.amplitude-song-container[data-amplitude-song-index="' +
            activePlaylistIndex +
            '"][data-amplitude-playlist="' +
            config.active_playlist +
            '"]'
        )
      ) {
        let songContainers = document.querySelectorAll(
          '.amplitude-song-container[data-amplitude-song-index="' +
            activePlaylistIndex +
            '"][data-amplitude-playlist="' +
            config.active_playlist +
            '"]'
        );
 
        for (let i = 0; i < songContainers.length; i++) {
          songContainers[i].classList.add("amplitude-active-song-container");
        }
      }
    }
  }
 
  return {
    setActive: setActive
  };
})();
 
export default ContainerElements;