(function (global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jquery'), require('@pluginjs/pluginjs')) :
	typeof define === 'function' && define.amd ? define(['exports', 'jquery', '@pluginjs/pluginjs'], factory) :
	(factory((global['@pluginjs/video'] = {}),global.jQuery,global.Pj));
}(this, (function (exports,$$1,Pj) { 'use strict';

$$1 = $$1 && $$1.hasOwnProperty('default') ? $$1['default'] : $$1;
var Pj__default = 'default' in Pj ? Pj['default'] : Pj;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  return typeof obj;
} : function (obj) {
  return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};





var asyncGenerator = function () {
  function AwaitValue(value) {
    this.value = value;
  }

  function AsyncGenerator(gen) {
    var front, back;

    function send(key, arg) {
      return new Promise(function (resolve, reject) {
        var request = {
          key: key,
          arg: arg,
          resolve: resolve,
          reject: reject,
          next: null
        };

        if (back) {
          back = back.next = request;
        } else {
          front = back = request;
          resume(key, arg);
        }
      });
    }

    function resume(key, arg) {
      try {
        var result = gen[key](arg);
        var value = result.value;

        if (value instanceof AwaitValue) {
          Promise.resolve(value.value).then(function (arg) {
            resume("next", arg);
          }, function (arg) {
            resume("throw", arg);
          });
        } else {
          settle(result.done ? "return" : "normal", result.value);
        }
      } catch (err) {
        settle("throw", err);
      }
    }

    function settle(type, value) {
      switch (type) {
        case "return":
          front.resolve({
            value: value,
            done: true
          });
          break;

        case "throw":
          front.reject(value);
          break;

        default:
          front.resolve({
            value: value,
            done: false
          });
          break;
      }

      front = front.next;

      if (front) {
        resume(front.key, front.arg);
      } else {
        back = null;
      }
    }

    this._invoke = send;

    if (typeof gen.return !== "function") {
      this.return = undefined;
    }
  }

  if (typeof Symbol === "function" && Symbol.asyncIterator) {
    AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
      return this;
    };
  }

  AsyncGenerator.prototype.next = function (arg) {
    return this._invoke("next", arg);
  };

  AsyncGenerator.prototype.throw = function (arg) {
    return this._invoke("throw", arg);
  };

  AsyncGenerator.prototype.return = function (arg) {
    return this._invoke("return", arg);
  };

  return {
    wrap: function (fn) {
      return function () {
        return new AsyncGenerator(fn.apply(this, arguments));
      };
    },
    await: function (value) {
      return new AwaitValue(value);
    }
  };
}();





var classCallCheck = function (instance, Constructor) {
  if (!(instance instanceof Constructor)) {
    throw new TypeError("Cannot call a class as a function");
  }
};

var createClass = function () {
  function defineProperties(target, props) {
    for (var i = 0; i < props.length; i++) {
      var descriptor = props[i];
      descriptor.enumerable = descriptor.enumerable || false;
      descriptor.configurable = true;
      if ("value" in descriptor) descriptor.writable = true;
      Object.defineProperty(target, descriptor.key, descriptor);
    }
  }

  return function (Constructor, protoProps, staticProps) {
    if (protoProps) defineProperties(Constructor.prototype, protoProps);
    if (staticProps) defineProperties(Constructor, staticProps);
    return Constructor;
  };
}();







var get = function get(object, property, receiver) {
  if (object === null) object = Function.prototype;
  var desc = Object.getOwnPropertyDescriptor(object, property);

  if (desc === undefined) {
    var parent = Object.getPrototypeOf(object);

    if (parent === null) {
      return undefined;
    } else {
      return get(parent, property, receiver);
    }
  } else if ("value" in desc) {
    return desc.value;
  } else {
    var getter = desc.get;

    if (getter === undefined) {
      return undefined;
    }

    return getter.call(receiver);
  }
};

var inherits = function (subClass, superClass) {
  if (typeof superClass !== "function" && superClass !== null) {
    throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  }

  subClass.prototype = Object.create(superClass && superClass.prototype, {
    constructor: {
      value: subClass,
      enumerable: false,
      writable: true,
      configurable: true
    }
  });
  if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};











var possibleConstructorReturn = function (self, call) {
  if (!self) {
    throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  }

  return call && (typeof call === "object" || typeof call === "function") ? call : self;
};

var Plugin = function () {
  function Plugin(namespace, element) {
    classCallCheck(this, Plugin);

    this.plugin = namespace;
    this.element = element;
    this.$element = $$1(element);
  }

  createClass(Plugin, [{
    key: 'getDataOptions',
    value: function getDataOptions() {
      var _this = this;

      var data = this.$element.data();
      var length = 0;
      var newData = {};

      $$1.each(data, function () {
        length++;
      });

      if (length > 0) {
        $$1.each(data, function (name, content) {
          var cache = {};
          var items = name.split('-');
          // let items = name.split('-');

          var deep = items.length;

          if (deep > 1) {
            for (var j = 0; j < deep; j++) {
              var item = items[j].substring(0, 1).toLowerCase() + items[j].substring(1);

              if (j === 0) {
                cache[item] = {};
              } else if (j === deep - 1) {} else {}
            }
          } else if (items[0] === 'as' + _this.plugin.substring(0, 1).toUpperCase() + _this.plugin.substring(1)) {
            cache = content;
          } else {
            cache[name] = content;
          }

          $$1.extend(newData, cache);
        });
      }

      return newData;
    }
  }, {
    key: 'destroy',
    value: function destroy() {
      this.plugin = null;
      this.element = null;
      this.$element = null;
    }
  }]);
  return Plugin;
}();

var namespace = 'video';

var events = {
  READY: 'ready',
  DESTROY: 'destroy',
  LOAD: 'load',
  LOADED: 'loaded',
  PLAY: 'play',
  PAUSE: 'pause',
  STOP: 'stop',
  PLAYEND: 'playend',
  PLAYERR: 'playerr'
};

var classes = {
  NAMESPACE: 'pj-' + namespace,
  THEME: '{namespace}--{theme}',
  POSTER: '{namespace}-poster'
};

var methods = ['enable', 'disable', 'destroy', 'pause', 'load', 'play', 'stop', 'volume'];

var defaults$1 = {
  template: function template() {
    return '<div class="{classes.NAMESPACE}">' + '{poster}' + '</div>';
  },

  templates: {
    poster: function poster() {
      return '<div class="{classes.POSTER}"></div>';
    }
  },
  url: '',
  id: '',
  type: '',
  autoplay: true,
  loop: true,
  controls: false,
  poster: ''
};

var info = { version: '0.0.1' };

/* eslint no-undef: "off" */

/* Credit to http://featurejs.com MIT */
/**
 * Test if it's an old device that we want to filter out
 */
/**
 * Function that takes a standard CSS property name as a parameter and
 * returns it's prefixed version valid for current browser it runs in
 */
var pfx = function () {
  var prefixes = ['Webkit', 'Moz', 'O', 'ms'];
  var memory = {};
  var style = document.createElement('dummy').style;
  return function (prop) {
    if (typeof memory[prop] === 'undefined') {
      var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1);
      var props = (prop + ' ' + prefixes.join(ucProp + ' ') + ucProp).split(' ');
      memory[prop] = null;

      for (var i in props) {
        if (style[props[i]] !== undefined) {
          memory[prop] = props[i];
          break;
        }
      }
    }
    return memory[prop];
  };
}();

var transitionEndEvent = function transitionEndEvent() {
  var eventNames = {
    transition: 'transitionend',
    OTransition: 'oTransitionEnd',
    MozTransition: 'transitionend',
    WebkitTransition: 'webkitTransitionEnd'
  };
  var style = document.createElement('dummy').style;
  for (var i in eventNames) {
    if (eventNames.hasOwnProperty(i)) {
      if (style[i] !== undefined) {
        return eventNames[i];
      }
    }
  }
  return false;
};

var asyncGenerator$1 = function () {
  function AwaitValue(value) {
    this.value = value;
  }

  function AsyncGenerator(gen) {
    var front, back;

    function send(key, arg) {
      return new Promise(function (resolve, reject) {
        var request = {
          key: key,
          arg: arg,
          resolve: resolve,
          reject: reject,
          next: null
        };

        if (back) {
          back = back.next = request;
        } else {
          front = back = request;
          resume(key, arg);
        }
      });
    }

    function resume(key, arg) {
      try {
        var result = gen[key](arg);
        var value = result.value;

        if (value instanceof AwaitValue) {
          Promise.resolve(value.value).then(function (arg) {
            resume("next", arg);
          }, function (arg) {
            resume("throw", arg);
          });
        } else {
          settle(result.done ? "return" : "normal", result.value);
        }
      } catch (err) {
        settle("throw", err);
      }
    }

    function settle(type, value) {
      switch (type) {
        case "return":
          front.resolve({
            value: value,
            done: true
          });
          break;

        case "throw":
          front.reject(value);
          break;

        default:
          front.resolve({
            value: value,
            done: false
          });
          break;
      }

      front = front.next;

      if (front) {
        resume(front.key, front.arg);
      } else {
        back = null;
      }
    }

    this._invoke = send;

    if (typeof gen.return !== "function") {
      this.return = undefined;
    }
  }

  if (typeof Symbol === "function" && Symbol.asyncIterator) {
    AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
      return this;
    };
  }

  AsyncGenerator.prototype.next = function (arg) {
    return this._invoke("next", arg);
  };

  AsyncGenerator.prototype.throw = function (arg) {
    return this._invoke("throw", arg);
  };

  AsyncGenerator.prototype.return = function (arg) {
    return this._invoke("return", arg);
  };

  return {
    wrap: function wrap(fn) {
      return function () {
        return new AsyncGenerator(fn.apply(this, arguments));
      };
    },
    await: function _await(value) {
      return new AwaitValue(value);
    }
  };
}();

