vendor/assets/javascripts/webshims/shims/combos/12.js in webshims-rails-1.11.1 vs vendor/assets/javascripts/webshims/shims/combos/12.js in webshims-rails-1.11.2
- old
+ new
@@ -1191,12 +1191,12 @@
activeCues: null,
cues: null,
kind: 'subtitles',
label: '',
language: '',
+ id: '',
mode: 'disabled',
- readyState: 0,
oncuechange: null,
toString: function() {
return "[object TextTrack]";
},
addCue: function(cue){
@@ -1232,19 +1232,19 @@
}
if(cue.track){
webshims.error("cue not part of track");
return;
}
- },
+ }/*,
DISABLED: 'disabled',
OFF: 'disabled',
HIDDEN: 'hidden',
SHOWING: 'showing',
ERROR: 3,
LOADED: 2,
LOADING: 1,
- NONE: 0
+ NONE: 0*/
};
var copyProps = ['kind', 'label', 'srclang'];
var copyName = {srclang: 'language'};
var owns = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
@@ -1309,40 +1309,64 @@
var refreshTrack = function(track, trackData){
if(!trackData){
trackData = webshims.data(track, 'trackData');
}
+
if(trackData && !trackData.isTriggering){
trackData.isTriggering = true;
setTimeout(function(){
- if(!(trackData.track || {}).readyState){
- $(track).triggerHandler('checktrackmode');
- } else {
- $(track).closest('audio, video').triggerHandler('updatetrackdisplay');
- }
+ $(track).closest('audio, video').triggerHandler('updatetrackdisplay');
trackData.isTriggering = false;
}, 1);
}
};
-
+ var isDefaultTrack = (function(){
+ var defaultKinds = {
+ subtitles: {
+ subtitles: 1,
+ captions: 1
+ },
+ descriptions: {descriptions: 1},
+ chapters: {chapters: 1}
+ };
+ defaultKinds.captions = defaultKinds.subtitles;
+
+ return function(track){
+ var kind, firstDefaultTrack;
+ var isDefault = $.prop(track, 'default');
+ if(isDefault && (kind = $.prop(track, 'kind')) != 'metadata'){
+ firstDefaultTrack = $(track)
+ .parent()
+ .find('track[default]')
+ .filter(function(){
+ return !!(defaultKinds[kind][$.prop(this, 'kind')]);
+ })[0]
+ ;
+ if(firstDefaultTrack != track){
+ isDefault = false;
+ webshims.error('more than one default track of a specific kind detected. Fall back to default = false');
+ }
+ }
+ return isDefault;
+ };
+ })();
var emptyDiv = $('<div />')[0];
- window.TextTrackCue = function(startTime, endTime, text){
+ var TextTrackCue = function(startTime, endTime, text){
if(arguments.length != 3){
webshims.error("wrong arguments.length for TextTrackCue.constructor");
}
this.startTime = startTime;
this.endTime = endTime;
this.text = text;
- this.id = "";
- this.pauseOnExit = false;
createEventTarget(this);
};
- window.TextTrackCue.prototype = {
+ TextTrackCue.prototype = {
onenter: null,
onexit: null,
pauseOnExit: false,
getCueAsHTML: function(){
@@ -1380,10 +1404,11 @@
// position: 50,
// vertical: '',
// align: 'middle'
};
+ window.TextTrackCue = TextTrackCue;
mediaelement.createCueList = function(){
@@ -1425,27 +1450,24 @@
return cueText.replace(tagSplits, replacer);
};
})();
mediaelement.loadTextTrack = function(mediaelem, track, trackData, _default){
- var loadEvents = 'play playing timeupdate updatetrackdisplay';
+ var loadEvents = 'play playing updatetrackdisplay';
var obj = trackData.track;
var load = function(){
- var src = $.prop(track, 'src');
- var error;
- var ajax;
- if(obj.mode != 'disabled' && src && $.attr(track, 'src')){
+ var error, ajax, src;
+ if(obj.mode != 'disabled' && $.attr(track, 'src') && (src = $.prop(track, 'src'))){
$(mediaelem).unbind(loadEvents, load);
- $(track).unbind('checktrackmode', load);
- if(!obj.readyState){
+ if(!trackData.readyState){
error = function(){
- obj.readyState = 3;
+ trackData.readyState = 3;
obj.cues = null;
obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = null;
$(track).triggerHandler('error');
};
- obj.readyState = 1;
+ trackData.readyState = 1;
try {
obj.cues = mediaelement.createCueList();
obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = mediaelement.createCueList();
ajax = $.ajax({
dataType: 'text',
@@ -1454,11 +1476,11 @@
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){
- obj.readyState = 2;
+ trackData.readyState = 2;
$(track).triggerHandler('load');
$(mediaelem).triggerHandler('updatetrackdisplay');
} else {
error();
}
@@ -1467,24 +1489,22 @@
},
error: error
});
} catch(er){
error();
- webshims.warn(er);
+ webshims.error(er);
}
}
}
};
- obj.readyState = 0;
+ trackData.readyState = 0;
obj.shimActiveCues = null;
obj._shimActiveCues = null;
obj.activeCues = null;
obj.cues = null;
$(mediaelem).unbind(loadEvents, load);
- $(track).unbind('checktrackmode', load);
$(mediaelem).on(loadEvents, load);
- $(track).on('checktrackmode', load);
if(_default){
obj.mode = showTracks[obj.kind] ? 'showing' : 'hidden';
load();
}
};
@@ -1522,13 +1542,13 @@
return $.prop(track, copyProp);
}
});
});
}
-
+ obj.id = $(track).prop('id');
trackData = webshims.data(track, 'trackData', {track: obj});
- mediaelement.loadTextTrack(mediaelem, track, trackData, ($.prop(track, 'default') && $(track).siblings('track[default]')[ADDBACK]()[0] == track));
+ mediaelement.loadTextTrack(mediaelem, track, trackData, isDefaultTrack(track));
} else {
if(supportTrackMod){
copyProps.forEach(function(copyProp){
webshims.defineProperty(obj, copyName[copyProp] || copyProp, {
value: track[copyProp],
@@ -1539,11 +1559,16 @@
obj.cues = mediaelement.createCueList();
obj.activeCues = obj._shimActiveCues = obj.shimActiveCues = mediaelement.createCueList();
obj.mode = 'hidden';
obj.readyState = 2;
}
+ if(obj.kind == 'subtitles' && !obj.language){
+ webshims.error('you must provide a language for track in subtitles state');
+ }
+ obj.__wsmode = obj.mode;
}
+
return obj;
};
/*
@@ -1732,13 +1757,37 @@
baseData = baseData || webshims.data(mediaelem, 'mediaelementBase') || webshims.data(mediaelem, 'mediaelementBase', {});
if(!baseData.textTracks){
baseData.textTracks = [];
webshims.defineProperties(baseData.textTracks, {
onaddtrack: {value: null},
- onremovetrack: {value: null}
+ onremovetrack: {value: null},
+ onchange: {value: null},
+ getTrackById: {
+ value: function(id){
+ var track = null;
+ for(var i = 0; i < baseData.textTracks.length; i++){
+ if(id == baseData.textTracks[i].id){
+ track = baseData.textTracks[i];
+ break;
+ }
+ }
+ return track;
+ }
+ }
});
createEventTarget(baseData.textTracks);
+ $(mediaelem).on('updatetrackdisplay', function(){
+ var track;
+ for(var i = 0; i < baseData.textTracks.length; i++){
+ track = baseData.textTracks[i];
+ if(track.__wsmode != track.mode){
+ track.__wsmode = track.mode;
+ $([ baseData.textTracks ]).triggerHandler('change');
+ }
+ }
+ });
+
}
return baseData.textTracks;
};
if(!Modernizr.track){
@@ -1789,14 +1838,10 @@
refreshTrack(this, trackData);
}
if(!supportTrackMod){
trackData.track[name] = $.prop(this, copyProp);
}
- clearTimeout(trackData.changedTrackPropTimer);
- trackData.changedTrackPropTimer = setTimeout(function(){
- $(track).trigger('updatesubtitlestate');
- }, 1);
}
});
});
@@ -1829,11 +1874,12 @@
NONE: {
value: 0
},
readyState: {
get: function(){
- return ($.prop(this, 'track') || {readyState: 0}).readyState;
+
+ return (webshims.data(this, 'trackData') || {readyState: 0}).readyState;
},
writeable: false
},
track: {
get: function(){
@@ -1947,9 +1993,9 @@
}, 9);
}
});
});
- if(Modernizr.track){
+ if(Modernizr.texttrackapi){
$('video, audio').trigger('trackapichange');
}
});
\ No newline at end of file