All files / src/events shuffle.js

100% Statements 11/11
75% Branches 3/4
100% Functions 4/4
100% Lines 11/11
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                                            31x                               8x       8x         8x 4x   4x                       4x         4x                       4x         4x           31x            
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Imports the shuffler utility
 * @module utilities/Shuffler
 */
import Shuffler from "../utilities/shuffler.js";
 
/**
 * Imports the visual shuffle elements
 * @module visual/ShuffleElements
 */
import ShuffleElements from "../visual/shuffleElements.js";
 
/**
 * Handles all of the shuffle events
 * @module events/Shuffle
 */
let Shuffle = (function() {
  /**
   * Handles an event on the shuffle button
   *
   * HANDLER FOR:       class="amplitude-shuffle"
   *
   * GLOBAL:            class="amplitude-shuffle"
   * PLAYLIST:          class="amplitude-shuffle" amplitude-playlist="playlist_key"
   *
   * @access public
   */
  function handle() {
    /*
      If the touch is moving, we do not want to accidentally touch the play
      pause element and fire an event.
    */
    Eif (!config.is_touch_moving) {
      /*
        Get the playlist attribute
      */
      let playlist = this.getAttribute("data-amplitude-playlist");
 
      /*
				Check to see if the shuffle button belongs to a playlist
			*/
      if (playlist == null) {
        handleGlobalShuffle();
      } else {
        handlePlaylistShuffle(playlist);
      }
    }
  }
 
  /**
   * Handles the event on the global shuffle button.
   */
  function handleGlobalShuffle() {
    /*
      Either shuffles or removes shuffle on the global state.
    */
    Shuffler.toggleShuffle();
 
    /*
      Visualize the shuffle state change.
    */
    ShuffleElements.syncMain(config.shuffle_on);
  }
 
  /**
   * Handles the event on the playlist shuffle button.
   *
   * @param {string} playlist - The playlist string the shuffle button belongs to.
   */
  function handlePlaylistShuffle(playlist) {
    /*
      Either shuffles or removes shuffle on the playlist state.
    */
    Shuffler.toggleShufflePlaylist(playlist);
 
    /*
      Visually sync the playlist shuffle statuses.
    */
    ShuffleElements.syncPlaylist(playlist);
  }
 
  /**
   * Returns public facing methods
   */
  return {
    handle: handle
  };
})();
 
export default Shuffle;