All files / src/visual bufferedProgressElements.js

6.9% Statements 2/29
0% Branches 0/12
14.29% Functions 1/7
6.9% Lines 2/29
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 178 179                      31x                                                                                                                                                                                                                                                                                                                               31x              
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * AmplitudeJS Visual Handler for Buffered Progress Elements
 *
 * @module visual/BufferedProgressElements
 */
let BufferedProgressElements = (function() {
  /**
   * Syncs the buffered progress bars to the current percentage in the config
   *
   * @access public
   */
  function sync() {
    syncGlobal();
    syncPlaylist();
    syncSong();
    syncSongInPlaylist();
  }
 
  /**
   * Sync the global song buffered progress elements.
   */
  function syncGlobal() {
    /*
			Gets all of the song buffered progress bars.
		*/
    const songBufferedProgressBars = document.getElementsByClassName(
      "amplitude-buffered-progress"
    );
 
    /*
			Iterate over all of the song buffered progress bar and
			set them to 0 which is like re-setting them.
		*/
    for (let i = 0; i < songBufferedProgressBars.length; i++) {
      let playlist = songBufferedProgressBars[i].getAttribute(
        "data-amplitude-playlist"
      );
      let song = songBufferedProgressBars[i].getAttribute(
        "data-amplitude-song-index"
      );
 
      if (playlist == null && song == null) {
        songBufferedProgressBars[i].value = parseFloat(
          parseFloat(config.buffered) / 100
        );
      }
    }
  }
 
  /**
   * Sync the playlist song buffered progress elements.
   */
  function syncPlaylist() {
    /*
			Gets all of the song buffered progress bars.
		*/
    const songBufferedProgressBarsPlaylist = document.querySelectorAll(
      '.amplitude-buffered-progress[data-amplitude-playlist="' +
        config.active_playlist +
        '"]'
    );
 
    /*
			Iterate over all of the song buffered progress bar and
			set them to 0 which is like re-setting them.
		*/
    for (let i = 0; i < songBufferedProgressBarsPlaylist.length; i++) {
      let song = songBufferedProgressBarsPlaylist[i].getAttribute(
        "data-amplitude-song-index"
      );
 
      if (song == null) {
        songBufferedProgressBarsPlaylist[i].value = parseFloat(
          parseFloat(config.buffered) / 100
        );
      }
    }
  }
 
  /**
   * Sync the song song buffered progress elements.
   */
  function syncSong() {
    /*
			Gets all of the song buffered progress bars.
		*/
    const songBufferedProgressBarsSongs = document.querySelectorAll(
      '.amplitude-buffered-progress[data-amplitude-song-index="' +
        config.active_index +
        '"]'
    );
 
    /*
			Iterate over all of the song buffered progress bar and
			set them to 0 which is like re-setting them.
		*/
    for (let i = 0; i < songBufferedProgressBarsSongs.length; i++) {
      let playlist = songBufferedProgressBarsSongs[i].getAttribute(
        "data-amplitude-playlist"
      );
 
      if (playlist == null) {
        songBufferedProgressBarsSongs[i].value = parseFloat(
          parseFloat(config.buffered) / 100
        );
      }
    }
  }
 
  /**
   * Sync the song in playlist song buffered progress elements.
   */
  function syncSongInPlaylist() {
    let activePlaylistIndex =
      config.active_playlist != null && config.active_playlist != ""
        ? config.playlists[config.active_playlist].active_index
        : null;
 
    /*
			Gets all of the song buffered progress bars.
		*/
    const songBufferedProgressBarsSongsInPlaylist = document.querySelectorAll(
      '.amplitude-buffered-progress[data-amplitude-song-index="' +
        activePlaylistIndex +
        '"][data-amplitude-playlist="' +
        config.active_playlist +
        '"]'
    );
 
    /*
			Iterate over all of the song buffered progress bar and
			set them to 0 which is like re-setting them.
		*/
    for (let i = 0; i < songBufferedProgressBarsSongsInPlaylist.length; i++) {
      songBufferedProgressBarsSongsInPlaylist[i].value = parseFloat(
        parseFloat(config.buffered) / 100
      );
    }
  }
 
  /**
   * Sets all of the song buffered progress bars to 0
   *
   * @access public
   */
  function reset() {
    /*
			Gets all of the song buffered progress bars.
		*/
    let songBufferedProgressBars = document.getElementsByClassName(
      "amplitude-buffered-progress"
    );
 
    /*
			Iterate over all of the song buffered progress bar and
			set them to 0 which is like re-setting them.
		*/
    for (let i = 0; i < songBufferedProgressBars.length; i++) {
      songBufferedProgressBars[i].value = 0;
    }
  }
 
  /**
   * Returns the public facing methods
   */
  return {
    sync: sync,
    reset: reset
  };
})();
 
export default BufferedProgressElements;