vendor/assets/javascripts/webshims/shims/combos/25.js in webshims-rails-1.11.2 vs vendor/assets/javascripts/webshims/shims/combos/25.js in webshims-rails-1.11.3

- old
+ new

@@ -1256,10 +1256,11 @@ //DOM-Extension helper webshims.register('dom-extend', function($, webshims, window, document, undefined){ "use strict"; var supportHrefNormalized = !('hrefNormalized' in $.support) || $.support.hrefNormalized; var supportGetSetAttribute = !('getSetAttribute' in $.support) || $.support.getSetAttribute; + var has = Object.prototype.hasOwnProperty; webshims.assumeARIA = supportGetSetAttribute || Modernizr.canvas || Modernizr.video || Modernizr.boxsizing; if($('<input type="email" />').attr('type') == 'text' || $('<form />').attr('novalidate') === "" || ('required' in $('<input />')[0].attributes)){ webshims.error("IE browser modes are busted in IE10+. Please test your HTML/CSS/JS with a real IE version or at least IETester or similiar tools"); } @@ -1328,10 +1329,11 @@ var listReg = /\s*,\s*/; //proxying attribute var olds = {}; var havePolyfill = {}; + var hasPolyfillMethod = {}; var extendedProps = {}; var extendQ = {}; var modifyProps = {}; var oldVal = $.fn.val; @@ -1433,10 +1435,43 @@ }); return this.pushStack(elems); }; }); + //add support for $('video').trigger('play') in case extendNative is set to false + if(!webshims.cfg.extendNative && !webshims.cfg.noTriggerOverride){ + (function(oldTrigger){ + $.event.trigger = function(event, data, elem, onlyHandlers){ + + if(!hasPolyfillMethod[event] || onlyHandlers || !elem || elem.nodeType !== 1){ + return oldTrigger.apply(this, arguments); + } + var ret, isOrig, origName; + var origFn = elem[event]; + var polyfilledFn = $.prop(elem, event); + var changeFn = polyfilledFn && origFn != polyfilledFn; + if(changeFn){ + origName = '__ws'+event; + isOrig = (event in elem) && has.call(elem, event); + elem[event] = polyfilledFn; + elem[origName] = origFn; + } + + ret = oldTrigger.apply(this, arguments); + if (changeFn) { + if(isOrig){ + elem[event] = origFn; + } else { + delete elem[event]; + } + delete elem[origName]; + } + + return ret; + }; + })($.event.trigger); + } ['removeAttr', 'prop', 'attr'].forEach(function(type){ olds[type] = $[type]; $[type] = function(elem, name, value, pass, _argless){ var isVal = (pass == 'val'); @@ -1517,10 +1552,11 @@ if(!extendedProps[nodeName][prop]){ extendedProps[nodeName][prop] = {}; } var oldDesc = extendedProps[nodeName][prop][type]; var getSup = function(propType, descriptor, oDesc){ + var origProp; if(descriptor && descriptor[propType]){ return descriptor[propType]; } if(oDesc && oDesc[propType]){ return oDesc[propType]; @@ -1533,12 +1569,14 @@ olds[type](elem, prop, value) ; }; } if(type == 'prop' && propType == 'value' && desc.value.apply){ + origProp = '__ws'+prop; + hasPolyfillMethod[prop] = true; return function(value){ - var sup = olds[type](this, prop); + var sup = this[origProp] || olds[type](this, prop); if(sup && sup.apply){ sup = sup.apply(this, arguments); } return sup; }; @@ -1572,11 +1610,11 @@ }); var extendNativeValue = (function(){ var UNKNOWN = webshims.getPrototypeOf(document.createElement('foobar')); - var has = Object.prototype.hasOwnProperty; + //see also: https://github.com/lojjic/PIE/issues/40 | https://prototype.lighthouseapp.com/projects/8886/tickets/1107-ie8-fatal-crash-when-prototypejs-is-loaded-with-rounded-cornershtc var isExtendNativeSave = Modernizr.advancedObjectProperties && Modernizr.objectAccessor; return function(nodeName, prop, desc){ var elem , elemProto; if( isExtendNativeSave && (elem = document.createElement(nodeName)) && (elemProto = webshims.getPrototypeOf(elem)) && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){ @@ -2880,11 +2918,11 @@ tmp = elem.attr('data-server'); if(tmp != null){ src.server = tmp; } - tmp = elem.attr('type'); + tmp = elem.attr('type') || elem.attr('data-type'); if(tmp){ src.type = tmp; src.container = $.trim(tmp.split(';')[0]); } else { if(!nodeName){ @@ -2904,10 +2942,15 @@ src.type = tmp; src.container = tmp; } } } + + if(!src.container){ + $(elem).attr('data-wsrecheckmimetype', ''); + } + tmp = elem.attr('media'); if(tmp){ src.media = tmp; } if(src.type == 'audio/rtmp' || src.type == 'video/rtmp'){ @@ -3137,19 +3180,22 @@ }; var handleThird = (function(){ var requested; + var readyType = hasSwf ? swfType : 'mediaelement-yt'; return function( mediaElem, ret, data ){ + //readd to ready - webshims.ready(hasSwf ? swfType : 'mediaelement-yt', function(){ - if(mediaelement.createSWF){ + + webshims.ready(readyType, function(){ + if(mediaelement.createSWF && $(mediaElem).parent()[0]){ mediaelement.createSWF( mediaElem, ret, data ); } else if(!requested) { requested = true; loadThird(); - //readd to ready + handleThird( mediaElem, ret, data ); } }); if(!requested && hasYt && !mediaelement.createSWF){ loadYt(); @@ -3486,20 +3532,11 @@ _ppFlag: undefined, _calledMeta: false, lastDuration: 0 }, getProps, getSetProps); - var idRep = /^jarisplayer-/; - var getSwfDataFromID = function(id){ - - var elem = document.getElementById(id.replace(idRep, '')); - if(!elem){return;} - var data = webshims.data(elem, 'mediaelement'); - return data.isActive == 'third' ? data : null; - }; - var getSwfDataFromElem = function(elem){ try { (elem.nodeName); } catch(er){ return null; @@ -4087,10 +4124,11 @@ data.api = false; data.actionQueue = []; box = data.shadowElem; resetSwfProps(data); } else { + $(document.getElementById('wrapper-'+ elemId )).remove(); box = $('<div class="polyfill-'+ (elemNodeName) +' polyfill-mediaelement" id="wrapper-'+ elemId +'"><div id="'+ elemId +'"></div>') .css({ position: 'relative', overflow: 'hidden' }) @@ -4169,12 +4207,15 @@ }) .onWSOff('updateshadowdom', setDimension) ; } - - if(!mediaelement.jarisEvent[data.id] || mediaelement.jarisEvent[data.id].elem != elem){ + if(mediaelement.jarisEvent[data.id] && mediaelement.jarisEvent[data.id].elem != elem){ + webshims.error('something went wrong'); + return; + } else if(!mediaelement.jarisEvent[data.id]){ + mediaelement.jarisEvent[data.id] = function(jaris){ if(jaris.type == 'ready'){ var onReady = function(){ if(data.api){ @@ -4376,10 +4417,11 @@ ['play', 'pause'].forEach(function(fn){ descs[fn] = { value: function(){ var data = getSwfDataFromElem(this); + if(data){ if(data.stopPlayPause){ clearTimeout(data.stopPlayPause); } queueSwfMethod(this, fn == 'play' ? 'api_play' : 'api_pause', [], data); @@ -4398,10 +4440,11 @@ getPropKeys.forEach(createGetProp); webshims.onNodeNamesPropertyModify(nodeName, 'controls', function(val, boolProp){ var data = getSwfDataFromElem(this); + $(this)[boolProp ? 'addClass' : 'removeClass']('webshims-controls'); if(data){ if(nodeName == 'audio'){ setElementDimension(data, boolProp); @@ -4530,8 +4573,63 @@ } }, 'prop'); } else if(!('media' in document.createElement('source'))){ webshims.reflectProperties('source', ['media']); + } + if(options.experimentallyMimetypeCheck){ + (function(){ + var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf'; + var getMimeType = function(){ + var done; + var unknown = 'media/unknown please provide mime type'; + var media = $(this); + var xhrs = []; + media + .not('.ws-after-check') + .find('source') + [ADDBACK]() + .filter('[data-wsrecheckmimetype]:not([type])') + .each(function(){ + var source = $(this).removeAttr('data-wsrecheckmimetype'); + var error = function(){ + source.attr('data-type', unknown); + }; + try { + xhrs.push( + $.ajax({ + type: 'head', + url: $.attr(this, 'src'), + success: function(content, status, xhr){ + var mime = xhr.getResponseHeader('Content-Type'); + if(mime){ + done = true; + } + source.attr('data-type', mime || unknown); + }, + error: error + }) + ) + ; + } catch(er){ + error(); + } + }) + ; + if(xhrs.length){ + media.addClass('ws-after-check'); + $.when.apply($, xhrs).always(function(){ + media.mediaLoad(); + setTimeout(function(){ + media.removeClass('ws-after-check'); + }, 9); + }); + } + }; + $('audio.media-error, video.media-error').each(getMimeType); + $(document).on('mediaerror', function(e){ + getMimeType.call(e.target); + }); + })(); } }); \ No newline at end of file