vendor/assets/javascripts/webshims/shims/dom-extend.js in webshims-rails-0.4.7 vs vendor/assets/javascripts/webshims/shims/dom-extend.js in webshims-rails-1.10.3

- old
+ new

@@ -1,8 +1,19 @@ //DOM-Extension helper jQuery.webshims.register('dom-extend', function($, webshims, window, document, undefined){ "use strict"; + + webshims.assumeARIA = Modernizr.localstorage || 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"); + } + + if(!$.parseHTML){ + webshims.error("Webshims needs jQuery 1.8+ to work properly. Please update your jQuery version or downgrade webshims."); + } + //shortcus var modules = webshims.modules; var listReg = /\s*,\s*/; //proxying attribute @@ -15,14 +26,11 @@ 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 = ''; } @@ -47,10 +55,13 @@ $.prop(elem, 'value', val, 'val'); } } }); }; + $.fn.onTrigger = function(evt, fn){ + return this.on(evt, fn).each(fn); + }; var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000)); var elementData = function(elem, key, val){ elem = elem.jquery ? elem[0] : elem; if(!elem){return val || {};} @@ -68,18 +79,74 @@ }; [{name: 'getNativeElement', prop: 'nativeElement'}, {name: 'getShadowElement', prop: 'shadowElement'}, {name: 'getShadowFocusElement', prop: 'shadowFocusElement'}].forEach(function(data){ $.fn[data.name] = function(){ - return this.map(function(){ + var elems = []; + this.each(function(){ var shadowData = elementData(this, 'shadowData'); - return shadowData && shadowData[data.prop] || this; + var elem = shadowData && shadowData[data.prop] || this; + if($.inArray(elem, elems) == -1){ + elems.push(elem); + } }); + return this.pushStack(elems); }; }); + if($.Tween.propHooks._default && $.css){ + (function(){ + var isjQ8 = false; + try { + isjQ8 = $.css($('<b style="width: 10px" />')[0], 'width', '') == '10px'; + } catch(er){ + webshims.error(er); + } + var css = isjQ8 ? + function(elem, prop){ + return $.css( elem, prop, false, "" ); + } : + function(elem, prop){ + return $.css( elem, prop, "" ); + } + ; + + $.extend($.Tween.propHooks._default, { + get: function( tween ) { + var result; + + if ( (tween.elem[ tween.prop ] != null || havePolyfill[ tween.prop ]) && + (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) { + return havePolyfill[ tween.prop ] ? $.prop(tween.elem, tween.prop) : tween.elem[ tween.prop ]; + } + + // passing an empty string as a 3rd parameter to .css will automatically + // attempt a parseFloat and fallback to a string if the parse fails + // so, simple values such as "10px" are parsed to Float. + // complex values such as "rotate(1rad)" are returned as is. + result = css( tween.elem, tween.prop ); + // Empty strings, null, undefined and "auto" are converted to 0. + return !result || result === "auto" ? 0 : result; + }, + set: function( tween ) { + // use step hook for back compat - use cssHook if its there - use .style if its + // available and use plain properties where available + if ( jQuery.fx.step[ tween.prop ] ) { + jQuery.fx.step[ tween.prop ]( tween ); + } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) { + jQuery.style( tween.elem, tween.prop, tween.now + tween.unit ); + } else if( !havePolyfill[ tween.prop ] ) { + tween.elem[ tween.prop ] = tween.now; + } else { + $.prop(tween.elem, tween.prop, tween.now); + } + } + }); + })(); + } + ['removeAttr', 'prop', 'attr'].forEach(function(type){ olds[type] = $[type]; $[type] = function(elem, name, value, pass, _argless){ var isVal = (pass == 'val'); var oldMethod = !isVal ? olds[type] : singleVal; @@ -194,11 +261,11 @@ if(!desc.set){ desc.set = desc.writeable ? getSup('set', desc, oldDesc) : (webshims.cfg.useStrict && prop == 'prop') ? function(){throw(prop +' is readonly on '+ nodeName);} : - $.noop + function(){webshims.info(prop +' is readonly on '+ nodeName);} ; } if(!desc.get){ desc.get = getSup('get', desc, oldDesc); } @@ -212,19 +279,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 = Modernizr.ES5; 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; - var elemProto; - if( isExtendNativeSave && (elem = document.createElement(nodeName)) && (elemProto = webshims.getPrototypeOf(elem)) && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){ + var elem , 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); } @@ -342,19 +408,28 @@ getID: (function(){ var ID = new Date().getTime(); return function(elem){ elem = $(elem); - var id = elem.attr('id'); + var id = elem.prop('id'); if(!id){ ID++; id = 'ID-'+ ID; - elem.attr('id', id); + elem.eq(0).prop('id', id); } return id; }; })(), + implement: function(elem, type){ + var data = elementData(elem, 'implemented') || elementData(elem, 'implemented', {}); + if(data[type]){ + webshims.info(type +' already implemented for element #'+elem.id); + return false; + } + data[type] = true; + return true; + }, extendUNDEFProp: function(obj, props){ $.each(props, function(name, prop){ if( !(name in obj) ){ obj[name] = prop; } @@ -829,11 +904,11 @@ return false; }; var callRegister = function(module){ if(registeredCallbacks[module]){ registeredCallbacks[module].forEach(function(data){ - data.callback(); + data.callback(currentLang, shortLang, ''); }); } }; var callLang = function(data, _noLoop){ if(data.activeLang != currentLang && data.activeLang !== shortLang){ @@ -870,11 +945,11 @@ if(lang.register){ if(!registeredCallbacks[lang.register]){ registeredCallbacks[lang.register] = []; } registeredCallbacks[lang.register].push(lang); - lang.callback(); + lang.callback(currentLang, shortLang, ''); } else { if(!lang.activeLang){ lang.activeLang = ''; } callbacks.push(lang); @@ -907,13 +982,25 @@ webshims.isReady('webshimLocalization', true); }); //html5a11y (function($, document){ - //if we support basic styleing or do not support ARIA (assumed) abort - if(!Modernizr.localstorage || ('hidden' in document.createElement('a'))){return;} + if(!$.webshims.assumeARIA || ('content' in document.createElement('template'))){return;} + $(function(){ + var main = $('main').attr({role: 'main'}); + if(main.length > 1){ + webshims.error('only one main element allowed in document'); + } else if(main.is('article *, section *')) { + webshims.error('main not allowed inside of article/section elements'); + } + }); + + if(('hidden' in document.createElement('a'))){ + return; + } + var elemMappings = { article: "article", aside: "complementary", section: "region", nav: "navigation", @@ -924,10 +1011,11 @@ 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); @@ -935,9 +1023,10 @@ }); 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;