/* Credit to https://github.com/jonschlinkert/get-value MIT */
function getValueByPath(obj, path) {
  if (Object(obj) !== obj || typeof path === 'undefined') {
    return obj;
  }

  if (path in obj) {
    return obj[path];
  }

  var segs = path.split('.');
  var length = segs.length;
  if (!length) {
    return undefined;
  }
  var i = -1;

  while (obj && ++i < length) {
    var key = segs[i];
    while (key[key.length - 1] === '\\') {
      key = key.slice(0, -1) + '.' + segs[++i];
    }
    obj = obj[key];
  }
  return obj;
}

var asTransitionEnd = 'asTransitionEnd';

function triggerTransitionEnd(element) {
  $$1(element).trigger(transitionEndEvent());
}
function setTransitionEndSupport() {
  $$1.fn.asTransitionEnd = function (duration) {
    var _this = this;

    var called = false;

    $$1(this).one(asTransitionEnd, function () {
      called = true;
    });

    setTimeout(function () {
      if (!called) {
        triggerTransitionEnd(_this);
      }
    }, duration);

    return this;
  };

  var isTransitionEndEvent = transitionEndEvent();

  if (isTransitionEndEvent) {
    // suport transition end
    $$1.event.special[asTransitionEnd] = {
      bindType: isTransitionEndEvent,
      delegateType: isTransitionEndEvent,
      handle: function handle(event) {
        if ($$1(event.target).is(this)) {
          return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
        }
        return undefined;
      }
    };
  }
}

