diff --git a/README.markdown b/README.markdown index 2a065ca..48a3c51 100644 --- a/README.markdown +++ b/README.markdown @@ -1,7 +1,7 @@ Captionator =========== -**Simple closed-captioning polyfill for HTML5. Less than 5KB when gzipped!** +**Simple closed-captioning polyfill for HTML5. Just 5KB when gzipped!** **Implements WHATWG TimedTextTrack Specification! Works in Firefox 3.5+, IE9, Safari 4+, Chrome, Opera 11... basically any browser which supports HTML5 Video!** diff --git a/js/captionator-min.js b/js/captionator-min.js index 24f9f80..6907ac1 100644 --- a/js/captionator-min.js +++ b/js/captionator-min.js @@ -6,38 +6,39 @@ https://github.com/cgiffard/Captionator */ -var captionator={createDOMException:function(a,g,d){try{document.querySelectorAll("div/[]")}catch(e){var c=function(h,b,a){this.code=h;this.message=b;this.name=a};c.prototype=e;return new c(a,g,d)}},captionify:function(a,g,d){var e=[],c=0,d=d instanceof Object?d:{};if(HTMLVideoElement){if(typeof document.createElement("video").addTrack==="function")return!1}else return!1;captionator.TextTrack=function(h,b,a,d,e,c){this.onload=function(){};this.onerror=function(){};this.oncuechange=function(){};this.id= -h||"";this.internalMode=captionator.TextTrack.OFF;this.cues=new captionator.TextTrackCueList(this);this.activeCues=new captionator.ActiveTextTrackCueList(this.cues);this.kind=b||"subtitles";this.label=a||"";this.language=d||"";this.src=e||"";this.readyState=captionator.TextTrack.NONE;this.internalDefault=c||!1;this.getMode=function(){return this.internalMode};this.setMode=function(b){var a;if([captionator.TextTrack.OFF,captionator.TextTrack.HIDDEN,captionator.TextTrack.SHOWING].indexOf(b)!==-1){if(b!== -this.internalMode){this.internalMode=b;this.readyState===captionator.TextTrack.NONE&&this.src.length>0&&b>captionator.TextTrack.OFF&&this.loadTrack(this.src,null);this.readyState===captionator.TextTrack.LOADED&&captionator.rebuildCaptions(this.videoNode);if(b===captionator.TextTrack.OFF||b===captionator.TextTrack.HIDDEN)a="captionator-"+this.videoNode.id+"-"+this.kind+"-"+this.language,(a=document.getElementById(a))&&a.parentNode.removeChild(a);if(b===captionator.TextTrack.OFF)this.cues.length=0, -this.readyState=captionator.TextTrack.NONE}}else throw Error("Illegal mode value for track: "+b);};this.getDefault=function(){return this.internalDefault};Object.prototype.__defineGetter__?(this.__defineGetter__("mode",this.getMode),this.__defineSetter__("mode",this.setMode),this.__defineGetter__("default",this.getDefault)):Object.defineProperty&&(Object.defineProperty(this,"mode",{get:this.getMode,set:this.setMode}),Object.defineProperty(this,"default",{get:this.getDefault}));this.loadTrack=function(b, -a){var h,d=new XMLHttpRequest;if(this.readyState===captionator.TextTrack.LOADED)a instanceof Function&&a(h);else{this.src=b;this.readyState=captionator.TextTrack.LOADING;var f=this;d.open("GET",b,!0);d.onreadystatechange=function(){if(d.readyState===4)d.status===200?(h=captionator.parseCaptions(d.responseText),f.readyState=captionator.TextTrack.LOADED,captionator.rebuildCaptions(f.videoNode),f.cues.loadCues(h),f.onload(),a instanceof Function&&a.call(f,h)):(f.readyState=captionator.TextTrack.ERROR, -f.onerror())};d.send(null)}};this.addCue=function(){};this.removeCue=function(){}};captionator.TextTrack.NONE=0;captionator.TextTrack.LOADING=1;captionator.TextTrack.LOADED=2;captionator.TextTrack.ERROR=3;captionator.TextTrack.OFF=0;captionator.TextTrack.HIDDEN=1;captionator.TextTrack.SHOWING=2;captionator.TextTrackCueList=function(a){this.track=a instanceof captionator.TextTrack?a:null;this.getCueById=function(b){return this.filter(function(a){return a.id===b})[0]};this.loadCues=function(b){for(var a= -0;a0});e instanceof Array&& -e.forEach(function(a){var b={D:"verticalText",L:"linePosition",T:"textPosition",A:"textAlignment",S:"textSize"},a=a.split(":");b[a[0]]&&(i[b[a[0]]]=a[1])})}this.getCueAsSource=function(){return this.text};this.getCueAsHTML=function(){var a=document.createDocumentFragment(),b=document.createElement("div");b.innerHTML=this.text;Array.prototype.forEach.call(b.childNodes,function(b){a.appendChild(b.cloneNode(!0))});return a};this.isActive=function(){var a=0;if(this.track instanceof captionator.TextTrack&& -this.track.mode===captionator.TextTrack.SHOWING&&this.track.readyState===captionator.TextTrack.LOADED)try{if(a=this.track.videoNode.currentTime,this.startTime<=a&&this.endTime>=a)return!0}catch(b){}return!1};Object.prototype.__defineGetter__?this.__defineGetter__("active",this.isActive):Object.defineProperty&&Object.defineProperty(this,"active",{get:this.isActive});this.onenter=function(){};this.onexit=function(){}};captionator.MediaTrack=function(a,b,d,e,c,g){var j=function(a){return a.filter(function(a){try{var b= -document.createElement(a.getAttribute("type").split("/").shift());return!(!b.canPlayType||!b.canPlayType(a.getAttribute("type")).replace(/no/,""))}catch(d){return!1}}).shift().getAttribute("src")};this.onload=function(){};this.onerror=function(){};this.id=a||"";this.internalMode=this.internalMode=captionator.TextTrack.OFF;this.mediaElement=null;this.kind=b||"audiodescription";this.label=d||"";this.language=e||"";this.readyState=captionator.TextTrack.NONE;this.type=g||"x/unknown";this.mediaType=null; -this.src="";if(typeof c==="string")this.src=c;else if(c instanceof NodeList)this.src=j(c);if(this.type.match(/^video\//))this.mediaType="video";else if(this.type.match(/^audio\//))this.mediaType="audio";this.getMode=function(){return this.internalMode};this.setMode=function(a){if([captionator.TextTrack.OFF,captionator.TextTrack.HIDDEN,captionator.TextTrack.SHOWING].indexOf(a)!==-1){if(a!==this.internalMode)this.internalMode=a,a===captionator.TextTrack.HIDDEN&&!this.mediaElement&&this.buildMediaElement(), +var captionator={createDOMException:function(b,g,d){try{document.querySelectorAll("div/[]")}catch(c){var f=function(e,a,b){this.code=e;this.message=a;this.name=b};f.prototype=c;return new f(b,g,d)}},captionify:function(b,g,d){var c=[],f=0,d=d instanceof Object?d:{};if(HTMLVideoElement){if(typeof document.createElement("video").addTrack==="function")return!1}else return!1;captionator.TextTrack=function(b,a,d,i,c,f){this.onload=function(){};this.onerror=function(){};this.oncuechange=function(){};this.id= +b||"";this.internalMode=captionator.TextTrack.OFF;this.cues=new captionator.TextTrackCueList(this);this.activeCues=new captionator.ActiveTextTrackCueList(this.cues);this.kind=a||"subtitles";this.label=d||"";this.language=i||"";this.src=c||"";this.readyState=captionator.TextTrack.NONE;this.internalDefault=f||!1;this.getMode=function(){return this.internalMode};this.setMode=function(a){var b;if([captionator.TextTrack.OFF,captionator.TextTrack.HIDDEN,captionator.TextTrack.SHOWING].indexOf(a)!==-1){if(a!== +this.internalMode){this.internalMode=a;this.readyState===captionator.TextTrack.NONE&&this.src.length>0&&a>captionator.TextTrack.OFF&&this.loadTrack(this.src,null);this.readyState===captionator.TextTrack.LOADED&&captionator.rebuildCaptions(this.videoNode);if(a===captionator.TextTrack.OFF||a===captionator.TextTrack.HIDDEN)b="captionator-"+this.videoNode.id+"-"+this.kind+"-"+this.language,(b=document.getElementById(b))&&b.parentNode.removeChild(b);if(a===captionator.TextTrack.OFF)this.cues.length=0, +this.readyState=captionator.TextTrack.NONE}}else throw Error("Illegal mode value for track: "+a);};this.getDefault=function(){return this.internalDefault};Object.prototype.__defineGetter__?(this.__defineGetter__("mode",this.getMode),this.__defineSetter__("mode",this.setMode),this.__defineGetter__("default",this.getDefault)):Object.defineProperty&&(Object.defineProperty(this,"mode",{get:this.getMode,set:this.setMode}),Object.defineProperty(this,"default",{get:this.getDefault}));this.loadTrack=function(a, +b){var i,d=new XMLHttpRequest;if(this.readyState===captionator.TextTrack.LOADED)b instanceof Function&&b(i);else{this.src=a;this.readyState=captionator.TextTrack.LOADING;var e=this;d.open("GET",a,!0);d.onreadystatechange=function(){if(d.readyState===4)d.status===200?(i=captionator.parseCaptions(d.responseText),e.readyState=captionator.TextTrack.LOADED,captionator.rebuildCaptions(e.videoNode),e.cues.loadCues(i),e.onload(),b instanceof Function&&b.call(e,i)):(e.readyState=captionator.TextTrack.ERROR, +e.onerror())};d.send(null)}};this.addCue=function(){};this.removeCue=function(){}};captionator.TextTrack.NONE=0;captionator.TextTrack.LOADING=1;captionator.TextTrack.LOADED=2;captionator.TextTrack.ERROR=3;captionator.TextTrack.OFF=0;captionator.TextTrack.HIDDEN=1;captionator.TextTrack.SHOWING=2;captionator.TextTrackCueList=function(b){this.track=b instanceof captionator.TextTrack?b:null;this.getCueById=function(a){return this.filter(function(b){return b.id===a})[0]};this.loadCues=function(a){for(var b= +0;b0});c instanceof Array&& +c.forEach(function(a){var b={D:"verticalText",L:"linePosition",T:"textPosition",A:"textAlignment",S:"textSize"},a=a.split(":");b[a[0]]&&(n[b[a[0]]]=a[1])})}this.getCueAsSource=function(){return this.text};this.getCueAsHTML=function(){var a=document.createDocumentFragment(),b=document.createElement("div");b.innerHTML=this.text;Array.prototype.forEach.call(b.childNodes,function(b){a.appendChild(b.cloneNode(!0))});return a};this.isActive=function(){var a=0;if(this.track instanceof captionator.TextTrack&& +this.track.mode===captionator.TextTrack.SHOWING&&this.track.readyState===captionator.TextTrack.LOADED)try{if(a=this.track.videoNode.currentTime,this.startTime<=a&&this.endTime>=a)return!0}catch(b){}return!1};Object.prototype.__defineGetter__?this.__defineGetter__("active",this.isActive):Object.defineProperty&&Object.defineProperty(this,"active",{get:this.isActive});this.onenter=function(){};this.onexit=function(){}};captionator.MediaTrack=function(b,a,d,i,c,f){var m=function(a){return a.filter(function(a){try{var b= +document.createElement(a.getAttribute("type").split("/").shift());return!(!b.canPlayType||!b.canPlayType(a.getAttribute("type")).replace(/no/,""))}catch(d){return!1}}).shift().getAttribute("src")};this.onload=function(){};this.onerror=function(){};this.id=b||"";this.internalMode=this.internalMode=captionator.TextTrack.OFF;this.mediaElement=null;this.kind=a||"audiodescription";this.label=d||"";this.language=i||"";this.readyState=captionator.TextTrack.NONE;this.type=f||"x/unknown";this.mediaType=null; +this.src="";if(typeof c==="string")this.src=c;else if(c instanceof NodeList)this.src=m(c);if(this.type.match(/^video\//))this.mediaType="video";else if(this.type.match(/^audio\//))this.mediaType="audio";this.getMode=function(){return this.internalMode};this.setMode=function(a){if([captionator.TextTrack.OFF,captionator.TextTrack.HIDDEN,captionator.TextTrack.SHOWING].indexOf(a)!==-1){if(a!==this.internalMode)this.internalMode=a,a===captionator.TextTrack.HIDDEN&&!this.mediaElement&&this.buildMediaElement(), a===captionator.TextTrack.SHOWING&&this.showMediaElement(),(a===captionator.TextTrack.OFF||a===captionator.TextTrack.HIDDEN)&&this.hideMediaElement()}else throw Error("Illegal mode value for track.");};Object.prototype.__defineGetter__?(this.__defineGetter__("mode",this.getMode),this.__defineSetter__("mode",this.setMode)):Object.defineProperty&&Object.defineProperty(this,"mode",{get:this.getMode,set:this.setMode});this.hideMediaElement=function(){if(this.mediaElement&&(this.mediaElement.paused||this.mediaElement.pause(), this.mediaElement instanceof HTMLVideoElement))this.mediaElement.style.display="none"};this.showMediaElement=function(){if(this.mediaElement){if(this.mediaElement.parentNode||document.body.appendChild(this.mediaElement),this.mediaElement instanceof HTMLVideoElement)this.mediaElement.style.display="block"}else this.buildMediaElement(),document.body.appendChild(this.mediaElement)};this.buildMediaElement=function(){try{if(this.type.match(/^video\//))this.mediaElement=document.createElement("video"), this.mediaElement.className="captionator-mediaElement-"+this.kind,captionator.styleNode(this.mediaElement,this.kind,this.videoNode);else if(this.type.match(/^audio\//))this.mediaElement=new Audio;this.mediaElement.type=this.type;this.mediaElement.src=this.src;this.mediaElement.load();this.mediaElement.trackObject=this;this.readyState=captionator.TextTrack.LOADING;var a=this.mediaElement;this.mediaElement.addEventListener("progress",function(){a.trackObject.readyState=captionator.TextTrack.LOADING}, !1);this.mediaElement.addEventListener("canplaythrough",function(){a.trackObject.readyState=captionator.TextTrack.LOADED;a.trackObject.onload.call(a.trackObject)},!1);this.mediaElement.addEventListener("error",function(b){a.trackObject.readyState=captionator.TextTrack.ERROR;a.trackObject.mode=captionator.TextTrack.OFF;a.trackObject.mediaElement=null;a.trackObject.onerror.call(a.trackObject,b)},!1)}catch(b){this.readyState=captionator.TextTrack.ERROR,this.mode=captionator.TextTrack.OFF,this.mediaElement= -null,this.onerror.call(this,b)}}};if(d.exportObjects)window.TextTrack=captionator.TextTrack,window.TextTrackCueList=captionator.TextTrackCueList,window.ActiveTextTrackCueList=captionator.ActiveTextTrackCueList,window.TextTrackCue=captionator.TextTrackCue,window.MediaTrack=captionator.MediaTrack;[].slice.call(document.getElementsByTagName("video"),0).forEach(function(a){a.addTrack=function(b,d,e,c,g,j,i){var l=["subtitles","captions","descriptions","captions","metadata","karaoke","lyrics","tickertext", -"audiodescription","commentary","alternate","signlanguage"],m=l.slice(0,7),b=typeof b==="string"?b:"",e=typeof e==="string"?e:"",c=typeof c==="string"?c:"",i=typeof i==="boolean"?i:!1;if(!l.filter(function(a){return d===a?!0:!1}).length)throw captionator.createDOMException(12,"DOMException 12: SYNTAX_ERR: You must use a valid kind when creating a TimedTextTrack.","SYNTAX_ERR");if(m.filter(function(a){return d===a?!0:!1}).length)if(b=new captionator.TextTrack(b,d,e,c,g)){if(!(a.tracks instanceof Array))a.tracks= -[];a.tracks.push(b);return b}else return!1;else if(b=new captionator.MediaTrack(b,d,e,c,g,j,i)){if(!(a.mediaTracks instanceof Array))a.mediaTracks=[];a.mediaTracks.push(b);return b}else return!1}});if(!a||a===!1||a===void 0||a===null)e=[].slice.call(document.getElementsByTagName("video"),0);else if(a instanceof Array)for(c=0;c0?c.querySelectorAll("source"):c.getAttribute("src"),b=a.addTrack(c.getAttribute("id"),c.getAttribute("kind"),c.getAttribute("label"),c.getAttribute("srclang").split("-")[0],b,c.getAttribute("type"),c.hasAttribute("default"));c.track=b;b.trackNode=c;b.videoNode=a;e.push(b);var f=!1;if((b.kind==="subtitles"||b.kind==="captions")&&g===b.language&& -d.enableCaptionsByDefault)e.filter(function(a){return(a.kind==="captions"||a.kind==="subtitles")&&g===a.language&&a.mode===captionator.TextTrack.SHOWING?!0:!1}).length||(f=!0);b.kind==="chapters"&&g===b.language&&(e.filter(function(a){return a.kind==="chapters"&&a.mode===captionator.TextTrack.SHOWING?!0:!1}).length||(f=!0));b.kind==="descriptions"&&d.enableDescriptionsByDefault===!0&&g===b.language&&(e.filter(function(a){return a.kind==="descriptions"&&a.mode===captionator.TextTrack.SHOWING?!0:!1}).length|| -(f=!0));f===!0&&e.forEach(function(a){if(a.trackNode.hasAttribute("default")&&a.mode===captionator.TextTrack.SHOWING)a.mode=captionator.TextTrack.HIDDEN});if(c.hasAttribute("default")&&!e.filter(function(a){return a.trackNode.hasAttribute("default")&&a.trackNode!==c?!0:!1}).length)f=!0,b.internalDefault=!0;if(f===!0)b.mode=captionator.TextTrack.SHOWING});a.addEventListener("timeupdate",function(a){a=a.target;try{a.tracks.forEach(function(a){a.activeCues.refreshCues()})}catch(b){}d.renderer instanceof -Function?d.renderer.call(captionator,a):captionator.rebuildCaptions(a);captionator.synchroniseMediaElements(a)},!1);a.addEventListener("play",function(){captionator.synchroniseMediaElements(a)},!1);a.addEventListener("pause",function(){captionator.synchroniseMediaElements(a)},!1)}return a},rebuildCaptions:function(a){var g="captionator-unset",d=null,e="",c=!1;(a.tracks||[]).forEach(function(h){if(h.mode===captionator.TextTrack.SHOWING&&h.readyState===captionator.TextTrack.LOADED){g="captionator-"+ -a.id+"-"+h.kind+"-"+h.language;(d=h.containerObject?h.containerObject:document.getElementById(g))?d.parentNode||document.body.appendChild(d):(d=document.createElement("div"),d.id=g,document.body.appendChild(d),h.containerObject=d,d.setAttribute("aria-live","polite"),d.setAttribute("aria-atomic","true"),captionator.styleNode(d,h.kind,h.videoNode));if(String(a.getAttribute("aria-describedby")).indexOf(g)===-1){var b=a.hasAttribute("aria-describedby")?a.getAttribute("aria-describedby")+" ":"";a.setAttribute("aria-describedby", -b+g)}e="";h.activeCues.forEach(function(a){e+='
'+a.getCueAsSource()+"
"});c=!1;if(String(d.innerHTML)!==e)d.innerHTML=e,c=!0;if(e.length){if(c||d.style.display==="none")if(d.style.display="block",window.navigator.userAgent.toLowerCase().indexOf("chrome/10")>-1)d.style.backgroundColor="rgba(0,0,0,0.5"+Math.random().toString().replace(".","")+")"}else d.style.display="none"}})},synchroniseMediaElements:function(a){var g=function(a,e){try{e.seeking&&a.pause();if(a.currentTime< -e.currentTime-0.5||a.currentTime>e.currentTime+0.5)a.currentTime=e.currentTime;a.paused&&!e.paused?a.play():!a.paused&&e.paused&&a.pause()}catch(c){}};(a.mediaTracks||[]).forEach(function(d){d.mode===captionator.TextTrack.SHOWING&&d.readyState>=captionator.TextTrack.LOADING&&g(d.mediaElement,a)});a.id&&[].slice.call(document.body.querySelectorAll("*[syncMaster="+a.id+"]"),0).forEach(function(d){(d.tagName.toLowerCase()==="video"||d.tagName.toLowerCase()==="audio")&&g(d,a)})},styleNode:function(a, -g,d){var e=function(a,b){for(var c in b)({}).hasOwnProperty.call(b,c)&&(a.style[c]=b[c])},c=function(a){for(var b=window.getComputedStyle(a,null),c=a,d=a.offsetTop,e=a.offsetLeft,g=a,f=0,h=0,g=parseInt(b.getPropertyValue("width"),10),f=parseInt(b.getPropertyValue("height"),10);c=c.offsetParent;)d+=c.offsetTop,e+=c.offsetLeft;a.hasAttribute("controls")&&(a=navigator.userAgent.toLowerCase(),a.indexOf("chrome")!==-1?h=32:a.indexOf("opera")!==-1?h=25:a.indexOf("firefox")!==-1?h=28:a.indexOf("ie 9")!== --1||a.indexOf("ipad")!==-1?h=44:a.indexOf("safari")!==-1&&(h=25));return{left:e,top:d,width:g,height:f,controlHeight:h}},h=function(a,b){var g=0;try{window.addEventListener("resize",function(){var f=c(d);b==="bottom"?(g=Math.ceil(f.height*0.15<30?30:f.height*0.15),e(a,{width:f.width-40+"px",height:g+"px",left:f.left+"px",top:f.top+f.height-(g+f.controlHeight)+"px",fontSize:(g<=50?g*0.7/96*72:g*0.3/96*72)+"pt",lineHeight:(g<=50?g/96*72:g/2/96*72)+"pt"})):(g=f.height*0.1<20?20:f.height*0.1,e(a,{width:f.width- -40+"px",minHeight:g+"px",left:f.left+"px",top:f.top+"px",fontSize:(g<=50?g*0.5/96*72:g*0.2/96*72)+"pt",lineHeight:(g<=50?g/96*72:g/2/96*72)+"pt"}))},!1)}catch(f){}};if(a instanceof HTMLElement&&d instanceof HTMLVideoElement){var b=c(d),f=0;switch(g){case "caption":case "captions":case "subtitle":case "subtitles":f=Math.ceil(b.height*0.15<30?30:b.height*0.15);e(a,{display:"block",position:"absolute",width:b.width-40+"px",height:f+"px",backgroundColor:"rgba(0,0,0,0.5)",left:b.left+"px",top:b.top+b.height- -(f+b.controlHeight)+"px",fontSize:(f<=50?f*0.7/96*72:f*0.3/96*72)+"pt",lineHeight:(f<=50?f/96*72:f/2/96*72)+"pt",color:"white",textShadow:"black 0px 0px 5px",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"bold",textAlign:"center",paddingLeft:"20px",paddingRight:"20px",overflow:"hidden",zIndex:20});h(a,"bottom");break;case "textaudiodesc":case "descriptions":case "karaoke":case "lyrics":f=b.height*0.1<20?20:b.height*0.1;e(a,{display:"block",position:"absolute",width:b.width-40+"px",minHeight:f+ -"px",backgroundColor:"rgba(0,0,0,0.5)",left:b.left+"px",top:b.top+"px",fontSize:(f<=50?f*0.5/96*72:f*0.2/96*72)+"pt",lineHeight:(f<=50?f/96*72:f/2/96*72)+"pt",color:"gold",fontStyle:"oblique",textShadow:"black 0px 0px 5px",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"lighter",textAlign:"center",paddingLeft:"20px",paddingRight:"20px",overflow:"hidden"});h(a,"top");break;case "toolbar":case "alternate":e(a,{display:"block",position:"absolute",width:b.width+"px",height:b.height-b.controlHeight+ -"px",backgroundColor:"black",left:b.left+"px",top:b.top+"px"});break;case "signlanguage":e(a,{display:"block",position:"absolute",maxWidth:b.width/20*6+"px",maxHeight:(b.height-b.controlHeight)/20*8+"px",backgroundColor:"black",left:b.left+b.width-b.width/20*7+"px",top:b.top+b.height-b.height/20*11+"px",border:"solid white 2px"})}a.className.indexOf("captionator-kind")===-1&&(a.className+=(a.className.length?" ":"")+"captionator-kind-"+g)}},parseCaptions:function(a){if(a)return a.replace(/\r\n/g, -"\n").replace(/\r/g,"\n").split(/\n\n/g).filter(function(a){return a.match(/WEBVTT FILE/ig)?!1:!0}).map(function(a){var a=a.split(/\n/g),d,e,c,h,b,f;a[0].match(/^\s*\d+\s*$/ig)&&(f=String(a.shift(0).split(/\s+/).join("")));for(h=0;h=4&&(b=c.splice(3).join(" "));a=a.slice(0,h).concat(a.slice(h+1));break}a=a.join("\n");return new captionator.TextTrackCue(f,d,e,a,b,!1,null)});else throw Error("Required parameter captionData not supplied.");}}; \ No newline at end of file +null,this.onerror.call(this,b)}}};if(d.exportObjects)window.TextTrack=captionator.TextTrack,window.TextTrackCueList=captionator.TextTrackCueList,window.ActiveTextTrackCueList=captionator.ActiveTextTrackCueList,window.TextTrackCue=captionator.TextTrackCue,window.MediaTrack=captionator.MediaTrack;[].slice.call(document.getElementsByTagName("video"),0).forEach(function(b){b.addTrack=function(a,d,i,c,f,m,g){var j=["subtitles","captions","descriptions","captions","metadata","karaoke","lyrics","tickertext", +"audiodescription","commentary","alternate","signlanguage"],k=j.slice(0,7),a=typeof a==="string"?a:"",i=typeof i==="string"?i:"",c=typeof c==="string"?c:"",g=typeof g==="boolean"?g:!1;if(!j.filter(function(a){return d===a?!0:!1}).length)throw captionator.createDOMException(12,"DOMException 12: SYNTAX_ERR: You must use a valid kind when creating a TimedTextTrack.","SYNTAX_ERR");if(k.filter(function(a){return d===a?!0:!1}).length)if(a=new captionator.TextTrack(a,d,i,c,f)){if(!(b.tracks instanceof Array))b.tracks= +[];b.tracks.push(a);return a}else return!1;else if(a=new captionator.MediaTrack(a,d,i,c,f,m,g)){if(!(b.mediaTracks instanceof Array))b.mediaTracks=[];b.mediaTracks.push(a);return a}else return!1}});if(!b||b===!1||b===void 0||b===null)c=[].slice.call(document.getElementsByTagName("video"),0);else if(b instanceof Array)for(f=0;f0?e.querySelectorAll("source"):e.getAttribute("src"),a=b.addTrack(e.getAttribute("id"),e.getAttribute("kind"),e.getAttribute("label"),e.getAttribute("srclang").split("-")[0],a,e.getAttribute("type"),e.hasAttribute("default"));e.track=a;a.trackNode=e;a.videoNode=b;c.push(a);var f=!1;if((a.kind==="subtitles"||a.kind==="captions")&&g===a.language&& +d.enableCaptionsByDefault)c.filter(function(a){return(a.kind==="captions"||a.kind==="subtitles")&&g===a.language&&a.mode===captionator.TextTrack.SHOWING?!0:!1}).length||(f=!0);a.kind==="chapters"&&g===a.language&&(c.filter(function(a){return a.kind==="chapters"&&a.mode===captionator.TextTrack.SHOWING?!0:!1}).length||(f=!0));a.kind==="descriptions"&&d.enableDescriptionsByDefault===!0&&g===a.language&&(c.filter(function(a){return a.kind==="descriptions"&&a.mode===captionator.TextTrack.SHOWING?!0:!1}).length|| +(f=!0));f===!0&&c.forEach(function(a){if(a.trackNode.hasAttribute("default")&&a.mode===captionator.TextTrack.SHOWING)a.mode=captionator.TextTrack.HIDDEN});if(e.hasAttribute("default")&&!c.filter(function(a){return a.trackNode.hasAttribute("default")&&a.trackNode!==e?!0:!1}).length)f=!0,a.internalDefault=!0;if(f===!0)a.mode=captionator.TextTrack.SHOWING});b.addEventListener("timeupdate",function(b){b=b.target;try{b.tracks.forEach(function(a){a.activeCues.refreshCues()})}catch(a){}d.renderer instanceof +Function?d.renderer.call(captionator,b):captionator.rebuildCaptions(b);captionator.synchroniseMediaElements(b)},!1);b.addEventListener("play",function(){captionator.synchroniseMediaElements(b)},!1);b.addEventListener("pause",function(){captionator.synchroniseMediaElements(b)},!1)}return b},rebuildCaptions:function(b){var g="captionator-unset",d=null,c="",f=!1;(b.tracks||[]).forEach(function(e){if(e.mode===captionator.TextTrack.SHOWING&&e.readyState===captionator.TextTrack.LOADED){g="captionator-"+ +b.id+"-"+e.kind+"-"+e.language;(d=e.containerObject?e.containerObject:document.getElementById(g))?d.parentNode||document.body.appendChild(d):(d=document.createElement("div"),d.id=g,document.body.appendChild(d),e.containerObject=d,d.setAttribute("aria-live","polite"),d.setAttribute("aria-atomic","true"),captionator.styleNode(d,e.kind,e.videoNode));if(String(b.getAttribute("aria-describedby")).indexOf(g)===-1){var a=b.hasAttribute("aria-describedby")?b.getAttribute("aria-describedby")+" ":"";b.setAttribute("aria-describedby", +a+g)}c="";e.activeCues.forEach(function(a){c+='
'+a.getCueAsSource()+"
"});f=!1;if(String(d.innerHTML)!==c)d.innerHTML=c,f=!0;if(c.length){if(f||d.style.display==="none")if(d.style.display="block",captionator.styleNode(d,e.kind,e.videoNode),window.navigator.userAgent.toLowerCase().indexOf("chrome/10")>-1)d.style.backgroundColor="rgba(0,0,0,0.5"+Math.random().toString().replace(".","")+")"}else d.style.display="none"}})},synchroniseMediaElements:function(b){var g=function(b, +c){try{c.seeking&&b.pause();if(b.currentTimec.currentTime+0.5)b.currentTime=c.currentTime;b.paused&&!c.paused?b.play():!b.paused&&c.paused&&b.pause()}catch(f){}};(b.mediaTracks||[]).forEach(function(d){d.mode===captionator.TextTrack.SHOWING&&d.readyState>=captionator.TextTrack.LOADING&&g(d.mediaElement,b)});b.id&&[].slice.call(document.body.querySelectorAll("*[syncMaster="+b.id+"]"),0).forEach(function(d){(d.tagName.toLowerCase()==="video"||d.tagName.toLowerCase()=== +"audio")&&g(d,b)})},styleNode:function(b,g,d){var c=function(a,b){for(var c in b)({}).hasOwnProperty.call(b,c)&&(a.style[c]=b[c])},f=function(a){for(var b=window.getComputedStyle(a,null),c=a,d=a.offsetTop,f=a.offsetLeft,e=a,g=0,h=0,e=parseInt(b.getPropertyValue("width"),10),g=parseInt(b.getPropertyValue("height"),10);c=c.offsetParent;)d+=c.offsetTop,f+=c.offsetLeft;a.hasAttribute("controls")&&(a=navigator.userAgent.toLowerCase(),a.indexOf("chrome")!==-1?h=32:a.indexOf("opera")!==-1?h=25:a.indexOf("firefox")!== +-1?h=28:a.indexOf("ie 9")!==-1||a.indexOf("ipad")!==-1?h=44:a.indexOf("safari")!==-1&&(h=25));return{left:f,top:d,width:e,height:g,controlHeight:h}},e=function(a,b){var e=0,g,h,j,k;try{var o=function(){g=f(d);h=g.height*0.045/96*72;h=h>=11?h:11;j=Math.floor(h*1.3);j=j>14?j:14;e=Math.ceil(g.height*0.13);a.textContent?a.textContent.replace(/\s\s+/ig," "):a.innerText&&a.innerText.replace(/\s\s+/ig," ");e=Math.ceil(g.height*0.13);k=g.top+g.height;k=b==="bottom"?k-(e+g.controlHeight):g.top;c(a,{width:g.width- +40+"px",height:e+"px",left:g.left+"px",top:k+"px",fontSize:h+"pt",lineHeight:j+"pt"});if(a.scrollHeight>e){var o=Math.ceil(0.33*g.height);e=a.scrollHeight<=o?a.scrollHeight:o;k=g.top+g.height;k=b==="bottom"?k-(e+g.controlHeight):g.top;c(a,{height:e+"px",top:k+"px"})}else{var p=0;Array.prototype.slice.call(a.childNodes,0).forEach(function(a){p+=a.offsetHeight});p\s+(\d{2})?:?(\d{2}):(\d{2})[\.\,](\d+)\s*(.*)/; +for(var m=/^([\d\.]+)\s+\+([\d\.]+)\s*(.*)/;!c[0].replace(/\s+/ig,"").length&&c.length>0;)c.shift();for(i=c[0].match(/^\s*\d+\s*$/ig)?String(c.shift().replace(/\s*/ig,"")):d;0