vendor/assets/javascripts/webshims/shims/combos/22.js in webshims-rails-1.12.3 vs vendor/assets/javascripts/webshims/shims/combos/22.js in webshims-rails-1.12.5

- old
+ new

@@ -360,24 +360,24 @@ } return isDefault; }; })(); var emptyDiv = $('<div />')[0]; - var TextTrackCue = function(startTime, endTime, text){ + function VTTCue(startTime, endTime, text){ if(arguments.length != 3){ - webshims.error("wrong arguments.length for TextTrackCue.constructor"); + webshims.error("wrong arguments.length for VTTCue.constructor"); } this.startTime = startTime; this.endTime = endTime; this.text = text; createEventTarget(this); - }; + } - TextTrackCue.prototype = { + VTTCue.prototype = { onenter: null, onexit: null, pauseOnExit: false, getCueAsHTML: function(){ @@ -415,15 +415,18 @@ // position: 50, // vertical: '', // align: 'middle' }; - window.TextTrackCue = TextTrackCue; - - - - + window.VTTCue = VTTCue; + window.TextTrackCue = function(){ + webshims.error("Use VTTCue constructor instead of abstract TextTrackCue constructor."); + VTTCue.apply(this, arguments); + }; + + window.TextTrackCue.prototype = VTTCue.prototype; + mediaelement.createCueList = function(){ return $.extend([], cueListProto); }; mediaelement.parseCueTextToHTML = (function(){ @@ -464,12 +467,14 @@ mediaelement.loadTextTrack = function(mediaelem, track, trackData, _default){ var loadEvents = 'play playing updatetrackdisplay'; var obj = trackData.track; var load = function(){ - var error, ajax, src, createAjax; - if(obj.mode != 'disabled' && $.attr(track, 'src') && (src = $.prop(track, 'src'))){ + var error, ajax, createAjax; + + var src = obj.mode != 'disabled' && ($.attr(track, 'src') && $.prop(track, 'src')); + if(src){ $(mediaelem).off(loadEvents, load); if(!trackData.readyState){ error = function(){ trackData.readyState = 3; obj.cues = null; @@ -503,12 +508,12 @@ }); }; if($.ajax){ createAjax(); } else { - webshims.ready('$ajax', createAjax); - webshims.loader.loadList(['$ajax']); + webshims.ready('jajax', createAjax); + webshims.loader.loadList(['jajax']); } } catch(er){ error(); webshims.error(er); } @@ -601,23 +606,21 @@ modified for webshims */ mediaelement.parseCaptionChunk = (function(){ // Set up timestamp parsers var WebVTTTimestampParser = /^(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s+\-\-\>\s+(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s*(.*)/; - var GoogleTimestampParser = /^([\d\.]+)\s+\+([\d\.]+)\s*(.*)/; var WebVTTDEFAULTSCueParser = /^(DEFAULTS|DEFAULT)\s+\-\-\>\s+(.*)/g; var WebVTTSTYLECueParser = /^(STYLE|STYLES)\s+\-\-\>\s*\n([\s\S]*)/g; var WebVTTCOMMENTCueParser = /^(COMMENT|COMMENTS)\s+\-\-\>\s+(.*)/g; return function(subtitleElement,objectCount){ - var cueDefaults = []; - - var subtitleParts, timeIn, timeOut, html, timeData, subtitlePartIndex, cueSettings = "", id, specialCueData; + + var subtitleParts, timeIn, timeOut, html, timeData, subtitlePartIndex, id, specialCueData; var timestampMatch, tmpCue; // WebVTT Special Cue Logic - if ((specialCueData = WebVTTDEFAULTSCueParser.exec(subtitleElement))) { + if (WebVTTDEFAULTSCueParser.exec(subtitleElement)) { // cueDefaults = specialCueData.slice(2).join(""); // cueDefaults = cueDefaults.split(/\s+/g).filter(function(def) { return def && !!def.length; }); return null; } else if ((specialCueData = WebVTTSTYLECueParser.exec(subtitleElement))) { return null; @@ -690,34 +693,34 @@ .reduce(function(previous,current,index,array){ previous[current.split(":")[0]] = current.split(":")[1]; return previous; },compositeCueSettings); - // Turn back into string like the TextTrackCue constructor expects + // Turn back into string like the VTTCue constructor expects cueSettings = ""; for (var key in compositeCueSettings) { if (compositeCueSettings.hasOwnProperty(key)) { cueSettings += !!cueSettings.length ? " " : ""; cueSettings += key + ":" + compositeCueSettings[key]; } } */ // The remaining lines are the subtitle payload itself (after removing an ID if present, and the time); html = subtitleParts.join("\n"); - tmpCue = new TextTrackCue(timeIn, timeOut, html); + tmpCue = new VTTCue(timeIn, timeOut, html); if(id){ tmpCue.id = id; } return tmpCue; }; })(); mediaelement.parseCaptions = function(captionData, track, complete) { - var subtitles = mediaelement.createCueList(); - var cue, lazyProcess, regWevVTT; - var startDate; - var isWEBVTT; + + var cue, lazyProcess, regWevVTT, startDate, isWEBVTT; + + mediaelement.createCueList(); if (captionData) { regWevVTT = /^WEBVTT(\s*FILE)?/ig; lazyProcess = function(i, len){ @@ -893,11 +896,10 @@ NONE: { value: 0 }, readyState: { get: function(){ - return (webshims.data(this, 'trackData') || {readyState: 0}).readyState; }, writeable: false }, track: { @@ -958,33 +960,31 @@ var stopOriginalEvent = function(e){ if(e.originalEvent){ e.stopImmediatePropagation(); } }; - var startTrackImplementation = function(){ + var hideNativeTracks = function(){ if(webshims.implement(this, 'track')){ - var shimedTrack = $.prop(this, 'track'); - var origTrack = this.track; var kind; - var readyState; + var origTrack = this.track; if(origTrack){ - kind = $.prop(this, 'kind'); - readyState = getNativeReadyState(this, origTrack); - if (origTrack.mode || readyState) { - shimedTrack.mode = numericModes[origTrack.mode] || origTrack.mode; + + if (!webshims.bugs.track && (origTrack.mode || getNativeReadyState(this, origTrack))) { + $.prop(this, 'track').mode = numericModes[origTrack.mode] || origTrack.mode; } //disable track from showing + remove UI - if(kind != 'descriptions'){ - origTrack.mode = (typeof origTrack.mode == 'string') ? 'disabled' : 0; - this.kind = 'metadata'; - $(this).attr({kind: kind}); - } + kind = $.prop(this, 'kind'); + origTrack.mode = (typeof origTrack.mode == 'string') ? 'disabled' : 0; + this.kind = 'metadata'; + + $(this).attr({kind: kind}); } $(this).on('load error', stopOriginalEvent); } }; + webshims.addReady(function(context, insertedElement){ var insertedMedia = insertedElement.filter('video, audio, track').closest('audio, video'); $('video, audio', context) .add(insertedMedia) .each(function(){ @@ -997,14 +997,15 @@ var origTextTracks = this.textTracks; if(shimedTextTracks.length != origTextTracks.length){ webshims.error("textTracks couldn't be copied"); } - $('track', this).each(startTrackImplementation); + $('track', this).each(hideNativeTracks); } }) ; + insertedMedia.each(function(){ var media = this; var baseData = webshims.data(media, 'mediaelementBase'); if(baseData){ clearTimeout(baseData.updateTrackListTimer); @@ -1016,6 +1017,6 @@ }); if(Modernizr.texttrackapi){ $('video, audio').trigger('trackapichange'); } -}); \ No newline at end of file +});