setTransitionEndSupport();

/* Credit to https://github.com/Matt-Esch/string-template MIT */
var template = function () {
  var pattern = /\{\s*([.0-9a-zA-Z_]+)\s*\}/g;

  function render(string) {
    for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
      args[_key - 1] = arguments[_key];
    }

    if (args.length === 1 && _typeof(args[0]) === 'object') {
      args = args[0];
    }

    if (!args || !args.hasOwnProperty) {
      args = {};
    }

    return string.replace(pattern, function (match, i, index) {
      var result = null;

      if (string[index - 1] === '{' && string[index + match.length] === '}') {
        return i;
      }

      if (args.hasOwnProperty(i)) {
        result = args[i];
      } else if (i.indexOf('.') !== -1) {
        result = getValueByPath(args, i);
      }

      if (result === null || result === undefined) {
        return '';
      }

      return result;
    });
  }

  return {
    render: render,
    compile: function compile(str) {
      return function () {
        for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
          args[_key2] = arguments[_key2];
        }

        return render.apply(undefined, [str].concat(args));
      };
    },
    parse: function parse(str) {
      var matches = str.match(pattern);

      if (matches === null) {
        return false;
      }

      var parsed = [];
      for (var i = 0; i < matches.length; i++) {
        if (!matches[i].match(/^\{\{.+\}\}$/g)) {
          parsed.push(matches[i].substring(1, matches[i].length - 1).trim());
        }
      }

      return parsed;
    }
  };
}();

