All files / src/events next.js

71.43% Statements 10/14
58.33% Branches 7/12
75% Functions 3/4
71.43% Lines 10/14
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                                                                                  31x                               5x       5x         5x 5x           5x                                 5x 2x   3x                                                     31x            
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Imports the AmplitudeJS Core module.
 * @module core/core
 */
import Core from "../core/core.js";
 
/**
 * Imports the Play Pause Elements Module.
 * @module visual/PlayPauseElements
 */
import PlayPauseElements from "../visual/playPauseElements.js";
 
/**
 * Imports the Callbacks Module
 * @module utilities/Callbacks
 */
import Callbacks from "../utilities/callbacks.js";
 
/**
 * Imports the Amplitude Audio Navigation Utility
 * @module utilities/AudioNavigation
 */
import AudioNavigation from "../utilities/audioNavigation.js";
 
/**
 * AmplitudeJS Debug Module
 * @module utilities/Debug
 */
import Debug from "../utilities/debug.js";
 
/**
 * AmplitudeJS Next Event Handler
 *
 * @module events/Next
 */
let Next = (function() {
  /**
   * Handles an event on the next button
   *
   * HANDLER FOR:       class="amplitude-next"
   *
   * GLOBAL:            class="amplitude-next"
   * PLAYLIST:          class="amplitude-next" 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 next.
      */
      Eif (playlist == null) {
        handleGlobalNext();
      }
 
      /*
        If the playlist is set, we handle the playlist next.
      */
      Iif (playlist != null) {
        handlePlaylistNext(playlist);
      }
    }
  }
 
  /**
   * Handles an event on a global enxt button.
   *
   * @access private
   */
  function handleGlobalNext() {
    /*
      Check to see if the current state of the player
      is in playlist mode or not playlist mode. If we are in playlist mode,
      we set next on the playlist.
    */
    if (config.active_playlist == "" || config.active_playlist == null) {
      AudioNavigation.setNext();
    } else {
      AudioNavigation.setNextPlaylist(config.active_playlist);
    }
  }
 
  /**
   * Handles an event on a next playlist button.
   *
   * @access private
   * @prop {string} playlist  - The playlist we are handling the next for.
   */
  function handlePlaylistNext(playlist) {
    /*
      Ensure the playlist is the same as the active playlist. To get to change
      the scope to a new playlist, you need to play that playlist.
    */
    if (playlist == config.active_playlist) {
      AudioNavigation.setNextPlaylist(playlist);
    } else {
      Debug.writeMessage(
        "You can not go to the next song on a playlist that is not being played!"
      );
    }
  }
 
  /*
    Returns the public facing methods.
  */
  return {
    handle: handle
  };
})();
 
export default Next;