FuruholmAnton
6/14/2016 - 1:08 PM

Video module - JavaScript

/*---------- VIDEO  ----------*/
var video = (function() {
  'use strict';

  function video(elem) {
    // enforces new
    if (!(this instanceof video)) {
      return new video(elem);
    }
    this.player = document.querySelector(elem);
  }

  video.prototype.play = function() {
    this.player.play();
  };

  video.prototype.pause = function() {
    this.player.pause();
  };

  video.prototype.seek = function(time) {
    this.player.currentTime = parseInt(time);
  };

  return video;
}());

var video = new video('.js-video');
var button = document.querySelector(".play");
button.addEventListener("click", function(){
  video.play();
});
var pause = document.querySelector(".pause");
pause.addEventListener("click", function(){
  video.pause();
});