vendor/assets/javascripts/webshims/shims/track.js in webshims-rails-1.11.3.1 vs vendor/assets/javascripts/webshims/shims/track.js in webshims-rails-1.11.6

- old
+ new

@@ -316,13 +316,13 @@ mediaelement.loadTextTrack = function(mediaelem, track, trackData, _default){ var loadEvents = 'play playing updatetrackdisplay'; var obj = trackData.track; var load = function(){ - var error, ajax, src; + var error, ajax, src, createAjax; if(obj.mode != 'disabled' && $.attr(track, 'src') && (src = $.prop(track, 'src'))){ - $(mediaelem).unbind(loadEvents, load); + $(mediaelem).off(loadEvents, load); if(!trackData.readyState){ error = function(){ trackData.readyState = 3; obj.cues = null; obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = null; @@ -330,30 +330,38 @@ }; trackData.readyState = 1; try { obj.cues = mediaelement.createCueList(); obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = mediaelement.createCueList(); - ajax = $.ajax({ - dataType: 'text', - url: src, - success: function(text){ - if(ajax.getResponseHeader('content-type') != 'text/vtt'){ - webshims.error('set the mime-type of your WebVTT files to text/vtt. see: http://dev.w3.org/html5/webvtt/#text/vtt'); - } - mediaelement.parseCaptions(text, obj, function(cues){ - if(cues && 'length' in cues){ - trackData.readyState = 2; - $(track).triggerHandler('load'); - $(mediaelem).triggerHandler('updatetrackdisplay'); - } else { - error(); + createAjax = function(){ + ajax = $.ajax({ + dataType: 'text', + url: src, + success: function(text){ + if(ajax.getResponseHeader('content-type') != 'text/vtt'){ + webshims.error('set the mime-type of your WebVTT files to text/vtt. see: http://dev.w3.org/html5/webvtt/#text/vtt'); } - }); - - }, - error: error - }); + mediaelement.parseCaptions(text, obj, function(cues){ + if(cues && 'length' in cues){ + trackData.readyState = 2; + $(track).triggerHandler('load'); + $(mediaelem).triggerHandler('updatetrackdisplay'); + } else { + error(); + } + }); + + }, + error: error + }); + }; + if($.ajax){ + createAjax(); + } else { + webshims.ready('$ajax', createAjax); + webshims.loader.loadList(['$ajax']); + } } catch(er){ error(); webshims.error(er); } } @@ -362,11 +370,11 @@ trackData.readyState = 0; obj.shimActiveCues = null; obj._shimActiveCues = null; obj.activeCues = null; obj.cues = null; - $(mediaelem).unbind(loadEvents, load); + $(mediaelem).off(loadEvents, load); $(mediaelem).on(loadEvents, load); if(_default){ obj.mode = showTracks[obj.kind] ? 'showing' : 'hidden'; load(); } @@ -781,22 +789,22 @@ return textTrack; } } }, 'prop'); - - $(document).on('emptied ended updatetracklist', function(e){ + //wsmediareload + var thUpdateList = function(e){ if($(e.target).is('audio, video')){ var baseData = webshims.data(e.target, 'mediaelementBase'); if(baseData){ clearTimeout(baseData.updateTrackListTimer); baseData.updateTrackListTimer = setTimeout(function(){ updateMediaTrackList.call(e.target, baseData); }, 0); } } - }); + }; var getNativeReadyState = function(trackElem, textTrack){ return textTrack.readyState || trackElem.readyState; }; var stopOriginalEvent = function(e){ @@ -832,9 +840,10 @@ $('video, audio', context) .add(insertedMedia) .each(function(){ updateMediaTrackList.call(this); }) + .on('emptied updatetracklist wsmediareload', thUpdateList) .each(function(){ if(Modernizr.track){ var shimedTextTracks = $.prop(this, 'textTracks'); var origTextTracks = this.textTracks; if(shimedTextTracks.length != origTextTracks.length){ \ No newline at end of file