All files / src/events events.js

75.44% Statements 129/171
45.65% Branches 21/46
92% Functions 23/25
75.44% Lines 129/171
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872                                                                                    31x                   159x         159x               159x                   159x         159x                 159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x         159x                         159x 159x         159x 159x                     159x 159x                         159x 159x                     159x 159x                       159x             159x 16x               16x 16x                           159x             159x 32x               32x 32x                           159x                 159x 40x               40x 40x                           159x             159x 1x               1x 1x                           159x             159x           1x                                   1x 1x                           159x                 159x           3x                                   3x 3x                           159x                 159x           2x                                               2x 2x                             159x 159x         159x             159x 12x       12x 12x                             159x 159x         159x                 159x           1x         1x       1x 1x                             159x             159x 10x               10x 10x                           159x             159x 8x               8x 8x                           159x             159x         8x 8x   8x               8x 8x                           159x             159x         10x 10x   10x               10x 10x                           159x                 159x         4x 4x   4x                     4x 4x                           159x                 159x 4x                           4x       4x                                 159x             159x 4x               4x 4x                     159x 159x           31x            
/*
	Import the necessary classes and config to use
	with the events.
*/
import config from "../config.js";
 
/**
 * Imports all of the handler objects used by the events.
 */
import KeyDown from "./keydown.js";
import TimeUpdate from "./timeUpdate.js";
import Ended from "./ended.js";
import Progress from "./progress.js";
import Play from "./play.js";
import Pause from "./pause.js";
import PlayPause from "./playPause.js";
import Stop from "./stop.js";
import Mute from "./mute.js";
import VolumeUp from "./volumeUp.js";
import VolumeDown from "./volumeDown.js";
import SongSlider from "./songSlider.js";
import VolumeSlider from "./volumeSlider.js";
import Next from "./next.js";
import Prev from "./prev.js";
import Repeat from "./repeat.js";
import RepeatSong from "./repeatSong.js";
import PlaybackSpeed from "./playbackSpeed.js";
import Shuffle from "./shuffle.js";
import SkipTo from "./skipTo.js";
import WaveForm from "../fx/waveform.js";
 
/**
 * Imports the utility classes used by the evnets.
 */
import Debug from "../utilities/debug.js";
 
/**
 * AmplitudeJS Events Module. Handles all of the events we listen to in
 * AmplitudeJS.
 *
 * @module events/Events
 */
