-
Notifications
You must be signed in to change notification settings - Fork 20
/
jquery.videosub.min.js
8 lines (7 loc) · 2.33 KB
/
jquery.videosub.min.js
1
2
3
4
5
6
7
8
/* ------------------------------------------------------------------------------
VideoSub v0.9.6
Original MooTools implementation by [Thomas Sturm](http://www.storiesinflight.com)
jQuery port by [Max Wheeler](http://www.icelab.com.au)
Freeware, Attribution Appreciated
------------------------------------------------------------------------------ */
(function(c){var a,b,d;c.fn.videoSub=function(e){var f,g;if(typeof(typeof(f=c("<video>").addtrack)!=="undefined"&&f!==null)){g=c.extend({},c.fn.videoSub.defaults,e);return this.each(function(){var l,i,k,h,j,n,m;j=this;l=c(this);n=(typeof(i=c.meta)!=="undefined"&&i!==null)?c.extend(g,l.data()):g;m=c("track",this).attr("src");if(typeof m!=="undefined"&&m!==null){h=c('<div class="'+n.containerClass+'">');h.css("position","relative");h=l.wrap(h).parent();k=c('<div class="'+n.barClass+'">');k.css("width",l.outerWidth()-40);if(n.useBarDefaultStyle){k.css({position:"absolute",bottom:"40px",padding:"0 25px","text-align":"center",color:"#ffffff","font-family":"Helvetica, Arial, sans-serif","font-size":"16px","font-weight":"bold","text-shadow":"#000000 1px 1px 0px"})}k=k.appendTo(h);j.subtitles=[];j.subcount=0;j.update=function(q){var p,o;o=q.replace(/(\r\n|\r|\n)/g,"\n").split("\n\n");p=0;c(o).each(function(r){j.subtitles[p]=[];return(j.subtitles[p++]=o[r].split("\n"))});l.bind("play",function(r){return(j.subcount=0)});l.bind("ended",function(r){return(j.subcount=0)});l.bind("seeked",function(s){var r;j.subcount=0;r=[];while(b(j.subtitles[j.subcount][1])<this.currentTime.toFixed(1)){j.subcount++;if(j.subcount>j.subtitles.length-1){j.subcount=j.subtitles.length-1;break}}return r});return l.bind("timeupdate",function(s){var r;r="";if(j.currentTime.toFixed(1)>d(j.subtitles[j.subcount][1])&&j.currentTime.toFixed(1)<b(j.subtitles[j.subcount][1])){r=j.subtitles[j.subcount][2]}if(j.currentTime.toFixed(1)>b(j.subtitles[j.subcount][1])&&j.subcount<(j.subtitles.length-1)){j.subcount++}return k.html(r)})};return c.ajax({method:"get",url:m,success:j.update})}})}};d=function(e){var f;f=e.split(" --> ");return a(f[0])};b=function(e){var f;f=e.split(" --> ");return a(f[1])};a=function(e){var h,g,f;g=e.split(",");f=g[0].split(":");return(h=Math.floor(f[0]*60*60)+Math.floor(f[1]*60)+Math.floor(f[2]))};c.fn.videoSub.defaults={containerClass:"videosub-container",barClass:"videosub-bar",useBarDefaultStyle:true}})(jQuery);