This repository has been archived by the owner on Jul 29, 2021. It is now read-only.
forked from timesheets/timesheets.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timesheets-controls.min.js
1 lines (1 loc) · 8.53 KB
/
timesheets-controls.min.js
1
(function(){var b=["controlBar","play","first","prev","next","last","toc","tocList","tocTitles","tocDisplay","timeline","timeCursor","timeSlider","timeSegments","currentTime","duration","currentIndex","length"];a.prototype.playButtonHandler=function(){var j=this.controlElement;var f=this.timeContainer.mediaSyncAPI;if(!f||!this.play){return}var g=(/(^|\s+)(playing|paused|seeking)(\s+|$)/i);if(!g.test(j.className)){j.className+=" seeking"}function h(){var k=j.className;if(f.seeking){j.className=k.replace(g," seeking")}else{if(f.paused){j.className=k.replace(g," paused")}else{j.className=k.replace(g," playing")}}}function i(){if(f.paused){j.className=j.className.replace(g," seeking");f.play()}else{f.pause()}}EVENTS.bind(this.play,"click",i);f.addEventListener("play",h,false);f.addEventListener("playing",h,false);f.addEventListener("pause",h,false);f.addEventListener("seeked",h,false);f.addEventListener("canplay",h,false);f.addEventListener("progress",h,false);f.addEventListener("loadeddata",h,false);f.addEventListener("loadedmetadata",h,false);f.addEventListener("ended",function(){f.pause()},false);h()};a.prototype.navButtonHandler=function(){var f=this.timeContainer;if(this.first){EVENTS.bind(this.first,"click",function(){f.selectIndex(0)})}if(this.prev){EVENTS.bind(this.prev,"click",function(){f.selectIndex(f.currentIndex-1)})}if(this.next){EVENTS.bind(this.next,"click",function(){f.selectIndex(f.currentIndex+1)})}if(this.last){EVENTS.bind(this.last,"click",function(){f.selectIndex(f.timeNodes.length-1)})}};if(!window.getComputedStyle){getComputedStyle=function(g,f){return g.currentStyle}}function e(f){var g=parseFloat(f);return(isNaN(g))?0:Math.ceil(g)}a.prototype._setTimelineWidth=function(){if(!this.timeline){return}var k=this.timeline.parentNode.childNodes;var h=getComputedStyle(this.timeline.parentNode,null);var g=parseFloat(h.width);if(isNaN(g)){return}var j=0;for(var f=0;f<k.length;f++){if(k[f].nodeType==1){h=getComputedStyle(k[f],null);if(k[f]==this.timeline){j=e(h.width)}else{g-=e(h.width)}g-=e(h.marginLeft);g-=e(h.marginRight);g-=e(h.paddingLeft);g-=e(h.paddingRight);g-=e(h.borderLeftWidth);g-=e(h.borderRightWidth)}}if((j<50)&&(g>0)){this.timeline.style.width=g+"px"}};a.prototype.setTimelineWidth=function(g){if(!this.timeline){return}var n=this.timeline.parentNode.childNodes;var f=this.timeline.parentNode.getBoundingClientRect();var l=f.right-f.left;var m=0;for(var j=0;j<n.length;j++){if(n[j].nodeType==1){f=n[j].getBoundingClientRect();var h=f.right-f.left;if(n[j]==this.timeline){m=h}else{l-=e(h)}var k=getComputedStyle(n[j],null);l-=e(k.marginLeft);l-=e(k.marginRight);l-=e(k.paddingLeft);l-=e(k.paddingRight);l-=e(k.borderLeftWidth);l-=e(k.borderRightWidth)}}if(!window.XMLHttpRequest){l-=20}if(g||((m<50)&&(l>0))){this.timeline.style.width=l+"px"}else{l=m}this.timelineWidth=l};a.prototype.timeUpdateHandler=function(){var l=this.timeContainer.dur;var h=this.timeContainer.mediaSyncAPI;if(!h){return}function j(q){q=Math.floor(q);var o=q%60;var p=o;if(o<10){p="0"+p}var m=Math.floor(q/60);min=m%60;p=min+":"+p;if(l<3600){return p}if(min<10){p="0"+p}var n=Math.floor(m/60);p=n+":"+p;return p}var i=this.currentTime;var f=this.timeCursor;var k=this.timeSlider;var g=this;if(i||f||k){h.addEventListener("timeupdate",function(){if(g.timelineDragging){return}var m=h.currentTime;var n=(100*m/l)+"%";if(i){i.innerHTML=j(m)}if(f){f.style.left=n}if(k){k.style.width=n}},false)}};function c(f){var g=f.getBoundingClientRect();f.rect={top:g.top,right:g.right,bottom:g.bottom,left:g.left,height:g.bottom-g.top,width:g.right-g.left}}a.prototype.setCurrentTime=function(h){if(!h){h=window.event}var k=this.timeContainer.dur;var j=this.timeline.rect;var f=h.pageX;if(!f){f=h.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft)}var l=(f-j.left)/j.width;if(l<0){l=0}else{if(l>0.99){l=0.99}}function g(q){q=Math.floor(q);var o=q%60;var p=o;if(o<10){p="0"+p}var m=Math.floor(q/60);min=m%60;p=min+":"+p;if(k<3600){return p}if(min<10){p="0"+p}var n=Math.floor(m/60);p=n+":"+p;return p}var i=k*l;l=(100*l)+"%";if(this.currentTime){this.currentTime.innerHTML=g(i)}if(this.timeCursor){this.timeCursor.style.left=l}if(this.timeSlider){this.timeSlider.style.width=l}this.timeContainer.setCurrentTime(i)};a.prototype.timeDragHandler=function(){if(!this.timeline){return}var g=this.controlBar||this.timeline;var h=this;var j=new RegExp("(^|\\s)dragging(\\s|$)");function f(){h.timelineDragging=true;c(h.timeline);g.className+=" dragging";g.onmousemove=function(k){h.setCurrentTime(k)}}function i(){g.onmousemove=null;g.className=g.className.replace(j," ");h.timelineDragging=false}if(this.timeCursor){this.timeCursor.onmousedown=function(k){f()}}else{if(this.timeSlider){this.timeline.onmousedown=function(k){f();h.setCurrentTime(k)}}}if(this.timeCursor||this.timeSlider){g.onmouseup=i;g.onmouseout=function(l){var k=l?l.relatedTarget:window.event.toElement;while(k&&k!=g&&k!=document.body){k=k.parentNode}if(k!=g){i()}}}};a.prototype.tocDisplayHandler=function(i){var g=this.toc;var j=this.tocDisplay;var h=new RegExp("(^|\\s)"+i+"(\\s|$)");function k(){g.className=g.className.replace(h," ")}function f(){if(h.test(g.className)){k()}else{g.className+=" "+i}}EVENTS.bind(g,"click",k);EVENTS.bind(j,"click",f)};a.prototype.fillTimelineAnchors=function(f){var n=this.tocList;var m=this.timeSegments;var g=this.timeContainer.dur;if(!n||!m||!g){return}var k=[];var q=n.childNodes;for(var t=0;t<q.length;t++){if((q[t].nodeType==1)&&(q[t].nodeName.toLowerCase()=="li")){var h=q[t].getElementsByTagName("a");if(h&&h.length){var u=h[0].href.replace(/^.*#/,"");var z=document.getElementById(u)||document.getElementById(u.substr(1));var p=document.getTimeNodesByTarget(z);if(p.length){k.push({link:h[0],begin:p[0].time_in})}}}}if(f){var l=this.timeContainer.parseAttribute("mediaSync");m.setAttribute("timeContainer","excl");m.setAttribute("timeAction",f);m.setAttribute("mediaSync",l)}var w=k.length-1;var j=g;for(t=w;t>=0;t--){var o=k[t].link;var y=k[t].begin;var r=100*(j-y)/g;var v=document.createElement("a");var s=document.createElement("span");s.appendChild(o.firstChild.cloneNode(true));s.style.width=this.timelineWidth+"px";v.appendChild(s);v.href=o.href;v.style.width=r+"%";m.insertBefore(v,m.firstChild);j=y;if(f){v.setAttribute("begin",y)}}if(f){var x=document.createTimeContainer(m);x.show()}};a.prototype.syncTableOfContents=function(o){var q=this.timeContainer.parseAttribute("mediaSync");var h=this.tocList;if(!h){return}h.setAttribute("timeContainer","excl");h.setAttribute("timeAction",o);h.setAttribute("mediaSync",q);var m=h.getElementsByTagName("ul");for(var k=0;k<m.length;k++){m[k].setAttribute("timeContainer","excl");m[k].setAttribute("timeAction",o);m[k].setAttribute("mediaSync",q);m[k].parentNode.setAttribute("timeContainer","par")}var p=h.getElementsByTagName("li");for(k=0;k<p.length;k++){var n=p[k].getElementsByTagName("a").item(0);var f=n.href.replace(/^.*#/,"");var l=document.getElementById(f);var j=document.getTimeNodesByTarget(l);if(j.length){p[k].setAttribute("begin",j[0].time_in+"s")}}var g=document.createTimeContainer(h);g.show()};function a(h,g){this.timeContainer=h;this.controlElement=g;this.timelineDragging=false;if(!g.getElementsByTagName("*").length){g.innerHTML='<!-- auto-filled by timecontroller.js -->\n <div class="smil-left">\n <button class="smil-play"><span>▶||</span></button>\n </div>\n <div class="smil-timeline">\n <div class="smil-timeSlider"></div>\n </div>\n <div class="smil-right">\n <span class="smil-currentTime">0:00</span>\n </div>';if(!(/(^|\\s)smil-controlBar(\\s|$)/).test(g.className)){g.className+="smil-controlBar"}}function k(o){var p=new RegExp("(^|\\s)"+o+"(\\s|$)");if(p.test(g.className)){return g}if(g.querySelector){return g.querySelector("."+o)}var n=g.getElementsByTagName("*");var l=n.length;for(var m=0;m<l;m++){if(p.test(n[m].className)){return n[m]}}return null}for(var f=0;f<b.length;f++){var j=b[f];this[j]=k("smil-"+j)}this.setTimelineWidth();this.navButtonHandler();this.playButtonHandler();this.timeUpdateHandler();this.timeDragHandler();if(this.toc&&this.tocDisplay){this.tocDisplayHandler("active")}if(this.toc&&this.tocList){this.syncTableOfContents("class:current");this.fillTimelineAnchors("class:current")}}function d(){var h=document.getTimeContainersByTagName("*");for(var g=0;g<h.length;g++){var k=h[g];var f=k.parseAttribute("controls");var j=document.querySelector(f);if(j){k.controls=new a(k,j)}}}if(1){EVENTS.onSMILReady(function(){setTimeout(d,500)})}else{d()}document.redrawTimelines=function(){var h=document.getTimeContainersByTagName("*");for(var g=0;g<h.length;g++){var f=h[g].controls;if(f){f.setTimelineWidth(true)}}}})();