/*eslint-disable */
/* Credit to http://is.js.org MIT */
var toString = Object.prototype.toString;
var is = {
  // Type checks
  /* -------------------------------------------------------------------------- */
  // is a given value Arguments?
  arguments: function _arguments(value) {
    // fallback check is for IE
    return toString.call(value) === '[object Arguments]' || value != null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && 'callee' in value;
  },

  // is a given value Array?
  array: function array(val) {
    if (Array.isArray) {
      return Array.isArray(val);
    }
    return toString.call(val) === '[object Array]';
  },

  // is a given value Boolean?
  boolean: function boolean(val) {
    return val === true || val === false || toString.call(val) === '[object Boolean]';
  },

  // is a given value Char?
  char: function char(val) {
    return this.string(val) && val.length === 1;
  },

  // is a given value Date Object?
  date: function date(value) {
    return toString.call(value) === '[object Date]';
  },

  // is a given object a DOM node?
  domNode: function domNode(object) {
    return this.object(object) && object.nodeType > 0;
  },

  // is a given value Error object?
  error: function error(val) {
    return toString.call(val) === '[object Error]';
  },

  // is a given value function?
  function: function _function(val) {
    // fallback check is for IE
    return toString.call(val) === '[object Function]' || typeof val === 'function';
  },

  // is given value a pure JSON object?
  json: function json(value) {
    return toString.call(value) === '[object Object]';
  },

  // is a given value NaN?
  nan: function nan(val) {
    // NaN is number :) Also it is the only value which does not equal itself
    return val !== val;
  },

  // is a given value null?
  null: function _null(val) {
    return val === null;
  },

  // is a given value number?
  number: function number(val) {
    return !this.nan(val) && toString.call(val) === '[object Number]';
  },

  // is a given value object?
  object: function object(val) {
    return Object(val) === val;
  },

  // is a given value empty object?
  emptyObject: function emptyObject(val) {
    return this.object(val) && Object.getOwnPropertyNames(val).length == 0;
  },

  // is a given value RegExp?
  regexp: function regexp(val) {
    return toString.call(val) === '[object RegExp]';
  },

  // is a given value String?
  string: function string(val) {
    return typeof val === 'string' || toString.call(val) === '[object String]';
  },

  // is a given value undefined?
  undefined: function undefined(val) {
    return val === void 0;
  },

  // Arithmetic checks
  /* -------------------------------------------------------------------------- */
  // is a given value numeric?
  numeric: function numeric(n) {
    return (this.number(n) || this.string(n)) && !this.nan(n - parseFloat(n));
  },

  // is a given number percentage?
  percentage: function percentage(n) {
    return typeof n === 'string' && n.indexOf('%') !== -1;
  },

  // is a given number decimal?
  decimal: function decimal(n) {
    return this.number(n) && n % 1 !== 0;
  },

  // is a given number finite?
  finite: function finite(n) {
    if (isFinite) {
      return isFinite(n);
    }
    return !this.infinite(n) && !this.nan(n);
  },

  // is a given number infinite?
  infinite: function infinite(n) {
    return n === Infinity || n === -Infinity;
  },

  integer: function integer(n) {
    return this.number(n) && n % 1 === 0;
  },

  // is a given number negative?
  negative: function negative(n) {
    return this.number(n) && n < 0;
  },

  // is a given number positive?
  positive: function positive(n) {
    return this.number(n) && n > 0;
  }
};

