1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-21 20:35:31 +02:00
This commit is contained in:
Antonio Laguna
2017-03-30 09:22:33 +02:00
parent 2e1b39d088
commit 3bd5502443
2 changed files with 69 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
/*! /*!
* Name: WebSlides * Name: WebSlides
* Version: 1.2.1 * Version: 1.2.1
* Date: 2017-03-22 * Date: 2017-03-30
* Description: Making HTML presentations easy * Description: Making HTML presentations easy
* URL: https://github.com/webslides/webslides#readme * URL: https://github.com/webslides/webslides#readme
* Credits: @jlantunez, @LuisSacristan, @Belelros * Credits: @jlantunez, @LuisSacristan, @Belelros
@@ -2143,12 +2143,38 @@ var Player = function () {
_classCallCheck(this, Player); _classCallCheck(this, Player);
/**
* Whether the Player is ready or not.
* @type {boolean}
*/
this.ready = false; this.ready = false;
this.onReadyC = null; /**
* Ready callback.
* @type {?function}
*/
this.onReadyCb = null;
/**
* Slide element in which the video is located.
* @type {Node}
*/
this.slide = __WEBPACK_IMPORTED_MODULE_1__modules_slide__["a" /* default */].getSectionFromEl(el).section; this.slide = __WEBPACK_IMPORTED_MODULE_1__modules_slide__["a" /* default */].getSectionFromEl(el).section;
/**
* Whether it should autoplay on load or not.
* @type {boolean}
*/
this.autoplay = typeof el.dataset.autoplay !== 'undefined';
/**
* Whether the video should be muted or not.
* @type {boolean}
*/
this.isMuted = typeof el.dataset.mute !== 'undefined';
var playerVars = this.getPlayerVars(el); var playerVars = this.getPlayerVars(el);
/**
* Youtube player.
* @type {YT.Player}
*/
this.player = new YT.Player(el, { this.player = new YT.Player(el, {
videoId: el.dataset.youtubeId, videoId: el.dataset.youtubeId,
playerVars: playerVars, playerVars: playerVars,
@@ -2159,20 +2185,28 @@ var Player = function () {
_this.play(); _this.play();
} }
if (_this.onReadyC) { if (_this.onReadyCb) {
_this.onReadyC(); _this.onReadyCb();
_this.onReadyC = null; _this.onReadyCb = null;
} }
} }
} }
}); });
/**
* The iframe in which the video is loaded.
* @type {Element}
*/
this.el = this.player.getIframe(); this.el = this.player.getIframe();
/**
* Timeout id.
* @type {?number}
*/
this.timeout = null; this.timeout = null;
} }
/** /**
* * Plays the video.
*/ */
@@ -2185,30 +2219,40 @@ var Player = function () {
this.timeout = setTimeout(function () { this.timeout = setTimeout(function () {
_this2.timeout = null; _this2.timeout = null;
}, 1000); }, 1000);
if (this.isMuted) {
this.player.mute();
} else {
this.player.unMute();
}
this.player.playVideo(); this.player.playVideo();
} else { } else {
this.onReadyC = this.play; this.onReadyCb = this.play;
} }
} }
/** /**
* * Pause playing the video if it's already playing.
*/ */
}, { }, {
key: 'pause', key: 'pause',
value: function pause() { value: function pause() {
if (this.player && this.player.pauseVideo && this.player.getPlayerState() === 1) {
this.player.pauseVideo(); this.player.pauseVideo();
} }
}
/** /**
* Get player vars by element. * Parses the element to have the proper variables.
* @return {{modestbranding: number}} * @param {Element} element
* @return {Object} Player variables.
*/ */
}, { }, {
key: 'getPlayerVars', key: 'getPlayerVars',
value: function getPlayerVars() { value: function getPlayerVars(element) {
var vars = { var vars = {
modestbranding: 1, modestbranding: 1,
rel: 0, rel: 0,
@@ -2221,6 +2265,14 @@ var Player = function () {
vars.showinfo = 0; vars.showinfo = 0;
} }
if (typeof element.dataset.noControls !== 'undefined') {
vars.controls = 0;
}
if (typeof element.dataset.loop !== 'undefined') {
vars.loop = 0;
}
return vars; return vars;
} }
}]); }]);
@@ -2306,8 +2358,10 @@ var YouTube = function () {
}], [{ }], [{
key: 'onSectionEnabled', key: 'onSectionEnabled',
value: function onSectionEnabled(slide) { value: function onSectionEnabled(slide) {
if (slide.player.autoplay) {
slide.player.play(); slide.player.play();
} }
}
/** /**
* On Section enable hook. Will pause the video. * On Section enable hook. Will pause the video.

File diff suppressed because one or more lines are too long