Skip to content

Commit

Permalink
Updated jQuery plugin to version 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 18, 2014
1 parent 09a7a77 commit 64b0a1f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 21 deletions.
112 changes: 93 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.4.0 */
/*! rocksolid-slider v1.4.1 */
(function($, window, document) {

var Rst = {};
Expand Down Expand Up @@ -32,7 +32,10 @@ Rst.Slide = (function() {
name: this.content.attr('data-rsts-name') || this.content.attr('title')
};

if (element.nodeName === 'IMG') {
if (
element.nodeName.toLowerCase() === 'img'
|| element.nodeName.toLowerCase() === 'picture'
) {
this.type = 'image';
}
this.type = this.content.attr('data-rsts-type') || this.type || 'default';
Expand Down Expand Up @@ -63,7 +66,7 @@ Rst.Slide = (function() {
|| this.slider.device === 'iPod'
) {
this.element.find('[data-rsts-background]').each(function() {
if (this.nodeName !== 'VIDEO') {
if (this.nodeName.toLowerCase() !== 'video') {
return;
}
var $this = $(this);
Expand All @@ -78,15 +81,24 @@ Rst.Slide = (function() {
});
}

this.backgrounds = this.element.find('[data-rsts-background]')
.attr('autoplay', true)
.attr('loop', true)
.css({
this.backgrounds = [];
this.element.find('[data-rsts-background]').each(function() {
var element = $(this);
if (element.is('img') && element.parent().is('picture')) {
element = element.parent();
}
if (element.is('video')) {
element.attr('autoplay', true).attr('loop', true);
}
element.css({
position: 'absolute',
top: 0,
left: 0
})
.prependTo(this.element);
});
self.backgrounds.push(element[0]);
});

this.backgrounds = $(this.backgrounds).prependTo(this.element);

if (this.backgrounds.length) {
this.element.children().last().css({
Expand Down Expand Up @@ -164,8 +176,8 @@ 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})(?:$|&|\/)/i,
vimeo: /^https?:\/\/(?:player\.)?vimeo\.com\/(?:video\/)?([0-9]+)/i
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
};

/**
Expand All @@ -186,6 +198,8 @@ Rst.Slide = (function() {

var autoSize = !x || !y;

this.updateResponsiveImages(true);

if (x && ! y) {
this.slider.modify(this.element, {width: x, height: ''});
this.resetScaledContent();
Expand Down Expand Up @@ -219,6 +233,24 @@ Rst.Slide = (function() {

};

/**
* update responsive images if picturefill or respimage are present
*/
Slide.prototype.updateResponsiveImages = function(reevaluate) {

var polyfill = window.picturefill || window.respimage;

if (!polyfill) {
return;
}

polyfill({
elements: this.element.find('img').get(),
reevaluate: !!reevaluate
});

};

/**
* scale slide contents based on width and height
*/
Expand Down Expand Up @@ -256,7 +288,11 @@ Rst.Slide = (function() {
var self = this;

this.backgrounds.each(function() {
self.scaleImage($(this), x, y);
var element = $(this);
if (element.is('picture')) {
element = element.find('img').first();
}
self.scaleImage(element, x, y);
});

};
Expand Down Expand Up @@ -336,7 +372,7 @@ Rst.Slide = (function() {
element = $(element);
var size = {};

if (element[0].nodeName === 'IMG') {
if (element[0].nodeName.toLowerCase() === 'img') {

if ('naturalWidth' in new Image()) {
size.x = element[0].naturalWidth;
Expand All @@ -350,7 +386,7 @@ Rst.Slide = (function() {
}

}
else if (element[0].nodeName === 'VIDEO') {
else if (element[0].nodeName.toLowerCase() === 'video') {

size.x = element[0].videoWidth;
size.y = element[0].videoHeight;
Expand Down Expand Up @@ -506,7 +542,7 @@ Rst.Slide = (function() {
Slide.prototype.startVideo = function() {

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

this.slider.stopAutoplay(true);

Expand All @@ -515,12 +551,21 @@ Rst.Slide = (function() {
this.element.addClass(this.slider.options.cssPrefix + 'video-youtube');

videoId = matches[1];
time = matches[2];
if (time) {
time = time.split(/[hm]/).reverse();
time[0] = parseInt(time[0] || 0, 10);
time[1] = parseInt(time[1] || 0, 10);
time[2] = parseInt(time[2] || 0, 10);
time = time[0] + (time[1] * 60) + (time[2] * 60 * 60);
}
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'
'?autoplay=1&enablejsapi=1&wmode=opaque' +
(time ? '&start=' + time : '')
)
.attr('frameborder', 0)
.attr('allowfullscreen', 'allowfullscreen')
Expand Down Expand Up @@ -559,12 +604,14 @@ Rst.Slide = (function() {
this.element.addClass(this.slider.options.cssPrefix + 'video-vimeo');

videoId = matches[1];
time = matches[2];
this.videoElement = $(document.createElement('iframe'))
.addClass(this.slider.options.cssPrefix + 'video-iframe')
.attr('src',
'http://player.vimeo.com/video/' +
videoId +
'?autoplay=1&api=1'
'?autoplay=1&api=1' +
(time ? '#t=' + time : '')
)
.attr('frameborder', 0)
.attr('allowfullscreen', 'allowfullscreen')
Expand Down Expand Up @@ -1942,6 +1989,16 @@ Rst.Slider = (function() {
if (pauseAutoplay) {
this.pauseAutoplay();
}
if (
this.elements.main.css('position') === 'static'
|| this.elements.main.css('position') === 'relative'
) {
// Prevent scrolling issues, see #18
this.elements.main.css(
'margin-bottom',
this.elements.main.outerHeight(true) + 100 + 'px'
);
}
this.elements.view.css({display: 'none'});
if (this.nav.elements.main) {
this.nav.elements.main.css({display: 'none'});
Expand All @@ -1963,6 +2020,7 @@ Rst.Slider = (function() {
if (this.elements.footer) {
this.elements.footer.css({display: ''});
}
this.elements.main.css('margin-bottom', '');
if (pauseAutoplay) {
this.playAutoplay();
}
Expand Down Expand Up @@ -2142,7 +2200,20 @@ Rst.Slider = (function() {
move: 'mousemove'
};

if (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints) {
if (window.navigator.pointerEnabled && window.navigator.maxTouchPoints) {
eventNames = {
start: 'pointerdown',
stop: 'pointerup',
move: 'pointermove'
};
this.elements.crop.css('touch-action', 'pan-' + (this.options.direction === 'x' ? 'y' : 'x') + ' pinch-zoom double-tap-zoom');
this.elements.main.on('pointerdown', function(event) {
if (event.originalEvent.pointerType === 'touch') {
self.setTouch(true);
}
});
}
else if (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints) {
eventNames = {
start: 'MSPointerDown',
stop: 'MSPointerUp',
Expand Down Expand Up @@ -2196,7 +2267,10 @@ Rst.Slider = (function() {
}

// detect mouse or touch event
if (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints) {
if (window.navigator.pointerEnabled && window.navigator.maxTouchPoints) {
this.setTouch(event.originalEvent.pointerType === 'touch');
}
else if (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints) {
this.setTouch(event.originalEvent.pointerType === event.originalEvent.MSPOINTER_TYPE_TOUCH);
}
else {
Expand Down
Loading

0 comments on commit 64b0a1f

Please sign in to comment.