var Html5 = function () {
  function Html5(video, element, options) {
    classCallCheck(this, Html5);

    this.element = element;
    this.options = options;
    this.video = video;
    this.classes = video.classes;
  }

  createClass(Html5, [{
    key: 'load',
    value: function load() {
      console.log('load html5 html');
      this.$wrap = $(this.createHtml());
      this.$wrap.appendTo(this.element);
      if (this.options.poster) {
        this.$poster = this.$wrap.find('.' + this.video.classes.POSTER);
        this.$poster.css({ 'background-image': 'url(' + this.options.poster + ')' });
      }

      this.$video = $('<video></video>');
      this.setdefault();
      this.$video.appendTo(this.$wrap);

      this.video.trigger(events.LOAD);
      this.video.trigger(events.LOADED);
      if (this.options.poster) {
        this.$poster.hide();
      }
      this.bind();
    }
  }, {
    key: 'setdefault',
    value: function setdefault() {
      if (is.array(this.options.url)) {
        for (var i = 0; i < this.options.url.length; i++) {
          var videoTypeArr = this.options.url[i].split('.');
          var videoType = videoTypeArr[videoTypeArr.length - 1];

          this.addSourceToVideo(this.options.url[i], videoType);
        }
      } else {
        var _videoTypeArr = this.options.url.split('.');
        var _videoType = _videoTypeArr[_videoTypeArr.length - 1];

        this.addSourceToVideo(this.options.url, _videoType);
      }

      this.$video[0].autoplay = this.options.autoplay;
      this.$video[0].controls = this.options.controls;
      this.$video[0].loop = this.options.loop;
    }
  }, {
    key: 'createHtml',
    value: function createHtml() {
      var poster = '';

      if (this.options.poster !== '') {
        poster = template.render(this.options.templates.poster.call(this), { classes: this.classes });
      }

      var html = template.render(this.options.template.call(this), {
        classes: this.classes,
        poster: poster
      });
      return html;
    }
  }, {
    key: 'addSourceToVideo',
    value: function addSourceToVideo(src, type) {
      var source = document.createElement('source');

      source.src = src;
      source.type = 'video/' + type;

      this.$video[0].appendChild(source);
    }
  }, {
    key: 'setSize',
    value: function setSize(width, height) {
      this.$wrap.css('width', width);
      this.$wrap.css('height', height);
    }
  }, {
    key: 'switchVideo',
    value: function switchVideo(id) {
      this.$video[0].src = id;
    }
  }, {
    key: 'bind',
    value: function bind() {
      this.eventListener('play');
      this.eventListener('pause');
      this.eventListener('error');
      // this.eventListener('stalled')
    }
  }, {
    key: 'eventListener',
    value: function eventListener(event) {
      var _this = this;

      var capitalEvent = event.toUpperCase();
      this.$video.on(event, function () {
        _this.video.trigger(events[capitalEvent]);
      });
    }
  }, {
    key: 'currentTime',
    value: function currentTime() {
      return this.$video[0].currentTime;
    }
  }, {
    key: 'duration',
    value: function duration() {
      return this.$video[0].duration;
    }
  }, {
    key: 'setCurrentTime',
    value: function setCurrentTime(val) {
      this.$video[0].currentTime = val;
    }
  }, {
    key: 'pause',
    value: function pause() {
      this.$video[0].pause();
    }
  }, {
    key: 'play',
    value: function play() {
      this.$video[0].play();
    }
  }, {
    key: 'mute',
    value: function mute() {
      this.$video[0].muted = true;
    }
  }, {
    key: 'unMute',
    value: function unMute() {
      this.$video[0].muted = false;
    }
  }, {
    key: 'stop',
    value: function stop() {
      this.$video[0].currentTime = 0;
      this.$video[0].pause();
      this.video.trigger(events.STOP);
    }
  }, {
    key: 'volume',
    value: function volume(value) {
      this.$video[0].volume = value / 100;
    }
  }, {
    key: 'destroy',
    value: function destroy() {
      var element = this.$wrap.find('video');
      if (element.length) {
        element[0].src = '//about:blank';
      }
      this.$wrap.remove();
    }
  }]);
  return Html5;
}();

window.AsVimeoAPIReady = false;

