UNPKG

react-wistia

Version:

React.js wrapper for Wistia player

706 lines (565 loc) 24.8 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react")); else if(typeof define === 'function' && define.amd) define(["react"], factory); else if(typeof exports === 'object') exports["ReactWistia"] = factory(require("react")); else root["ReactWistia"] = factory(root["React"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_0__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 3); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_0__; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 _react = __webpack_require__(0); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(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; } function _inherits(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 WistiaPlayer = function (_Component) { _inherits(WistiaPlayer, _Component); function WistiaPlayer() { var _ref; var _temp, _this, _ret; _classCallCheck(this, WistiaPlayer); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WistiaPlayer.__proto__ || Object.getPrototypeOf(WistiaPlayer)).call.apply(_ref, [this].concat(args))), _this), _this.state = {}, _this.onReady = function (video) { video.bind('end', _this.props.onEnd); video.bind('play', _this.props.onPlay); video.bind('pause', _this.props.onPause); video.bind('secondchange', _this.props.onSecondChange); video.bind('timechange', _this.props.onTimeChange); _this.setState({ video: video }, function () { return _this.handleProps(); }); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(WistiaPlayer, [{ key: 'handleProps', value: function handleProps() { var video = this.state.video; if (!video) { return; } this.props.onReady && this.props.onReady(video); if (this.props.play) { video.play(); } else { video.pause(); } } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { var video = this.state.video; if (!video) { return; } if (typeof nextProps.timeValue !== 'undefined' && Math.abs(nextProps.timeValue - video.time()) > 0.3) { video.time(nextProps.timeValue); } if (this.props.play && !nextProps.play) { video.pause(); } else if (!this.props.play && nextProps.play) { video.play(); } } }, { key: 'componentDidMount', value: function componentDidMount() { var _props = this.props, wq = _props.wq, id = _props.videoId, options = _props.playerOptions; wq.push({ id: id, onReady: this.onReady, options: options }); } }, { key: 'render', value: function render() { var _props2 = this.props, videoId = _props2.videoId, _props2$className = _props2.className, additionalClasses = _props2$className === undefined ? '' : _props2$className; var className = 'wistia_embed wistia_async_' + videoId + ' ' + additionalClasses; return _react2.default.createElement('div', { className: className }); } }]); return WistiaPlayer; }(_react.Component); WistiaPlayer.propTypes = { videoId: _react.PropTypes.string.isRequired, wq: _react.PropTypes.array.isRequired, playerOptions: _react.PropTypes.object, play: _react.PropTypes.bool, onEnd: _react.PropTypes.func, onPlay: _react.PropTypes.func, onPause: _react.PropTypes.func, onSecondChange: _react.PropTypes.func, onTimeChange: _react.PropTypes.func }; exports.default = WistiaPlayer; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 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 _react = __webpack_require__(0); var _react2 = _interopRequireDefault(_react); var _reactAsyncScriptLoader = __webpack_require__(5); var _reactAsyncScriptLoader2 = _interopRequireDefault(_reactAsyncScriptLoader); var _WistiaPlayer = __webpack_require__(1); var _WistiaPlayer2 = _interopRequireDefault(_WistiaPlayer); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(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; } function _inherits(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 WistiaPlayerWrapper = function (_Component) { _inherits(WistiaPlayerWrapper, _Component); function WistiaPlayerWrapper() { _classCallCheck(this, WistiaPlayerWrapper); return _possibleConstructorReturn(this, (WistiaPlayerWrapper.__proto__ || Object.getPrototypeOf(WistiaPlayerWrapper)).apply(this, arguments)); } _createClass(WistiaPlayerWrapper, [{ key: 'componentWillReceiveProps', value: function componentWillReceiveProps(_ref) { var isScriptLoaded = _ref.isScriptLoaded, isScriptLoadSucceed = _ref.isScriptLoadSucceed; if (isScriptLoaded && !this.props.isScriptLoaded) { if (isScriptLoadSucceed) { window._wq = window._wq || []; if (this.props.onLoaded) { this.props.onLoaded(); } } else if (this.props.onError) { this.props.onError(); } } } }, { key: 'render', value: function render() { var _props = this.props, isScriptLoaded = _props.isScriptLoaded, isScriptLoadSucceed = _props.isScriptLoadSucceed, errorContent = _props.errorContent; return isScriptLoaded ? isScriptLoadSucceed ? _react2.default.createElement(_WistiaPlayer2.default, _extends({ wq: window._wq }, this.props)) : errorContent : _react2.default.createElement( 'div', { className: this.props.notLoadedClassName }, this.props.children ); } }]); return WistiaPlayerWrapper; }(_react.Component); WistiaPlayerWrapper.propTypes = { onLoaded: _react.PropTypes.func, onError: _react.PropTypes.func, errorContent: _react.PropTypes.oneOfType([_react.PropTypes.element, _react.PropTypes.string]) }; exports.default = (0, _reactAsyncScriptLoader2.default)(['//fast.wistia.com/assets/external/E-v1.js'])(WistiaPlayerWrapper); /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WistiaPlayerWrapper = exports.WistiaPlayer = undefined; var _WistiaPlayer = __webpack_require__(1); var _WistiaPlayer2 = _interopRequireDefault(_WistiaPlayer); var _WistiaPlayerWrapper = __webpack_require__(2); var _WistiaPlayerWrapper2 = _interopRequireDefault(_WistiaPlayerWrapper); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var WistiaPlayer = exports.WistiaPlayer = _WistiaPlayer2.default; var WistiaPlayerWrapper = exports.WistiaPlayerWrapper = _WistiaPlayerWrapper2.default; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * Copyright 2015, Yahoo! Inc. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ var REACT_STATICS = { childContextTypes: true, contextTypes: true, defaultProps: true, displayName: true, getDefaultProps: true, mixins: true, propTypes: true, type: true }; var KNOWN_STATICS = { name: true, length: true, prototype: true, caller: true, arguments: true, arity: true }; var isGetOwnPropertySymbolsAvailable = typeof Object.getOwnPropertySymbols === 'function'; module.exports = function hoistNonReactStatics(targetComponent, sourceComponent, customStatics) { if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components var keys = Object.getOwnPropertyNames(sourceComponent); /* istanbul ignore else */ if (isGetOwnPropertySymbolsAvailable) { keys = keys.concat(Object.getOwnPropertySymbols(sourceComponent)); } for (var i = 0; i < keys.length; ++i) { if (!REACT_STATICS[keys[i]] && !KNOWN_STATICS[keys[i]] && (!customStatics || !customStatics[keys[i]])) { try { targetComponent[keys[i]] = sourceComponent[keys[i]]; } catch (error) { } } } } return targetComponent; }; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 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; }; }(); exports.startLoadingScripts = startLoadingScripts; var _react = __webpack_require__(0); var _react2 = _interopRequireDefault(_react); var _hoistNonReactStatics = __webpack_require__(4); var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics); var _utils = __webpack_require__(6); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(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; } function _inherits(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; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var loadedScript = []; var pendingScripts = {}; var failedScript = []; function startLoadingScripts(scripts) { var onComplete = arguments.length <= 1 || arguments[1] === undefined ? _utils.noop : arguments[1]; // sequence load var loadNewScript = function loadNewScript(src) { if (loadedScript.indexOf(src) < 0) { return function (taskComplete) { var callbacks = pendingScripts[src] || []; callbacks.push(taskComplete); pendingScripts[src] = callbacks; if (callbacks.length === 1) { return (0, _utils.newScript)(src)(function (err) { pendingScripts[src].forEach(function (cb) { return cb(err, src); }); delete pendingScripts[src]; }); } }; } }; var tasks = scripts.map(function (src) { if (Array.isArray(src)) { return src.map(loadNewScript); } else return loadNewScript(src); }); _utils.series.apply(undefined, _toConsumableArray(tasks))(function (err, src) { if (err) { failedScript.push(src); } else { if (Array.isArray(src)) { src.forEach(addCache); } else addCache(src); } })(function (err) { removeFailedScript(); onComplete(err); }); } var addCache = function addCache(entry) { if (loadedScript.indexOf(entry) < 0) { loadedScript.push(entry); } }; var removeFailedScript = function removeFailedScript() { if (failedScript.length > 0) { failedScript.forEach(function (script) { var node = document.querySelector('script[src=\'' + script + '\']'); if (node != null) { node.parentNode.removeChild(node); } }); failedScript = []; } }; var scriptLoader = function scriptLoader() { for (var _len = arguments.length, scripts = Array(_len), _key = 0; _key < _len; _key++) { scripts[_key] = arguments[_key]; } return function (WrappedComponent) { var ScriptLoader = function (_Component) { _inherits(ScriptLoader, _Component); function ScriptLoader(props, context) { _classCallCheck(this, ScriptLoader); var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ScriptLoader).call(this, props, context)); _this.state = { isScriptLoaded: false, isScriptLoadSucceed: false }; _this._isMounted = false; return _this; } _createClass(ScriptLoader, [{ key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; this._isMounted = true; startLoadingScripts(scripts, function (err) { if (_this2._isMounted) { _this2.setState({ isScriptLoaded: true, isScriptLoadSucceed: !err }, function () { if (!err) { _this2.props.onScriptLoaded(); } }); } }); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { this._isMounted = false; } }, { key: 'render', value: function render() { var props = _extends({}, this.props, this.state); return _react2.default.createElement(WrappedComponent, props); } }]); return ScriptLoader; }(_react.Component); ScriptLoader.propTypes = { onScriptLoaded: _react.PropTypes.func }; ScriptLoader.defaultProps = { onScriptLoaded: _utils.noop }; return (0, _hoistNonReactStatics2.default)(ScriptLoader, WrappedComponent); }; }; exports.default = scriptLoader; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var isDefined = exports.isDefined = function isDefined(val) { return val != null; }; var isFunction = exports.isFunction = function isFunction(val) { return typeof val === 'function'; }; var noop = exports.noop = function noop(_) {}; var newScript = exports.newScript = function newScript(src) { return function (cb) { var script = document.createElement('script'); script.src = src; script.addEventListener('load', function () { return cb(null, src); }); script.addEventListener('error', function () { return cb(true, src); }); document.body.appendChild(script); return script; }; }; var keyIterator = function keyIterator(cols) { var keys = Object.keys(cols); var i = -1; return { next: function next() { i++; // inc if (i >= keys.length) return null;else return keys[i]; } }; }; // tasks should be a collection of thunk var parallel = exports.parallel = function parallel() { for (var _len = arguments.length, tasks = Array(_len), _key = 0; _key < _len; _key++) { tasks[_key] = arguments[_key]; } return function (each) { return function (cb) { var hasError = false; var successed = 0; var ret = []; tasks = tasks.filter(isFunction); if (tasks.length <= 0) cb(null);else { tasks.forEach(function (task, i) { var thunk = task; thunk(function (err) { for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { args[_key2 - 1] = arguments[_key2]; } if (err) hasError = true;else { // collect result if (args.length <= 1) args = args[0]; ret[i] = args; successed++; } if (isFunction(each)) each.call(null, err, args, i); if (hasError) cb(true);else if (tasks.length === successed) { cb(null, ret); } }); }); } }; }; }; // tasks should be a collection of thunk var series = exports.series = function series() { for (var _len3 = arguments.length, tasks = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { tasks[_key3] = arguments[_key3]; } return function (each) { return function (cb) { tasks = tasks.filter(function (val) { return val != null; }); var nextKey = keyIterator(tasks); var nextThunk = function nextThunk() { var key = nextKey.next(); var thunk = tasks[key]; if (Array.isArray(thunk)) thunk = parallel.apply(null, thunk).call(null, each); return [+key, thunk]; // convert `key` to number }; var key = void 0, thunk = void 0; var next = nextThunk(); key = next[0]; thunk = next[1]; if (thunk == null) return cb(null); var ret = []; var iterator = function iterator() { thunk(function (err) { for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { args[_key4 - 1] = arguments[_key4]; } if (args.length <= 1) args = args[0]; if (isFunction(each)) each.call(null, err, args, key); if (err) cb(err);else { // collect result ret.push(args); next = nextThunk(); key = next[0]; thunk = next[1]; if (thunk == null) return cb(null, ret); // finished else iterator(); } }); }; iterator(); }; }; }; /***/ }) /******/ ]); }); //# sourceMappingURL=ReactWistia.js.map