All files / src/visual/time currentHourElements.js

13.33% Statements 4/30
0% Branches 0/14
28.57% Functions 2/7
13.33% Lines 4/30
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177                      31x                                                                                                                                                                                                                                                                                               370x           370x               31x              
/**
 * Imports the config module
 * @module config
 */
import config from "../../config.js";
 
/**
 * Handles all of the current time hour elements.
 *
 * @module visual/time/CurrentHourElements
 */
let CurrentHourElements = (function() {
  function sync(hours) {
    syncGlobal(hours);
    syncPlaylist(hours);
    syncSong(hours);
    syncSongInPlaylist(hours);
  }
 
  /**
   * Updates any elements that display the current hour for the song.
   *
   * @access public
   * @param {number} hours 	- An integer conaining how many hours into the song.
   */
  function syncGlobal(hours) {
    /*
			Get all of the hour selectors
		*/
    const currentHourSelectors = document.querySelectorAll(
      ".amplitude-current-hours"
    );
 
    /*
			Set the current hour selector's inner html to hours passed in.
		*/
    for (let i = 0; i < currentHourSelectors.length; i++) {
      let playlist = currentHourSelectors[i].getAttribute(
        "data-amplitude-playlist"
      );
      let songIndex = currentHourSelectors[i].getAttribute(
        "data-amplitude-song-index"
      );
 
      /*
        Updates the current hour selector for a global display.
      */
      if (playlist == null && songIndex == null) {
        currentHourSelectors[i].innerHTML = hours;
      }
    }
  }
 
  /**
   * Syncs the playlist current hour elements.
   *
   * @param {Integer} hour - The current audio hour.
   */
  function syncPlaylist(hours) {
    /*
			Get all of the hour selectors
		*/
    const currentHourPlaylistSelectors = document.querySelectorAll(
      '.amplitude-current-hours[data-amplitude-playlist="' +
        config.active_playlist +
        '"]'
    );
 
    /*
			Set the current hour selector's inner html to hours passed in.
		*/
    for (let i = 0; i < currentHourPlaylistSelectors.length; i++) {
      let songIndex = currentHourPlaylistSelectors[i].getAttribute(
        "data-amplitude-song-index"
      );
 
      /*
        Updates the current hour selector for a global display.
      */
      if (songIndex == null) {
        currentHourPlaylistSelectors[i].innerHTML = hours;
      }
    }
  }
 
  /**
   * Syncs the song hour elements.
   *
   * @param {Integer} hour - The current audio hour.
   */
  function syncSong(hours) {
    if (config.active_playlist == null) {
      /*
  			Get all of the hour selectors
  		*/
      const currentHourSongSelectors = document.querySelectorAll(
        '.amplitude-current-hours[data-amplitude-song-index="' +
          config.active_index +
          '"]'
      );
 
      /*
  			Set the current hour selector's inner html to hours passed in.
  		*/
      for (let i = 0; i < currentHourSongSelectors.length; i++) {
        let playlist = currentHourSongSelectors[i].getAttribute(
          "data-amplitude-playlist"
        );
 
        /*
          Updates the current hour selector for a global display.
        */
        if (playlist == null) {
          currentHourSongSelectors[i].innerHTML = hours;
        }
      }
    }
  }
 
  /**
   * Syncs the song in playlist song hour elements.
   *
   * @param {Integer} hour - The current audio hour.
   */
  function syncSongInPlaylist(hours) {
    let activePlaylistIndex =
      config.active_playlist != "" && config.active_playlist != null
        ? config.playlists[config.active_playlist].active_index
        : null;
    /*
			Get all of the hour selectors
		*/
    const currentHourPlaylistSongSelectors = document.querySelectorAll(
      '.amplitude-current-hours[data-amplitude-playlist="' +
        config.active_playlist +
        '"][data-amplitude-song-index="' +
        activePlaylistIndex +
        '"]'
    );
 
    /*
			Set the current hour selector's inner html to hours passed in.
		*/
    for (let i = 0; i < currentHourPlaylistSongSelectors.length; i++) {
      currentHourPlaylistSongSelectors[i].innerHTML = hours;
    }
  }
 
  /**
   * Reset the current hour elements.
   */
  function resetTimes() {
    /*
      Gets the hour display elements
    */
    let hourSelectors = document.querySelectorAll(".amplitude-current-hours");
 
    /*
      Iterates over all of the hour selectors and sets the inner HTML
      to 00.
    */
    for (var i = 0; i < hourSelectors.length; i++) {
      hourSelectors[i].innerHTML = "00";
    }
  }
 
  /**
   * Returns the publically facing methods.
   */
  return {
    sync: sync,
    resetTimes: resetTimes
  };
})();
 
export default CurrentHourElements;