vendor/assets/javascripts/webshims/shims/combos/25.js in webshims-rails-1.10.9 vs vendor/assets/javascripts/webshims/shims/combos/25.js in webshims-rails-1.10.10

- old
+ new

@@ -6,11 +6,11 @@ var swfmini = function() { var UNDEF = "undefined", OBJECT = "object", - webshims = jQuery.webshims || window.webshims, + webshims = window.webshims, SHOCKWAVE_FLASH = "Shockwave Flash", SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash", FLASH_MIME_TYPE = "application/x-shockwave-flash", win = window, @@ -1203,15 +1203,15 @@ if(props){ shims.defineProperties(o, props); } if(opts){ - o.options = jQuery.extend(true, {}, o.options || {}, opts); + o.options = $.extend(true, {}, o.options || {}, opts); opts = o.options; } - if(o._create && jQuery.isFunction(o._create)){ + if(o._create && $.isFunction(o._create)){ o._create(opts); } return o; }; @@ -1293,11 +1293,11 @@ return descriptor; }; } -})(jQuery, jQuery.webshims); +})(webshims.$, webshims); //DOM-Extension helper webshims.register('dom-extend', function($, webshims, window, document, undefined){ @@ -1311,18 +1311,18 @@ if(!$.parseHTML){ webshims.error("Webshims needs jQuery 1.8+ to work properly. Please update your jQuery version or downgrade webshims."); } - if(webshims.cfg.extendNative == 1){ + if(webshims.cfg.extendNative === 1){ webshims.warn("extendNative configuration will be set to false by default with next release. In case you rely on it set it to 'true' otherwise to 'false'. See http://bit.ly/16OOTQO"); } if (!webshims.cfg.no$Switch) { var switch$ = function(){ if (window.jQuery && (!window.$ || window.jQuery == window.$) && !window.jQuery.webshims) { - webshims.error("jQuery was included more than once. Make sure to include it only once or try the $.noConflict(extreme) feature! Webshims and other Plugins might not work properly.."); + webshims.error("jQuery was included more than once. Make sure to include it only once or try the $.noConflict(extreme) feature! Webshims and other Plugins might not work properly. Or set webshims.cfg.no$Switch to 'true'."); if (window.$) { window.$ = webshims.$; } window.jQuery = webshims.$; } @@ -1860,10 +1860,11 @@ this.height = docObserve.getHeight(); this.width = docObserve.getWidth(); setInterval(this.test, 600); $(this.test); webshims.ready('WINDOWLOAD', this.test); + $(document).on('updatelayout', this.handler); $(window).bind('resize', this.handler); (function(){ var oldAnimate = $.fn.animate; var animationTimer; @@ -1907,11 +1908,13 @@ shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData); } $(nativeElem).on('remove', function(e){ if (!e.originalEvent) { - $(shadowElem).remove(); + setTimeout(function(){ + $(shadowElem).remove(); + }, 4); } }); nativeData.hasShadow = shadowElem; shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem; @@ -2385,11 +2388,11 @@ addRole(footer, 'contentinfo'); } } }); -})(jQuery, document); +})(webshims.$, document); webshims.register('filereader', function( $, webshims ){ "use strict"; (function(){ @@ -2774,12 +2777,13 @@ $('input[type="file"].ws-filereader', context).fileReader(); }); }); }); -(function($, Modernizr, webshims){ +(function(Modernizr, webshims){ "use strict"; + var $ = webshims.$; var hasNative = Modernizr.audio && Modernizr.video; var supportsLoop = false; var bugs = webshims.bugs; var swfType = 'mediaelement-jaris'; var loadSwf = function(){ @@ -2879,10 +2883,11 @@ 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; + mediaelement.parseRtmp = function(data){ var src = data.src.split('://'); var paths = src[1].split('/'); var i, len, found; data.server = src[0]+'://'+paths[0]+'/'; @@ -3048,11 +3053,10 @@ srces = []; var nodeName = mediaElem[0].nodeName.toLowerCase(); var src = getSrcObj(mediaElem, nodeName); if(!src.src){ - $('source', mediaElem).each(function(){ src = getSrcObj(this, nodeName); if(src.src){srces.push(src);} }); } else { @@ -3063,22 +3067,14 @@ mediaElem.removeAttr('src').removeAttr('type').find('source').remove(); if(!$.isArray(srces)){ srces = [srces]; } srces.forEach(function(src){ - var source = document.createElement('source'); if(typeof src == 'string'){ src = {src: src}; } - source.setAttribute('src', src.src); - if(src.type){ - source.setAttribute('type', src.type); - } - if(src.media){ - source.setAttribute('media', src.media); - } - mediaElem.append(source); + mediaElem.append($(document.createElement('source')).attr(src)); }); } }; @@ -3222,10 +3218,13 @@ clearTimeout(baseData.loadTimer); $.data(elem, 'mediaerror', false); if(!_srces.length || !parent || parent.nodeType != 1 || stopParent.test(parent.nodeName || '')){return;} data = data || webshims.data(elem, 'mediaelement'); + if(mediaelement.sortMedia){ + _srces.sort(mediaelement.sortMedia); + } stepSources(elem, data, options.preferFlash || undefined, _srces); }; mediaelement.selectSource = selectSource; @@ -3396,11 +3395,11 @@ } else { webshims.ready(swfType, initMediaElements); } webshims.ready('track', loadTrackUi); }); -})(jQuery, Modernizr, webshims); +})(Modernizr, webshims); webshims.register('mediaelement-jaris', function($, webshims, window, document, undefined, options){ "use strict"; var mediaelement = webshims.mediaelement; var swfmini = window.swfmini; @@ -3837,24 +3836,88 @@ trigger(data._elem, 'emptied'); } }; })(); + + var transformDimension = (function(){ + var dimCache = {}; + var getRealDims = function(data){ + var ret, poster, img; + if(dimCache[data.currentSrc]){ + ret = dimCache[data.currentSrc]; + } else if(data.videoHeight && data.videoWidth){ + dimCache[data.currentSrc] = { + width: data.videoWidth, + height: data.videoHeight + }; + ret = dimCache[data.currentSrc]; + } else if((poster = $.attr(data._elem, 'poster'))){ + ret = dimCache[poster]; + if(!ret){ + img = document.createElement('img'); + img.onload = function(){ + dimCache[poster] = { + width: this.width, + height: this.height + }; + + if(dimCache[poster].height && dimCache[poster].width){ + setElementDimension(data, $.prop(data._elem, 'controls')); + } else { + delete dimCache[poster]; + } + }; + img.src = poster; + if(img.complete){ + img.onload(); + } + } + } + return ret || {width: 300, height: data._elemNodeName == 'video' ? 150 : 50}; + }; + return function(data){ + var realDims, ratio; + var ret = data.elemDimensions; + + if(ret.width == 'auto' || ret.height == 'auto'){ + ret = $.extend({}, data.elemDimensions); + realDims = getRealDims(data); + ratio = realDims.width / realDims.height; + + if(ret.width == 'auto' && ret.height == 'auto'){ + ret = realDims; + } else if(ret.width == 'auto'){ + data.shadowElem.css({height: ret.height}); + ret.width = data.shadowElem.height() * ratio; + } else { + data.shadowElem.css({width: ret.width}); + ret.height = data.shadowElem.width() / ratio; + } + } + return ret; + }; + })(); var setElementDimension = function(data, hasControls){ - var cAttr; + var dims; var elem = data._elem; var box = data.shadowElem; - $(elem)[hasControls ? 'addClass' : 'removeClass']('webshims-controls'); - if(data._elemNodeName == 'audio' && !hasControls){ - box.css({width: 0, height: 0}); - } else { - - box.css({ - width: elem.style.width || ((cAttr = $(elem).attr('width')) && cAttr+'px') || $(elem).width(), - height: elem.style.height|| ((cAttr = $(elem).attr('height')) && cAttr+'px') || $(elem).height() - }); + + if(data.isActive == 'third'){ + if(data._elemNodeName == 'audio' && !hasControls){ + box.css({width: 0, height: 0}); + } else { + data.elemDimensions = { + width: elem.style.width || $.attr(elem, 'width') || $(elem).width(), + height: elem.style.height || $.attr(elem, 'height') || $(elem).height() + }; + dims = transformDimension(data); + dims.minWidth = elem.style.minWidth; + dims.minHeight = elem.style.minHeight; + box.css(dims); + } } }; var bufferSrc = (function(){ var preloads = { @@ -3878,10 +3941,31 @@ q: /\?/g }, replaceVar = function(val){ return (val.replace) ? val.replace(regs.A, '%26').replace(regs.a, '%26').replace(regs.e, '%3D').replace(regs.q, '%3F') : val; }; + + if('matchMedia' in window){ + var allowMediaSorting = false; + try { + allowMediaSorting = window.matchMedia('only all').matches; + } catch(er){} + if(allowMediaSorting){ + mediaelement.sortMedia = function(src1, src2){ + try { + src1 = !src1.media || matchMedia( src1.media ).matches; + src2 = !src2.media || matchMedia( src2.media ).matches; + } catch(er){ + return 0; + } + return src1 == src2 ? + 0 : + src1 ? -1 + : 1; + }; + } + } mediaelement.createSWF = function( elem, canPlaySrc, data ){ if(!hasFlash){ setTimeout(function(){ $(elem).mediaLoad(); //<- this should produce a mediaerror @@ -3929,11 +4013,13 @@ id: elemId }, $(elem).data('attrs') ); var setDimension = function(){ - setElementDimension(data, $.prop(elem, 'controls')); + if(data.isActive == 'third'){ + setElementDimension(data, $.prop(elem, 'controls')); + } }; var box; if(data && data.swfCreated){ @@ -3995,11 +4081,11 @@ length: 0 } } })); - setElementDimension(data, hasControls); + box.insertBefore(elem); if(hasNative){ $.extend(data, {volume: $.prop(elem, 'volume'), muted: $.prop(elem, 'muted'), paused: $.prop(elem, 'paused')}); @@ -4011,21 +4097,24 @@ } addMediaToStopEvents(elem); mediaelement.setActive(elem, 'third', data); + setElementDimension(data, hasControls); + $(elem) - .on({'updatemediaelementdimensions': setDimension}) - .onWSOff('updateshadowdom', setDimension) - .on('remove', function(e){ - if(!e.originalEvent && mediaelement.jarisEvent[data.id] && mediaelement.jarisEvent[data.id].elem == elem){ - delete mediaelement.jarisEvent[data.id]; - clearTimeout(localConnectionTimer); - clearTimeout(data.flashBlock); + .on({ + 'updatemediaelementdimensions loadedmetadata emptied': setDimension, + 'remove': function(e){ + if(!e.originalEvent && mediaelement.jarisEvent[data.id] && mediaelement.jarisEvent[data.id].elem == elem){ + delete mediaelement.jarisEvent[data.id]; + clearTimeout(localConnectionTimer); + clearTimeout(data.flashBlock); + } } - box.remove(); }) + .onWSOff('updateshadowdom', setDimension) ; } if(!mediaelement.jarisEvent[data.id] || mediaelement.jarisEvent[data.id].elem != elem){ @@ -4327,11 +4416,13 @@ propType: 'enumarated', defaultValue: '', limitedTo: ['', 'auto', 'metadata', 'none'] }); + webshims.reflectProperties('source', ['type', 'media']); + ['autoplay', 'controls'].forEach(function(name){ webshims.defineNodeNamesBooleanProperty(['audio', 'video'], name); }); webshims.defineNodeNamesProperties(['audio', 'video'], { @@ -4362,8 +4453,10 @@ NETWORK_NO_SOURCE: { value: 3 } }, 'prop'); + } else if(!('media' in document.createElement('source'))){ + webshims.reflectProperties('source', ['media']); } }); \ No newline at end of file