diff --git a/README.md b/README.md index 2ec9bd2..e2bc97b 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,11 @@ $(window).on("backstretch.after", function (e, instance, index) { ## Changelog +### Version 2.1.13 + +* Bugfix: Native video source tags were misspelled +* Bugfix: Youtube matching regex was not constrained to `youtube.com`/`youtu.be` domain + ### Version 2.1.12 * New: Added `'fade_in_out'` transition diff --git a/bower.json b/bower.json index e915aa1..bfa7f64 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jquery-backstretch-2", "description": "An updated version of: A simple jQuery plugin that allows you to add a dynamically-resized, slideshow-capable background image to any page or element.", - "version": "2.1.12", + "version": "2.1.13", "homepage": "http://srobbin.com/jquery-plugins/backstretch/", "author": { "name": "Scott Robbin", diff --git a/jquery.backstretch.js b/jquery.backstretch.js index cecc0a8..58e7185 100644 --- a/jquery.backstretch.js +++ b/jquery.backstretch.js @@ -10,7 +10,7 @@ 'use strict'; /** @const */ - var YOUTUBE_REGEXP = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/i; + var YOUTUBE_REGEXP = /^.*(youtu\.be\/|youtube\.com\/v\/|youtube\.com\/embed\/|youtube\.com\/watch\?v=|youtube\.com\/watch\?.*\&v=)([^#\&\?]*).*/i; /* PLUGIN DEFINITION * ========================= */ @@ -1169,7 +1169,7 @@ if (typeof(sourceItem) === 'string') { sourceItem = { src: sourceItem }; } - $('') + $('') .attr('src', sourceItem.src) // Make sure to not specify type if unknown - // so the browser will try to autodetect. diff --git a/jquery.backstretch.min.js b/jquery.backstretch.min.js index 01b5220..eaf044e 100644 --- a/jquery.backstretch.min.js +++ b/jquery.backstretch.min.js @@ -1 +1 @@ -/*! Backstretch - v2.1.12 - 2016-03-03\n* Copyright (c) 2016 Scott Robbin;* Fork of improvements - by Daniel Cohen Gindi (danielgindi@gmail.com) Licensed MIT */!function(a,b,c){"use strict";var d=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/i;a.fn.backstretch=function(d,e){var f=arguments;0===a(b).scrollTop()&&b.scrollTo(0,0);var g;return this.each(function(b){var h=a(this),i=h.data("backstretch");if(i){if("string"==typeof f[0]&&"function"==typeof i[f[0]]){var j=i[f[0]].apply(i,Array.prototype.slice.call(f,1));return j===i&&(j=c),void(j!==c&&(g=g||[],g[b]=j))}e=a.extend(i.options,e),i.hasOwnProperty("destroy")&&i.destroy(!0)}if(!d||d&&0===d.length){var k=h.css("background-image");k&&"none"!==k?d=[{url:h.css("backgroundImage").replace(/url\(|\)|"|'/g,"")}]:a.error("No images were supplied for Backstretch, or element must have a CSS-defined background image.")}i=new l(this,d,e||{}),h.data("backstretch",i)}),g?1===g.length?g[0]:g:this},a.backstretch=function(b,c){return a("body").backstretch(b,c).data("backstretch")},a.expr[":"].backstretch=function(b){return a(b).data("backstretch")!==c},a.fn.backstretch.defaults={duration:5e3,transition:"fade",transitionDuration:0,animateFirst:!0,alignX:.5,alignY:.5,paused:!1,start:0,preload:2,preloadSize:1,resolutionRefreshRate:2500,resolutionChangeRatioThreshold:.1};var e={wrap:{left:0,top:0,overflow:"hidden",margin:0,padding:0,height:"100%",width:"100%",zIndex:-999999},itemWrapper:{position:"absolute",display:"none",margin:0,padding:0,border:"none",width:"100%",height:"100%",zIndex:-999999},item:{position:"absolute",margin:0,padding:0,border:"none",width:"100%",height:"100%",maxWidth:"none"}},f=function(){var c=function(a){for(var b=1;bparseInt(c.width,10);)a[d]=a[d-1],--d;a[d]=c}return a},d=function(a,c){for(var d,e,f=b.devicePixelRatio||1,g=0,h=0;h=d)));h++);return c[Math.min(h,g)]},e=function(a,b){if("string"==typeof a)a=a.replace(/{{(width|height)}}/g,b);else if(a instanceof Array)for(var c=0;cd?b.length:Math.min(d,b.length),e="function"!=typeof e&&e?e:1,c>=b.length&&(c=0,d=0),0>e&&(e=d),e=Math.min(e,d);var h=b.slice(c+e,d-e);if(b=b.slice(c,e),d=b.length,!d)return void j(b,f,!0);for(var l,m=0,n=function(){m++,m===d&&(j(b,f,!h),k(h,0,0,e,f))},o=0;o=this.images.length&&(this.options.start=this.images.length-1),this.options.start<0&&(this.options.start=0),this.isBody=c===document.body;var k=a(b);this.$container=a(c),this.$root=this.isBody?o?k:a(document):this.$container,this.originalImages=this.images,this.images=f(this.options.alwaysTestWindowResolution?k:this.$root,this.originalImages),h(this.images,this.options.start||0,this.options.preload||1);var l=this.$container.children(".backstretch").first();if(this.$wrap=l.length?l:a('
').css(this.options.bypassCss?{}:e.wrap).appendTo(this.$container),!this.options.bypassCss){if(!this.isBody){var m=this.$container.css("position"),n=this.$container.css("zIndex");this.$container.css({position:"static"===m?"relative":m,zIndex:"auto"===n?0:n}),this.$wrap.css({zIndex:-999998})}this.$wrap.css({position:this.isBody&&o?"fixed":"absolute"})}this.index=this.options.start,this.show(this.index),k.on("resize.backstretch",a.proxy(this.resize,this)).on("orientationchange.backstretch",a.proxy(function(){this.isBody&&0===b.pageYOffset&&(b.scrollTo(0,1),this.resize())},this))},m=function(b){var d=b.transition||"fade";"string"==typeof d&&d.indexOf("|")>-1&&(d=d.split("|")),d instanceof Array&&(d=d[Math.round(Math.random()*(d.length-1))]);var e=b["new"],f=b.old?b.old:a([]);switch(d.toString().toLowerCase()){default:case"fade":e.fadeIn({duration:b.duration,complete:b.complete,easing:b.easing||c});break;case"fadeinout":case"fade_in_out":var g=function(){e.fadeIn({duration:b.duration/2,complete:b.complete,easing:b.easing||c})};f.length?f.fadeOut({duration:b.duration/2,complete:g,easing:b.easing||c}):g();break;case"pushleft":case"push_left":case"pushright":case"push_right":case"pushup":case"push_up":case"pushdown":case"push_down":case"coverleft":case"cover_left":case"coverright":case"cover_right":case"coverup":case"cover_up":case"coverdown":case"cover_down":var h=d.match(/^(cover|push)_?(.*)$/),i="left"===h[2]?"right":"right"===h[2]?"left":"down"===h[2]?"top":"up"===h[2]?"bottom":"right",j={display:""},k={};if(j[i]="-100%",k[i]=0,e.css(j).animate(k,{duration:b.duration,complete:function(){e.css(i,""),b.complete.apply(this,arguments)},easing:b.easing||c}),"push"===h[1]&&f.length){var l={};l[i]="100%",f.animate(l,{duration:b.duration,complete:function(){f.css("display","none")},easing:b.easing||c})}}};l.prototype={resize:function(){try{var d=this.options.alwaysTestWindowResolution?a(b):this.$root,e=d.width(),g=d.height(),i=e/(this._lastResizeContainerWidth||0),j=g/(this._lastResizeContainerHeight||0),k=this.options.resolutionChangeRatioThreshold||0;if((e!==this._lastResizeContainerWidth||g!==this._lastResizeContainerHeight)&&(Math.abs(i-1)>=k||isNaN(i)||Math.abs(j-1)>=k||isNaN(j))&&(this._lastResizeContainerWidth=e,this._lastResizeContainerHeight=g,this.images=f(d,this.originalImages),this.options.preload&&h(this.images,(this.index+1)%this.images.length,this.options.preload),1===this.images.length&&this._currentImage.url!==this.images[0].url)){var l=this;clearTimeout(l._selectAnotherResolutionTimeout),l._selectAnotherResolutionTimeout=setTimeout(function(){l.show(0)},this.options.resolutionRefreshRate)}var m,n={left:0,top:0,right:"auto",bottom:"auto"},o=this.isBody?this.$root.width():this.$root.innerWidth(),p=this.isBody?b.innerHeight?b.innerHeight:this.$root.height():this.$root.innerHeight(),q=o,r=q/this.$itemWrapper.data("ratio"),s=a.Event("backstretch.resize",{relatedTarget:this.$container[0]}),t=this._currentImage.alignX===c?this.options.alignX:this._currentImage.alignX,u=this._currentImage.alignY===c?this.options.alignY:this._currentImage.alignY;r>=p?n.top=-(r-p)*u:(r=p,q=r*this.$itemWrapper.data("ratio"),m=(q-o)/2,n.left=-(q-o)*t),this.options.bypassCss||this.$wrap.css({width:o,height:p}).find(">.backstretch-item").not(".deleteable").each(function(){var b=a(this);b.find("img,video,iframe").css({width:q,height:r}).css(n)}),this.$container.trigger(s,this)}catch(v){}return this},show:function(b,d){if(!(Math.abs(b)>this.images.length-1)){var f=this,h=f.$wrap.find(">.backstretch-item").addClass("deleteable"),i=f.videoWrapper,j={relatedTarget:f.$container[0]};f.$container.trigger(a.Event("backstretch.before",j),[f,b]),this.index=b;var k=f.images[b];clearTimeout(f._cycleTimeout),delete f.videoWrapper;var l=g(k);return l?(f.videoWrapper=new n(k),f.$item=f.videoWrapper.$video.css("pointer-events","none")):f.$item=a(""),f.$itemWrapper=a('
').append(f.$item),this.options.bypassCss?f.$itemWrapper.css({display:"none"}):(f.$itemWrapper.css(e.itemWrapper),f.$item.css(e.item)),f.$item.bind(l?"canplay":"load",function(e){var g=a(this),k=g.parent(),n=k.data("options");d&&(n=a.extend({},n,d));var o=this.naturalWidth||this.videoWidth||this.width,p=this.naturalHeight||this.videoHeight||this.height;k.data("ratio",o/p);var q=function(a){return n[a]!==c?n[a]:f.options[a]},r=q("transition"),s=q("transitionEasing"),t=q("transitionDuration"),u=function(){i&&(i.stop(),i.destroy()),h.remove(),!f.paused&&f.images.length>1&&f.cycle(),f.options.bypassCss||f.isBody||f.$container.css("background","none"),a(["after","show"]).each(function(){f.$container.trigger(a.Event("backstretch."+this,j),[f,b])}),l&&f.videoWrapper.play()};f.firstShow&&!f.options.animateFirst||!t||!r?(k.show(),u()):m({"new":k,old:h,transition:r,duration:t,easing:s,complete:u}),f.firstShow=!1,f.resize()}),f.$itemWrapper.appendTo(f.$wrap),f.$item.attr("alt",k.alt||""),f.$itemWrapper.data("options",k),l||f.$item.attr("src",k.url),f._currentImage=k,f}},current:function(){return this.index},next:function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(this.index1){clearTimeout(this._cycleTimeout);var b=this._currentImage&&this._currentImage.duration||this.options.duration,c=g(this._currentImage),d=function(){this.$item.off(".cycle"),this.paused||this.next()};if(c){if(!this._currentImage.loop){var e=0;this.$item.on("playing.cycle",function(){var b=a(this).data("player");clearTimeout(e),e=setTimeout(function(){b.pause(),b.$video.trigger("ended")},1e3*(b.getDuration()-b.getCurrentTime()))}).on("ended.cycle",function(){clearTimeout(e)})}this.$item.on("error.cycle initerror.cycle",a.proxy(d,this))}c&&!this._currentImage.duration?this.$item.on("ended.cycle",a.proxy(d,this)):this._cycleTimeout=setTimeout(a.proxy(d,this),b)}return this},destroy:function(c){a(b).off("resize.backstretch orientationchange.backstretch"),this.videoWrapper&&this.videoWrapper.destroy(),clearTimeout(this._cycleTimeout),c||this.$wrap.remove(),this.$container.removeData("backstretch")}};var n=function(){this.init.apply(this,arguments)};n.prototype.init=function(e){var f,g=this,h=function(){g.$video=f,g.video=f[0]},i="video";if(e.url instanceof Array||!d.test(e.url)||(i="youtube"),g.type=i,"youtube"===i){n.loadYoutubeAPI(),g.ytId=e.url.match(d)[2];var j="https://www.youtube.com/embed/"+g.ytId+"?rel=0&autoplay=0&showinfo=0&controls=0&modestbranding=1&cc_load_policy=0&disablekb=1&iv_load_policy=3&loop=0&enablejsapi=1&origin="+encodeURIComponent(b.location.origin);g.__ytStartMuted=!!e.mute||e.mute===c,f=a("