vendor/assets/javascripts/webshims/shims/combos/23.js in webshims-rails-1.10.6 vs vendor/assets/javascripts/webshims/shims/combos/23.js in webshims-rails-1.10.9
- old
+ new
@@ -528,56 +528,59 @@
webshims.addPolyfill('mediaelement-native-fix', {
d: ['dom-support']
});
webshims.loader.loadList(['mediaelement-native-fix']);
}
- }
-
- if(hasNative && !options.preferFlash){
- var noSwitch = {
- 1: 1,
- 2: 1
- };
- var switchOptions = function(e){
- var media;
- var parent;
- if(!options.preferFlash &&
+
+ if(!options.preferFlash){
+ var noSwitch = {
+ 1: 1,
+ 2: 1
+ };
+ var switchOptions = function(e){
+ var media, error, parent;
+ if(!options.preferFlash &&
($(e.target).is('audio, video') || ((parent = e.target.parentNode) && $('source:last', parent)[0] == e.target)) &&
- (media = $(e.target).closest('audio, video')) && !noSwitch[media.prop('error')]
+ (media = $(e.target).closest('audio, video')) && !noSwitch[(error = media.prop('error'))]
){
- $(function(){
- if(hasSwf && !options.preferFlash){
- loadSwf();
- webshims.ready('WINDOWLOAD '+swfType, function(){
- setTimeout(function(){
- if(!options.preferFlash && webshims.mediaelement.createSWF && !media.is('.nonnative-api-active')){
- options.preferFlash = true;
- document.removeEventListener('error', switchOptions, true);
- $('audio, video').each(function(){
- webshims.mediaelement.selectSource(this);
- });
- webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error'));
- }
- }, 9);
- });
- } else{
- document.removeEventListener('error', switchOptions, true);
+ if(error == null){
+ webshims.warn("There was an unspecified error on a mediaelement");
+ return;
+
}
- });
- }
- };
- document.addEventListener('error', switchOptions, true);
- $('audio, video').each(function(){
- var error = $.prop(this, 'error');
- if(error && !noSwitch[error]){
- switchOptions({target: this});
- return false;
- }
- });
+ $(function(){
+ if(hasSwf && !options.preferFlash){
+ loadSwf();
+ webshims.ready('WINDOWLOAD '+swfType, function(){
+ setTimeout(function(){
+ if(!options.preferFlash && webshims.mediaelement.createSWF && !media.is('.nonnative-api-active')){
+ options.preferFlash = true;
+ document.removeEventListener('error', switchOptions, true);
+ $('audio, video').each(function(){
+ webshims.mediaelement.selectSource(this);
+ });
+ webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error'));
+ }
+ }, 9);
+ });
+ } else{
+ document.removeEventListener('error', switchOptions, true);
+ }
+ });
+ }
+ };
+ document.addEventListener('error', switchOptions, true);
+ $('audio, video').each(function(){
+ var error = $.prop(this, 'error');
+ if(error && !noSwitch[error]){
+ switchOptions({target: this});
+ return false;
+ }
+ });
+ }
}
-
if(Modernizr.track && !bugs.track){
(function(){
if(!bugs.track){
bugs.track = typeof $('<track />')[0].readyState != 'number';
@@ -954,67 +957,18 @@
$(e.target).prop('currentTime', 0).play();
}, 1);
});
- webshims.ready('dom-support', function(){
- if(!supportsLoop){
- webshims.defineNodeNamesBooleanProperty(['audio', 'video'], 'loop');
- }
-
- ['audio', 'video'].forEach(function(nodeName){
- var supLoad = webshims.defineNodeNameProperty(nodeName, 'load', {
- prop: {
- value: function(){
- var data = webshims.data(this, 'mediaelement');
- selectSource(this, data);
- if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
- supLoad.prop._supvalue.apply(this, arguments);
- }
- }
- }
- });
- nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
- prop: {
- value: function(type){
- var ret = '';
- if(hasNative && nativeCanPlayType[nodeName].prop._supvalue){
- ret = nativeCanPlayType[nodeName].prop._supvalue.call(this, type);
- if(ret == 'no'){
- ret = '';
- }
- }
- if(!ret && hasSwf){
- type = $.trim((type || '').split(';')[0]);
- if(mediaelement.swfMimeTypes.indexOf(type) != -1){
- ret = 'maybe';
- }
- }
- return ret;
- }
- }
- });
- });
- webshims.onNodeNamesPropertyModify(['audio', 'video'], ['src', 'poster'], {
- set: function(){
- var elem = this;
- var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
- clearTimeout(baseData.loadTimer);
- baseData.loadTimer = setTimeout(function(){
- selectSource(elem);
- elem = null;
- }, 9);
- }
- });
- });
-
+ var handleMedia = false;
var initMediaElements = function(){
var testFixMedia = function(){
if(webshims.implement(this, 'mediaelement')){
selectSource(this);
- if(hasNative){
+ //fixes for FF 12 and IE9/10 || does not hurt, if run in other browsers
+ if(hasNative && (!supportsLoop || ('ActiveXObject' in window))){
var bufferTimer;
var lastBuffered;
var elem = this;
var getBufferedString = function(){
var buffered = $.prop(elem, 'buffered');
@@ -1039,11 +993,11 @@
'play loadstart progress': function(e){
if(e.type == 'progress'){
lastBuffered = getBufferedString();
}
clearTimeout(bufferTimer);
- bufferTimer = setTimeout(testBuffer, 999);
+ bufferTimer = setTimeout(testBuffer, 400);
},
'emptied stalled mediaerror abort suspend': function(e){
if(e.type == 'emptied'){
lastBuffered = false;
}
@@ -1056,14 +1010,65 @@
}
}
}
};
- var handleMedia = false;
+
webshims.ready('dom-support', function(){
handleMedia = true;
+
+ if(!supportsLoop){
+ webshims.defineNodeNamesBooleanProperty(['audio', 'video'], 'loop');
+ }
+
+ ['audio', 'video'].forEach(function(nodeName){
+ var supLoad = webshims.defineNodeNameProperty(nodeName, 'load', {
+ prop: {
+ value: function(){
+ var data = webshims.data(this, 'mediaelement');
+ selectSource(this, data);
+ if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
+ supLoad.prop._supvalue.apply(this, arguments);
+ }
+ }
+ }
+ });
+ nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
+ prop: {
+ value: function(type){
+ var ret = '';
+ if(hasNative && nativeCanPlayType[nodeName].prop._supvalue){
+ ret = nativeCanPlayType[nodeName].prop._supvalue.call(this, type);
+ if(ret == 'no'){
+ ret = '';
+ }
+ }
+ if(!ret && hasSwf){
+ type = $.trim((type || '').split(';')[0]);
+ if(mediaelement.swfMimeTypes.indexOf(type) != -1){
+ ret = 'maybe';
+ }
+ }
+ return ret;
+ }
+ }
+ });
+ });
+ webshims.onNodeNamesPropertyModify(['audio', 'video'], ['src', 'poster'], {
+ set: function(){
+ var elem = this;
+ var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
+ clearTimeout(baseData.loadTimer);
+ baseData.loadTimer = setTimeout(function(){
+ selectSource(elem);
+ elem = null;
+ }, 9);
+ }
+ });
+
+
webshims.addReady(function(context, insertedElement){
var media = $('video, audio', context)
.add(insertedElement.filter('video, audio'))
.each(testFixMedia)
;
\ No newline at end of file