Skip to content

Commit

Permalink
Updated jQuery plugin to version 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 18, 2015
1 parent 2721611 commit 72efad7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
70 changes: 51 additions & 19 deletions assets/js/rocksolid-slider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! rocksolid-slider v1.5.2 */
/*! rocksolid-slider v1.5.3 */
(function($, window, document) {

var Rst = {};
Expand Down Expand Up @@ -266,8 +266,10 @@ Rst.Slide = (function() {
* @var object regular expressions for video URLs
*/
Slide.prototype.videoRegExp = {
youtube: /^https?:\/\/(?:www\.youtube\.com\/(?:watch\?v=|v\/|embed\/)|youtu\.be\/)([0-9a-z_\-]{11})(?:$|&|\?|#|\/)(?:(?:.*[?&#]|)t=([0-9hms]+))?/i,
vimeo: /^https?:\/\/(?:player\.)?vimeo\.com\/(?:video\/)?([0-9]+)(?:.*#t=([0-9hms]+))?/i
youtube: /^https?:\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|v\/|embed\/)|youtu\.be\/)([0-9a-z_\-]{11})(?:$|&|\?|#|\/)(?:(?:.*[?&#]|)t=([0-9hms]+))?/i,
youtubePlayer: /^https?:\/\/(?:www\.)?youtube\.com\/embed\/[0-9a-z_\-]{11}/i,
vimeo: /^https?:\/\/(?:player\.)?vimeo\.com\/(?:video\/)?([0-9]+)(?:.*#t=([0-9hms]+))?/i,
vimeoPlayer: /^https?:\/\/player\.vimeo\.com\/video\/[0-9]+/i
};

/**
Expand Down Expand Up @@ -660,7 +662,7 @@ Rst.Slide = (function() {
Slide.prototype.startVideo = function() {

var self = this;
var videoId, apiCallback, matches, time;
var videoId, apiCallback, matches, time, src;

if (this.isVideoPlaying) {
return;
Expand Down Expand Up @@ -690,14 +692,28 @@ Rst.Slide = (function() {
time[2] = parseInt(time[2] || 0, 10);
time = time[0] + (time[1] * 60) + (time[2] * 60 * 60);
}

src = 'https://www.youtube.com/embed/' + videoId;
if (this.data.video.match(this.videoRegExp.youtubePlayer)) {
src = this.data.video;
}

if (!src.match(/[?&]autoplay=/i)) {
src += (src.match(/\?/) ? '&' : '?') + 'autoplay=1';
}
if (!src.match(/[?&]enablejsapi=/i)) {
src += '&enablejsapi=1';
}
if (!src.match(/[?&]wmode=/i)) {
src += '&wmode=opaque';
}
if (time && !src.match(/[?&]start=/i)) {
src += '&start=' + time;
}

this.videoElement = $(document.createElement('iframe'))
.addClass(this.slider.options.cssPrefix + 'video-iframe')
.attr('src',
'http://www.youtube.com/embed/' +
videoId +
'?autoplay=1&enablejsapi=1&wmode=opaque' +
(time ? '&start=' + time : '')
)
.attr('src', src)
.attr('frameborder', 0)
.attr('allowfullscreen', 'allowfullscreen')
.appendTo(this.element);
Expand Down Expand Up @@ -736,14 +752,25 @@ Rst.Slide = (function() {

videoId = matches[1];
time = matches[2];

src = 'https://player.vimeo.com/video/' + videoId;
if (this.data.video.match(this.videoRegExp.vimeoPlayer)) {
src = this.data.video;
}

if (!src.match(/[?&]autoplay=/i)) {
src += (src.match(/\?/) ? '&' : '?') + 'autoplay=1';
}
if (!src.match(/[?&]api=/i)) {
src += '&api=1';
}
if (time && !src.match(/#t=/i)) {
src += '#t=' + time;
}

this.videoElement = $(document.createElement('iframe'))
.addClass(this.slider.options.cssPrefix + 'video-iframe')
.attr('src',
'http://player.vimeo.com/video/' +
videoId +
'?autoplay=1&api=1' +
(time ? '#t=' + time : '')
)
.attr('src', src)
.attr('frameborder', 0)
.attr('allowfullscreen', 'allowfullscreen')
.appendTo(this.element);
Expand Down Expand Up @@ -987,8 +1014,6 @@ Rst.Slider = (function() {
.appendTo(this.elements.main);
}

this.autoplay();

this.preloadSlides(this.slideIndex);
// Sets active states
this.cleanupSlides();
Expand All @@ -1000,6 +1025,8 @@ Rst.Slider = (function() {
// Resize again for edge cases when combineItems changed the nav height
this.resize();

this.autoplay();

$(window).on('domready.rsts load.rsts', function(){
if (self.windowSizeHasChanged()) {
self.resize();
Expand Down Expand Up @@ -1452,7 +1479,7 @@ Rst.Slider = (function() {

var self = this;

if (!this.options.autoplay) {
if (!this.options.autoplay || this.getVisibleCount() >= this.slides.length) {
return;
}

Expand Down Expand Up @@ -2534,9 +2561,14 @@ Rst.Slider = (function() {

if (this.getVisibleCount() >= this.slides.length) {
this.nav.hide();
this.stopAutoplay(true);
}
else {
this.nav.show();
if (visibleCountBefore >= this.slides.length) {
// restart autoplay
this.stopAutoplay();
}
}

if (visibleCountBefore !== this.getVisibleCount()) {
Expand Down
Loading

0 comments on commit 72efad7

Please sign in to comment.