var Vimeo = function () {
  function Vimeo(video, element, options) {
    classCallCheck(this, Vimeo);

    this.element = element;
    this.options = options;
    this.video = video;
    this.classes = video.classes;
  }

  createClass(Vimeo, [{
    key: 'load',
    value: function load() {
      var _this = this;

      this.$wrap = $$1(this.createHtml());
      this.$wrap.appendTo(this.element);
      if (this.options.poster) {
        this.$poster = this.$wrap.find('.' + this.video.classes.POSTER);
        this.$poster.css({ 'background-image': 'url(' + this.options.poster + ')' });
      }

      if (window.AsVimeoAPIReady) {
        this.init();
        this.video.trigger(events.LOAD);
      } else {
        this.loadApi();
        Pj__default.$window.on('AsVideoVimeoAPIReady', function () {
          _this.init();
          _this.video.trigger(events.LOAD);
        });
      }
    }
  }, {
    key: 'init',
    value: function init() {
      var playerSettings = {
        id: this.getId(),
        loop: this.options.loop,
        autoplay: this.options.autoplay,
        // height:400,
        // url:'https://player.vimeo.com/video/76979871',
        title: false, // defaults to true
        portrait: false, // Show the user’s portrait on the video. Defaults to true.
        // maxwidth: '',
        // maxheight '',
        xhtml: false, // Make the embed code XHTML compliant. Defaults to false.
        byline: false, // Show the byline on the video. Defaults to true.
        autopause: false // Pause this video automatically when another one plays. Defaults to true.
      };

      this.media = new window.Vimeo.Player(this.$wrap[0], playerSettings);
      this.bind();
    }
  }, {
    key: 'getId',
    value: function getId() {
      if (this.options.id) {
        return this.options.id;
      } else if (this.options.url) {
        return this.options.url.split('/')[3].split('?')[0];
      }
      return undefined;
    }
  }, {
    key: 'createHtml',
    value: function createHtml() {
      var poster = '';

      if (this.options.poster !== '') {
        poster = template.render(this.options.templates.poster.call(this), { classes: this.classes });
      }

      var html = template.render(this.options.template.call(this), {
        classes: this.classes,
        poster: poster
      });
      return html;
    }
  }, {
    key: 'loadApi',
    value: function loadApi() {
      var _this2 = this;

      var tag = document.createElement('script');
      tag.src = 'https://player.vimeo.com/api/player.js';
      document.querySelector('body').appendChild(tag);

      var event = document.createEvent('Event');
      event.initEvent('AsVideoVimeoAPIReady', true, true);
      var count = 1;
      var vimeoApiReady = setInterval(function () {
        if (count > 50) {
          clearInterval(vimeoApiReady);
          console.log('loadApi error');
          _this2.video.destroy();
        }
        count++;
        if (typeof window.Vimeo === 'undefined') {
          return;
        }
        window.AsVimeoAPIReady = true;
        window.dispatchEvent(event);
        clearInterval(vimeoApiReady);
      }, 350);
    }
  }, {
    key: 'bind',
    value: function bind() {
      var _this3 = this;

      this.media.on('play', function () {
        _this3.video.trigger(events.PLAY);
      });
      this.media.on('pause', function () {
        _this3.video.trigger(events.PAUSE);
      });
      this.media.on('loaded', function () {
        _this3.video.trigger(events.LOADED);
        if (_this3.options.poster) {
          _this3.$poster.hide();
        }
      });
    }
  }, {
    key: 'setSize',
    value: function setSize(width, height) {
      this.$wrap.css('width', width);
      this.$wrap.css('height', height);
    }
  }, {
    key: 'switchVideo',
    value: function switchVideo(id) {
      this.media.loadVideo(id);
    }
  }, {
    key: '_currentTime',
    value: function _currentTime() {
      var _this4 = this;

      this.media.getCurrentTime().then(function (seconds) {
        _this4.options.currentTime = seconds;
      });
    }
  }, {
    key: 'currentTime',
    value: function currentTime() {
      this._currentTime();
      return this.options.currentTime;
    }
  }, {
    key: '_duration',
    value: function _duration() {
      var _this5 = this;

      return this.media.getDuration().then(function (duration) {
        _this5.options.duration = duration;
      });
    }
  }, {
    key: 'duration',
    value: function duration() {
      this._duration();
      return this.options.duration;
    }
  }, {
    key: 'setCurrentTime',
    value: function setCurrentTime(val) {
      this.media.setCurrentTime(val);
    }
  }, {
    key: 'stop',
    value: function stop() {
      this.media.setCurrentTime(0);
      this.media.pause();
      this.video.trigger(events.STOP);
    }
  }, {
    key: 'mute',
    value: function mute() {
      this.volume(0);
    }
  }, {
    key: 'unMute',
    value: function unMute() {
      this.volume(50);
    }
  }, {
    key: 'pause',
    value: function pause() {
      this.media.pause();
      this.video.trigger('pause');
    }
  }, {
    key: 'volume',
    value: function volume(value) {
      this.media.setVolume(value / 100);
    }
  }, {
    key: 'play',
    value: function play() {
      this.media.play();
    }
  }, {
    key: 'destroy',
    value: function destroy() {
      var element = this.$wrap.find('iframe');
      if (element.length) {
        element[0].src = '//about:blank';
      }
      this.$wrap.remove();
    }
  }]);
  return Vimeo;
}();

window.AsYTAPIReady = false;

