vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-0.4.6 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-0.4.7

- old
+ new

@@ -14,10 +14,15 @@ var oldVal = $.fn.val; var singleVal = function(elem, name, val, pass, _argless){ return (_argless) ? oldVal.call($(elem)) : oldVal.call($(elem), val); }; + + $.fn.onTrigger = function(evt, fn){ + return this.on(evt, fn).each(fn); + }; + $.fn.val = function(val){ var elem = this[0]; if(arguments.length && val == null){ val = ''; } @@ -208,18 +213,18 @@ }; }); //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 = (!$.browser.msie || parseInt($.browser.version, 10) > 8); + var isExtendNativeSave = Modernizr.ES5; var extendNativeValue = (function(){ var UNKNOWN = webshims.getPrototypeOf(document.createElement('foobar')); var has = Object.prototype.hasOwnProperty; return function(nodeName, prop, desc){ - var elem = document.createElement(nodeName); - var elemProto = webshims.getPrototypeOf(elem); - if( isExtendNativeSave && elemProto && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){ + var elem; + var elemProto; + if( isExtendNativeSave && (elem = document.createElement(nodeName)) && (elemProto = webshims.getPrototypeOf(elem)) && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){ var sup = elem[prop]; desc._supvalue = function(){ if(sup && sup.apply){ return sup.apply(this, arguments); } @@ -415,11 +420,11 @@ docObserve.height = docObserve.getHeight(); docObserve.width = docObserve.getWidth(); } - $.event.trigger('updateshadowdom'); + $(document).triggerHandler('updateshadowdom'); }, (e.type == 'resize') ? 50 : 9); }, _create: function(){ $.each({ Height: "getHeight", Width: "getWidth" }, function(name, type){ var body = document.body; @@ -459,11 +464,10 @@ } } }; - $.event.customEvent.updateshadowdom = true; webshims.docObserve = function(){ webshims.ready('DOM', function(){ docObserve.start(); }); }; @@ -903,56 +907,57 @@ webshims.isReady('webshimLocalization', true); }); //html5a11y (function($, document){ - var browserVersion = $.webshims.browserVersion; - if($.browser.mozilla && browserVersion > 5){return;} - if (!$.browser.msie || (browserVersion < 12 && browserVersion > 7)) { - var elemMappings = { - article: "article", - aside: "complementary", - section: "region", - nav: "navigation", - address: "contentinfo" - }; - var addRole = function(elem, role){ - var hasRole = elem.getAttribute('role'); - if (!hasRole) { - elem.setAttribute('role', role); + //if we support basic styleing or do not support ARIA (assumed) abort + if(!Modernizr.localstorage || ('hidden' in document.createElement('a'))){return;} + + var elemMappings = { + article: "article", + aside: "complementary", + section: "region", + nav: "navigation", + address: "contentinfo" + }; + var addRole = function(elem, role){ + var hasRole = elem.getAttribute('role'); + if (!hasRole) { + elem.setAttribute('role', role); + } + }; + + $.webshims.addReady(function(context, contextElem){ + $.each(elemMappings, function(name, role){ + var elems = $(name, context).add(contextElem.filter(name)); + for (var i = 0, len = elems.length; i < len; i++) { + addRole(elems[i], role); } - }; - - $.webshims.addReady(function(context, contextElem){ - $.each(elemMappings, function(name, role){ - var elems = $(name, context).add(contextElem.filter(name)); - for (var i = 0, len = elems.length; i < len; i++) { - addRole(elems[i], role); - } - }); - if (context === document) { - var header = document.getElementsByTagName('header')[0]; - var footers = document.getElementsByTagName('footer'); - var footerLen = footers.length; - if (header && !$(header).closest('section, article')[0]) { - addRole(header, 'banner'); - } - if (!footerLen) { - return; - } - var footer = footers[footerLen - 1]; - if (!$(footer).closest('section, article')[0]) { - addRole(footer, 'contentinfo'); - } - } }); - } + if (context === document) { + var header = document.getElementsByTagName('header')[0]; + var footers = document.getElementsByTagName('footer'); + var footerLen = footers.length; + if (header && !$(header).closest('section, article')[0]) { + addRole(header, 'banner'); + } + if (!footerLen) { + return; + } + var footer = footers[footerLen - 1]; + if (!$(footer).closest('section, article')[0]) { + addRole(footer, 'contentinfo'); + } + } + }); + })(jQuery, document); //additional tests for partial implementation of forms features (function($){ "use strict"; + var isWebkit = /webkit/i.test(navigator.userAgent); var Modernizr = window.Modernizr; var webshims = $.webshims; var bugs = webshims.bugs; var form = $('<form action="#" style="width: 1px; height: 1px; overflow: hidden;"><select name="b" required="" /><input required="" name="a" /></form>'); var testRequiredFind = function(){ @@ -991,85 +996,85 @@ } }; if(!Modernizr.formvalidation || bugs.bustedValidity){ testRequiredFind(); - return; - } - - //create delegatable events - webshims.capturingEvents(['input']); - webshims.capturingEvents(['invalid'], true); - - if(window.opera || window.testGoodWithFix){ + } else { + //create delegatable events + webshims.capturingEvents(['input']); + webshims.capturingEvents(['invalid'], true); - form.appendTo('head'); - - testRequiredFind(); - bugs.validationMessage = !(inputElem.prop('validationMessage')); - - webshims.reTest(['form-native-extend', 'form-message']); - - form.remove(); + if(window.opera || window.testGoodWithFix){ - $(function(){ - onDomextend(function(){ + form.appendTo('head'); + + testRequiredFind(); + bugs.validationMessage = !(inputElem.prop('validationMessage')); + + webshims.reTest(['form-native-extend', 'form-message']); + + form.remove(); - //Opera shows native validation bubbles in case of input.checkValidity() - // Opera 11.6/12 hasn't fixed this issue right, it's buggy - var preventDefault = function(e){ - e.preventDefault(); - }; - - ['form', 'input', 'textarea', 'select'].forEach(function(name){ - var desc = webshims.defineNodeNameProperty(name, 'checkValidity', { - prop: { - value: function(){ - if (!webshims.fromSubmit) { - $(this).on('invalid.checkvalidity', preventDefault); + $(function(){ + onDomextend(function(){ + + //Opera shows native validation bubbles in case of input.checkValidity() + // Opera 11.6/12 hasn't fixed this issue right, it's buggy + var preventDefault = function(e){ + e.preventDefault(); + }; + + ['form', 'input', 'textarea', 'select'].forEach(function(name){ + var desc = webshims.defineNodeNameProperty(name, 'checkValidity', { + prop: { + value: function(){ + if (!webshims.fromSubmit) { + $(this).on('invalid.checkvalidity', preventDefault); + } + + webshims.fromCheckValidity = true; + var ret = desc.prop._supvalue.apply(this, arguments); + if (!webshims.fromSubmit) { + $(this).unbind('invalid.checkvalidity', preventDefault); + } + webshims.fromCheckValidity = false; + return ret; } - - webshims.fromCheckValidity = true; - var ret = desc.prop._supvalue.apply(this, arguments); - if (!webshims.fromSubmit) { - $(this).unbind('invalid.checkvalidity', preventDefault); - } - webshims.fromCheckValidity = false; - return ret; } - } + }); }); + }); - }); - }); + } + + if(isWebkit && !webshims.bugs.bustedValidity){ + (function(){ + var elems = /^(?:textarea|input)$/i; + var form = false; + + document.addEventListener('contextmenu', function(e){ + if(elems.test( e.target.nodeName || '') && (form = e.target.form)){ + setTimeout(function(){ + form = false; + }, 1); + } + }, false); + + $(window).on('invalid', function(e){ + if(e.originalEvent && form && form == e.target.form){ + e.wrongWebkitInvalid = true; + e.stopImmediatePropagation(); + } + }); + + })(); + } } - if($.browser.webkit && !webshims.bugs.bustedValidity){ - (function(){ - var elems = /^(?:textarea|input)$/i; - var form = false; - - document.addEventListener('contextmenu', function(e){ - if(elems.test( e.target.nodeName || '') && (form = e.target.form)){ - setTimeout(function(){ - form = false; - }, 1); - } - }, false); - - $(window).on('invalid', function(e){ - if(e.originalEvent && form && form == e.target.form){ - e.wrongWebkitInvalid = true; - e.stopImmediatePropagation(); - } - }); - - })(); - } -})(jQuery); + jQuery.webshims.register('form-core', function($, webshims, window, document, undefined, options){ "use strict"; var checkTypes = {checkbox: 1, radio: 1}; @@ -1179,11 +1184,11 @@ return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus()); } catch(e){} return false; }; - if(Modernizr.formvalidation && $.browser.webkit && !webshims.bugs.bustedValidity && webshims.browserVersion < 27){ + if(Modernizr.formvalidation && isWebkit && !webshims.bugs.bustedValidity){ (function(){ var retriggerRadioValidity = function(){ var validity; if((validity = this.validity) && !validity.customError){ this.setCustomValidity(''); @@ -1358,11 +1363,11 @@ webshims.modules["form-core"].getGroupElements = getGroupElements; var setRoot = function(){ - webshims.scrollRoot = ($.browser.webkit || document.compatMode == 'BackCompat') ? + webshims.scrollRoot = (isWebkit || document.compatMode == 'BackCompat') ? $(document.body) : $(document.documentElement) ; }; setRoot(); @@ -1380,11 +1385,11 @@ return offset; }; /* some extra validation UI */ webshims.validityAlert = (function(){ - var alertElem = (!$.browser.msie || parseInt($.browser.version, 10) > 7) ? 'span' : 'label'; + var alertElem = 'span'; var errorBubble; var hideTimer = false; var focusTimer = false; var resizeTimer = false; var boundHide; @@ -1495,11 +1500,11 @@ _create: function(){ if(errorBubble){return;} errorBubble = api.errorBubble = $('<'+alertElem+' class="validity-alert-wrapper" role="alert"><span class="validity-alert"><span class="va-arrow"><span class="va-arrow-box"></span></span><span class="va-box"></span></span></'+alertElem+'>').css({position: 'absolute', display: 'none'}); webshims.ready('DOM', function(){ errorBubble.appendTo('body'); - if($.fn.bgIframe && $.browser.msie && parseInt($.browser.version, 10) < 7){ + if($.fn.bgIframe){ errorBubble.bgIframe(); } }); } }; @@ -1575,12 +1580,13 @@ $.webshims.validityAlert.showFor( e.target ); } }); }); } - }); + +})(jQuery); jQuery.webshims.register('form-message', function($, webshims, window, document, undefined, options){ "use strict"; var validityMessages = webshims.validityMessages; var implementProperties = (options.overrideMessages || options.customMessages) ? ['customValidationMessage'] : []; @@ -1806,11 +1812,13 @@ webshims.ready('WINDOWLOAD '+swfType, function(){ setTimeout(function(){ if(hasSwf && !options.preferFlash && webshims.mediaelement.createSWF && !$(e.target).closest('audio, video').is('.nonnative-api-active')){ options.preferFlash = true; document.removeEventListener('error', switchOptions, true); - $('audio, video').mediaLoad(); + $('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); } else if(!hasSwf){ document.removeEventListener('error', switchOptions, true); } }, 20); @@ -2210,12 +2218,12 @@ if(!_srces.length || !parent || parent.nodeType != 1 || stopParent.test(parent.nodeName || '')){return;} data = data || webshims.data(elem, 'mediaelement'); stepSources(elem, data, options.preferFlash || undefined, _srces); }; + mediaelement.selectSource = selectSource; - $(document).on('ended', function(e){ var data = webshims.data(e.target, 'mediaelement'); if( supportsLoop && (!data || data.isActive == 'html5') && !$.prop(e.target, 'loop')){return;} setTimeout(function(){ if( $.prop(e.target, 'paused') || !$.prop(e.target, 'loop') ){return;} @@ -2276,55 +2284,60 @@ webshims.addReady(function(context, insertedElement){ var media = $('video, audio', context) .add(insertedElement.filter('video, audio')) .each(function(){ - if($.browser.msie && webshims.browserVersion > 8 && $.prop(this, 'paused') && !$.prop(this, 'readyState') && $(this).is('audio[preload="none"][controls]:not([autoplay])')){ + var data = webshims.data(this, 'mediaelement'); + + if(hasNative && $.prop(this, 'paused') && !$.prop(this, 'readyState') && $(this).is('audio[preload="none"][controls]:not([autoplay])') && (!data || data.isActive == 'html5')){ + //IE controls not visible bug $(this).prop('preload', 'metadata').mediaLoad(); } else { - selectSource(this); + selectSource(this, data); } - - if(hasNative){ - var bufferTimer; - var lastBuffered; - var elem = this; - var getBufferedString = function(){ - var buffered = $.prop(elem, 'buffered'); - if(!buffered){return;} - var bufferString = ""; - for(var i = 0, len = buffered.length; i < len;i++){ - bufferString += buffered.end(i); - } - return bufferString; - }; - var testBuffer = function(){ - var buffered = getBufferedString(); - if(buffered != lastBuffered){ - lastBuffered = buffered; - $(elem).triggerHandler('progress'); - } - }; - $(this) - .on({ - 'play loadstart progress': function(e){ - if(e.type == 'progress'){ - lastBuffered = getBufferedString(); - } - clearTimeout(bufferTimer); - bufferTimer = setTimeout(testBuffer, 999); - }, - 'emptied stalled mediaerror abort suspend': function(e){ - if(e.type == 'emptied'){ - lastBuffered = false; - } - clearTimeout(bufferTimer); + //FF progress bug + (function(){ + var bufferTimer; + var lastBuffered; + var elem = this; + var getBufferedString = function(){ + var buffered = $.prop(elem, 'buffered'); + if(!buffered){return;} + var bufferString = ""; + for(var i = 0, len = buffered.length; i < len;i++){ + bufferString += buffered.end(i); } - }) - ; + return bufferString; + }; + var testBuffer = function(){ + var buffered = getBufferedString(); + if(buffered != lastBuffered){ + lastBuffered = buffered; + $(elem).triggerHandler('progress'); + } + }; + + $(this) + .on({ + 'play loadstart progress': function(e){ + if(e.type == 'progress'){ + lastBuffered = getBufferedString(); + } + clearTimeout(bufferTimer); + bufferTimer = setTimeout(testBuffer, 999); + }, + 'emptied stalled mediaerror abort suspend': function(e){ + if(e.type == 'emptied'){ + lastBuffered = false; + } + clearTimeout(bufferTimer); + } + }) + ; + })(); } }) ; if(!loadTrackUi.loaded && $('track', media).length){ \ No newline at end of file