All files / src/events volumeDown.js

100% Statements 10/10
83.33% Branches 5/6
100% Functions 2/2
100% Lines 10/10
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                                                      31x                         13x                     13x   13x 10x   3x             13x         13x         13x             31x            
/**
 * Imports the config to use the values
 */
import config from "../config.js";
 
/**
 * Imports the AmplitudeJS Core Methods
 * @module core/core
 */
import Core from "../core/core.js";
 
/**
 * Imports the AmplitudeJS Visual Mute Elements
 * @module visual/MuteElements
 */
import MuteElements from "../visual/muteElements.js";
 
/**
 * Imports the AmplitudeJS Visual Volume Slider Elements
 * @module visual/VolumeSliderElements
 */
import VolumeSliderElements from "../visual/volumeSliderElements.js";
 
/**
 * Handles all events for a volume down event.
 * @module events/VolumeDown
 */
let VolumeDown = (function() {
  /**
   * Handles a click on a volume down element.
   *
   * HANDLER FOR:       class="amplitude-volume-down"
   *
   * @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) {
      /*
				The volume range is from 0 to 1 for an audio element. We make this
				a base of 100 for ease of working with.
 
				If the new value is less than 100, we use the new calculated
				value which gets converted to the proper unit for the audio element.
 
				If the new value is greater than 100, we set the volume to 1 which
				is the max for the audio element.
			*/
      let volume = null;
 
      if (config.volume - config.volume_increment > 0) {
        volume = config.volume - config.volume_increment;
      } else {
        volume = 0;
      }
 
      /*
				Calls the core function to set the volume to the computed value
				based on the user's intent.
			*/
      Core.setVolume(volume);
 
      /*
        Sync Mute Elements.
      */
      MuteElements.setMuted(config.volume == 0 ? true : false);
 
      /*
        Sync Volume Slider Elements
      */
      VolumeSliderElements.sync();
    }
  }
 
  /**
   * Returns the public facing methods
   */
  return {
    handle: handle
  };
})();
 
export default VolumeDown;