var Youtube = function () {
  function Youtube(video, element, options) {
    classCallCheck(this, Youtube);

    this.element = element;
    this.options = options;
    this.video = video;
    this.classes = video.classes;
  }

  createClass(Youtube, [{
    key: 'load',
    value: function load() {
      this.$wrap = $$1(this.createHtml());
      this.$wrap.appendTo(this.element);
      if (this.options.poster) {
        this.$poster = this.$wrap.find('.' + this.video.classes.POSTER);
        this.$poster.css({ 'background-image': 'url(' + this.options.poster + ')' });
      }

      if (window.AsYTAPIReady) {
        this.init();
        this.video.trigger(events.LOAD);
      } else {
        this.loadApi();
      }
    }
  }, {
    key: 'init',
    value: function init() {
      var _this = this;

      this.$iframe = $$1('<div></div>');
      this.$iframe.appendTo(this.$wrap);

      this.setdefault();

      var playerSettings = {
        volume: 0, // 0 - 100
        autohide: 0, // autohide controls
        autoplay: this.options.autoplay, // autoplay on load
        color: 'red', // red, white
        controls: this.options.controls, // show control UI
        disablekb: 0, // enable/disable keyboard control
        enablejsapi: 1,
        fs: 0, // display fullscreen button
        hl: null, // interface language
        // iv_load_policy: 3,
        loop: 1, // loop video flag (doesn't work properly)
        modestbranding: 1, // show/hide youtube logo
        playsinline: 0,
        rel: 0, // shows relative videos
        showinfo: 0,
        start: 0, // set beginning of the video
        end: 0, // set end of the video
        quality: 'default' // small, medium, large, hd720, hd1080, highres or default
      };

      this.media = new YT.Player(this.$iframe[0], {
        videoId: this.getId(),
        mute: true,
        repeat: true,
        playButtonClass: 'YTPlayer-play',
        pauseButtonClass: 'YTPlayer-pause',
        muteButtonClass: 'YTPlayer-mute',
        volumeUpClass: 'YTPlayer-volume-up',
        volumeDownClass: 'YTPlayer-volume-down',
        start: 0,
        pauseOnScroll: false,
        fitToBackground: true,
        playerVars: playerSettings,
        events: { onReady: function onReady() {
            _this.video.trigger(events.LOADED);
            if (_this.options.poster) {
              _this.$poster.hide();
            }
          } }
      });
      this.bind();
    }
  }, {
    key: 'getId',
    value: function getId() {
      if (this.options.id) {
        return this.options.id;
      } else if (this.options.url) {
        return this.options.url.split('/')[3].split('?v=')[1];
      }
      return undefined;
    }
  }, {
    key: 'loadApi',
    value: function loadApi() {
      var _this2 = this;

      $$1.getScript('//www.youtube.com/iframe_api', function (response, status) {
        console.log('text status', status);
        window.AsYTAPIReady = true;

        window.onYouTubeIframeAPIReady = function () {
          _this2.init();
          _this2.video.trigger(events.LOAD);
        };
      });
    }
  }, {
    key: 'setdefault',
    value: function setdefault() {
      this.options.autoplay = this.options.autoplay ? 1 : 0;
      this.options.controls = this.options.controls ? 1 : 0;
    }
  }, {
    key: 'setSize',
    value: function setSize(width, height) {
      this.$wrap.css('width', width);
      this.$wrap.css('height', height);
    }
  }, {
    key: 'switchVideo',
    value: function switchVideo(id) {
      this.media.loadVideoById({ videoId: id });
    }
  }, {
    key: 'createHtml',
    value: function createHtml() {
      var poster = '';

      if (this.options.poster !== '') {
        poster = template.render(this.options.templates.poster.call(this), { classes: this.classes });
      }
      console.log('text', this.classes);
      var html = template.render(this.options.template.call(this), {
        classes: this.classes,
        poster: poster
      });
      return html;
    }
  }, {
    key: 'bind',
    value: function bind() {
      var _this3 = this;

      this.media.addEventListener('onStateChange', function (event) {
        if (event.data === 1) {
          _this3.video.trigger(events.PLAY);
        } else if (event.data === 2) {
          _this3.video.trigger(events.PAUSE);
        } else if (event.data === 0) {
          _this3.video.trigger(events.PLAYEND);
          if (_this3.options.loop === true) {
            _this3.play();
          }
        }
      });
      this.media.addEventListener('onError', function () {
        _this3.video.trigger(events.PLAYERR);
      });
    }
  }, {
    key: 'currentTime',
    value: function currentTime() {
      return this.media.getCurrentTime();
    }
  }, {
    key: 'duration',
    value: function duration() {
      return this.media.getDuration();
    }
  }, {
    key: 'setCurrentTime',
    value: function setCurrentTime(val) {
      this.media.seekTo(val, true);
    }
  }, {
    key: 'volume',
    value: function volume(value) {
      this.media.setVolume(value);
    }
  }, {
    key: 'mute',
    value: function mute() {
      this.media.mute();
    }
  }, {
    key: 'unMute',
    value: function unMute() {
      this.media.unMute();
    }
  }, {
    key: 'pause',
    value: function pause() {
      this.media.pauseVideo();
    }
  }, {
    key: 'stop',
    value: function stop() {
      this.media.stopVideo();
      this.video.trigger(events.STOP);
    }
  }, {
    key: 'play',
    value: function play() {
      this.media.playVideo();
    }
  }, {
    key: 'destroy',
    value: function destroy() {
      var element = this.$wrap.find('iframe');
      if (element.length) {
        element[0].src = '//about:blank';
      }
      this.$wrap.remove();
    }
  }]);
  return Youtube;
}();

