All files / src/events repeat.js

100% Statements 12/12
83.33% Branches 5/6
100% Functions 4/4
100% Lines 12/12
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                                              31x                               8x       8x         8x 4x           8x 4x                           4x         4x                         4x         4x           31x            
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Imports the repeater utility module.
 * @module utilities/Repeater
 */
import Repeater from "../utilities/repeater.js";
 
/**
 * Imports the visual repeat elements module
 * @module visual/RepeatElements
 */
import RepeatElements from "../visual/repeatElements.js";
 
/**
 * AmplitudeJS Repeat Event Handler
 *
 * @module events/Repeat
 */
let Repeat = (function() {
  /**
   * Handles an event on the repeat button
   *
   * HANDLER FOR:       class="amplitude-repeat"
   *
   * GLOBAL:            class="amplitude-repeat"
   * PLAYLIST:          class="amplitude-repeat" amplitude-playlist="playlist_key"
   *
   * @access public
   */
  function handle() {
    /*
      We don't fire this if the user is touching the screen and it's moving.
      This could lead to a mis-fire
    */
    Eif (!config.is_touch_moving) {
      /*
        Gets the playlist attribute from the element.
      */
      let playlist = this.getAttribute("data-amplitude-playlist");
 
      /*
        If the playlist is null, we handle the global repeat.
      */
      if (playlist == null) {
        handleGlobalRepeat();
      }
 
      /*
        If the playlist is set, we handle the playlist repeat.
      */
      if (playlist != null) {
        handlePlaylistRepeat(playlist);
      }
    }
  }
 
  /**
   * Handles an event on a global repeat button.
   *
   * @access private
   */
  function handleGlobalRepeat() {
    /*
      Sets repeat to the opposite of what it was set to
    */
    Repeater.setRepeat(!config.repeat);
 
    /*
      Visually sync repeat
    */
    RepeatElements.syncRepeat();
  }
 
  /**
   * Handles an event on a playlist repeat button.
   *
   * @access private
   * @prop {string} playlist - The playlist we are handling the repeat store.
   */
  function handlePlaylistRepeat(playlist) {
    /*
      Sets repeat to the opposite of what it was set to for the playlist.
    */
    Repeater.setRepeatPlaylist(!config.playlists[playlist].repeat, playlist);
 
    /*
      Visually sync playlist repeat
    */
    RepeatElements.syncRepeatPlaylist(playlist);
  }
 
  /*
    Returns the public facing methods.
  */
  return {
    handle: handle
  };
})();
 
export default Repeat;