var Events = (function() {
  /**
   * Initializes the handlers for the events listened to by Amplitude
   *
   * @access public
   */
  function initialize() {
    /*
			Write out debug message
		*/
    Debug.writeMessage("Beginning initialization of event handlers..");
 
    /*
			Sets flag that the screen is moving and not a tap
		*/
    document.addEventListener("touchmove", function() {
      config.is_touch_moving = true;
    });
 
    /*
			On touch end if it was a touch move event, set moving to
			false
		*/
    document.addEventListener("touchend", function() {
      if (config.is_touch_moving) {
        config.is_touch_moving = false;
      }
    });
 
    /*
			On time update for the audio element, update visual displays that
			represent the time on either a visualized element or time display.
		*/
    bindTimeUpdate();
 
    /*
			Binds key down event handlers for matching key codes to functions.
		*/
    bindKeyDownEventHandlers();
 
    /*
			When the audio element has ended playing, we handle the song
			ending. In a single song or multiple modular song instance,
			this just synchronizes the visuals for time and song time
			visualization, but for a playlist it determines whether
			it should play the next song or not.
		*/
    bindSongEnded();
 
    /*
			Binds progress event so we can see how much of the song is loaded.
		*/
    bindProgress();
 
    /*
			Binds 'amplitude-play' event handlers
		*/
    bindPlay();
 
    /*
			Binds 'amplitude-pause' event handlers.
		*/
    bindPause();
 
    /*
			Binds 'amplitude-play-pause' event handlers.
		*/
    bindPlayPause();
 
    /*
			Binds 'amplitude-stop' event handlers.
		*/
    bindStop();
 
    /*
			Binds 'amplitude-mute' event handlers.
		*/
    bindMute();
 
    /*
			Binds 'amplitude-volume-up' event handlers
		*/
    bindVolumeUp();
 
    /*
			Binds 'amplitude-volume-down' event handlers
		*/
    bindVolumeDown();
 
    /*
			Binds 'amplitude-song-slider' event handlers
		*/
    bindSongSlider();
 
    /*
			Binds 'amplitude-volume-slider' event handlers.
		*/
    bindVolumeSlider();
 
    /*
			Binds 'amplitude-next' event handlers.
		*/
    bindNext();
 
    /*
			Binds 'amplitude-prev' event handlers.
		*/
    bindPrev();
 
    /*
			Binds 'amplitude-shuffle' event handlers.
		*/
    bindShuffle();
 
    /*
			Binds 'amplitude-repeat' event handlers.
		*/
    bindRepeat();
 
    /*
			Binds 'amplitude-repeat-song' event handlers.
		*/
    bindRepeatSong();
 
    /*
			Binds 'amplitude-playback-speed' event handlers.
		*/
    bindPlaybackSpeed();
 
    /*
			Binds 'amplitude-skip-to' event handlers.
		*/
    bindSkipTo();
 
    /*
			Binds `canplaythrough` event to build the waveform.
		*/
    bindCanPlayThrough();
  }
 
  /**
   * On time update for the audio element, update visual displays that
   * represent the time on either a visualized element or time display.
   *
   * @access private
   */
  function bindTimeUpdate() {
    /*
			Bind for time update
		*/
    config.audio.removeEventListener("timeupdate", TimeUpdate.handle);
    config.audio.addEventListener("timeupdate", TimeUpdate.handle);
 
    /*
			Bind for duration change
		*/
    config.audio.removeEventListener("durationchange", TimeUpdate.handle);
    config.audio.addEventListener("durationchange", TimeUpdate.handle);
  }
 
  /**
   * On keydown, we listen to what key got pressed so we can map the key to
   * a function. This allows the user to map pause and play, next, etc. to key
   * presses.
   *
   * @access private
   */
  function bindKeyDownEventHandlers() {
    document.removeEventListener("keydown", KeyDown.handle);
    document.addEventListener("keydown", KeyDown.handle);
  }
 
  /**
   * When the audio element has ended playing, we handle the song
   * ending. In a single song or multiple modular song instance,
   * this just synchronizes the visuals for time and song time
   * visualization, but for a playlist it determines whether
   * it should play the next song or not.
   *
   * @access private
   */
  function bindSongEnded() {
    config.audio.removeEventListener("ended", Ended.handle);
    config.audio.addEventListener("ended", Ended.handle);
  }
 
  /**
   * As the audio is loaded, the progress event gets fired. We bind into this
   * to grab the buffered percentage of the song. We can then add more elements
   * to show the buffered amount.
   *
   * @access private
   */
  function bindProgress() {
    config.audio.removeEventListener("progress", Progress.handle);
    config.audio.addEventListener("progress", Progress.handle);
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS play buttons
   *
   * @access private
   */
  function bindPlay() {
    /*
			Gets all of the elements with the class amplitude-play
		*/
    var play_classes = document.getElementsByClassName("amplitude-play");
 
    /*
			Iterates over all of the play classes and binds the event interaction
			method to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < play_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        play_classes[i].removeEventListener("touchend", Play.handle);
        play_classes[i].addEventListener("touchend", Play.handle);
      } else {
        play_classes[i].removeEventListener("click", Play.handle);
        play_classes[i].addEventListener("click", Play.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS pause buttons.
   *
   * @access private
   */
  function bindPause() {
    /*
			Gets all of the elements with the class amplitude-pause
		*/
    var pause_classes = document.getElementsByClassName("amplitude-pause");
 
    /*
			Iterates over all of the pause classes and binds the event interaction
			method to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < pause_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        pause_classes[i].removeEventListener("touchend", Pause.handle);
        pause_classes[i].addEventListener("touchend", Pause.handle);
      } else {
        pause_classes[i].removeEventListener("click", Pause.handle);
        pause_classes[i].addEventListener("click", Pause.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS play pause buttons
   *
   * @access private
   */
  function bindPlayPause() {
    /*
			Gets all of the elements with the class amplitude-play-pause
		*/
    var play_pause_classes = document.getElementsByClassName(
      "amplitude-play-pause"
    );
 
    /*
			Iterates over all of the play/pause classes and binds the event interaction
			method to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < play_pause_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        play_pause_classes[i].removeEventListener("touchend", PlayPause.handle);
        play_pause_classes[i].addEventListener("touchend", PlayPause.handle);
      } else {
        play_pause_classes[i].removeEventListener("click", PlayPause.handle);
        play_pause_classes[i].addEventListener("click", PlayPause.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS stop buttons
   *
   * @access private
   */
  function bindStop() {
    /*
			Gets all of the elements with the class amplitude-stop
		*/
    var stop_classes = document.getElementsByClassName("amplitude-stop");
 
    /*
			Iterates over all of the stop classes and binds the event interaction
			method to the element.  If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < stop_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        stop_classes[i].removeEventListener("touchend", Stop.handle);
        stop_classes[i].addEventListener("touchend", Stop.handle);
      } else {
        stop_classes[i].removeEventListener("click", Stop.handle);
        stop_classes[i].addEventListener("click", Stop.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS mute buttons
   *
   * @access private
   */
  function bindMute() {
    /*
			Gets all of the elements with the class amplitue-mute
		*/
    var mute_classes = document.getElementsByClassName("amplitude-mute");
 
    /*
			Iterates over all of the mute classes and binds the event interaction
			method to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < mute_classes.length; i++) {
      /*
				WARNING: If iOS, we don't do anything because iOS does not allow the
				volume to be adjusted through anything except the buttons on the side of
				the device.
			*/
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        /*
					Checks for an iOS device and displays an error message if debugging
					is turned on.
				*/
        if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
          Debug.writeMessage(
            "iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4"
          );
        } else {
          mute_classes[i].removeEventListener("touchend", Mute.handle);
          mute_classes[i].addEventListener("touchend", Mute.handle);
        }
      } else {
        mute_classes[i].removeEventListener("click", Mute.handle);
        mute_classes[i].addEventListener("click", Mute.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS Volume Up Buttons
   *
   * @access private
   */
  function bindVolumeUp() {
    /*
			Gets all of the elements with the class amplitude-volume-up
		*/
    var volume_up_classes = document.getElementsByClassName(
      "amplitude-volume-up"
    );
 
    /*
			Iterates over all of the volume up classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < volume_up_classes.length; i++) {
      /*
				WARNING: If iOS, we don't do anything because iOS does not allow the
				volume to be adjusted through anything except the buttons on the side of
				the device.
			*/
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        /*
					Checks for an iOS device and displays an error message if debugging
					is turned on.
				*/
        if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
          Debug.writeMessage(
            "iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4"
          );
        } else {
          volume_up_classes[i].removeEventListener("touchend", VolumeUp.handle);
          volume_up_classes[i].addEventListener("touchend", VolumeUp.handle);
        }
      } else {
        volume_up_classes[i].removeEventListener("click", VolumeUp.handle);
        volume_up_classes[i].addEventListener("click", VolumeUp.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS Volume Down Buttons
   *
   * @access private
   */
  function bindVolumeDown() {
    /*
			Gets all of the elements with the class amplitude-volume-down
		*/
    var volume_down_classes = document.getElementsByClassName(
      "amplitude-volume-down"
    );
 
    /*
			Iterates over all of the volume down classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < volume_down_classes.length; i++) {
      /*
				WARNING: If iOS, we don't do anything because iOS does not allow the
				volume to be adjusted through anything except the buttons on the side of
				the device.
			*/
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        /*
					Checks for an iOS device and displays an error message if debugging
					is turned on.
				*/
        if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
          Debug.writeMessage(
            "iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4"
          );
        } else {
          volume_down_classes[i].removeEventListener(
            "touchend",
            VolumeDown.handle
          );
          volume_down_classes[i].addEventListener(
            "touchend",
            VolumeDown.handle
          );
        }
      } else {
        volume_down_classes[i].removeEventListener("click", VolumeDown.handle);
        volume_down_classes[i].addEventListener("click", VolumeDown.handle);
      }
    }
  }
 
  /**
   * Binds change and input events for AmplitudeJS Song Slider Inputs
   *
   * @access private
   */
  function bindSongSlider() {
    /*
			Gets browser so if we need to apply overrides, like we usually
			have to do for anything cool in IE, we can do that.
		*/
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE ");
 
    /*
			Gets all of the elements with the class amplitude-song-slider
		*/
    var song_sliders = document.getElementsByClassName("amplitude-song-slider");
 
    /*
			Iterates over all of the song slider classes and binds the event interaction
			methods to the element. If the browser is IE we listen to the change event
			where if it is anything else, it's the input method.
		*/
    for (var i = 0; i < song_sliders.length; i++) {
      Iif (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
        song_sliders[i].removeEventListener("change", SongSlider.handle);
        song_sliders[i].addEventListener("change", SongSlider.handle);
      } else {
        song_sliders[i].removeEventListener("input", SongSlider.handle);
        song_sliders[i].addEventListener("input", SongSlider.handle);
      }
    }
  }
 
  /**
   * Binds change and input events fro AmplitudeJS Volume Slider inputs
   *
   * @access private
   */
  function bindVolumeSlider() {
    /*
			Gets browser so if we need to apply overrides, like we usually
			have to do for anything cool in IE, we can do that.
		*/
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE ");
 
    /*
			Gets all of the elements with the class amplitude-volume-slider
        */
    var volume_sliders = document.getElementsByClassName(
      "amplitude-volume-slider"
    );
 
    /*
			Iterates over all of the volume slider classes and binds the event interaction
			methods to the element. If the browser is IE we listen to the change event
			where if it is anything else, it's the input method.
		*/
    for (var i = 0; i < volume_sliders.length; i++) {
      /*
				WARNING: If iOS, we don't do anything because iOS does not allow the
				volume to be adjusted through anything except the buttons on the side of
				the device.
			*/
      Iif (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
        Debug.writeMessage(
          "iOS does NOT allow volume to be set through javascript: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4"
        );
      } else {
        Iif (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
          volume_sliders[i].removeEventListener("change", VolumeSlider.handle);
          volume_sliders[i].addEventListener("change", VolumeSlider.handle);
        } else {
          volume_sliders[i].removeEventListener("input", VolumeSlider.handle);
          volume_sliders[i].addEventListener("input", VolumeSlider.handle);
        }
      }
    }
  }
 
  /**
   * Binds click and touchend events fro AmplitudeJS Next buttons
   *
   * @access private
   */
  function bindNext() {
    /*
			Gets all of the elements with the class amplitude-next
        */
    var next_classes = document.getElementsByClassName("amplitude-next");
 
    /*
			Iterates over all of the next classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < next_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        next_classes[i].removeEventListener("touchend", Next.handle);
        next_classes[i].addEventListener("touchend", Next.handle);
      } else {
        next_classes[i].removeEventListener("click", Next.handle);
        next_classes[i].addEventListener("click", Next.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS prev buttons.
   *
   * @access private
   */
  function bindPrev() {
    /*
			Gets all of the elements with the class amplitude-prev
		*/
    var prev_classes = document.getElementsByClassName("amplitude-prev");
 
    /*
			Iterates over all of the prev classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < prev_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        prev_classes[i].removeEventListener("touchend", Prev.handle);
        prev_classes[i].addEventListener("touchend", Prev.handle);
      } else {
        prev_classes[i].removeEventListener("click", Prev.handle);
        prev_classes[i].addEventListener("click", Prev.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS shuffle buttons.
   *
   * @access private
   */
  function bindShuffle() {
    /*
			Gets all of the elements with the class amplitude-shuffle
		*/
    var shuffle_classes = document.getElementsByClassName("amplitude-shuffle");
 
    /*
			Iterates over all of the shuffle classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < shuffle_classes.length; i++) {
      /*
				Since we are re-binding everything we remove any classes that signify
				a state of the shuffle control.
			*/
      shuffle_classes[i].classList.remove("amplitude-shuffle-on");
      shuffle_classes[i].classList.add("amplitude-shuffle-off");
 
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        shuffle_classes[i].removeEventListener("touchend", Shuffle.handle);
        shuffle_classes[i].addEventListener("touchend", Shuffle.handle);
      } else {
        shuffle_classes[i].removeEventListener("click", Shuffle.handle);
        shuffle_classes[i].addEventListener("click", Shuffle.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS repeat buttons.
   *
   * @access private
   */
  function bindRepeat() {
    /*
			Gets all of the elements with the class amplitude-repeat
		*/
    var repeat_classes = document.getElementsByClassName("amplitude-repeat");
 
    /*
			Iterates over all of the repeat classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < repeat_classes.length; i++) {
      /*
				Since we are re-binding everything we remove any classes that signify
				a state of the repeat control.
			*/
      repeat_classes[i].classList.remove("amplitude-repeat-on");
      repeat_classes[i].classList.add("amplitude-repeat-off");
 
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        repeat_classes[i].removeEventListener("touchend", Repeat.handle);
        repeat_classes[i].addEventListener("touchend", Repeat.handle);
      } else {
        repeat_classes[i].removeEventListener("click", Repeat.handle);
        repeat_classes[i].addEventListener("click", Repeat.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS repeat song buttons.
   *
   * @access private
   */
  function bindRepeatSong() {
    /*
			Gets all of the elements with the class amplitude-repeat-song
		*/
    var repeat_song_classes = document.getElementsByClassName(
      "amplitude-repeat-song"
    );
 
    /*
			Iterates over all of the repeat song classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < repeat_song_classes.length; i++) {
      /*
				Since we are re-binding everything we remove any classes that signify
				a state of the repeat control.
			*/
      repeat_song_classes[i].classList.remove("amplitude-repeat-on");
      repeat_song_classes[i].classList.add("amplitude-repeat-off");
 
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        repeat_song_classes[i].removeEventListener(
          "touchend",
          RepeatSong.handle
        );
        repeat_song_classes[i].addEventListener("touchend", RepeatSong.handle);
      } else {
        repeat_song_classes[i].removeEventListener("click", RepeatSong.handle);
        repeat_song_classes[i].addEventListener("click", RepeatSong.handle);
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS playback speed buttons
   *
   * @access private
   */
  function bindPlaybackSpeed() {
    /*
			Gets all of the elements with the class amplitude-playback-speed
		*/
    var playback_speed_classes = document.getElementsByClassName(
      "amplitude-playback-speed"
    );
 
    /*
			Iterates over all of the playback speed classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it is click.
		*/
    for (var i = 0; i < playback_speed_classes.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        playback_speed_classes[i].removeEventListener(
          "touchend",
          PlaybackSpeed.handle
        );
        playback_speed_classes[i].addEventListener(
          "touchend",
          PlaybackSpeed.handle
        );
      } else {
        playback_speed_classes[i].removeEventListener(
          "click",
          PlaybackSpeed.handle
        );
        playback_speed_classes[i].addEventListener(
          "click",
          PlaybackSpeed.handle
        );
      }
    }
  }
 
  /**
   * Binds click and touchend events for AmplitudeJS skip to buttons.
   *
   * @access private
   */
  function bindSkipTo() {
    /*
			Gets all of the skip to elements with the class 'amplitude-skip-to'
		*/
    var skipToClasses = document.getElementsByClassName("amplitude-skip-to");
 
    /*
			Iterates over all of the skip to classes and binds the event interaction
			methods to the element. If the browser is mobile, then the event is touchend
			otherwise it's a click.
		*/
    for (var i = 0; i < skipToClasses.length; i++) {
      Iif (
        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
          navigator.userAgent
        )
      ) {
        skipToClasses[i].removeEventListener("touchend", SkipTo.handle);
        skipToClasses[i].addEventListener("touchend", SkipTo.handle);
      } else {
        skipToClasses[i].removeEventListener("click", SkipTo.handle);
        skipToClasses[i].addEventListener("click", SkipTo.handle);
      }
    }
  }
 
  /**
   * Binds can play through to a song.
   *
   * @access private
   */
  function bindCanPlayThrough() {
    config.audio.removeEventListener("canplaythrough", WaveForm.build);
    config.audio.addEventListener("canplaythrough", WaveForm.build);
  }
 
  /*
		Returns the public facing functions.
	*/
  return {
    initialize: initialize
  };
})();
 
export default Events;