Skip to content

Commit

Permalink
Add second parameter to changeSource to allow changing the poster as …
Browse files Browse the repository at this point in the history
…well
  • Loading branch information
OriginalEXE committed Nov 4, 2016
1 parent 89b3c29 commit 6059132
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
30 changes: 29 additions & 1 deletion dist/vidim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* vidim v1.0.0
* 2016-11-03T14:17:43.707Z
* 2016-11-04T00:33:53.043Z
* https://github.com/OriginalEXE/vidim
*
* Made by Ante Sepic
Expand Down Expand Up @@ -548,6 +548,8 @@ var html5Provider = function (vidim) {
* @param {Object} src Hash of video types and sources
*/
changeSource: function changeSource(src) {
var newPoster = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;


this.el.innerHTML = '';

Expand All @@ -570,6 +572,18 @@ var html5Provider = function (vidim) {

this.el.currentTime = this._options.startAt;
}

if (newPoster) {

var oldPoster = this._options.poster;

if (-1 !== this.wrapper.style.backgroundImage.indexOf(oldPoster)) {

this.wrapper.style.backgroundImage = 'url(\'' + newPoster + '\')';
}

this._options.poster = newPoster;
}
},

/**
Expand Down Expand Up @@ -956,6 +970,8 @@ var YouTubeProvider = function (vidim) {
* @param {Object} src Hash of video types and sources
*/
changeSource: function changeSource(src) {
var newPoster = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;


if (11 === src.length) {

Expand All @@ -977,6 +993,18 @@ var YouTubeProvider = function (vidim) {
this.player.loadPlaylist(this.videoID, 0, this._options.startAt, this._options.quality);

this.player.setLoop(this._options.loop);

if (newPoster) {

var oldPoster = this._options.poster;

if (-1 !== this.wrapper.style.backgroundImage.indexOf(oldPoster)) {

this.wrapper.style.backgroundImage = 'url(\'' + newPoster + '\')';
}

this._options.poster = newPoster;
}
},

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/vidim.min.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/providers/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default function( vidim ) {
* Changes the source of the current video
* @param {Object} src Hash of video types and sources
*/
changeSource: function( src ) {
changeSource: function( src, newPoster = false ) {

this.el.innerHTML = '';

Expand All @@ -335,6 +335,20 @@ export default function( vidim ) {

}

if ( newPoster ) {

var oldPoster = this._options.poster;

if ( -1 !== this.wrapper.style.backgroundImage.indexOf( oldPoster ) ) {

this.wrapper.style.backgroundImage = `url('${newPoster}')`;

}

this._options.poster = newPoster;

}

},

/**
Expand Down
16 changes: 15 additions & 1 deletion src/providers/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export default function( vidim ) {
* Changes the source of the current video
* @param {Object} src Hash of video types and sources
*/
changeSource: function( src ) {
changeSource: function( src, newPoster = false ) {

if ( 11 === src.length ) {

Expand Down Expand Up @@ -378,6 +378,20 @@ export default function( vidim ) {

this.player.setLoop( this._options.loop );

if ( newPoster ) {

var oldPoster = this._options.poster;

if ( -1 !== this.wrapper.style.backgroundImage.indexOf( oldPoster ) ) {

this.wrapper.style.backgroundImage = `url('${newPoster}')`;

}

this._options.poster = newPoster;

}

},

/**
Expand Down

0 comments on commit 6059132

Please sign in to comment.