var _dec;
var _dec2;
var _dec3;
var _dec4;
var _class;
var _class2;

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

var sources = {};

var Video = (_dec = Pj.styleable(classes), _dec2 = Pj.eventable(events), _dec3 = Pj.stateable(), _dec4 = Pj.register(namespace, {
  defaults: defaults$1,
  methods: methods
}, info), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = (_class2 = function (_Component) {
  inherits(Video, _Component);

  function Video(element) {
    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    classCallCheck(this, Video);

    var _this = possibleConstructorReturn(this, (Video.__proto__ || Object.getPrototypeOf(Video)).call(this, namespace, element));

    _this.options = $$1.extend(true, {}, defaults$1, options, _this.getDataOptions());
    _this.initClasses(classes);
    _this.initStates();
    _this.initialize();
    return _this;
  }

  createClass(Video, [{
    key: 'initialize',
    value: function initialize() {
      if (typeof sources[this.options.type] !== 'undefined') {
        this.player = new sources[this.options.type](this, this.$element, this.options);
      }

      this.enter('initialized');
      this.trigger(events.READY);
    }
  }, {
    key: 'load',
    value: function load() {
      if (!this.is('loaded')) {
        this.player.load();
        this.enter('loaded');
      }
    }
  }, {
    key: 'switchVideo',
    value: function switchVideo(id) {
      this.player.switchVideo(id);
    }
  }, {
    key: 'duration',
    value: function duration() {
      return this.player.duration();
    }
  }, {
    key: 'currentTime',
    value: function currentTime() {
      return this.player.currentTime();
    }
  }, {
    key: 'setCurrentTime',
    value: function setCurrentTime(val) {
      this.player.setCurrentTime(val);
    }
  }, {
    key: 'setSize',
    value: function setSize(width, height) {
      this.player.setSize(width, height);
      this.options.width = width;
    }
  }, {
    key: 'play',
    value: function play() {
      this.player.play();
    }
  }, {
    key: 'stop',
    value: function stop() {
      this.player.stop();
    }
  }, {
    key: 'volume',
    value: function volume(val) {
      this.player.volume(val);
    }
  }, {
    key: 'pause',
    value: function pause() {
      this.player.pause();
    }
  }, {
    key: 'mute',
    value: function mute() {
      this.player.mute();
    }
  }, {
    key: 'unMute',
    value: function unMute() {
      this.player.unMute();
    }
  }, {
    key: 'destroy',
    value: function destroy() {
      if (this.is('initialized')) {
        this.leave('initialized');
      }
      if (this.is('loaded')) {
        this.leave('loaded');
        this.player.destroy();
      }

      this.trigger(events.DESTROY);
      get(Video.prototype.__proto__ || Object.getPrototypeOf(Video.prototype), 'destroy', this).call(this);
    }
  }], [{
    key: 'registerSource',
    value: function registerSource(type, API) {
      sources[type] = API;
    }
  }]);
  return Video;
}(Plugin), (_applyDecoratedDescriptor(_class2.prototype, 'destroy', [Pj.deregister], Object.getOwnPropertyDescriptor(_class2.prototype, 'destroy'), _class2.prototype)), _class2)) || _class) || _class) || _class) || _class);


Video.registerSource('youtube', Youtube);
Video.registerSource('vimeo', Vimeo);
Video.registerSource('html5', Html5);

exports['default'] = Video;

Object.defineProperty(exports, '__esModule', { value: true });

})));
