vendor/assets/javascripts/webshims/shims/combos/12.js in webshims-rails-1.12.5 vs vendor/assets/javascripts/webshims/shims/combos/12.js in webshims-rails-1.12.7
- old
+ new
@@ -236,11 +236,10 @@
});
};
var wsCfg = webshims.cfg;
var options = wsCfg.mediaelement;
- var hasFullTrackSupport;
var hasSwf;
if(!options){
webshims.error("mediaelement wasn't implemented but loaded");
return;
}
@@ -278,15 +277,13 @@
bugs.track = true;
}
}
})();
}
- hasFullTrackSupport = Modernizr.track && !bugs.track;
webshims.register('mediaelement-core', function($, webshims, window, document, undefined, options){
hasSwf = swfmini.hasFlashPlayerVersion('10.0.3');
- $('html').addClass(hasSwf ? 'swf' : 'no-swf');
var mediaelement = webshims.mediaelement;
mediaelement.parseRtmp = function(data){
var src = data.src.split('://');
var paths = src[1].split('/');
@@ -661,10 +658,13 @@
var data = webshims.data(this, 'mediaelement');
selectSource(this, data);
if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
supLoad.prop._supvalue.apply(this, arguments);
}
+ if(!loadTrackUi.loaded && $('track', this).length){
+ loadTrackUi();
+ }
$(this).triggerHandler('wsmediareload');
}
}
});
nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
@@ -731,17 +731,11 @@
}
});
}
};
- if(hasFullTrackSupport){
- webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', {
- get: function(){
- return this._shimActiveCues || this.activeCues;
- }
- });
- }
+
//set native implementation ready, before swf api is retested
if(hasNative){
webshims.isReady('mediaelement-core', true);
initMediaElements();
webshims.ready('WINDOWLOAD mediaelement', loadThird);
@@ -754,16 +748,12 @@
})(Modernizr, webshims);
;webshims.register('track', function($, webshims, window, document, undefined){
"use strict";
var mediaelement = webshims.mediaelement;
var id = new Date().getTime();
- var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf';
//descriptions are not really shown, but they are inserted into the dom
var showTracks = {subtitles: 1, captions: 1, descriptions: 1};
- var notImplemented = function(){
- webshims.error('not implemented yet');
- };
var dummyTrack = $('<track />');
var supportTrackMod = Modernizr.ES5 && Modernizr.objectAccessor;
var createEventTarget = function(obj){
var eventList = {};
obj.addEventListener = function(name, fn){
@@ -861,13 +851,11 @@
LOADING: 1,
NONE: 0*/
};
var copyProps = ['kind', 'label', 'srclang'];
var copyName = {srclang: 'language'};
-
- var owns = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
-
+
var updateMediaTrackList = function(baseData, trackList){
var removed = [];
var added = [];
var newTracks = [];
var i, len;
@@ -966,64 +954,48 @@
}
return isDefault;
};
})();
var emptyDiv = $('<div />')[0];
+
function VTTCue(startTime, endTime, text){
if(arguments.length != 3){
webshims.error("wrong arguments.length for VTTCue.constructor");
}
-
+
this.startTime = startTime;
this.endTime = endTime;
this.text = text;
-
-
- createEventTarget(this);
- }
-
- VTTCue.prototype = {
-
- onenter: null,
- onexit: null,
- pauseOnExit: false,
- getCueAsHTML: function(){
+ this.onenter = null;
+ this.onexit = null;
+ this.pauseOnExit = false;
+ this.track = null;
+ this.id = null;
+ this.getCueAsHTML = (function(){
var lastText = "";
var parsedText = "";
- var fragment = document.createDocumentFragment();
- var fn;
- if(!owns(this, 'getCueAsHTML')){
- fn = this.getCueAsHTML = function(){
- var i, len;
- if(lastText != this.text){
- lastText = this.text;
- parsedText = mediaelement.parseCueTextToHTML(lastText);
- emptyDiv.innerHTML = parsedText;
-
- for(i = 0, len = emptyDiv.childNodes.length; i < len; i++){
- fragment.appendChild(emptyDiv.childNodes[i].cloneNode(true));
- }
+ var fragment;
+
+ return function(){
+ var i, len;
+ if(!fragment){
+ fragment = document.createDocumentFragment();
+ }
+ if(lastText != this.text){
+ lastText = this.text;
+ parsedText = mediaelement.parseCueTextToHTML(lastText);
+ emptyDiv.innerHTML = parsedText;
+
+ for(i = 0, len = emptyDiv.childNodes.length; i < len; i++){
+ fragment.appendChild(emptyDiv.childNodes[i].cloneNode(true));
}
- return fragment.cloneNode(true);
- };
-
- }
- return fn ? fn.apply(this, arguments) : fragment.cloneNode(true);
- },
- track: null,
-
-
- id: ''
- //todo-->
-// ,
-// snapToLines: true,
-// line: 'auto',
-// size: 100,
-// position: 50,
-// vertical: '',
-// align: 'middle'
- };
+ }
+ return fragment.cloneNode(true);
+ };
+
+ })();
+ }
window.VTTCue = VTTCue;
window.TextTrackCue = function(){
webshims.error("Use VTTCue constructor instead of abstract TextTrackCue constructor.");
VTTCue.apply(this, arguments);
@@ -1070,18 +1042,19 @@
return cueText.replace(tagSplits, replacer);
};
})();
mediaelement.loadTextTrack = function(mediaelem, track, trackData, _default){
- var loadEvents = 'play playing updatetrackdisplay';
+ var loadEvents = 'play playing';
var obj = trackData.track;
var load = function(){
var error, ajax, createAjax;
-
var src = obj.mode != 'disabled' && ($.attr(track, 'src') && $.prop(track, 'src'));
+
if(src){
- $(mediaelem).off(loadEvents, load);
+ $(mediaelem).off(loadEvents, load).off('updatetrackdisplay', load);
+
if(!trackData.readyState){
error = function(){
trackData.readyState = 3;
obj.cues = null;
obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = null;
@@ -1111,11 +1084,11 @@
},
error: error
});
};
- if($.ajax){
+ if($.ajax && $.ajaxSettings.xhr){
createAjax();
} else {
webshims.ready('jajax', createAjax);
webshims.loader.loadList(['jajax']);
}
@@ -1129,15 +1102,19 @@
trackData.readyState = 0;
obj.shimActiveCues = null;
obj._shimActiveCues = null;
obj.activeCues = null;
obj.cues = null;
- $(mediaelem).off(loadEvents, load);
+
$(mediaelem).on(loadEvents, load);
if(_default){
obj.mode = showTracks[obj.kind] ? 'showing' : 'hidden';
- load();
+ webshims.ready('WINDOWLOAD', load);
+ } else {
+ webshims.ready('WINDOWLOAD', function(){
+ $(mediaelem).on('updatetrackdisplay', load);
+ });
}
};
mediaelement.createTextTrack = function(mediaelem, track){
var obj, trackData;
@@ -1162,11 +1139,10 @@
});
}
if(track.nodeName){
-
if(supportTrackMod){
copyProps.forEach(function(copyProp){
webshims.defineProperty(obj, copyName[copyProp] || copyProp, {
get: function(){
return $.prop(track, copyProp);
@@ -1197,12 +1173,12 @@
obj.__wsmode = obj.mode;
}
return obj;
};
-
-
+
+
/*
taken from:
Captionator 0.5.1 [CaptionCrunch]
Christopher Giffard, 2011
Share and enjoy
@@ -1215,11 +1191,11 @@
// Set up timestamp parsers
var WebVTTTimestampParser = /^(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s+\-\-\>\s+(\d{2})?:?(\d{2}):(\d{2})\.(\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 subtitleParts, timeIn, timeOut, html, timeData, subtitlePartIndex, id, specialCueData;
var timestampMatch, tmpCue;
@@ -1231,48 +1207,48 @@
} else if ((specialCueData = WebVTTSTYLECueParser.exec(subtitleElement))) {
return null;
} else if ((specialCueData = WebVTTCOMMENTCueParser.exec(subtitleElement))) {
return null; // At this stage, we don't want to do anything with these.
}
-
+
subtitleParts = subtitleElement.split(/\n/g);
-
+
// Trim off any blank lines (logically, should only be max. one, but loop to be sure)
while (!subtitleParts[0].replace(/\s+/ig,"").length && subtitleParts.length > 0) {
subtitleParts.shift();
}
-
+
if (subtitleParts[0].match(/^\s*[a-z0-9-\_]+\s*$/ig)) {
// The identifier becomes the cue ID (when *we* load the cues from file. Programatically created cues can have an ID of whatever.)
id = String(subtitleParts.shift().replace(/\s*/ig,""));
}
-
+
for (subtitlePartIndex = 0; subtitlePartIndex < subtitleParts.length; subtitlePartIndex ++) {
var timestamp = subtitleParts[subtitlePartIndex];
-
+
if ((timestampMatch = WebVTTTimestampParser.exec(timestamp))) {
-
+
// WebVTT
-
+
timeData = timestampMatch.slice(1);
-
+
timeIn = parseInt((timeData[0]||0) * 60 * 60,10) + // Hours
parseInt((timeData[1]||0) * 60,10) + // Minutes
parseInt((timeData[2]||0),10) + // Seconds
parseFloat("0." + (timeData[3]||0)); // MS
-
+
timeOut = parseInt((timeData[4]||0) * 60 * 60,10) + // Hours
parseInt((timeData[5]||0) * 60,10) + // Minutes
parseInt((timeData[6]||0),10) + // Seconds
parseFloat("0." + (timeData[7]||0)); // MS
/*
if (timeData[8]) {
cueSettings = timeData[8];
}
*/
}
-
+
// We've got the timestamp - return all the other unmatched lines as the raw subtitle data
subtitleParts = subtitleParts.slice(0,subtitlePartIndex).concat(subtitleParts.slice(subtitlePartIndex+1));
break;
}
@@ -1287,22 +1263,22 @@
cueDefaults
.reduce(function(previous,current,index,array){
previous[current.split(":")[0]] = current.split(":")[1];
return previous;
},{});
-
+
// Loop through cue settings, replace defaults with cue specific settings if they exist
compositeCueSettings =
cueSettings
.split(/\s+/g)
.filter(function(set) { return set && !!set.length; })
// Convert array to a key/val object
.reduce(function(previous,current,index,array){
previous[current.split(":")[0]] = current.split(":")[1];
return previous;
},compositeCueSettings);
-
+
// Turn back into string like the VTTCue constructor expects
cueSettings = "";
for (var key in compositeCueSettings) {
if (compositeCueSettings.hasOwnProperty(key)) {
cueSettings += !!cueSettings.length ? " " : "";
@@ -1317,22 +1293,22 @@
tmpCue.id = id;
}
return tmpCue;
};
})();
-
+
mediaelement.parseCaptions = function(captionData, track, complete) {
var cue, lazyProcess, regWevVTT, startDate, isWEBVTT;
mediaelement.createCueList();
if (captionData) {
-
+
regWevVTT = /^WEBVTT(\s*FILE)?/ig;
-
+
lazyProcess = function(i, len){
-
+
for(; i < len; i++){
cue = captionData[i];
if(regWevVTT.test(cue)){
isWEBVTT = true;
} else if(cue.replace(/\s*/ig,"").length){
@@ -1350,39 +1326,39 @@
i++;
setTimeout(function(){
startDate = new Date().getTime();
lazyProcess(i, len);
}, 90);
-
+
break;
}
}
if(i >= len){
if(!isWEBVTT){
webshims.error('please use WebVTT format. This is the standard');
}
complete(track.cues);
}
};
-
+
captionData = captionData.replace(/\r\n/g,"\n");
-
+
setTimeout(function(){
captionData = captionData.replace(/\r/g,"\n");
setTimeout(function(){
startDate = new Date().getTime();
captionData = captionData.split(/\n\n+/g);
lazyProcess(0, captionData.length);
}, 9);
}, 9);
-
+
} else {
webshims.error("Required parameter captionData not supplied.");
}
};
+
-
mediaelement.createTrackList = function(mediaelem, baseData){
baseData = baseData || webshims.data(mediaelem, 'mediaelementBase') || webshims.data(mediaelem, 'mediaelementBase', {});
if(!baseData.textTracks){
baseData.textTracks = [];
webshims.defineProperties(baseData.textTracks, {
@@ -1599,11 +1575,12 @@
.on('emptied updatetracklist wsmediareload', thUpdateList)
.each(function(){
if(Modernizr.track){
var shimedTextTracks = $.prop(this, 'textTracks');
var origTextTracks = this.textTracks;
+
if(shimedTextTracks.length != origTextTracks.length){
- webshims.error("textTracks couldn't be copied");
+ webshims.warn("textTracks couldn't be copied");
}
$('track', this).each(hideNativeTracks);
}
})