From 7c5f38311b3261a9cbdabff816240f6d737401b7 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 4 Apr 2015 12:51:24 +1100 Subject: [PATCH] Bug fixes for controls changes --- changelog.md | 4 ++++ dist/plyr.js | 2 +- docs/error.html | 2 +- docs/index.html | 10 +++++----- package.json | 2 +- readme.md | 8 ++++---- src/js/plyr.js | 34 +++++++++++++++++----------------- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/changelog.md b/changelog.md index 7c8adca4..ae0b2ff3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## v1.1.1 +- Fix for unsupported browser handling +- Fix for config.controls having no effect + ## v1.1.0 - Added config option to set which controls are shown (if using the default controls html) and better handling of missing controls diff --git a/dist/plyr.js b/dist/plyr.js index 82d19ec8..1815863c 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -1 +1 @@ -!function(e){"use strict";function t(e,t){w.debug&&window.console&&console[t?"error":"log"](e)}function n(){var e,t,n,r=navigator.userAgent,s=navigator.appName,a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(s="IE",a="11;"):-1!==(t=r.indexOf("MSIE"))?(s="IE",a=r.substring(t+5)):-1!==(t=r.indexOf("Chrome"))?(s="Chrome",a=r.substring(t+7)):-1!==(t=r.indexOf("Safari"))?(s="Safari",a=r.substring(t+7),-1!==(t=r.indexOf("Version"))&&(a=r.substring(t+8))):-1!==(t=r.indexOf("Firefox"))?(s="Firefox",a=r.substring(t+8)):(e=r.lastIndexOf(" ")+1)<(t=r.lastIndexOf("/"))&&(s=r.substring(e,t),a=r.substring(t+1),s.toLowerCase()==s.toUpperCase()&&(s=navigator.appName)),-1!==(n=a.indexOf(";"))&&(a=a.substring(0,n)),-1!==(n=a.indexOf(" "))&&(a=a.substring(0,n)),o=parseInt(""+a,10),isNaN(o)&&(a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10)),{name:s,version:o,ios:/(iPad|iPhone|iPod)/g.test(navigator.platform)}}function r(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 s(e,t){return-1!=e.indexOf(t)}function a(e,t,n){return e.replace(new RegExp(t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}function o(e,t){e.length||(e=[e]);for(var n=e.length-1;n>=0;n--){var r=n>0?t.cloneNode(!0):t,s=e[n],a=s.parentNode,o=s.nextSibling;r.appendChild(s),o?a.insertBefore(r,o):a.appendChild(r)}}function i(e){e.parentNode.removeChild(e)}function l(e,t){e.insertBefore(t,e.firstChild)}function c(e,t){for(var n in t)e.setAttribute(n,t[n])}function u(e,t,n){if(e)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=r+(n?" "+t:"")}}function p(e,t,n,r){if(t=t.split(" "),e instanceof NodeList)for(var s=0;sn;n++){if(e.prefix=t[n],"undefined"!=typeof document[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}if("undefined"!=typeof document.msExitFullscreen&&document.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}return"webkit"===e.prefix&&navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)&&(e.supportsFullScreen=!1),e.supportsFullScreen&&(e.fullScreenEventName="ms"==e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(){switch(this.prefix){case"":return document.fullScreen;case"webkit":return document.webkitIsFullScreen;case"ms":return null!==document.msFullscreenElement;default:return document[this.prefix+"FullScreen"]}},e.requestFullScreen=function(e){return""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"==this.prefix?"RequestFullscreen":"RequestFullScreen")]("webkit"===this.prefix?e.ALLOW_KEYBOARD_INPUT:null)},e.cancelFullScreen=function(){return""===this.prefix?document.cancelFullScreen():document[this.prefix+("ms"==this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?document.fullscreenElement:document[this.prefix+"FullscreenElement"]}),e}function h(){var e={supported:function(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}()};return e}function k(s){function p(e){if(!nt.usingTextTracks&&"video"===nt.type&&nt.supported.full){for(nt.subcount=0,e="number"==typeof e?e:nt.media.currentTime;k(nt.captions[nt.subcount][0])nt.captions.length-1){nt.subcount=nt.captions.length-1;break}nt.media.currentTime.toFixed(1)>=g(nt.captions[nt.subcount][0])&&nt.media.currentTime.toFixed(1)<=k(nt.captions[nt.subcount][0])?(nt.currentCaption=nt.captions[nt.subcount][1],nt.captionsContainer.innerHTML=nt.currentCaption):nt.captionsContainer.innerHTML=""}}function m(){nt.buttons.captions&&(u(nt.container,w.classes.captions.enabled,!0),w.captions.defaultActive&&(u(nt.container,w.classes.captions.active,!0),nt.buttons.captions.checked=!0))}function g(e){var t=[];return t=e.split(" --> "),T(t[0])}function k(e){var t=[];return t=e.split(" --> "),T(t[1])}function T(e){if(null===e||void 0===e)return 0;var t,n=[],r=[];return n=e.split(","),r=n[0].split(":"),t=Math.floor(60*r[0]*60)+Math.floor(60*r[1])+Math.floor(r[2])}function S(e){return nt.container.querySelectorAll(e)}function F(e){return S(e)[0]}function C(){try{return window.self!==window.top}catch(e){return!0}}function E(){if(t("Injecting custom controls."),w.html&&(w.html=a(w.html,"{seektime}",w.seekTime),w.html=a(w.html,"{id}",nt.random),nt.container.insertAdjacentHTML("beforeend",w.html),w.tooltips))for(var e=S(w.selectors.labels),n=e.length-1;n>=0;n--){var r=e[n];u(r,w.classes.hidden,!1),u(r,w.classes.tooltip,!0)}}function A(){try{return nt.controls=F(w.selectors.controls),nt.buttons={},nt.buttons.seek=F(w.selectors.buttons.seek),nt.buttons.play=F(w.selectors.buttons.play),nt.buttons.pause=F(w.selectors.buttons.pause),nt.buttons.restart=F(w.selectors.buttons.restart),nt.buttons.rewind=F(w.selectors.buttons.rewind),nt.buttons.forward=F(w.selectors.buttons.forward),nt.buttons.fullscreen=F(w.selectors.buttons.fullscreen),nt.buttons.mute=F(w.selectors.buttons.mute),nt.buttons.captions=F(w.selectors.buttons.captions),nt.checkboxes=S("[type='checkbox']"),nt.progress={},nt.progress.container=F(w.selectors.progress.container),nt.progress.buffer={},nt.progress.buffer.bar=F(w.selectors.progress.buffer),nt.progress.buffer.text=nt.progress.buffer.bar&&nt.progress.buffer.bar.getElementsByTagName("span")[0],nt.progress.played={},nt.progress.played.bar=F(w.selectors.progress.played),nt.progress.played.text=nt.progress.played.bar&&nt.progress.played.bar.getElementsByTagName("span")[0],nt.volume=F(w.selectors.buttons.volume),nt.duration=F(w.selectors.duration),nt.currentTime=F(w.selectors.currentTime),nt.seekTime=S(w.selectors.seekTime),!0}catch(e){return t("It looks like there's a problem with your controls html. Bailing.",!0),nt.media.setAttribute("controls",""),!1}}function N(){if(nt.buttons.play){var e=nt.buttons.play.innerText||"Play";"undefined"!=typeof w.title&&w.title.length&&(e+=", "+w.title),nt.buttons.play.setAttribute("aria-label",e)}}function P(){if(!nt.media)return t("No audio or video element found!",!0),!1;if(nt.supported.full&&(nt.media.removeAttribute("controls"),u(nt.container,w.classes[nt.type],!0),u(nt.container,w.classes.stopped,null===nt.media.getAttribute("autoplay")),nt.browser.ios&&u(nt.container,"ios",!0),"video"===nt.type)){var e=document.createElement("div");e.setAttribute("class",w.classes.videoWrapper),o(nt.media,e),nt.videoContainer=e}null!==nt.media.getAttribute("autoplay")&&L()}function I(){if("video"===nt.type){nt.videoContainer.insertAdjacentHTML("afterbegin","
"),nt.captionsContainer=F(w.selectors.captions),nt.usingTextTracks=!1,nt.media.textTracks&&(nt.usingTextTracks=!0);for(var e,n="",r=nt.media.childNodes,s=0;s=31||"Safari"===nt.browser.name&&nt.browser.version>=7)&&(t("Detected IE 10/11 or Firefox 31+ or Safari 7+."),nt.usingTextTracks=!1),nt.usingTextTracks){t("TextTracks supported.");for(var i=0;i=7){t("Safari 7+ detected; removing track from DOM."),a=nt.media.getElementsByTagName("track");for(var p=0;pn?n=0:n>nt.media.duration&&(n=nt.media.duration);try{nt.media.currentTime=n.toFixed(1)}catch(r){}t("Seeking to "+nt.media.currentTime+" seconds"),p(n)}function R(){u(nt.container,w.classes.playing,!nt.media.paused),u(nt.container,w.classes.stopped,nt.media.paused)}function j(e){var t=x.supportsFullScreen;e&&e.type===x.fullScreenEventName?w.fullscreen.active=x.isFullScreen():t?(x.isFullScreen()?x.cancelFullScreen():x.requestFullScreen(nt.container),w.fullscreen.active=x.isFullScreen()):(w.fullscreen.active=!w.fullscreen.active,w.fullscreen.active?(d(document,"keyup",B),document.body.style.overflow="hidden"):(f(document,"keyup",B),document.body.style.overflow="")),u(nt.container,w.classes.fullscreen.active,w.fullscreen.active)}function B(e){27===(e.which||e.charCode||e.keyCode)&&w.fullscreen.active&&j()}function D(e){nt.volume&&("undefined"==typeof e&&(e=w.storage.enabled&&h().supported?window.localStorage[w.storage.key]||w.volume:w.volume),e>10&&(e=10),nt.supported.full&&(nt.volume.value=e),nt.media.volume=parseFloat(e/10),U(),w.storage.enabled&&h().supported&&(window.localStorage.plyr_volume=e))}function W(e){"undefined"==typeof e&&(e=!nt.media.muted),nt.supported.full&&(nt.buttons.mute.checked=e),nt.media.muted=e,U()}function _(e){nt.supported.full&&nt.buttons.captions&&("undefined"==typeof e&&(e=-1===nt.container.className.indexOf(w.classes.captions.active),nt.buttons.captions.checked=e),u(nt.container,w.classes.captions.active,e))}function U(){u(nt.container,w.classes.muted,0===nt.media.volume||nt.media.muted)}function X(e){var t="waiting"===e.type;clearTimeout(nt.loadingTimer),nt.loadingTimer=setTimeout(function(){u(nt.container,w.classes.loading,t)},t?250:0)}function J(e){var t=nt.progress.played.bar,n=nt.progress.played.text,r=0;if(e)switch(e.type){case"timeupdate":case"seeking":r=v(nt.media.currentTime,nt.media.duration),"timeupdate"==e.type&&nt.buttons.seek&&(nt.buttons.seek.value=r);break;case"change":case"input":r=e.target.value;break;case"playing":case"progress":t=nt.progress.buffer.bar,n=nt.progress.buffer.text,r=function(){var e=nt.media.buffered;return e.length?v(e.end(0),nt.media.duration):0}()}t&&(t.value=r),n&&(n.innerHTML=r)}function $(e,t){if(t){nt.secs=parseInt(e%60),nt.mins=parseInt(e/60%60),nt.hours=parseInt(e/60/60%60);var n=parseInt(nt.media.duration/60/60%60)>0;nt.secs=("0"+nt.secs).slice(-2),nt.mins=("0"+nt.mins).slice(-2),t.innerHTML=(n?nt.hours+":":"")+nt.mins+":"+nt.secs}}function z(){var e=nt.media.duration||0;!nt.duration&&w.displayDuration&&nt.media.paused&&$(e,nt.currentTime),nt.duration&&$(e,nt.duration)}function K(e){$(nt.media.currentTime,nt.currentTime),J(e)}function Y(){for(var e=nt.media.querySelectorAll("source"),t=e.length-1;t>=0;t--)i(e[t]);nt.media.removeAttribute("src")}function G(e){if(e.src){var t=document.createElement("source");c(t,e),l(nt.media,t)}}function Q(e){if(O(),V(),Y(),"string"==typeof e)nt.media.setAttribute("src",e);else if(e.constructor===Array)for(var t in e)G(e[t]);nt.supported.full&&(K(),R()),nt.media.load(),null!==nt.media.getAttribute("autoplay")&&L()}function Z(e){"video"===nt.type&&nt.media.setAttribute("poster",e)}function et(){d(nt.buttons.play,"click",function(){L(),setTimeout(function(){nt.buttons.pause.focus()},100)}),d(nt.buttons.pause,"click",function(){O(),setTimeout(function(){nt.buttons.play.focus()},100)}),d(nt.buttons.restart,"click",V),d(nt.buttons.rewind,"click",q),d(nt.buttons.forward,"click",H),d(nt.volume,"change input",function(){D(this.value)}),d(nt.buttons.mute,"change",function(){W(this.checked)}),d(nt.buttons.fullscreen,"click",j),x.supportsFullScreen&&d(document,x.fullScreenEventName,j),d(nt.media,"timeupdate seeking",K),d(nt.media,"timeupdate",p),d(nt.media,"loadedmetadata",z),d(nt.buttons.seek,"change input",V),d(nt.buttons.captions,"change",function(){_(this.checked)}),d(nt.media,"ended",function(){"video"===nt.type&&(nt.captionsContainer.innerHTML=""),R()}),d(nt.media,"progress",J),d(nt.media,"playing",J),d(nt.media,"volumechange",U),d(nt.media,"play pause",R),d(nt.media,"waiting canplay seeked",X),d(nt.checkboxes,"keyup",y),"video"===nt.type&&w.click&&d(nt.videoContainer,"click",function(){nt.media.paused?L():nt.media.ended?(V(),L()):O()}),w.fullscreen.hideControls&&d(nt.controls,"mouseenter mouseleave",function(e){u(nt.controls,w.classes.hover,"mouseenter"===e.type)})}function tt(){if(x=b(),nt.browser=n(),nt.media=nt.container.querySelectorAll("audio, video")[0],nt.type=nt.media.tagName.toLowerCase(),nt.supported=e.supported(nt.type),!nt.supported.basic)return!1;if(t(nt.browser.name+" "+nt.browser.version),P(),nt.random=Math.floor(1e4*Math.random()),nt.supported.full){if(E(),!A())return!1;w.displayDuration&&z(),N(),I(),D(),M(),et()}return!0}var nt=this;return nt.container=s,tt()?{media:nt.media,play:L,pause:O,restart:V,rewind:q,forward:H,seek:V,setVolume:D,toggleMute:W,toggleCaptions:_,source:Q,poster:Z,support:function(e){return r(nt,e)}}:{}}var x,w,T={enabled:!0,debug:!1,seekTime:10,volume:5,click:!0,tooltips:!1,displayDuration:!0,selectors:{container:".player",controls:".player-controls",labels:"[data-player] .sr-only, label .sr-only",buttons:{seek:"[data-player='seek']",play:"[data-player='play']",pause:"[data-player='pause']",restart:"[data-player='restart']",rewind:"[data-player='rewind']",forward:"[data-player='fast-forward']",mute:"[data-player='mute']",volume:"[data-player='volume']",captions:"[data-player='captions']",fullscreen:"[data-player='fullscreen']"},progress:{container:".player-progress",buffer:".player-progress-buffer",played:".player-progress-played"},captions:".player-captions",currentTime:".player-current-time",duration:".player-duration"},classes:{video:"player-video",videoWrapper:"player-video-wrapper",audio:"player-audio",stopped:"stopped",playing:"playing",muted:"muted",loading:"loading",tooltip:"player-tooltip",hidden:"sr-only",hover:"hover",captions:{enabled:"captions-enabled",active:"captions-active"},fullscreen:{enabled:"fullscreen-enabled",active:"fullscreen-active",hideControls:"fullscreen-hide-controls"}},captions:{defaultActive:!1},fullscreen:{enabled:!0,fallback:!0,hideControls:!0},storage:{enabled:!0,key:"plyr_volume"},controls:["restart","rewind","play","fast-forward","current-time","duration","mute","volume","captions","fullscreen"]};T.html=function(){var e=["
","
","","","","0% played","","","0% buffered","","
",""];return s(T.controls,"restart")&&e.push(""),s(T.controls,"rewind")&&e.push(""),s(T.controls,"play")&&e.push("",""),s(T.controls,"fast-forward")&&e.push(""),s(T.controls,"current-time")&&e.push("","Current time","00:00",""),s(T.controls,"duration")&&e.push("","Duration","00:00",""),e.push("",""),s(T.controls,"mute")&&e.push("",""),s(T.controls,"volume")&&e.push("",""),s(T.controls,"captions")&&e.push("",""),s(T.controls,"fullscreen")&&e.push(""),e.push("","
"),e.join("")}(),e.supported=function(e){var t,r,s=n(),a="IE"===s.name&&s.version<=9,o=/iPhone|iPod/i.test(navigator.userAgent),i=!!document.createElement("audio").canPlayType,l=!!document.createElement("video").canPlayType;switch(e){case"video":t=l,r=t&&!a&&!o;break;case"audio":t=i,r=t&&!a;break;default:t=i&&l,r=t&&!a}return{basic:t,full:r}},e.setup=function(t){if(w=g(T,t),!w.enabled||!e.supported().basic)return!1;for(var n=document.querySelectorAll(w.selectors.container),r=[],s=n.length-1;s>=0;s--){var a=n[s];if("undefined"==typeof a.plyr){var o=new k(a);a.plyr=Object.keys(o).length?o:!1}r.push(a.plyr)}return r}}(this.plyr=this.plyr||{}); \ No newline at end of file +!function(e){"use strict";function t(){var e=["
","
","","","","0% played","","","0% buffered","","
",""];return a(T.controls,"restart")&&e.push(""),a(T.controls,"rewind")&&e.push(""),a(T.controls,"play")&&e.push("",""),a(T.controls,"fast-forward")&&e.push(""),a(T.controls,"current-time")&&e.push("","Current time","00:00",""),a(T.controls,"duration")&&e.push("","Duration","00:00",""),e.push("",""),a(T.controls,"mute")&&e.push("",""),a(T.controls,"volume")&&e.push("",""),a(T.controls,"captions")&&e.push("",""),a(T.controls,"fullscreen")&&e.push(""),e.push("","
"),e.join("")}function n(e,t){T.debug&&window.console&&console[t?"error":"log"](e)}function r(){var e,t,n,r=navigator.userAgent,s=navigator.appName,a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(s="IE",a="11;"):-1!==(t=r.indexOf("MSIE"))?(s="IE",a=r.substring(t+5)):-1!==(t=r.indexOf("Chrome"))?(s="Chrome",a=r.substring(t+7)):-1!==(t=r.indexOf("Safari"))?(s="Safari",a=r.substring(t+7),-1!==(t=r.indexOf("Version"))&&(a=r.substring(t+8))):-1!==(t=r.indexOf("Firefox"))?(s="Firefox",a=r.substring(t+8)):(e=r.lastIndexOf(" ")+1)<(t=r.lastIndexOf("/"))&&(s=r.substring(e,t),a=r.substring(t+1),s.toLowerCase()==s.toUpperCase()&&(s=navigator.appName)),-1!==(n=a.indexOf(";"))&&(a=a.substring(0,n)),-1!==(n=a.indexOf(" "))&&(a=a.substring(0,n)),o=parseInt(""+a,10),isNaN(o)&&(a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10)),{name:s,version:o,ios:/(iPad|iPhone|iPod)/g.test(navigator.platform)}}function s(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 a(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 r=n>0?t.cloneNode(!0):t,s=e[n],a=s.parentNode,o=s.nextSibling;r.appendChild(s),o?a.insertBefore(r,o):a.appendChild(r)}}function l(e){e.parentNode.removeChild(e)}function c(e,t){e.insertBefore(t,e.firstChild)}function u(e,t){for(var n in t)e.setAttribute(n,t[n])}function p(e,t,n){if(e)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=r+(n?" "+t:"")}}function d(e,t,n,r){if(t=t.split(" "),e instanceof NodeList)for(var s=0;sn;n++){if(e.prefix=t[n],"undefined"!=typeof document[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}if("undefined"!=typeof document.msExitFullscreen&&document.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}return"webkit"===e.prefix&&navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)&&(e.supportsFullScreen=!1),e.supportsFullScreen&&(e.fullScreenEventName="ms"==e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(){switch(this.prefix){case"":return document.fullScreen;case"webkit":return document.webkitIsFullScreen;case"ms":return null!==document.msFullscreenElement;default:return document[this.prefix+"FullScreen"]}},e.requestFullScreen=function(e){return""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"==this.prefix?"RequestFullscreen":"RequestFullScreen")]("webkit"===this.prefix?e.ALLOW_KEYBOARD_INPUT:null)},e.cancelFullScreen=function(){return""===this.prefix?document.cancelFullScreen():document[this.prefix+("ms"==this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?document.fullscreenElement:document[this.prefix+"FullscreenElement"]}),e}function k(){var e={supported:function(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}()};return e}function x(a){function d(e){if(!rt.usingTextTracks&&"video"===rt.type&&rt.supported.full){for(rt.subcount=0,e="number"==typeof e?e:rt.media.currentTime;x(rt.captions[rt.subcount][0])rt.captions.length-1){rt.subcount=rt.captions.length-1;break}rt.media.currentTime.toFixed(1)>=b(rt.captions[rt.subcount][0])&&rt.media.currentTime.toFixed(1)<=x(rt.captions[rt.subcount][0])?(rt.currentCaption=rt.captions[rt.subcount][1],rt.captionsContainer.innerHTML=rt.currentCaption):rt.captionsContainer.innerHTML=""}}function y(){rt.buttons.captions&&(p(rt.container,T.classes.captions.enabled,!0),T.captions.defaultActive&&(p(rt.container,T.classes.captions.active,!0),rt.buttons.captions.checked=!0))}function b(e){var t=[];return t=e.split(" --> "),S(t[0])}function x(e){var t=[];return t=e.split(" --> "),S(t[1])}function S(e){if(null===e||void 0===e)return 0;var t,n=[],r=[];return n=e.split(","),r=n[0].split(":"),t=Math.floor(60*r[0]*60)+Math.floor(60*r[1])+Math.floor(r[2])}function F(e){return rt.container.querySelectorAll(e)}function C(e){return F(e)[0]}function E(){try{return window.self!==window.top}catch(e){return!0}}function A(){if(n("Injecting custom controls."),T.html||(T.html=t()),T.html=o(T.html,"{seektime}",T.seekTime),T.html=o(T.html,"{id}",rt.random),rt.container.insertAdjacentHTML("beforeend",T.html),T.tooltips)for(var e=F(T.selectors.labels),r=e.length-1;r>=0;r--){var s=e[r];p(s,T.classes.hidden,!1),p(s,T.classes.tooltip,!0)}}function N(){try{return rt.controls=C(T.selectors.controls),rt.buttons={},rt.buttons.seek=C(T.selectors.buttons.seek),rt.buttons.play=C(T.selectors.buttons.play),rt.buttons.pause=C(T.selectors.buttons.pause),rt.buttons.restart=C(T.selectors.buttons.restart),rt.buttons.rewind=C(T.selectors.buttons.rewind),rt.buttons.forward=C(T.selectors.buttons.forward),rt.buttons.fullscreen=C(T.selectors.buttons.fullscreen),rt.buttons.mute=C(T.selectors.buttons.mute),rt.buttons.captions=C(T.selectors.buttons.captions),rt.checkboxes=F("[type='checkbox']"),rt.progress={},rt.progress.container=C(T.selectors.progress.container),rt.progress.buffer={},rt.progress.buffer.bar=C(T.selectors.progress.buffer),rt.progress.buffer.text=rt.progress.buffer.bar&&rt.progress.buffer.bar.getElementsByTagName("span")[0],rt.progress.played={},rt.progress.played.bar=C(T.selectors.progress.played),rt.progress.played.text=rt.progress.played.bar&&rt.progress.played.bar.getElementsByTagName("span")[0],rt.volume=C(T.selectors.buttons.volume),rt.duration=C(T.selectors.duration),rt.currentTime=C(T.selectors.currentTime),rt.seekTime=F(T.selectors.seekTime),!0}catch(e){return n("It looks like there's a problem with your controls html. Bailing.",!0),rt.media.setAttribute("controls",""),!1}}function P(){if(rt.buttons.play){var e=rt.buttons.play.innerText||"Play";"undefined"!=typeof T.title&&T.title.length&&(e+=", "+T.title),rt.buttons.play.setAttribute("aria-label",e)}}function I(){if(!rt.media)return n("No audio or video element found!",!0),!1;if(rt.supported.full&&(rt.media.removeAttribute("controls"),p(rt.container,T.classes[rt.type],!0),p(rt.container,T.classes.stopped,null===rt.media.getAttribute("autoplay")),rt.browser.ios&&p(rt.container,"ios",!0),"video"===rt.type)){var e=document.createElement("div");e.setAttribute("class",T.classes.videoWrapper),i(rt.media,e),rt.videoContainer=e}null!==rt.media.getAttribute("autoplay")&&O()}function M(){if("video"===rt.type){rt.videoContainer.insertAdjacentHTML("afterbegin","
"),rt.captionsContainer=C(T.selectors.captions),rt.usingTextTracks=!1,rt.media.textTracks&&(rt.usingTextTracks=!0);for(var e,t="",r=rt.media.childNodes,s=0;s=31||"Safari"===rt.browser.name&&rt.browser.version>=7)&&(n("Detected IE 10/11 or Firefox 31+ or Safari 7+."),rt.usingTextTracks=!1),rt.usingTextTracks){n("TextTracks supported.");for(var i=0;i=7){n("Safari 7+ detected; removing track from DOM."),a=rt.media.getElementsByTagName("track");for(var u=0;ut?t=0:t>rt.media.duration&&(t=rt.media.duration);try{rt.media.currentTime=t.toFixed(1)}catch(r){}n("Seeking to "+rt.media.currentTime+" seconds"),d(t)}function j(){p(rt.container,T.classes.playing,!rt.media.paused),p(rt.container,T.classes.stopped,rt.media.paused)}function B(e){var t=w.supportsFullScreen;e&&e.type===w.fullScreenEventName?T.fullscreen.active=w.isFullScreen():t?(w.isFullScreen()?w.cancelFullScreen():w.requestFullScreen(rt.container),T.fullscreen.active=w.isFullScreen()):(T.fullscreen.active=!T.fullscreen.active,T.fullscreen.active?(f(document,"keyup",D),document.body.style.overflow="hidden"):(m(document,"keyup",D),document.body.style.overflow="")),p(rt.container,T.classes.fullscreen.active,T.fullscreen.active)}function D(e){27===(e.which||e.charCode||e.keyCode)&&T.fullscreen.active&&B()}function W(e){rt.volume&&("undefined"==typeof e&&(e=T.storage.enabled&&k().supported?window.localStorage[T.storage.key]||T.volume:T.volume),e>10&&(e=10),rt.supported.full&&(rt.volume.value=e),rt.media.volume=parseFloat(e/10),X(),T.storage.enabled&&k().supported&&(window.localStorage.plyr_volume=e))}function _(e){"undefined"==typeof e&&(e=!rt.media.muted),rt.supported.full&&(rt.buttons.mute.checked=e),rt.media.muted=e,X()}function U(e){rt.supported.full&&rt.buttons.captions&&("undefined"==typeof e&&(e=-1===rt.container.className.indexOf(T.classes.captions.active),rt.buttons.captions.checked=e),p(rt.container,T.classes.captions.active,e))}function X(){p(rt.container,T.classes.muted,0===rt.media.volume||rt.media.muted)}function J(e){var t="waiting"===e.type;clearTimeout(rt.loadingTimer),rt.loadingTimer=setTimeout(function(){p(rt.container,T.classes.loading,t)},t?250:0)}function $(e){var t=rt.progress.played.bar,n=rt.progress.played.text,r=0;if(e)switch(e.type){case"timeupdate":case"seeking":r=g(rt.media.currentTime,rt.media.duration),"timeupdate"==e.type&&rt.buttons.seek&&(rt.buttons.seek.value=r);break;case"change":case"input":r=e.target.value;break;case"playing":case"progress":t=rt.progress.buffer.bar,n=rt.progress.buffer.text,r=function(){var e=rt.media.buffered;return e.length?g(e.end(0),rt.media.duration):0}()}t&&(t.value=r),n&&(n.innerHTML=r)}function z(e,t){if(t){rt.secs=parseInt(e%60),rt.mins=parseInt(e/60%60),rt.hours=parseInt(e/60/60%60);var n=parseInt(rt.media.duration/60/60%60)>0;rt.secs=("0"+rt.secs).slice(-2),rt.mins=("0"+rt.mins).slice(-2),t.innerHTML=(n?rt.hours+":":"")+rt.mins+":"+rt.secs}}function K(){var e=rt.media.duration||0;!rt.duration&&T.displayDuration&&rt.media.paused&&z(e,rt.currentTime),rt.duration&&z(e,rt.duration)}function Y(e){z(rt.media.currentTime,rt.currentTime),$(e)}function G(){for(var e=rt.media.querySelectorAll("source"),t=e.length-1;t>=0;t--)l(e[t]);rt.media.removeAttribute("src")}function Q(e){if(e.src){var t=document.createElement("source");u(t,e),c(rt.media,t)}}function Z(e){if(q(),R(),G(),"string"==typeof e)rt.media.setAttribute("src",e);else if(e.constructor===Array)for(var t in e)Q(e[t]);rt.supported.full&&(Y(),j()),rt.media.load(),null!==rt.media.getAttribute("autoplay")&&O()}function et(e){"video"===rt.type&&rt.media.setAttribute("poster",e)}function tt(){f(rt.buttons.play,"click",function(){O(),setTimeout(function(){rt.buttons.pause.focus()},100)}),f(rt.buttons.pause,"click",function(){q(),setTimeout(function(){rt.buttons.play.focus()},100)}),f(rt.buttons.restart,"click",R),f(rt.buttons.rewind,"click",H),f(rt.buttons.forward,"click",V),f(rt.volume,"change input",function(){W(this.value)}),f(rt.buttons.mute,"change",function(){_(this.checked)}),f(rt.buttons.fullscreen,"click",B),w.supportsFullScreen&&f(document,w.fullScreenEventName,B),f(rt.media,"timeupdate seeking",Y),f(rt.media,"timeupdate",d),f(rt.media,"loadedmetadata",K),f(rt.buttons.seek,"change input",R),f(rt.buttons.captions,"change",function(){U(this.checked)}),f(rt.media,"ended",function(){"video"===rt.type&&(rt.captionsContainer.innerHTML=""),j()}),f(rt.media,"progress",$),f(rt.media,"playing",$),f(rt.media,"volumechange",X),f(rt.media,"play pause",j),f(rt.media,"waiting canplay seeked",J),f(rt.checkboxes,"keyup",v),"video"===rt.type&&T.click&&f(rt.videoContainer,"click",function(){rt.media.paused?O():rt.media.ended?(R(),O()):q()}),T.fullscreen.hideControls&&f(rt.controls,"mouseenter mouseleave",function(e){p(rt.controls,T.classes.hover,"mouseenter"===e.type)})}function nt(){if(w=h(),rt.browser=r(),rt.media=rt.container.querySelectorAll("audio, video")[0],rt.type=rt.media.tagName.toLowerCase(),rt.supported=e.supported(rt.type),!rt.supported.basic)return!1;if(n(rt.browser.name+" "+rt.browser.version),I(),rt.random=Math.floor(1e4*Math.random()),rt.supported.full){if(A(),!N())return!1;T.displayDuration&&K(),P(),M(),W(),L(),tt()}return!0}var rt=this;return rt.container=a,nt()?{media:rt.media,play:O,pause:q,restart:R,rewind:H,forward:V,seek:R,setVolume:W,toggleMute:_,toggleCaptions:U,source:Z,poster:et,support:function(e){return s(rt,e)}}:{}}var w,T,S={enabled:!0,debug:!1,seekTime:10,volume:5,click:!0,tooltips:!1,displayDuration:!0,selectors:{container:".player",controls:".player-controls",labels:"[data-player] .sr-only, label .sr-only",buttons:{seek:"[data-player='seek']",play:"[data-player='play']",pause:"[data-player='pause']",restart:"[data-player='restart']",rewind:"[data-player='rewind']",forward:"[data-player='fast-forward']",mute:"[data-player='mute']",volume:"[data-player='volume']",captions:"[data-player='captions']",fullscreen:"[data-player='fullscreen']"},progress:{container:".player-progress",buffer:".player-progress-buffer",played:".player-progress-played"},captions:".player-captions",currentTime:".player-current-time",duration:".player-duration"},classes:{video:"player-video",videoWrapper:"player-video-wrapper",audio:"player-audio",stopped:"stopped",playing:"playing",muted:"muted",loading:"loading",tooltip:"player-tooltip",hidden:"sr-only",hover:"hover",captions:{enabled:"captions-enabled",active:"captions-active"},fullscreen:{enabled:"fullscreen-enabled",active:"fullscreen-active",hideControls:"fullscreen-hide-controls"}},captions:{defaultActive:!1},fullscreen:{enabled:!0,fallback:!0,hideControls:!0},storage:{enabled:!0,key:"plyr_volume"},controls:["restart","rewind","play","fast-forward","current-time","duration","mute","volume","captions","fullscreen"]};e.supported=function(e){var t,n,s=r(),a="IE"===s.name&&s.version<=9,o=/iPhone|iPod/i.test(navigator.userAgent),i=!!document.createElement("audio").canPlayType,l=!!document.createElement("video").canPlayType;switch(e){case"video":t=l,n=t&&!a&&!o;break;case"audio":t=i,n=t&&!a;break;default:t=i&&l,n=t&&!a}return{basic:t,full:n}},e.setup=function(t){if(T=b(S,t),!T.enabled||!e.supported().basic)return!1;for(var n=document.querySelectorAll(T.selectors.container),r=[],s=n.length-1;s>=0;s--){var a=n[s];if("undefined"==typeof a.plyr){var o=new x(a);a.plyr=Object.keys(o).length?o:!1}r.push(a.plyr)}return r}}(this.plyr=this.plyr||{}); \ No newline at end of file diff --git a/docs/error.html b/docs/error.html index 93d02829..acac1c9c 100644 --- a/docs/error.html +++ b/docs/error.html @@ -6,7 +6,7 @@ - +
diff --git a/docs/index.html b/docs/index.html index 1ec375c8..88a31fb0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -8,10 +8,10 @@ - + - +
@@ -83,13 +83,13 @@ b.insertBefore(c, b.childNodes[0]); } } - })(document, "https://cdn.plyr.io/1.1.0/sprite.svg"); + })(document, "https://cdn.plyr.io/1.1.1/sprite.svg"); - + - + \ No newline at end of file diff --git a/package.json b/package.json index 56fc10e0..3deb776a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plyr", - "version": "1.1.0", + "version": "1.1.1", "description": "A simple HTML5 media player using custom controls", "homepage": "http://plyr.io", "main": "gulpfile.js", diff --git a/readme.md b/readme.md index c50a6030..d1ae48b4 100644 --- a/readme.md +++ b/readme.md @@ -38,7 +38,7 @@ If you have any cool ideas or features, please let me know by [creating an issue 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.1.0/plyr.js` to `https://cdn.plyr.io/1.1.0/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.1.1/plyr.js` to `https://cdn.plyr.io/1.1.1/plyr.js` ### Bower If bower is your thang, you can grab Plyr using: @@ -51,11 +51,11 @@ More info on setting up dependencies can be found in the [Bower Docs](http://bow If you want to use our CDN, you can use the following. HTTPS (SSL) is supported. ```html - - + + ``` -You can also access the `sprite.svg` file at `//cdn.plyr.io/1.1.0/sprite.svg`. +You can also access the `sprite.svg` file at `//cdn.plyr.io/1.1.1/sprite.svg`. ### CSS 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.sass` file included in `/src` in your build to save a request. diff --git a/src/js/plyr.js b/src/js/plyr.js index 8b995303..b8b2f17d 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1,6 +1,6 @@ // ========================================================================== // Plyr -// plyr.js v1.1.0 +// plyr.js v1.1.1 // https://github.com/selz/plyr // License: The MIT License (MIT) // ========================================================================== @@ -84,7 +84,7 @@ }; // Build the default HTML - defaults.html = (function() { + function _buildControls() { // Open and add the progress and seek elements var html = [ "
", @@ -101,7 +101,7 @@ ""]; // Restart button - if(_inArray(defaults.controls, "restart")) { + if(_inArray(config.controls, "restart")) { html.push( "