vendor/assets/javascripts/webshims/shims/combos/12.js in webshims-rails-1.10.3 vs vendor/assets/javascripts/webshims/shims/combos/12.js in webshims-rails-1.10.6

- old
+ new

@@ -6,11 +6,11 @@ var swfmini = function() { var UNDEF = "undefined", OBJECT = "object", - webshims = jQuery.webshims, + webshims = jQuery.webshims || window.webshims, SHOCKWAVE_FLASH = "Shockwave Flash", SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash", FLASH_MIME_TYPE = "application/x-shockwave-flash", win = window, @@ -499,21 +499,21 @@ (function($, Modernizr, webshims){ "use strict"; var hasNative = Modernizr.audio && Modernizr.video; var supportsLoop = false; var bugs = webshims.bugs; - + var swfType = 'mediaelement-jaris'; var loadSwf = function(){ webshims.ready(swfType, function(){ if(!webshims.mediaelement.createSWF){ webshims.mediaelement.loadSwf = true; webshims.reTest([swfType], hasNative); } }); }; var options = webshims.cfg.mediaelement; - var swfType = 'mediaelement-jaris'; + var hasFullTrackSupport; var hasSwf; if(!options){ webshims.error("mediaelement wasn't implemented but loaded"); return; } @@ -522,31 +522,28 @@ Modernizr.videoBuffered = ('buffered' in videoElem); supportsLoop = ('loop' in videoElem); webshims.capturingEvents(['play', 'playing', 'waiting', 'paused', 'ended', 'durationchange', 'loadedmetadata', 'canplay', 'volumechange']); - if(!Modernizr.videoBuffered){ + if(!Modernizr.videoBuffered ){ webshims.addPolyfill('mediaelement-native-fix', { - f: 'mediaelement', - test: Modernizr.videoBuffered, d: ['dom-support'] }); - - webshims.reTest('mediaelement-native-fix'); + webshims.loader.loadList(['mediaelement-native-fix']); } } if(hasNative && !options.preferFlash){ var noSwitch = { 1: 1, 2: 1 }; var switchOptions = function(e){ var media; - var parent = e.target.parentNode; + var parent; if(!options.preferFlash && - ($(e.target).is('audio, video') || (parent && $('source:last', parent)[0] == e.target)) && + ($(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')] ){ $(function(){ if(hasSwf && !options.preferFlash){ loadSwf(); @@ -556,11 +553,11 @@ options.preferFlash = true; document.removeEventListener('error', switchOptions, true); $('audio, video').each(function(){ webshims.mediaelement.selectSource(this); }); - webshims.info("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error')); + 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); @@ -591,47 +588,13 @@ new TextTrackCue(2, 3, ''); } catch(e){ bugs.track = true; } } - - var trackOptions = webshims.cfg.track; - var trackListener = function(e){ - $(e.target).filter('track').each(changeApi); - }; - var changeApi = function(){ - if(bugs.track || (!trackOptions.override && $.prop(this, 'readyState') == 3)){ - trackOptions.override = true; - webshims.reTest('track'); - document.removeEventListener('error', trackListener, true); - if(this && $.nodeName(this, 'track')){ - webshims.error("track support was overwritten. Please check your vtt including your vtt mime-type"); - } else { - webshims.info("track support was overwritten. due to bad browser support"); - } - return false; - } - }; - var detectTrackError = function(){ - document.addEventListener('error', trackListener, true); - - if(bugs.track){ - changeApi(); - } else { - $('track').each(changeApi); - } - }; - if(!trackOptions.override){ - if(webshims.isReady('track')){ - detectTrackError(); - } else { - $(detectTrackError); - } - } })(); - } + hasFullTrackSupport = Modernizr.track && !bugs.track; webshims.register('mediaelement-core', function($, webshims, window, document, undefined){ hasSwf = swfmini.hasFlashPlayerVersion('9.0.115'); $('html').addClass(hasSwf ? 'swf' : 'no-swf'); var mediaelement = webshims.mediaelement; @@ -712,11 +675,12 @@ var hasYt = !hasSwf && ('postMessage' in window) && hasNative; var loadTrackUi = function(){ if(loadTrackUi.loaded){return;} loadTrackUi.loaded = true; - $(function(){ + webshims.ready('WINDOWLOAD', function(){ + loadThird(); webshims.loader.loadList(['track-ui']); }); }; var loadYt = (function(){ var loaded; @@ -885,31 +849,44 @@ } }); } return ret; }; - + var emptyType = (/^\s*application\/octet\-stream\s*$/i); + var getRemoveEmptyType = function(){ + var ret = emptyType.test($.attr(this, 'type') || ''); + if(ret){ + $(this).removeAttr('type'); + } + return ret; + }; mediaelement.setError = function(elem, message){ - if(!message){ - message = "can't play sources"; + if($('source', elem).filter(getRemoveEmptyType).length){ + webshims.error('"application/octet-stream" is a useless mimetype for audio/video. Please change this attribute.'); + try { + $(elem).mediaLoad(); + } catch(er){} + } else { + if(!message){ + message = "can't play sources"; + } + $(elem).pause().data('mediaerror', message); + webshims.error('mediaelementError: '+ message); + setTimeout(function(){ + if($(elem).data('mediaerror')){ + $(elem).trigger('mediaerror'); + } + }, 1); } - $(elem).pause().data('mediaerror', message); - webshims.error('mediaelementError: '+ message); - setTimeout(function(){ - if($(elem).data('mediaerror')){ - $(elem).trigger('mediaerror'); - } - }, 1); + }; var handleThird = (function(){ var requested; return function( mediaElem, ret, data ){ - if(!requested){ - loadTrackUi(); - } + webshims.ready(hasSwf ? swfType : 'mediaelement-yt', function(){ if(mediaelement.createSWF){ mediaelement.createSWF( mediaElem, ret, data ); } else if(!requested) { requested = true; @@ -1050,10 +1027,11 @@ }; var testBuffer = function(){ var buffered = getBufferedString(); if(buffered != lastBuffered){ lastBuffered = buffered; + webshims.info('needed to trigger progress manually'); $(elem).triggerHandler('progress'); } }; $(this) @@ -1101,23 +1079,26 @@ webshims.addReady(function(context, insertedElement){ if(!handleMedia){ $('video, audio', context) .add(insertedElement.filter('video, audio')) .each(function(){ - if(!mediaelement.canNativePlaySrces(this) || (!loadTrackUi.loaded && $('track', this).length)){ + if(!mediaelement.canNativePlaySrces(this)){ loadThird(); handleMedia = true; return false; } + if((!hasFullTrackSupport || webshims.modules.track.options.override) && !loadTrackUi.loaded && $('track', this).length){ + loadTrackUi(); + } }) ; } }); } }; - if(Modernizr.track && !bugs.track){ + if(hasFullTrackSupport){ webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', { get: function(){ return this._shimActiveCues || this.activeCues; } }); @@ -1128,13 +1109,13 @@ initMediaElements(); webshims.ready('WINDOWLOAD mediaelement', loadThird); } else { webshims.ready(swfType, initMediaElements); } - webshims.ready('WINDOWLOAD mediaelement', loadTrackUi); + webshims.ready('track', loadTrackUi); }); -})(jQuery, Modernizr, jQuery.webshims); -jQuery.webshims.register('track', function($, webshims, window, document, undefined){ +})(jQuery, 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 \ No newline at end of file