vendor/assets/javascripts/webshims/shims/combos/30.js in webshims-rails-1.10.6 vs vendor/assets/javascripts/webshims/shims/combos/30.js in webshims-rails-1.10.9

- old
+ new

@@ -9,14 +9,19 @@ } 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){ + 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! 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.."); if (window.$) { window.$ = webshims.$; } window.jQuery = webshims.$; } @@ -30,11 +35,14 @@ Modernizr = webshims.M; } }; switch$(); setTimeout(switch$, 90); + webshims.ready('DOM', switch$); $(switch$); + webshims.ready('WINDOWLOAD', switch$); + } // (function(){ // var hostNames = { // 'afarkas.github.io': 1, // localhost: 1, @@ -138,10 +146,11 @@ this.on('remove', function(e){ if(!e.originalEvent){ $(evtDel).off(evt, fn); } }); + return this; }; var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000)); var elementData = function(elem, key, val){ elem = elem.jquery ? elem[0] : elem; @@ -172,62 +181,11 @@ }); 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; @@ -626,52 +584,54 @@ webshims.ready('DOM', function(){ docObserve.start(); }); }; return function(nativeElem, shadowElem, opts){ - opts = opts || {}; - if(nativeElem.jquery){ - nativeElem = nativeElem[0]; - } - if(shadowElem.jquery){ - shadowElem = shadowElem[0]; - } - var nativeData = $.data(nativeElem, dataID) || $.data(nativeElem, dataID, {}); - var shadowData = $.data(shadowElem, dataID) || $.data(shadowElem, dataID, {}); - var shadowFocusElementData = {}; - if(!opts.shadowFocusElement){ - opts.shadowFocusElement = shadowElem; - } else if(opts.shadowFocusElement){ - if(opts.shadowFocusElement.jquery){ - opts.shadowFocusElement = opts.shadowFocusElement[0]; + if(nativeElem && shadowElem){ + opts = opts || {}; + if(nativeElem.jquery){ + nativeElem = nativeElem[0]; } - shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData); - } - - $(nativeElem).on('remove', function(e){ - if (!e.originalEvent) { - $(shadowElem).remove(); + if(shadowElem.jquery){ + shadowElem = shadowElem[0]; } - }); - - nativeData.hasShadow = shadowElem; - shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem; - shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = { - nativeElement: nativeElem, - shadowElement: shadowElem, - shadowFocusElement: opts.shadowFocusElement - }; - if(opts.shadowChilds){ - opts.shadowChilds.each(function(){ - elementData(this, 'shadowData', shadowData.shadowData); + var nativeData = $.data(nativeElem, dataID) || $.data(nativeElem, dataID, {}); + var shadowData = $.data(shadowElem, dataID) || $.data(shadowElem, dataID, {}); + var shadowFocusElementData = {}; + if(!opts.shadowFocusElement){ + opts.shadowFocusElement = shadowElem; + } else if(opts.shadowFocusElement){ + if(opts.shadowFocusElement.jquery){ + opts.shadowFocusElement = opts.shadowFocusElement[0]; + } + shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData); + } + + $(nativeElem).on('remove', function(e){ + if (!e.originalEvent) { + $(shadowElem).remove(); + } }); + + nativeData.hasShadow = shadowElem; + shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem; + shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = { + nativeElement: nativeElem, + shadowElement: shadowElem, + shadowFocusElement: opts.shadowFocusElement + }; + if(opts.shadowChilds){ + opts.shadowChilds.each(function(){ + elementData(this, 'shadowData', shadowData.shadowData); + }); + } + + if(opts.data){ + shadowFocusElementData.shadowData.data = shadowData.shadowData.data = nativeData.shadowData.data = opts.data; + } + opts = null; } - - if(opts.data){ - shadowFocusElementData.shadowData.data = shadowData.shadowData.data = nativeData.shadowData.data = opts.data; - } - opts = null; webshims.docObserve(); }; })(), propTypes: { standard: function(descs, name){ @@ -951,11 +911,11 @@ // get current lang // webshims.activeLang({ // register: moduleName:string, // callback: callback:function // }); -// get/set including removeLang +// get/set including remoteLang // - webshims.activeLang({ // module: moduleName:string, // callback: callback:function, // langObj: languageObj:array/object // }); @@ -1203,16 +1163,17 @@ ['valid', 'invalid', 'required', 'optional'].forEach(function(name){ $.expr[":"][name] = $.expr.filters[name+"-element"]; }); - - $.expr[":"].focus = function( elem ) { + var pseudoFocus = $.expr[":"].focus; + $.expr[":"].focus = function(){ try { - var doc = elem.ownerDocument; - return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus()); - } catch(e){} + return pseudoFocus.apply(this, arguments); + } catch(e){ + webshims.error(e); + } return false; }; webshims.triggerInlineForm = function(elem, event){ $(elem).trigger(event); @@ -1223,19 +1184,19 @@ webshims.ready('form-validation', function(){ obj[fn].apply(obj, args); }); }; - + var transClass = ('transitionDelay' in document.documentElement.style) ? '' : ' no-transition'; webshims.wsPopover = { id: 0, _create: function(){ this.options = $.extend({}, webshims.cfg.wspopover, this.options); this.id = webshims.wsPopover.id++; this.eventns = '.wsoverlay' + this.id; this.timers = {}; - this.element = $('<div class="ws-popover" tabindex="-1"><div class="ws-po-outerbox"><div class="ws-po-arrow"><div class="ws-po-arrowbox" /></div><div class="ws-po-box" /></div></div>'); + this.element = $('<div class="ws-popover'+transClass+'" tabindex="-1"><div class="ws-po-outerbox"><div class="ws-po-arrow"><div class="ws-po-arrowbox" /></div><div class="ws-po-box" /></div></div>'); this.contentElement = $('.ws-po-box', this.element); this.lastElement = $([]); this.bindElement(); this.element.data('wspopover', this); @@ -1270,51 +1231,10 @@ lazyLoadProxy(this, 'showFor', arguments); } }; - /* extension, but also used to fix native implementation workaround/bugfixes */ - (function(){ - var firstEvent, - invalids = [], - stopSubmitTimer, - form - ; - - $(document).on('invalid', function(e){ - if(e.wrongWebkitInvalid){return;} - var jElm = $(e.target); - - - if(!firstEvent){ - //trigger firstinvalid - firstEvent = $.Event('firstinvalid'); - firstEvent.isInvalidUIPrevented = e.isDefaultPrevented; - var firstSystemInvalid = $.Event('firstinvalidsystem'); - $(document).triggerHandler(firstSystemInvalid, {element: e.target, form: e.target.form, isInvalidUIPrevented: e.isDefaultPrevented}); - jElm.trigger(firstEvent); - } - - //if firstinvalid was prevented all invalids will be also prevented - if( firstEvent && firstEvent.isDefaultPrevented() ){ - e.preventDefault(); - } - invalids.push(e.target); - e.extraData = 'fix'; - clearTimeout(stopSubmitTimer); - stopSubmitTimer = setTimeout(function(){ - var lastEvent = {type: 'lastinvalid', cancelable: false, invalidlist: $(invalids)}; - //reset firstinvalid - firstEvent = false; - invalids = []; - $(e.target).trigger(lastEvent, lastEvent); - }, 9); - jElm = null; - }); - })(); - - webshims.getContentValidationMessage = function(elem, validity, key){ var message = $(elem).data('errormessage') || elem.getAttribute('x-moz-errormessage') || ''; if(key && message[key]){ message = message[key]; } @@ -1344,36 +1264,69 @@ } return message; }; - webshims.ready('forms', function(){ - $(document).on('focusin.lazyloadvalidation', function(e){ - if('form' in e.target && $(e.target).is(':invalid')){ - lazyLoad(); - } - }); + $(document).on('focusin.lazyloadvalidation', function(e){ + if('form' in e.target && $(e.target).is(':invalid')){ + lazyLoad(); + } }); webshims.ready('WINDOWLOAD', lazyLoad); - if(options.overrideMessages){ - options.customMessages = true; - webshims.reTest('form-message'); - webshims.error('overrideMessages is deprecated. use customMessages instead.'); - } + if(options.replaceValidationUI){ webshims.ready('DOM forms', function(){ $(document).on('firstinvalid', function(e){ if(!e.isInvalidUIPrevented()){ e.preventDefault(); webshims.validityAlert.showFor( e.target ); } }); }); } + + /* extension, but also used to fix native implementation workaround/bugfixes */ + (function(){ + var firstEvent, + invalids = [], + stopSubmitTimer, + form + ; + + $(document).on('invalid', function(e){ + if(e.wrongWebkitInvalid){return;} + var jElm = $(e.target); + + + if(!firstEvent){ + //trigger firstinvalid + firstEvent = $.Event('firstinvalid'); + firstEvent.isInvalidUIPrevented = e.isDefaultPrevented; + var firstSystemInvalid = $.Event('firstinvalidsystem'); + $(document).triggerHandler(firstSystemInvalid, {element: e.target, form: e.target.form, isInvalidUIPrevented: e.isDefaultPrevented}); + jElm.trigger(firstEvent); + } + + //if firstinvalid was prevented all invalids will be also prevented + if( firstEvent && firstEvent.isDefaultPrevented() ){ + e.preventDefault(); + } + invalids.push(e.target); + e.extraData = 'fix'; + clearTimeout(stopSubmitTimer); + stopSubmitTimer = setTimeout(function(){ + var lastEvent = {type: 'lastinvalid', cancelable: false, invalidlist: $(invalids)}; + //reset firstinvalid + firstEvent = false; + invalids = []; + $(e.target).trigger(lastEvent, lastEvent); + }, 9); + jElm = null; + }); + })(); }); - webshims.register('form-message', function($, webshims, window, document, undefined, options){ "use strict"; if(options.overrideMessages){ options.customMessages = true; webshims.error('overrideMessages is deprecated. use customMessages instead.'); @@ -1422,12 +1375,19 @@ if(typeof validityMessages.en.rangeOverflow == 'object'){ ['date', 'time', 'datetime-local', 'month'].forEach(function(type){ validityMessages.en.rangeOverflow[type] = validityMessages.en.rangeOverflow[type] || 'Value must be at or before {%max}.'; }); } - - validityMessages['en-US'] = validityMessages['en-US'] || validityMessages.en; + if(!validityMessages['en-US']){ + validityMessages['en-US'] = $.extend(true, {}, validityMessages.en); + } + if(!validityMessages['en-GB']){ + validityMessages['en-GB'] = $.extend(true, {}, validityMessages.en); + } + if(!validityMessages['en-AU']){ + validityMessages['en-AU'] = $.extend(true, {}, validityMessages.en); + } validityMessages[''] = validityMessages[''] || validityMessages['en-US']; validityMessages.de = $.extend(true, { typeMismatch: { defaultMessage: '{%value} ist in diesem Feld nicht zulässig.', @@ -1523,16 +1483,26 @@ implementProperties.push('validationMessage'); } webshims.activeLang({ langObj: validityMessages, - module: 'form-core', + module: 'form-core', callback: function(langObj){ - currentValidationMessage = langObj; } }); + webshims.activeLang({ + register: 'form-core', + callback: function(val){ + $.each(validityMessages, function(i, val){ + if(validityMessages[val]){ + currentValidationMessage = validityMessages[val]; + return false; + } + }); + } + }); implementProperties.forEach(function(messageProp){ webshims.defineNodeNamesProperty(['fieldset', 'output', 'button'], messageProp, { prop: { value: '', @@ -1575,9 +1545,10 @@ }); }); }); }); + webshims.register('form-datalist', function($, webshims, window, document, undefined, options){ "use strict"; var doc = document; var lazyLoad = function(name){ if(!name || typeof name != 'string'){ \ No newline at end of file