diff --git a/changelog.md b/changelog.md index 0adfd3bf..fc8962b7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## v1.6.14 +- SVG sprite loading automatically for an easier setup +- Touch devices now show controls on touch rather than pausing playback + ## v1.6.13 - Decreased sensitivity and inverted scroll on volume slider (scroll up to increase, down to decrease) diff --git a/dist/plyr.js b/dist/plyr.js index 325678f3..cc6f44c9 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=t(e,document):"function"==typeof define&&define.amd?define(null,function(){t(e,document)}):e.plyr=t(e,document)}("undefined"!=typeof window?window:this,function(e,t){"use strict";function n(){var e,n,a,r=navigator.userAgent,s=navigator.appName,o=""+parseFloat(navigator.appVersion),i=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(s="IE",o="11;"):-1!==(n=r.indexOf("MSIE"))?(s="IE",o=r.substring(n+5)):-1!==(n=r.indexOf("Chrome"))?(s="Chrome",o=r.substring(n+7)):-1!==(n=r.indexOf("Safari"))?(s="Safari",o=r.substring(n+7),-1!==(n=r.indexOf("Version"))&&(o=r.substring(n+8))):-1!==(n=r.indexOf("Firefox"))?(s="Firefox",o=r.substring(n+8)):(e=r.lastIndexOf(" ")+1)<(n=r.lastIndexOf("/"))&&(s=r.substring(e,n),o=r.substring(n+1),s.toLowerCase()==s.toUpperCase()&&(s=navigator.appName)),-1!==(a=o.indexOf(";"))&&(o=o.substring(0,a)),-1!==(a=o.indexOf(" "))&&(o=o.substring(0,a)),i=parseInt(""+o,10),isNaN(i)&&(o=""+parseFloat(navigator.appVersion),i=parseInt(navigator.appVersion,10)),{name:s,version:i,ios:/(iPad|iPhone|iPod)/g.test(navigator.platform),touch:"ontouchstart"in t.documentElement}}function a(e,t){var n=e.media;if("video"==e.type)switch(t){case"video/webm":return!(!n.canPlayType||!n.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/,""));case"video/mp4":return!(!n.canPlayType||!n.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/,""));case"video/ogg":return!(!n.canPlayType||!n.canPlayType('video/ogg; codecs="theora"').replace(/no/,""))}else if("audio"==e.type)switch(t){case"audio/mpeg":return!(!n.canPlayType||!n.canPlayType("audio/mpeg;").replace(/no/,""));case"audio/ogg":return!(!n.canPlayType||!n.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/,""));case"audio/wav":return!(!n.canPlayType||!n.canPlayType('audio/wav; codecs="1"').replace(/no/,""))}return!1}function r(e){if(!t.querySelectorAll('script[src="'+e+'"]').length){var n=t.createElement("script");n.src=e;var a=t.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a)}}function s(e,t){return Array.prototype.indexOf&&-1!=e.indexOf(t)}function o(e,t,n){return e.replace(new RegExp(t.replace(/([.*+?\^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}function i(e,t){e.length||(e=[e]);for(var n=e.length-1;n>=0;n--){var a=n>0?t.cloneNode(!0):t,r=e[n],s=r.parentNode,o=r.nextSibling;a.appendChild(r),o?s.insertBefore(a,o):s.appendChild(a)}}function l(e){for(var t=e.parentNode;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}function u(e){e&&e.parentNode.removeChild(e)}function c(e,t){e.insertBefore(t,e.firstChild)}function p(e,t){for(var n in t)e.setAttribute(n,"boolean"==typeof t[n]&&t[n]?"":t[n])}function d(e,n,a){var r=t.createElement(e);p(r,a),c(n,r)}function A(e){return e.replace(".","")}function m(e,t,n){if(e)if(e.classList)e.classList[n?"add":"remove"](t);else{var a=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=a+(n?" "+t:"")}}function f(e,t){return e?e.classList?e.classList.contains(t):new RegExp("(\\s|^)"+t+"(\\s|$)").test(e.className):!1}function y(e,t,n,a){e&&g(e,t,n,!0,a)}function b(e,t,n,a){e&&g(e,t,n,!1,a)}function v(e,t,n,a,r){y(e,t,function(t){n&&n.apply(e,[t]),a.apply(e,[t])},r)}function g(e,t,n,a,r){var s=t.split(" ");if("boolean"!=typeof r&&(r=!1),e instanceof NodeList)for(var o=0;oa;a++){var r=e[a];for(var s in r)r[s]&&r[s].constructor&&r[s].constructor===Object?(t[s]=t[s]||{},x(t[s],r[s])):t[s]=r[s]}return t}}function T(){var e={supportsFullScreen:!1,isFullScreen:function(){return!1},requestFullScreen:function(){},cancelFullScreen:function(){},fullScreenEventName:"",element:null,prefix:""},n="webkit moz o ms khtml".split(" ");if("undefined"!=typeof t.cancelFullScreen)e.supportsFullScreen=!0;else for(var a=0,r=n.length;r>a;a++){if(e.prefix=n[a],"undefined"!=typeof t[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}if("undefined"!=typeof t.msExitFullscreen&&t.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}return e.supportsFullScreen&&(e.fullScreenEventName="ms"==e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(e){switch("undefined"==typeof e&&(e=t.body),this.prefix){case"":return t.fullscreenElement==e;case"moz":return t.mozFullScreenElement==e;default:return t[this.prefix+"FullscreenElement"]==e}},e.requestFullScreen=function(e){return"undefined"==typeof e&&(e=t.body),""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"==this.prefix?"RequestFullscreen":"RequestFullScreen")]()},e.cancelFullScreen=function(){return""===this.prefix?t.cancelFullScreen():t[this.prefix+("ms"==this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?t.fullscreenElement:t[this.prefix+"FullscreenElement"]}),e}function _(){var t={supported:function(){if(!("localStorage"in e))return!1;try{e.localStorage.setItem("___test","OK");var t=e.localStorage.getItem("___test");return e.localStorage.removeItem("___test"),"OK"===t}catch(n){return!1}return!1}()};return t}function E(g,x){function E(t,n){x.debug&&e.console&&console[n?"warn":"log"](t)}function S(){var e=[],t=x.iconUrl+"#"+x.iconPrefix;return s(x.controls,"play-large")&&e.push('"),e.push('
'),s(x.controls,"restart")&&e.push('"),s(x.controls,"rewind")&&e.push('"),s(x.controls,"play")&&e.push('",'"),s(x.controls,"fast-forward")&&e.push('"),s(x.controls,"progress")&&(e.push('','','','','',"0% "+x.i18n.buffered,""),x.tooltips.seek&&e.push('00:00'),e.push("")),s(x.controls,"current-time")&&e.push('',''+x.i18n.currentTime+"",'00:00',""),s(x.controls,"duration")&&e.push('',''+x.i18n.duration+"",'00:00',""),s(x.controls,"mute")&&e.push('"),s(x.controls,"volume")&&e.push('','",'','',""),s(x.controls,"captions")&&e.push('"),s(x.controls,"fullscreen")&&e.push('"),e.push("
"),e.join("")}function I(){if(Ne.supported.full&&("audio"!=Ne.type||x.fullscreen.allowAudio)&&x.fullscreen.enabled){var e=C.supportsFullScreen;e||x.fullscreen.fallback&&!V()?(E((e?"Native":"Fallback")+" fullscreen enabled"),m(Ne.container,x.classes.fullscreen.enabled,!0)):E("Fullscreen not supported and fallback disabled"),k(Ne.buttons.fullscreen,!1),H()}}function N(){if("video"===Ne.type){L(x.selectors.captions)||Ne.videoContainer.insertAdjacentHTML("afterbegin",'
'),Ne.usingTextTracks=!1,Ne.media.textTracks&&(Ne.usingTextTracks=!0);for(var e,t="",n=Ne.media.childNodes,a=0;a=10||"Firefox"===Ne.browser.name&&Ne.browser.version>=31)&&(E("Detected browser with known TextTrack issues - using manual fallback"),Ne.usingTextTracks=!1),Ne.usingTextTracks){E("TextTracks supported");for(var o=0;o ");for(var a=0;aNe.captions.length-1){Ne.subcount=Ne.captions.length-1;break}Ne.media.currentTime.toFixed(1)>=n(Ne.captions[Ne.subcount][0])&&Ne.media.currentTime.toFixed(1)<=a(Ne.captions[Ne.subcount][0])?(Ne.currentCaption=Ne.captions[Ne.subcount][1],M(Ne.currentCaption)):M()}}function R(){Ne.buttons.captions&&(m(Ne.container,x.classes.captions.enabled,!0),x.captions.defaultActive&&(m(Ne.container,x.classes.captions.active,!0),k(Ne.buttons.captions,!0)))}function B(e){return Ne.container.querySelectorAll(e)}function L(e){return B(e)[0]}function V(){try{return e.self!==e.top}catch(t){return!0}}function H(){function e(e){9===e.which&&Ne.isFullscreen&&(e.target!==a||e.shiftKey?e.target===n&&e.shiftKey&&(e.preventDefault(),a.focus()):(e.preventDefault(),n.focus()))}var t=B("input:not([disabled]), button:not([disabled])"),n=t[0],a=t[t.length-1];y(Ne.container,"keydown",e)}function O(e,t){if("string"==typeof t)d(e,Ne.media,{src:t});else if(t.constructor===Array)for(var n=t.length-1;n>=0;n--)d(e,Ne.media,t[n])}function W(){var e=x.html;E("Injecting custom controls"),e||(e=S()),e=o(e,"{seektime}",x.seekTime),e=o(e,"{id}",Math.floor(1e4*Math.random()));var n;if(null!==x.selectors.controls.container&&(n=x.selectors.controls.container,"string"==typeof selector&&(n=t.querySelector(n))),n instanceof HTMLElement||(n=Ne.container),n.insertAdjacentHTML("beforeend",e),x.tooltips.controls)for(var a=B([x.selectors.controls.wrapper," ",x.selectors.labels," .",x.classes.hidden].join("")),r=a.length-1;r>=0;r--){var s=a[r];m(s,x.classes.hidden,!1),m(s,x.classes.tooltip,!0)}}function G(){try{return Ne.controls=L(x.selectors.controls.wrapper),Ne.buttons={},Ne.buttons.seek=L(x.selectors.buttons.seek),Ne.buttons.play=B(x.selectors.buttons.play),Ne.buttons.pause=L(x.selectors.buttons.pause),Ne.buttons.restart=L(x.selectors.buttons.restart),Ne.buttons.rewind=L(x.selectors.buttons.rewind),Ne.buttons.forward=L(x.selectors.buttons.forward),Ne.buttons.fullscreen=L(x.selectors.buttons.fullscreen),Ne.buttons.mute=L(x.selectors.buttons.mute),Ne.buttons.captions=L(x.selectors.buttons.captions),Ne.progress={},Ne.progress.container=L(x.selectors.progress.container),Ne.progress.buffer={},Ne.progress.buffer.bar=L(x.selectors.progress.buffer),Ne.progress.buffer.text=Ne.progress.buffer.bar&&Ne.progress.buffer.bar.getElementsByTagName("span")[0],Ne.progress.played=L(x.selectors.progress.played),Ne.progress.tooltip=Ne.progress.container&&Ne.progress.container.querySelector("."+x.classes.tooltip),Ne.volume={},Ne.volume.input=L(x.selectors.volume.input),Ne.volume.display=L(x.selectors.volume.display),Ne.duration=L(x.selectors.duration),Ne.currentTime=L(x.selectors.currentTime),Ne.seekTime=B(x.selectors.seekTime),!0}catch(e){return E("It looks like there is a problem with your controls html",!0),q(!0),!1}}function Y(){m(Ne.container,x.selectors.container.replace(".",""),Ne.supported.full)}function q(e){e?Ne.media.setAttribute("controls",""):Ne.media.removeAttribute("controls")}function z(e){var t=x.i18n.play;if("undefined"!=typeof x.title&&x.title.length&&(t+=", "+x.title),Ne.supported.full&&Ne.buttons.play)for(var n=Ne.buttons.play.length-1;n>=0;n--)Ne.buttons.play[n].setAttribute("aria-label",t);e instanceof HTMLElement&&e.setAttribute("title",x.i18n.frameTitle.replace("{title}",x.title))}function Q(){if(!Ne.media)return E("No audio or video element found",!0),!1;if(Ne.supported.full&&(m(Ne.container,x.classes.type.replace("{0}",Ne.type),!0),s(x.types.embed,Ne.type)&&m(Ne.container,x.classes.type.replace("{0}","video"),!0),m(Ne.container,x.classes.stopped,x.autoplay),m(Ne.container,x.classes.isIos,Ne.browser.ios),m(Ne.container,x.classes.isTouch,Ne.browser.touch),"video"===Ne.type)){var e=t.createElement("div");e.setAttribute("class",x.classes.videoWrapper),i(Ne.media,e),Ne.videoContainer=e}s(x.types.embed,Ne.type)&&(j(),Ne.embedId=null)}function j(){for(var n=t.createElement("div"),a=Ne.embedId,s=Ne.type+"-"+Math.floor(1e4*Math.random()),o=B('[id^="'+Ne.type+'-"]'),i=o.length-1;i>=0;i--)u(o[i]);if(m(Ne.media,x.classes.videoWrapper,!0),m(Ne.media,x.classes.embedWrapper,!0),"youtube"===Ne.type)Ne.media.appendChild(n),n.setAttribute("id",s),"object"==typeof YT?D(a,n):(r(x.urls.youtube.api),e.onYouTubeReadyCallbacks=e.onYouTubeReadyCallbacks||[],e.onYouTubeReadyCallbacks.push(function(){D(a,n)}),e.onYouTubeIframeAPIReady=function(){e.onYouTubeReadyCallbacks.forEach(function(e){e()})});else if("vimeo"===Ne.type){var l=t.createElement("iframe");l.loaded=!1,y(l,"load",function(){l.loaded=!0}),p(l,{src:"https://player.vimeo.com/video/"+a+"?player_id="+s+"&api=1&badge=0&byline=0&portrait=0&title=0",id:s,webkitallowfullscreen:"",mozallowfullscreen:"",allowfullscreen:"",frameborder:0}),Ne.supported.full?(n.appendChild(l),Ne.media.appendChild(n)):Ne.media.appendChild(l),"$f"in e||r(x.urls.vimeo.api);var c=e.setInterval(function(){"$f"in e&&l.loaded&&(e.clearInterval(c),U.call(l))},50)}else if("soundcloud"===Ne.type){var d=t.createElement("iframe");d.loaded=!1,y(d,"load",function(){d.loaded=!0}),p(d,{src:"https://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/"+a,id:s}),n.appendChild(d),Ne.media.appendChild(n),e.SC||r(x.urls.soundcloud.api);var A=e.setInterval(function(){e.SC&&d.loaded&&(e.clearInterval(A),Z.call(d))},50)}}function X(){Ne.container.plyr.embed=Ne.embed,Ie(),z(L("iframe"))}function D(t,n){"timer"in Ne||(Ne.timer={}),Ne.embed=new YT.Player(n.id,{videoId:t,playerVars:{autoplay:x.autoplay?1:0,controls:Ne.supported.full?0:1,rel:0,showinfo:0,iv_load_policy:3,cc_load_policy:x.captions.defaultActive?1:0,cc_lang_pref:"en",wmode:"transparent",modestbranding:1,disablekb:1,origin:"*"},events:{onError:function(e){h(Ne.container,"error",!0,{code:e.data,embed:e.target})},onReady:function(t){var n=t.target;Ne.media.play=function(){n.playVideo(),Ne.media.paused=!1},Ne.media.pause=function(){n.pauseVideo(),Ne.media.paused=!0},Ne.media.stop=function(){n.stopVideo(),Ne.media.paused=!0},Ne.media.duration=n.getDuration(),Ne.media.paused=!0,Ne.media.currentTime=n.getCurrentTime(),Ne.media.muted=n.isMuted(),x.title=n.getVideoData().title,h(Ne.media,"timeupdate"),e.clearInterval(Ne.timer.buffering),Ne.timer.buffering=e.setInterval(function(){Ne.media.buffered=n.getVideoLoadedFraction(),h(Ne.media,"progress"),1===Ne.media.buffered&&(e.clearInterval(Ne.timer.buffering),h(Ne.media,"canplaythrough"))},200),X(),be()},onStateChange:function(t){var n=t.target;switch(e.clearInterval(Ne.timer.playing),t.data){case 0:Ne.media.paused=!0,h(Ne.media,"ended");break;case 1:Ne.media.paused=!1,Ne.media.seeking=!1,h(Ne.media,"play"),h(Ne.media,"playing"),Ne.timer.playing=e.setInterval(function(){Ne.media.currentTime=n.getCurrentTime(),h(Ne.media,"timeupdate")},100);break;case 2:Ne.media.paused=!0,h(Ne.media,"pause")}h(Ne.container,"statechange",!1,{code:t.data})}}})}function U(){Ne.embed=$f(this),Ne.embed.addEvent("ready",function(){Ne.media.play=function(){Ne.embed.api("play"),Ne.media.paused=!1},Ne.media.pause=function(){Ne.embed.api("pause"),Ne.media.paused=!0},Ne.media.stop=function(){Ne.embed.api("stop"),Ne.media.paused=!0},Ne.media.paused=!0,Ne.media.currentTime=0,X(),Ne.embed.api("getCurrentTime",function(e){Ne.media.currentTime=e,h(Ne.media,"timeupdate")}),Ne.embed.api("getDuration",function(e){Ne.media.duration=e,be()}),Ne.embed.addEvent("play",function(){Ne.media.paused=!1,h(Ne.media,"play"),h(Ne.media,"playing")}),Ne.embed.addEvent("pause",function(){Ne.media.paused=!0,h(Ne.media,"pause")}),Ne.embed.addEvent("playProgress",function(e){Ne.media.seeking=!1,Ne.media.currentTime=e.seconds,h(Ne.media,"timeupdate")}),Ne.embed.addEvent("loadProgress",function(e){Ne.media.buffered=e.percent,h(Ne.media,"progress"),1===parseInt(e.percent)&&h(Ne.media,"canplaythrough")}),Ne.embed.addEvent("finish",function(){Ne.media.paused=!0,h(Ne.media,"ended")}),x.autoplay&&Ne.embed.api("play")})}function Z(){Ne.embed=e.SC.Widget(this),Ne.embed.bind(e.SC.Widget.Events.READY,function(){Ne.media.play=function(){Ne.embed.play(),Ne.media.paused=!1},Ne.media.pause=function(){Ne.embed.pause(),Ne.media.paused=!0},Ne.media.stop=function(){Ne.embed.seekTo(0),Ne.embed.pause(),Ne.media.paused=!0},Ne.media.paused=!0,Ne.media.currentTime=0,X(),Ne.embed.getPosition(function(e){Ne.media.currentTime=e,h(Ne.media,"timeupdate")}),Ne.embed.getDuration(function(e){Ne.media.duration=e/1e3,be()}),Ne.embed.bind(e.SC.Widget.Events.PLAY,function(){Ne.media.paused=!1,h(Ne.media,"play"),h(Ne.media,"playing")}),Ne.embed.bind(e.SC.Widget.Events.PAUSE,function(){Ne.media.paused=!0,h(Ne.media,"pause")}),Ne.embed.bind(e.SC.Widget.Events.PLAY_PROGRESS,function(e){Ne.media.seeking=!1,Ne.media.currentTime=e.currentPosition/1e3,h(Ne.media,"timeupdate")}),Ne.embed.bind(e.SC.Widget.Events.LOAD_PROGRESS,function(e){Ne.media.buffered=e.loadProgress,h(Ne.media,"progress"),1===parseInt(e.loadProgress)&&h(Ne.media,"canplaythrough")}),Ne.embed.bind(e.SC.Widget.Events.FINISH,function(){Ne.media.paused=!0,h(Ne.media,"ended")}),x.autoplay&&Ne.embed.play()})}function $(){"play"in Ne.media&&Ne.media.play()}function J(){"pause"in Ne.media&&Ne.media.pause()}function K(e){e===!0?$():e===!1?J():Ne.media[Ne.media.paused?"play":"pause"]()}function ee(e){"number"!=typeof e&&(e=x.seekTime),ne(Ne.media.currentTime-e)}function te(e){"number"!=typeof e&&(e=x.seekTime),ne(Ne.media.currentTime+e)}function ne(e){var t=0,n=Ne.media.paused,a=ae();"number"==typeof e?t=e:"object"!=typeof e||"input"!==e.type&&"change"!==e.type||(t=e.target.value/e.target.max*a),0>t?t=0:t>a&&(t=a),ge(t);try{Ne.media.currentTime=t.toFixed(1)}catch(r){}if(s(x.types.embed,Ne.type)){switch(Ne.type){case"youtube":Ne.embed.seekTo(t);break;case"vimeo":Ne.embed.api("seekTo",t.toFixed(0));break;case"soundcloud":Ne.embed.seekTo(1e3*t)}n&&J(),h(Ne.media,"timeupdate"),Ne.media.seeking=!0}E("Seeking to "+Ne.media.currentTime+" seconds"),P(t)}function ae(){var e=parseInt(x.duration),t=0;return null===Ne.media.duration||isNaN(Ne.media.duration)||(t=Ne.media.duration),isNaN(e)?t:e}function re(){m(Ne.container,x.classes.playing,!Ne.media.paused),m(Ne.container,x.classes.stopped,Ne.media.paused),ke(Ne.media.paused)}function se(e){var n=C.supportsFullScreen;e&&e.type===C.fullScreenEventName?Ne.isFullscreen=C.isFullScreen(Ne.container):n?(C.isFullScreen(Ne.container)?C.cancelFullScreen():C.requestFullScreen(Ne.container),Ne.isFullscreen=C.isFullScreen(Ne.container)):(Ne.isFullscreen=!Ne.isFullscreen,Ne.isFullscreen?(y(t,"keyup",oe),t.body.style.overflow="hidden"):(b(t,"keyup",oe),t.body.style.overflow="")),m(Ne.container,x.classes.fullscreen.active,Ne.isFullscreen),Ne.isFullscreen?Ne.container.setAttribute("tabindex","-1"):Ne.container.removeAttribute("tabindex"),H(Ne.isFullscreen),k(Ne.buttons.fullscreen,Ne.isFullscreen),h(Ne.container,Ne.isFullscreen?"enterfullscreen":"exitfullscreen")}function oe(e){27===(e.which||e.charCode||e.keyCode)&&Ne.isFullscreen&&se()}function ie(e){if("boolean"!=typeof e&&(e=!Ne.media.muted),k(Ne.buttons.mute,e),Ne.media.muted=e,0===Ne.media.volume&&le(x.volume),s(x.types.embed,Ne.type)){switch(Ne.type){case"youtube":Ne.embed[Ne.media.muted?"mute":"unMute"]();break;case"vimeo":Ne.embed.api("setVolume",Ne.media.muted?0:parseFloat(x.volume/x.volumeMax));break;case"soundcloud":Ne.embed.setVolume(Ne.media.muted?0:parseFloat(x.volume/x.volumeMax))}h(Ne.media,"volumechange")}}function le(t){var n=x.volumeMax,a=x.volumeMin;if("undefined"==typeof t&&(t=x.volume,x.storage.enabled&&_().supported&&(t=e.localStorage.getItem(x.storage.key),e.localStorage.removeItem("plyr-volume"))),(null===t||isNaN(t))&&(t=x.volume),t>n&&(t=n),a>t&&(t=a),Ne.media.volume=parseFloat(t/n),Ne.volume.display&&(Ne.volume.display.value=t),s(x.types.embed,Ne.type)){switch(Ne.type){case"youtube":Ne.embed.setVolume(100*Ne.media.volume);break;case"vimeo":Ne.embed.api("setVolume",Ne.media.volume);break;case"soundcloud":Ne.embed.setVolume(Ne.media.volume)}h(Ne.media,"volumechange")}Ne.media.muted&&t>0&&ie()}function ue(){var e=Ne.media.muted?0:Ne.media.volume*x.volumeMax;le(e+x.volumeStep/5)}function ce(){var e=Ne.media.muted?0:Ne.media.volume*x.volumeMax;le(e-x.volumeStep/5)}function pe(){var t=Ne.media.muted?0:Ne.media.volume*x.volumeMax;Ne.supported.full&&(Ne.volume.input&&(Ne.volume.input.value=t),Ne.volume.display&&(Ne.volume.display.value=t)),x.storage.enabled&&_().supported&&!isNaN(t)&&e.localStorage.setItem(x.storage.key,t),m(Ne.container,x.classes.muted,0===t),Ne.supported.full&&Ne.buttons.mute&&k(Ne.buttons.mute,0===t)}function de(e){Ne.supported.full&&Ne.buttons.captions&&("boolean"!=typeof e&&(e=-1===Ne.container.className.indexOf(x.classes.captions.active)),Ne.captionsEnabled=e,k(Ne.buttons.captions,Ne.captionsEnabled),m(Ne.container,x.classes.captions.active,Ne.captionsEnabled),h(Ne.container,Ne.captionsEnabled?"captionsenabled":"captionsdisabled"))}function Ae(e){var t="waiting"===e.type;clearTimeout(Ne.timers.loading),Ne.timers.loading=setTimeout(function(){m(Ne.container,x.classes.loading,t)},t?250:0)}function me(e){if(Ne.supported.full){var t=Ne.progress.played,n=0,a=ae();if(e)switch(e.type){case"timeupdate":case"seeking":n=w(Ne.media.currentTime,a),"timeupdate"==e.type&&Ne.buttons.seek&&(Ne.buttons.seek.value=n);break;case"playing":case"progress":t=Ne.progress.buffer,n=function(){var e=Ne.media.buffered;return e&&e.length?w(e.end(0),a):"number"==typeof e?100*e:0}()}fe(t,n)}}function fe(e,t){if(Ne.supported.full){if("undefined"==typeof t&&(t=0),"undefined"==typeof e){if(!Ne.progress||!Ne.progress.buffer)return;e=Ne.progress.buffer}e instanceof HTMLElement?e.value=t:e&&(e.bar&&(e.bar.value=t),e.text&&(e.text.innerHTML=t))}}function ye(e,t){if(t){isNaN(e)&&(e=0),Ne.secs=parseInt(e%60),Ne.mins=parseInt(e/60%60),Ne.hours=parseInt(e/60/60%60);var n=parseInt(ae()/60/60%60)>0;Ne.secs=("0"+Ne.secs).slice(-2),Ne.mins=("0"+Ne.mins).slice(-2),t.innerHTML=(n?Ne.hours+":":"")+Ne.mins+":"+Ne.secs}}function be(){if(Ne.supported.full){var e=ae()||0;!Ne.duration&&x.displayDuration&&Ne.media.paused&&ye(e,Ne.currentTime),Ne.duration&&ye(e,Ne.duration),he()}}function ve(e){ye(Ne.media.currentTime,Ne.currentTime),e&&"timeupdate"==e.type&&Ne.media.seeking||me(e)}function ge(e){"number"!=typeof e&&(e=0);var t=ae(),n=w(e,t);Ne.progress&&Ne.progress.played&&(Ne.progress.played.value=n),Ne.buttons&&Ne.buttons.seek&&(Ne.buttons.seek.value=n)}function he(e){var t=ae();if(x.tooltips.seek&&Ne.progress.container&&0!==t){var n=Ne.progress.container.getBoundingClientRect(),a=0,r=x.classes.tooltip+"--visible";if(e)a=100/n.width*(e.pageX-n.left);else{if(!f(Ne.progress.tooltip,r))return;a=Ne.progress.tooltip.style.left.replace("%","")}0>a?a=0:a>100&&(a=100),ye(t/100*a,Ne.progress.tooltip),Ne.progress.tooltip.style.left=a+"%",e&&s(["mouseenter","mouseleave"],e.type)&&m(Ne.progress.tooltip,r,"mouseenter"===e.type)}}function ke(t){if(x.hideControls&&"audio"!==Ne.type){var n=0,a=!1,r=t;"boolean"!=typeof t&&(t&&t.type?(a="enterfullscreen"===t.type,r=s(["mousemove","mouseenter","focus"],t.type),"mousemove"===t.type&&(n=2e3),"focus"===t.type&&(n=3e3)):r=!1),e.clearTimeout(Ne.timers.hover),(r||Ne.media.paused)&&(m(Ne.container,x.classes.hideControls,!1),Ne.media.paused)||r&&Ne.media.paused||(Ne.timers.hover=e.setTimeout(function(){Ne.controls.active&&!a||m(Ne.container,x.classes.hideControls,!0)},n))}}function we(e){if("undefined"!=typeof e)return void xe(e);var t;switch(Ne.type){case"youtube":t=Ne.embed.getVideoUrl();break;case"vimeo":Ne.embed.api("getVideoUrl",function(e){t=e});break;case"soundcloud":Ne.embed.getCurrentSound(function(e){t=e.permalink_url});break;default:t=Ne.media.currentSrc}return t||""}function xe(n){if(!("undefined"!=typeof n&&"sources"in n&&n.sources.length))return void E("Invalid source format",!0);if(J(),ge(),fe(),Ce(),"youtube"===Ne.type?(Ne.embed.destroy(),e.clearInterval(Ne.timer.buffering),e.clearInterval(Ne.timer.playing)):"video"===Ne.type&&Ne.videoContainer&&u(Ne.videoContainer),Ne.embed=null,u(Ne.media),"type"in n&&(Ne.type=n.type,"video"===Ne.type)){var a=n.sources[0];"type"in a&&s(x.types.embed,a.type)&&(Ne.type=a.type)}switch(Ne.supported=F.supported(Ne.type),Ne.type){case"video":Ne.media=t.createElement("video");break;case"audio":Ne.media=t.createElement("audio");break;case"youtube":case"vimeo":case"soundcloud":Ne.media=t.createElement("div"),Ne.embedId=n.sources[0].src}c(Ne.container,Ne.media),"undefined"!=typeof n.autoplay&&(x.autoplay=n.autoplay),s(x.types.html5,Ne.type)&&(x.crossorigin&&Ne.media.setAttribute("crossorigin",""),x.autoplay&&Ne.media.setAttribute("autoplay",""),"poster"in n&&Ne.media.setAttribute("poster",n.poster),x.loop&&Ne.media.setAttribute("loop","")),Ne.container.className=Ne.originalClassName,m(Ne.container,x.classes.fullscreen.active,Ne.isFullscreen),m(Ne.container,x.classes.captions.active,Ne.captionsEnabled),Y(),s(x.types.html5,Ne.type)&&O("source",n.sources),Q(),s(x.types.html5,Ne.type)&&("tracks"in n&&O("track",n.tracks),Ne.media.load(),Ie(),be()),x.title=n.title,z(),Ne.container.plyr.media=Ne.media}function Te(e){"video"===Ne.type&&Ne.media.setAttribute("poster",e)}function _e(){function n(){var e=Ne.media.paused;e?$():J();var t=Ne.buttons[e?"play":"pause"],n=Ne.buttons[e?"pause":"play"];if(n=n&&n.length>1?n[n.length-1]:n[0]){var a=f(t,x.classes.tabFocus);setTimeout(function(){n.focus(),a&&(m(t,x.classes.tabFocus,!1),m(n,x.classes.tabFocus,!0))},100)}}function a(){var e=t.activeElement;e&&e!=t.body?t.querySelector&&(e=t.querySelector(":focus")):e=null;for(var n in Ne.buttons){var a=Ne.buttons[n];if(a instanceof NodeList)for(var r=0;r0)&&ce(),(e.deltaY>0||e.deltaX<0)&&ue()})}function Ee(){if(y(Ne.media,"timeupdate seeking",ve),y(Ne.media,"timeupdate",P),y(Ne.media,"durationchange loadedmetadata",be),y(Ne.media,"ended",function(){"video"===Ne.type&&M(),re(),ne(0),be(),"video"===Ne.type&&x.showPosterOnEnd&&Ne.media.load()}),y(Ne.media,"progress playing",me),y(Ne.media,"volumechange",pe),y(Ne.media,"play pause",re),y(Ne.media,"waiting canplay seeked",Ae),x.clickToPlay&&"audio"!==Ne.type){var e=L("."+x.classes.videoWrapper);if(!e)return;e.style.cursor="pointer",y(e,"click",function(){Ne.media.paused?$():Ne.media.ended?(ne(),$()):J()})}y(Ne.media,x.events.join(" "),function(e){h(Ne.container,e.type,!0)})}function Ce(){if(s(x.types.html5,Ne.type)){for(var e=Ne.media.querySelectorAll("source"),t=0;t=0;n--){var a=n>0?t.cloneNode(!0):t,r=e[n],s=r.parentNode,o=r.nextSibling;a.appendChild(r),o?s.insertBefore(a,o):s.appendChild(a)}}function l(e){for(var t=e.parentNode;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}function u(e){e&&e.parentNode.removeChild(e)}function c(e,t){e.insertBefore(t,e.firstChild)}function p(e,t){for(var n in t)e.setAttribute(n,"boolean"==typeof t[n]&&t[n]?"":t[n])}function d(e,n,a){var r=t.createElement(e);p(r,a),c(n,r)}function A(e){return e.replace(".","")}function m(e,t,n){if(e)if(e.classList)e.classList[n?"add":"remove"](t);else{var a=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=a+(n?" "+t:"")}}function f(e,t){return e?e.classList?e.classList.contains(t):new RegExp("(\\s|^)"+t+"(\\s|$)").test(e.className):!1}function y(e,t,n,a){e&&g(e,t,n,!0,a)}function b(e,t,n,a){e&&g(e,t,n,!1,a)}function v(e,t,n,a,r){y(e,t,function(t){n&&n.apply(e,[t]),a.apply(e,[t])},r)}function g(e,t,n,a,r){var s=t.split(" ");if("boolean"!=typeof r&&(r=!1),e instanceof NodeList)for(var o=0;oa;a++){var r=e[a];for(var s in r)r[s]&&r[s].constructor&&r[s].constructor===Object?(t[s]=t[s]||{},x(t[s],r[s])):t[s]=r[s]}return t}}function T(){var e={supportsFullScreen:!1,isFullScreen:function(){return!1},requestFullScreen:function(){},cancelFullScreen:function(){},fullScreenEventName:"",element:null,prefix:""},n="webkit moz o ms khtml".split(" ");if("undefined"!=typeof t.cancelFullScreen)e.supportsFullScreen=!0;else for(var a=0,r=n.length;r>a;a++){if(e.prefix=n[a],"undefined"!=typeof t[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}if("undefined"!=typeof t.msExitFullscreen&&t.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}return e.supportsFullScreen&&(e.fullScreenEventName="ms"==e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(e){switch("undefined"==typeof e&&(e=t.body),this.prefix){case"":return t.fullscreenElement==e;case"moz":return t.mozFullScreenElement==e;default:return t[this.prefix+"FullscreenElement"]==e}},e.requestFullScreen=function(e){return"undefined"==typeof e&&(e=t.body),""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"==this.prefix?"RequestFullscreen":"RequestFullScreen")]()},e.cancelFullScreen=function(){return""===this.prefix?t.cancelFullScreen():t[this.prefix+("ms"==this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?t.fullscreenElement:t[this.prefix+"FullscreenElement"]}),e}function E(){var t={supported:function(){if(!("localStorage"in e))return!1;try{e.localStorage.setItem("___test","OK");var t=e.localStorage.getItem("___test");return e.localStorage.removeItem("___test"),"OK"===t}catch(n){return!1}return!1}()};return t}function _(g,x){function _(t,n){x.debug&&e.console&&console[n?"warn":"log"](t)}function F(){return{url:x.iconUrl,external:0===x.iconUrl.indexOf("http")}}function N(){var e=[],t=F(),n=(t.external?"":t.url)+"#"+x.iconPrefix;return s(x.controls,"play-large")&&e.push('"),e.push('
'),s(x.controls,"restart")&&e.push('"),s(x.controls,"rewind")&&e.push('"),s(x.controls,"play")&&e.push('",'"),s(x.controls,"fast-forward")&&e.push('"),s(x.controls,"progress")&&(e.push('','','','','',"0% "+x.i18n.buffered,""),x.tooltips.seek&&e.push('00:00'),e.push("")),s(x.controls,"current-time")&&e.push('',''+x.i18n.currentTime+"",'00:00',""),s(x.controls,"duration")&&e.push('',''+x.i18n.duration+"",'00:00',""),s(x.controls,"mute")&&e.push('"),s(x.controls,"volume")&&e.push('','",'','',""),s(x.controls,"captions")&&e.push('"),s(x.controls,"fullscreen")&&e.push('"),e.push("
"),e.join("")}function M(){if(Pe.supported.full&&("audio"!=Pe.type||x.fullscreen.allowAudio)&&x.fullscreen.enabled){var e=I.supportsFullScreen;e||x.fullscreen.fallback&&!O()?(_((e?"Native":"Fallback")+" fullscreen enabled"),m(Pe.container,x.classes.fullscreen.enabled,!0)):_("Fullscreen not supported and fallback disabled"),k(Pe.buttons.fullscreen,!1),G()}}function P(){if("video"===Pe.type){V(x.selectors.captions)||Pe.videoContainer.insertAdjacentHTML("afterbegin",'
'),Pe.usingTextTracks=!1,Pe.media.textTracks&&(Pe.usingTextTracks=!0);for(var e,t="",n=Pe.media.childNodes,a=0;a=10||"Firefox"===Pe.browser.name&&Pe.browser.version>=31)&&(_("Detected browser with known TextTrack issues - using manual fallback"),Pe.usingTextTracks=!1),Pe.usingTextTracks){_("TextTracks supported");for(var o=0;o ");for(var a=0;aPe.captions.length-1){Pe.subcount=Pe.captions.length-1;break}Pe.media.currentTime.toFixed(1)>=n(Pe.captions[Pe.subcount][0])&&Pe.media.currentTime.toFixed(1)<=a(Pe.captions[Pe.subcount][0])?(Pe.currentCaption=Pe.captions[Pe.subcount][1],R(Pe.currentCaption)):R()}}function B(){Pe.buttons.captions&&(m(Pe.container,x.classes.captions.enabled,!0),x.captions.defaultActive&&(m(Pe.container,x.classes.captions.active,!0),k(Pe.buttons.captions,!0)))}function H(e){return Pe.container.querySelectorAll(e)}function V(e){return H(e)[0]}function O(){try{return e.self!==e.top}catch(t){return!0}}function G(){function e(e){9===e.which&&Pe.isFullscreen&&(e.target!==a||e.shiftKey?e.target===n&&e.shiftKey&&(e.preventDefault(),a.focus()):(e.preventDefault(),n.focus()))}var t=H("input:not([disabled]), button:not([disabled])"),n=t[0],a=t[t.length-1];y(Pe.container,"keydown",e)}function W(e,t){if("string"==typeof t)d(e,Pe.media,{src:t});else if(t.constructor===Array)for(var n=t.length-1;n>=0;n--)d(e,Pe.media,t[n])}function Y(){if(x.loadSprite){var e=F();e.external?(_("Loading external SVG sprite"),C(e.url)):_("Sprite will be used inline")}var n=x.html;_("Injecting custom controls"),n||(n=N()),n=o(n,"{seektime}",x.seekTime),n=o(n,"{id}",Math.floor(1e4*Math.random()));var a;if(null!==x.selectors.controls.container&&(a=x.selectors.controls.container,"string"==typeof selector&&(a=t.querySelector(a))),a instanceof HTMLElement||(a=Pe.container),a.insertAdjacentHTML("beforeend",n),x.tooltips.controls)for(var r=H([x.selectors.controls.wrapper," ",x.selectors.labels," .",x.classes.hidden].join("")),s=r.length-1;s>=0;s--){var i=r[s];m(i,x.classes.hidden,!1),m(i,x.classes.tooltip,!0)}}function q(){try{return Pe.controls=V(x.selectors.controls.wrapper),Pe.buttons={},Pe.buttons.seek=V(x.selectors.buttons.seek),Pe.buttons.play=H(x.selectors.buttons.play),Pe.buttons.pause=V(x.selectors.buttons.pause),Pe.buttons.restart=V(x.selectors.buttons.restart),Pe.buttons.rewind=V(x.selectors.buttons.rewind),Pe.buttons.forward=V(x.selectors.buttons.forward),Pe.buttons.fullscreen=V(x.selectors.buttons.fullscreen),Pe.buttons.mute=V(x.selectors.buttons.mute),Pe.buttons.captions=V(x.selectors.buttons.captions),Pe.progress={},Pe.progress.container=V(x.selectors.progress.container),Pe.progress.buffer={},Pe.progress.buffer.bar=V(x.selectors.progress.buffer),Pe.progress.buffer.text=Pe.progress.buffer.bar&&Pe.progress.buffer.bar.getElementsByTagName("span")[0],Pe.progress.played=V(x.selectors.progress.played),Pe.progress.tooltip=Pe.progress.container&&Pe.progress.container.querySelector("."+x.classes.tooltip),Pe.volume={},Pe.volume.input=V(x.selectors.volume.input),Pe.volume.display=V(x.selectors.volume.display),Pe.duration=V(x.selectors.duration),Pe.currentTime=V(x.selectors.currentTime),Pe.seekTime=H(x.selectors.seekTime),!0}catch(e){return _("It looks like there is a problem with your controls html",!0),Q(!0),!1}}function z(){m(Pe.container,x.selectors.container.replace(".",""),Pe.supported.full)}function Q(e){e?Pe.media.setAttribute("controls",""):Pe.media.removeAttribute("controls")}function j(e){var t=x.i18n.play;if("undefined"!=typeof x.title&&x.title.length&&(t+=", "+x.title),Pe.supported.full&&Pe.buttons.play)for(var n=Pe.buttons.play.length-1;n>=0;n--)Pe.buttons.play[n].setAttribute("aria-label",t);e instanceof HTMLElement&&e.setAttribute("title",x.i18n.frameTitle.replace("{title}",x.title))}function X(){if(!Pe.media)return _("No audio or video element found",!0),!1;if(Pe.supported.full&&(m(Pe.container,x.classes.type.replace("{0}",Pe.type),!0),s(x.types.embed,Pe.type)&&m(Pe.container,x.classes.type.replace("{0}","video"),!0),m(Pe.container,x.classes.stopped,x.autoplay),m(Pe.container,x.classes.isIos,Pe.browser.ios),m(Pe.container,x.classes.isTouch,Pe.browser.touch),"video"===Pe.type)){var e=t.createElement("div");e.setAttribute("class",x.classes.videoWrapper),i(Pe.media,e),Pe.videoContainer=e}s(x.types.embed,Pe.type)&&(D(),Pe.embedId=null)}function D(){for(var n=t.createElement("div"),a=Pe.embedId,s=Pe.type+"-"+Math.floor(1e4*Math.random()),o=H('[id^="'+Pe.type+'-"]'),i=o.length-1;i>=0;i--)u(o[i]);if(m(Pe.media,x.classes.videoWrapper,!0),m(Pe.media,x.classes.embedWrapper,!0),"youtube"===Pe.type)Pe.media.appendChild(n),n.setAttribute("id",s),"object"==typeof YT?Z(a,n):(r(x.urls.youtube.api),e.onYouTubeReadyCallbacks=e.onYouTubeReadyCallbacks||[],e.onYouTubeReadyCallbacks.push(function(){Z(a,n)}),e.onYouTubeIframeAPIReady=function(){e.onYouTubeReadyCallbacks.forEach(function(e){e()})});else if("vimeo"===Pe.type){var l=t.createElement("iframe");l.loaded=!1,y(l,"load",function(){l.loaded=!0}),p(l,{src:"https://player.vimeo.com/video/"+a+"?player_id="+s+"&api=1&badge=0&byline=0&portrait=0&title=0",id:s,webkitallowfullscreen:"",mozallowfullscreen:"",allowfullscreen:"",frameborder:0}),Pe.supported.full?(n.appendChild(l),Pe.media.appendChild(n)):Pe.media.appendChild(l),"$f"in e||r(x.urls.vimeo.api);var c=e.setInterval(function(){"$f"in e&&l.loaded&&(e.clearInterval(c),$.call(l))},50)}else if("soundcloud"===Pe.type){var d=t.createElement("iframe");d.loaded=!1,y(d,"load",function(){d.loaded=!0}),p(d,{src:"https://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/"+a,id:s}),n.appendChild(d),Pe.media.appendChild(n),e.SC||r(x.urls.soundcloud.api);var A=e.setInterval(function(){e.SC&&d.loaded&&(e.clearInterval(A),J.call(d))},50)}}function U(){Pe.container.plyr.embed=Pe.embed,Me(),j(V("iframe"))}function Z(t,n){"timer"in Pe||(Pe.timer={}),Pe.embed=new YT.Player(n.id,{videoId:t,playerVars:{autoplay:x.autoplay?1:0,controls:Pe.supported.full?0:1,rel:0,showinfo:0,iv_load_policy:3,cc_load_policy:x.captions.defaultActive?1:0,cc_lang_pref:"en",wmode:"transparent",modestbranding:1,disablekb:1,origin:"*"},events:{onError:function(e){h(Pe.container,"error",!0,{code:e.data,embed:e.target})},onReady:function(t){var n=t.target;Pe.media.play=function(){n.playVideo(),Pe.media.paused=!1},Pe.media.pause=function(){n.pauseVideo(),Pe.media.paused=!0},Pe.media.stop=function(){n.stopVideo(),Pe.media.paused=!0},Pe.media.duration=n.getDuration(),Pe.media.paused=!0,Pe.media.currentTime=n.getCurrentTime(),Pe.media.muted=n.isMuted(),x.title=n.getVideoData().title,h(Pe.media,"timeupdate"),e.clearInterval(Pe.timer.buffering),Pe.timer.buffering=e.setInterval(function(){Pe.media.buffered=n.getVideoLoadedFraction(),h(Pe.media,"progress"),1===Pe.media.buffered&&(e.clearInterval(Pe.timer.buffering),h(Pe.media,"canplaythrough"))},200),U(),ge()},onStateChange:function(t){var n=t.target;switch(e.clearInterval(Pe.timer.playing),t.data){case 0:Pe.media.paused=!0,h(Pe.media,"ended");break;case 1:Pe.media.paused=!1,Pe.media.seeking=!1,h(Pe.media,"play"),h(Pe.media,"playing"),Pe.timer.playing=e.setInterval(function(){Pe.media.currentTime=n.getCurrentTime(),h(Pe.media,"timeupdate")},100);break;case 2:Pe.media.paused=!0,h(Pe.media,"pause")}h(Pe.container,"statechange",!1,{code:t.data})}}})}function $(){Pe.embed=$f(this),Pe.embed.addEvent("ready",function(){Pe.media.play=function(){Pe.embed.api("play"),Pe.media.paused=!1},Pe.media.pause=function(){Pe.embed.api("pause"),Pe.media.paused=!0},Pe.media.stop=function(){Pe.embed.api("stop"),Pe.media.paused=!0},Pe.media.paused=!0,Pe.media.currentTime=0,U(),Pe.embed.api("getCurrentTime",function(e){Pe.media.currentTime=e,h(Pe.media,"timeupdate")}),Pe.embed.api("getDuration",function(e){Pe.media.duration=e,ge()}),Pe.embed.addEvent("play",function(){Pe.media.paused=!1,h(Pe.media,"play"),h(Pe.media,"playing")}),Pe.embed.addEvent("pause",function(){Pe.media.paused=!0,h(Pe.media,"pause")}),Pe.embed.addEvent("playProgress",function(e){Pe.media.seeking=!1,Pe.media.currentTime=e.seconds,h(Pe.media,"timeupdate")}),Pe.embed.addEvent("loadProgress",function(e){Pe.media.buffered=e.percent,h(Pe.media,"progress"),1===parseInt(e.percent)&&h(Pe.media,"canplaythrough")}),Pe.embed.addEvent("finish",function(){Pe.media.paused=!0,h(Pe.media,"ended")}),x.autoplay&&Pe.embed.api("play")})}function J(){Pe.embed=e.SC.Widget(this),Pe.embed.bind(e.SC.Widget.Events.READY,function(){Pe.media.play=function(){Pe.embed.play(),Pe.media.paused=!1},Pe.media.pause=function(){Pe.embed.pause(),Pe.media.paused=!0},Pe.media.stop=function(){Pe.embed.seekTo(0),Pe.embed.pause(),Pe.media.paused=!0},Pe.media.paused=!0,Pe.media.currentTime=0,U(),Pe.embed.getPosition(function(e){Pe.media.currentTime=e,h(Pe.media,"timeupdate")}),Pe.embed.getDuration(function(e){Pe.media.duration=e/1e3,ge()}),Pe.embed.bind(e.SC.Widget.Events.PLAY,function(){Pe.media.paused=!1,h(Pe.media,"play"),h(Pe.media,"playing")}),Pe.embed.bind(e.SC.Widget.Events.PAUSE,function(){Pe.media.paused=!0,h(Pe.media,"pause")}),Pe.embed.bind(e.SC.Widget.Events.PLAY_PROGRESS,function(e){Pe.media.seeking=!1,Pe.media.currentTime=e.currentPosition/1e3,h(Pe.media,"timeupdate")}),Pe.embed.bind(e.SC.Widget.Events.LOAD_PROGRESS,function(e){Pe.media.buffered=e.loadProgress,h(Pe.media,"progress"),1===parseInt(e.loadProgress)&&h(Pe.media,"canplaythrough")}),Pe.embed.bind(e.SC.Widget.Events.FINISH,function(){Pe.media.paused=!0,h(Pe.media,"ended")}),x.autoplay&&Pe.embed.play()})}function K(){"play"in Pe.media&&Pe.media.play()}function ee(){"pause"in Pe.media&&Pe.media.pause()}function te(e){e===!0?K():e===!1?ee():Pe.media[Pe.media.paused?"play":"pause"]()}function ne(e){"number"!=typeof e&&(e=x.seekTime),re(Pe.media.currentTime-e)}function ae(e){"number"!=typeof e&&(e=x.seekTime),re(Pe.media.currentTime+e)}function re(e){var t=0,n=Pe.media.paused,a=se();"number"==typeof e?t=e:"object"!=typeof e||"input"!==e.type&&"change"!==e.type||(t=e.target.value/e.target.max*a),0>t?t=0:t>a&&(t=a),ke(t);try{Pe.media.currentTime=t.toFixed(1)}catch(r){}if(s(x.types.embed,Pe.type)){switch(Pe.type){case"youtube":Pe.embed.seekTo(t);break;case"vimeo":Pe.embed.api("seekTo",t.toFixed(0));break;case"soundcloud":Pe.embed.seekTo(1e3*t)}n&&ee(),h(Pe.media,"timeupdate"),Pe.media.seeking=!0}_("Seeking to "+Pe.media.currentTime+" seconds"),L(t)}function se(){var e=parseInt(x.duration),t=0;return null===Pe.media.duration||isNaN(Pe.media.duration)||(t=Pe.media.duration),isNaN(e)?t:e}function oe(){m(Pe.container,x.classes.playing,!Pe.media.paused),m(Pe.container,x.classes.stopped,Pe.media.paused),xe(Pe.media.paused)}function ie(e){var n=I.supportsFullScreen;e&&e.type===I.fullScreenEventName?Pe.isFullscreen=I.isFullScreen(Pe.container):n?(I.isFullScreen(Pe.container)?I.cancelFullScreen():I.requestFullScreen(Pe.container),Pe.isFullscreen=I.isFullScreen(Pe.container)):(Pe.isFullscreen=!Pe.isFullscreen,Pe.isFullscreen?(y(t,"keyup",le),t.body.style.overflow="hidden"):(b(t,"keyup",le),t.body.style.overflow="")),m(Pe.container,x.classes.fullscreen.active,Pe.isFullscreen),Pe.isFullscreen?Pe.container.setAttribute("tabindex","-1"):Pe.container.removeAttribute("tabindex"),G(Pe.isFullscreen),k(Pe.buttons.fullscreen,Pe.isFullscreen),h(Pe.container,Pe.isFullscreen?"enterfullscreen":"exitfullscreen")}function le(e){27===(e.which||e.charCode||e.keyCode)&&Pe.isFullscreen&&ie()}function ue(e){if("boolean"!=typeof e&&(e=!Pe.media.muted),k(Pe.buttons.mute,e),Pe.media.muted=e,0===Pe.media.volume&&ce(x.volume),s(x.types.embed,Pe.type)){switch(Pe.type){case"youtube":Pe.embed[Pe.media.muted?"mute":"unMute"]();break;case"vimeo":Pe.embed.api("setVolume",Pe.media.muted?0:parseFloat(x.volume/x.volumeMax));break;case"soundcloud":Pe.embed.setVolume(Pe.media.muted?0:parseFloat(x.volume/x.volumeMax))}h(Pe.media,"volumechange")}}function ce(t){var n=x.volumeMax,a=x.volumeMin;if("undefined"==typeof t&&(t=x.volume,x.storage.enabled&&E().supported&&(t=e.localStorage.getItem(x.storage.key),e.localStorage.removeItem("plyr-volume"))),(null===t||isNaN(t))&&(t=x.volume),t>n&&(t=n),a>t&&(t=a),Pe.media.volume=parseFloat(t/n),Pe.volume.display&&(Pe.volume.display.value=t),s(x.types.embed,Pe.type)){switch(Pe.type){case"youtube":Pe.embed.setVolume(100*Pe.media.volume);break;case"vimeo":Pe.embed.api("setVolume",Pe.media.volume);break;case"soundcloud":Pe.embed.setVolume(Pe.media.volume)}h(Pe.media,"volumechange")}Pe.media.muted&&t>0&&ue()}function pe(){var e=Pe.media.muted?0:Pe.media.volume*x.volumeMax;ce(e+x.volumeStep/5)}function de(){var e=Pe.media.muted?0:Pe.media.volume*x.volumeMax;ce(e-x.volumeStep/5)}function Ae(){var t=Pe.media.muted?0:Pe.media.volume*x.volumeMax;Pe.supported.full&&(Pe.volume.input&&(Pe.volume.input.value=t),Pe.volume.display&&(Pe.volume.display.value=t)),x.storage.enabled&&E().supported&&!isNaN(t)&&e.localStorage.setItem(x.storage.key,t),m(Pe.container,x.classes.muted,0===t),Pe.supported.full&&Pe.buttons.mute&&k(Pe.buttons.mute,0===t)}function me(e){Pe.supported.full&&Pe.buttons.captions&&("boolean"!=typeof e&&(e=-1===Pe.container.className.indexOf(x.classes.captions.active)),Pe.captionsEnabled=e,k(Pe.buttons.captions,Pe.captionsEnabled),m(Pe.container,x.classes.captions.active,Pe.captionsEnabled),h(Pe.container,Pe.captionsEnabled?"captionsenabled":"captionsdisabled"))}function fe(e){var t="waiting"===e.type;clearTimeout(Pe.timers.loading),Pe.timers.loading=setTimeout(function(){m(Pe.container,x.classes.loading,t)},t?250:0)}function ye(e){if(Pe.supported.full){var t=Pe.progress.played,n=0,a=se();if(e)switch(e.type){case"timeupdate":case"seeking":n=w(Pe.media.currentTime,a),"timeupdate"==e.type&&Pe.buttons.seek&&(Pe.buttons.seek.value=n);break;case"playing":case"progress":t=Pe.progress.buffer,n=function(){var e=Pe.media.buffered;return e&&e.length?w(e.end(0),a):"number"==typeof e?100*e:0}()}be(t,n)}}function be(e,t){if(Pe.supported.full){if("undefined"==typeof t&&(t=0),"undefined"==typeof e){if(!Pe.progress||!Pe.progress.buffer)return;e=Pe.progress.buffer}e instanceof HTMLElement?e.value=t:e&&(e.bar&&(e.bar.value=t),e.text&&(e.text.innerHTML=t))}}function ve(e,t){if(t){isNaN(e)&&(e=0),Pe.secs=parseInt(e%60),Pe.mins=parseInt(e/60%60),Pe.hours=parseInt(e/60/60%60);var n=parseInt(se()/60/60%60)>0;Pe.secs=("0"+Pe.secs).slice(-2),Pe.mins=("0"+Pe.mins).slice(-2),t.innerHTML=(n?Pe.hours+":":"")+Pe.mins+":"+Pe.secs}}function ge(){if(Pe.supported.full){var e=se()||0;!Pe.duration&&x.displayDuration&&Pe.media.paused&&ve(e,Pe.currentTime),Pe.duration&&ve(e,Pe.duration),we()}}function he(e){ve(Pe.media.currentTime,Pe.currentTime),e&&"timeupdate"==e.type&&Pe.media.seeking||ye(e)}function ke(e){"number"!=typeof e&&(e=0);var t=se(),n=w(e,t);Pe.progress&&Pe.progress.played&&(Pe.progress.played.value=n),Pe.buttons&&Pe.buttons.seek&&(Pe.buttons.seek.value=n)}function we(e){var t=se();if(x.tooltips.seek&&Pe.progress.container&&0!==t){var n=Pe.progress.container.getBoundingClientRect(),a=0,r=x.classes.tooltip+"--visible";if(e)a=100/n.width*(e.pageX-n.left);else{if(!f(Pe.progress.tooltip,r))return;a=Pe.progress.tooltip.style.left.replace("%","")}0>a?a=0:a>100&&(a=100),ve(t/100*a,Pe.progress.tooltip),Pe.progress.tooltip.style.left=a+"%",e&&s(["mouseenter","mouseleave"],e.type)&&m(Pe.progress.tooltip,r,"mouseenter"===e.type)}}function xe(t){if(x.hideControls&&"audio"!==Pe.type){var n=0,a=!1,r=t;if("boolean"!=typeof t&&(t&&t.type?(a="enterfullscreen"===t.type,r=s(["mousemove","mouseenter","focus"],t.type),"mousemove"===t.type&&(n=2e3),"focus"===t.type&&(n=3e3)):r=!f(Pe.container,x.classes.hideControls)),e.clearTimeout(Pe.timers.hover),r||Pe.media.paused){if(m(Pe.container,x.classes.hideControls,!1),Pe.media.paused)return;Pe.browser.touch&&(n=3e3)}r&&Pe.media.paused||(Pe.timers.hover=e.setTimeout(function(){Pe.controls.active&&!a||m(Pe.container,x.classes.hideControls,!0)},n))}}function Te(e){if("undefined"!=typeof e)return void Ee(e);var t;switch(Pe.type){case"youtube":t=Pe.embed.getVideoUrl();break;case"vimeo":Pe.embed.api("getVideoUrl",function(e){t=e});break;case"soundcloud":Pe.embed.getCurrentSound(function(e){t=e.permalink_url});break;default:t=Pe.media.currentSrc}return t||""}function Ee(n){if(!("undefined"!=typeof n&&"sources"in n&&n.sources.length))return void _("Invalid source format",!0);if(ee(),ke(),be(),Fe(),"youtube"===Pe.type?(Pe.embed.destroy(),e.clearInterval(Pe.timer.buffering),e.clearInterval(Pe.timer.playing)):"video"===Pe.type&&Pe.videoContainer&&u(Pe.videoContainer),Pe.embed=null,u(Pe.media),"type"in n&&(Pe.type=n.type,"video"===Pe.type)){var a=n.sources[0];"type"in a&&s(x.types.embed,a.type)&&(Pe.type=a.type)}switch(Pe.supported=S(Pe.type),Pe.type){case"video":Pe.media=t.createElement("video");break;case"audio":Pe.media=t.createElement("audio");break;case"youtube":case"vimeo":case"soundcloud":Pe.media=t.createElement("div"),Pe.embedId=n.sources[0].src}c(Pe.container,Pe.media),"undefined"!=typeof n.autoplay&&(x.autoplay=n.autoplay),s(x.types.html5,Pe.type)&&(x.crossorigin&&Pe.media.setAttribute("crossorigin",""),x.autoplay&&Pe.media.setAttribute("autoplay",""),"poster"in n&&Pe.media.setAttribute("poster",n.poster),x.loop&&Pe.media.setAttribute("loop","")),Pe.container.className=Pe.originalClassName,m(Pe.container,x.classes.fullscreen.active,Pe.isFullscreen),m(Pe.container,x.classes.captions.active,Pe.captionsEnabled),z(),s(x.types.html5,Pe.type)&&W("source",n.sources),X(),s(x.types.html5,Pe.type)&&("tracks"in n&&W("track",n.tracks),Pe.media.load(),Me(),ge()),x.title=n.title,j(),Pe.container.plyr.media=Pe.media}function _e(e){"video"===Pe.type&&Pe.media.setAttribute("poster",e)}function Ce(){function n(){var e=Pe.media.paused;e?K():ee();var t=Pe.buttons[e?"play":"pause"],n=Pe.buttons[e?"pause":"play"];if(n=n&&n.length>1?n[n.length-1]:n[0]){var a=f(t,x.classes.tabFocus);setTimeout(function(){n.focus(),a&&(m(t,x.classes.tabFocus,!1),m(n,x.classes.tabFocus,!0))},100)}}function a(){var e=t.activeElement;e&&e!=t.body?t.querySelector&&(e=t.querySelector(":focus")):e=null;for(var n in Pe.buttons){var a=Pe.buttons[n];if(a instanceof NodeList)for(var r=0;r0)&&de(),(e.deltaY>0||e.deltaX<0)&&pe()})}function Se(){if(y(Pe.media,"timeupdate seeking",he),y(Pe.media,"timeupdate",L),y(Pe.media,"durationchange loadedmetadata",ge),y(Pe.media,"ended",function(){"video"===Pe.type&&R(),oe(),re(0),ge(),"video"===Pe.type&&x.showPosterOnEnd&&Pe.media.load()}),y(Pe.media,"progress playing",ye),y(Pe.media,"volumechange",Ae),y(Pe.media,"play pause",oe),y(Pe.media,"waiting canplay seeked",fe),x.clickToPlay&&"audio"!==Pe.type){var e=V("."+x.classes.videoWrapper);if(!e)return;e.style.cursor="pointer",y(e,"click",function(){return Pe.browser.touch&&!Pe.media.paused?void xe(!0):void(Pe.media.paused?K():Pe.media.ended?(re(),K()):ee())})}y(Pe.media,x.events.join(" "),function(e){h(Pe.container,e.type,!0)})}function Fe(){if(s(x.types.html5,Pe.type)){for(var e=Pe.media.querySelectorAll("source"),t=0;ti;i++)e=arguments[i],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var i=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:i.call(this,e)}}e=null}():!function(e){"use strict";if("Element"in e){var t="classList",i="prototype",n=e.Element[i],o=Object,s=String[i].trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array[i].indexOf||function(e){for(var t=0,i=this.length;i>t;t++)if(t in this&&this[t]===e)return t;return-1},a=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},c=function(e,t){if(""===t)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},l=function(e){for(var t=s.call(e.getAttribute("class")||""),i=t?t.split(/\s+/):[],n=0,o=i.length;o>n;n++)this.push(i[n]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},u=l[i]=[],d=function(){return new l(this)};if(a[i]=Error[i],u.item=function(e){return this[e]||null},u.contains=function(e){return e+="",-1!==c(this,e)},u.add=function(){var e,t=arguments,i=0,n=t.length,o=!1;do e=t[i]+"",-1===c(this,e)&&(this.push(e),o=!0);while(++i=0;a--)e(i[a].parentElement,"active",!1);e(document.querySelector('[data-source="'+t+'"]').parentElement,"active",!0)}}for(var i=document.querySelectorAll("[data-source]"),n={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},o=window.location.hash.replace("#",""),s=window.history&&window.history.pushState,r=i.length-1;r>=0;r--)i[r].addEventListener("click",function(){var e=this.getAttribute("data-source");t(e),s&&history.pushState({type:e},"","#"+e)});if(window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&t(e.state.type)}),s){var a=!o.length;a&&(o=n.video),o in n&&history.replaceState({type:o},"",a?"":"#"+o),o!==n.video&&t(o,!0)}}(),document.domain.indexOf("plyr.io")>-1&&(!function(e,t,i,n,o,s,r){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,s=t.createElement(i),r=t.getElementsByTagName(i)[0],s.async=1,s.src=n,r.parentNode.insertBefore(s,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-40881672-11","auto"),ga("send","pageview")); \ No newline at end of file +"document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var i,s=arguments.length;for(i=0;s>i;i++)e=arguments[i],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var i=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:i.call(this,e)}}e=null}():!function(e){"use strict";if("Element"in e){var t="classList",i="prototype",s=e.Element[i],o=Object,n=String[i].trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array[i].indexOf||function(e){for(var t=0,i=this.length;i>t;t++)if(t in this&&this[t]===e)return t;return-1},a=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},c=function(e,t){if(""===t)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},l=function(e){for(var t=n.call(e.getAttribute("class")||""),i=t?t.split(/\s+/):[],s=0,o=i.length;o>s;s++)this.push(i[s]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},u=l[i]=[],d=function(){return new l(this)};if(a[i]=Error[i],u.item=function(e){return this[e]||null},u.contains=function(e){return e+="",-1!==c(this,e)},u.add=function(){var e,t=arguments,i=0,s=t.length,o=!1;do e=t[i]+"",-1===c(this,e)&&(this.push(e),o=!0);while(++i=0;a--)e(i[a].parentElement,"active",!1);e(document.querySelector('[data-source="'+t+'"]').parentElement,"active",!0)}}for(var i=document.querySelectorAll("[data-source]"),s={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},o=window.location.hash.replace("#",""),n=window.history&&window.history.pushState,r=i.length-1;r>=0;r--)i[r].addEventListener("click",function(){var e=this.getAttribute("data-source");t(e),n&&history.pushState({type:e},"","#"+e)});if(window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&t(e.state.type)}),n){var a=!o.length;a&&(o=s.video),o in s&&history.replaceState({type:o},"",a?"":"#"+o),o!==s.video&&t(o,!0)}}(),document.domain.indexOf("plyr.io")>-1&&(!function(e,t,i,s,o,n,r){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,n=t.createElement(i),r=t.getElementsByTagName(i)[0],n.async=1,n.src=s,r.parentNode.insertBefore(n,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-40881672-11","auto"),ga("send","pageview")); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 24e0a4cc..1d469e83 100644 --- a/docs/index.html +++ b/docs/index.html @@ -74,47 +74,6 @@ - - - - diff --git a/docs/src/js/docs.js b/docs/src/js/docs.js index 11cd6ac6..08557f76 100644 --- a/docs/src/js/docs.js +++ b/docs/src/js/docs.js @@ -8,6 +8,7 @@ plyr.setup('.js-media-player', { debug: true, title: 'Video demo', + iconUrl: '../dist/plyr.svg', tooltips: { controls: true }, @@ -15,6 +16,7 @@ plyr.setup('.js-media-player', { defaultActive: true } }); +plyr.loadSprite('dist/docs.svg'); // General functions (function() { diff --git a/gulpfile.js b/gulpfile.js index 364012c4..99fcfedd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -264,6 +264,7 @@ gulp.task("cdn", function () { .pipe(rename(function (path) { path.dirname = path.dirname.replace(".", version); })) + .pipe(replace(localPath, versionPath)) .pipe(s3(aws.cdn, options.cdn)); }); @@ -279,9 +280,10 @@ gulp.task("docs", function () { // Replace versioned files in plyr.js gulp.src(path.join(root, "src/js/plyr.js")) .pipe(replace(semver, "v" + version)) + .pipe(replace(cdnpath, aws.cdn.bucket + "/" + version)) .pipe(gulp.dest(path.join(root, "src/js/"))); - // Replace local file paths with remote paths in docs + // Replace local file paths with remote paths in docs HTML // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" gulp.src([paths.docs.root + "*.html"]) .pipe(replace(localPath, versionPath)) diff --git a/package.json b/package.json index ec584066..b4e8fd7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plyr", - "version": "1.6.13", + "version": "1.6.14", "description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player", "homepage": "http://plyr.io", "main": "src/js/plyr.js", diff --git a/readme.md b/readme.md index 75a6a921..0cdd3316 100644 --- a/readme.md +++ b/readme.md @@ -40,7 +40,7 @@ If you have any cool ideas or features, please let me know by [creating an issue ## Implementation Check `docs/index.html` and `docs/dist/docs.js` for an example setup. -**Heads up:** the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.6.13/plyr.js` to `https://cdn.plyr.io/1.6.13/plyr.js` +**Heads up:** the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.6.14/plyr.js` to `https://cdn.plyr.io/1.6.14/plyr.js` ### npm @@ -71,11 +71,11 @@ More info is on [npm](https://www.npmjs.com/package/ember-cli-plyr) and [GitHub] If you want to use our CDN, you can use the following: ```html - - + + ``` -The SVG sprite/defs file can be found here: `https://cdn.plyr.io/1.6.13/plyr.svg`. +The SVG sprite/defs file can be found here: `https://cdn.plyr.io/1.6.14/plyr.svg`. ### CSS & Styling If you want to use the default css, add the `plyr.css` file from `/dist` into your head, or even better use `plyr.less` or `plyr.scss` file included in `/src` in your build to save a request. @@ -87,35 +87,10 @@ If you want to use the default css, add the `plyr.css` file from `/dist` into yo The default setup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options. Check out the source for more on this. ### SVG -The SVG sprite for the controls icons can be loaded two ways: -- By passing the *relative* path to the sprite as the `iconUrl` option; or -- Using AJAX, injecting the sprite into a hidden div. +The icons used in the Plyr controls are loaded in an SVG sprite. The icons can be used in your own SVG sprite build (see `/src/sprite` for source icons) or using the default settings which sprite from the CDN automatically for a hassle free setup. #### Using the `iconUrl` option -This method requires the SVG sprite to be hosted on the *same domain* as your page hosting the player. Currently no browser supports cross origin SVG sprites due to XSS issues. Fingers crossed this will come soon though. An example value for this option would be: -``` -/path/to/plyr.svg -``` - -#### Using AJAX -Using AJAX means you can load the sprite from a different origin. Avoiding the issues above. This is an example script to load an SVG sprite best added before the closing ``, before any other scripts. - -```html - -``` +You can however specify your own `iconUrl` option and Plyr will determine if the url is absolute and requires loading by AJAX/CORS due to current browser limitations or if it's a relative path, just use the path directly. If you're using the `` tag on your site, you may need to use something like this: [svgfixer.js](https://gist.github.com/leonderijke/c5cf7c5b2e424c0061d2) @@ -188,7 +163,7 @@ Be sure to [validate your caption files](https://quuz.org/webvtt/) Here's an example of a default setup: ```html - + ``` @@ -258,16 +233,22 @@ Options must be passed as an object to the `setup()` method as above or as JSON Used for internationalization (i18n) of the tooltips/labels within the buttons. - iconPrefix - String - plyr - Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG defs file but with the default controls. Most people can ignore this option. + loadSprite + Boolean + true + Load the SVG sprite specified as the iconUrl option (if a URL). If false, it is assumed you are handling sprite loading yourself. iconUrl String null - Specify a relative path to the SVG sprite, hosted on the *same domain* as the page the player is hosted on. Using this menthod means no requirement for the AJAX sprite loading script. See the SVG section for more info. + Specify a URL or path to the SVG sprite. See the SVG section for more info. + + + iconPrefix + String + plyr + Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG sprite but with the default controls. Most people can ignore this option. debug diff --git a/src/js/plyr.js b/src/js/plyr.js index b8e158e1..928f80ad 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1,6 +1,6 @@ // ========================================================================== // Plyr -// plyr.js v1.6.13 +// plyr.js v1.6.14 // https://github.com/selz/plyr // License: The MIT License (MIT) // ========================================================================== @@ -26,7 +26,7 @@ /*global YT,$f*/ // Globals - var fullscreen, api = {}; + var fullscreen; // Default config var defaults = { @@ -41,8 +41,9 @@ volumeStep: 1, duration: null, displayDuration: true, + loadSprite: true, iconPrefix: 'plyr', - iconUrl: '', + iconUrl: 'https://cdn.plyr.io/1.6.14/plyr.svg', clickToPlay: true, hideControls: true, showPosterOnEnd: false, @@ -657,11 +658,20 @@ } } + // Get icon URL + function _getIconUrl() { + return { + url: config.iconUrl, + external: (config.iconUrl.indexOf("http") === 0) + }; + } + // Build the default HTML function _buildControls() { // Create html array - var html = [], - iconPath = config.iconUrl + '#' + config.iconPrefix; + var html = [], + iconUrl = _getIconUrl(), + iconPath = (!iconUrl.external ? iconUrl.url : '') + '#' + config.iconPrefix; // Larger overlaid play button if (_inArray(config.controls, 'play-large')) { @@ -1162,6 +1172,20 @@ // Insert controls function _injectControls() { + // Sprite + if (config.loadSprite) { + var iconUrl = _getIconUrl(); + + // Only load external sprite using AJAX + if (iconUrl.external) { + _log('Loading external SVG sprite'); + loadSprite(iconUrl.url); + } + else { + _log('Sprite will be used inline'); + } + } + // Make a copy of the html var html = config.html; @@ -2432,7 +2456,7 @@ } } else { - show = false; + show = !_hasClass(plyr.container, config.classes.hideControls); } } @@ -2443,21 +2467,26 @@ if (show || plyr.media.paused) { _toggleClass(plyr.container, config.classes.hideControls, false); - // Always show controls when paused + // Always show controls when paused or if touch if (plyr.media.paused) { return; } + + // Delay for hiding on touch + if (plyr.browser.touch) { + delay = 3000; + } } - // If toggle is false or if we're playing (regardless of toggle), then - // set the timer to hide the controls + // If toggle is false or if we're playing (regardless of toggle), + // then set the timer to hide the controls if (!show || !plyr.media.paused) { plyr.timers.hover = window.setTimeout(function() { // If the mouse is over the controls (and not entering fullscreen), bail if (plyr.controls.active && !isEnterFullscreen) { return; } - + _toggleClass(plyr.container, config.classes.hideControls, true); }, delay); } @@ -2554,7 +2583,7 @@ } // Check for support - plyr.supported = api.supported(plyr.type); + plyr.supported = supported(plyr.type); // Create new markup switch(plyr.type) { @@ -2863,6 +2892,11 @@ // On click play, pause ore restart _on(wrapper, 'click', function() { + if (plyr.browser.touch && !plyr.media.paused) { + _toggleControls(true); + return; + } + if (plyr.media.paused) { _play(); } @@ -3000,7 +3034,7 @@ } // Check for support - plyr.supported = api.supported(plyr.type); + plyr.supported = supported(plyr.type); // Add style hook _toggleStyleHook(); @@ -3130,6 +3164,7 @@ toggleMute: _toggleMute, toggleCaptions: _toggleCaptions, toggleFullscreen: _toggleFullscreen, + toggleControls: _toggleControls, isFullscreen: function() { return plyr.isFullscreen || false; }, support: function(mimeType) { return _supportMime(plyr, mimeType); }, destroy: _destroy, @@ -3137,8 +3172,31 @@ }; } + // Load a sprite + function loadSprite(url) { + var x = new XMLHttpRequest(); + + // Check for CORS support + if ('withCredentials' in x) { + x.open('GET', url, true); + } + else { + return; + } + + // Inject hidden div with sprite on load + x.onload = function() { + var c = document.createElement('div'); + c.setAttribute('hidden', ''); + c.innerHTML = x.responseText; + document.body.insertBefore(c, document.body.childNodes[0]); + } + + x.send(); + } + // Check for support - api.supported = function(type) { + function supported(type) { var browser = _browserSniff(), oldIE = (browser.name === 'IE' && browser.version <= 9), iPhone = /iPhone|iPod/i.test(navigator.userAgent), @@ -3173,10 +3231,10 @@ basic: basic, full: full }; - }; + } - // Expose setup function - api.setup = function(elements, options) { + // Setup function + function setup(elements, options) { // Get the players var instances = []; @@ -3202,7 +3260,7 @@ // Bail if disabled or no basic support // You may want to disable certain UAs etc - if (!api.supported().basic || !elements.length) { + if (!supported().basic || !elements.length) { return false; } @@ -3236,9 +3294,13 @@ } return instances; - }; + } - return api; + return { + setup: setup, + supported: supported, + loadSprite: loadSprite + }; })); // Custom event polyfill