vendor/assets/javascripts/webshims/shims/combos/3.js in webshims-rails-1.11.3.1 vs vendor/assets/javascripts/webshims/shims/combos/3.js in webshims-rails-1.11.6

- old
+ new

@@ -8,12 +8,12 @@ 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."); + if('debug' in webshims){ + webshims.error('Use webshims.setOptions("debug", true||false||"noCombo"); to debug flag'); } if (!webshims.cfg.no$Switch) { var switch$ = function(){ if (window.jQuery && (!window.$ || window.jQuery == window.$) && !window.jQuery.webshims) { @@ -45,11 +45,11 @@ // 'afarkas.github.io': 1, // localhost: 1, // '127.0.0.1': 1 // }; // -// if( webshims.debug && (hostNames[location.hostname] || location.protocol == 'file:') ){ +// if( webshims.cfg.debug && (hostNames[location.hostname] || location.protocol == 'file:') ){ // var list = $('<ul class="webshims-debug-list" />'); // webshims.errorLog.push = function(message){ // list.appendTo('body'); // $('<li style="display: none;">'+ message +'</li>') // .appendTo(list) @@ -477,11 +477,10 @@ descs.attr = {}; } }; $.extend(webshims, { - getID: (function(){ var ID = new Date().getTime(); return function(elem){ elem = $(elem); var id = elem.prop('id'); @@ -507,10 +506,55 @@ if( !(name in obj) ){ obj[name] = prop; } }); }, + getOptions: (function(){ + var regs = {}; + var regFn = function(f, upper){ + return upper.toLowerCase(); + }; + return function(elem, name, bases){ + var data = elementData(elem, 'cfg'+name); + var dataName; + var cfg = {}; + + if(data){ + return data; + } + data = $(elem).data(); + + if(!bases){ + bases = [true, {}]; + } else if(!Array.isArray(bases)){ + bases = [true, {}, bases]; + } else { + bases.unshift(true, {}); + } + + if(data && data[name]){ + if(typeof data[name] == 'object'){ + bases.push(data[name]); + } else { + webshims.error('data-'+ name +' attribute has to be a valid JSON, was: '+ data[name]); + } + } + + if(!regs[name]){ + regs[name] = new RegExp('^'+ name +'([A-Z])'); + } + + for(dataName in data){ + if(regs[name].test(dataName)){ + cfg[dataName.replace(regs[name], regFn)] = data[dataName]; + } + } + bases.push(cfg); + + return elementData(elem, 'cfg'+name, $.extend.apply($, bases)); + }; + })(), //http://www.w3.org/TR/html5/common-dom-interfaces.html#reflect createPropDefault: createPropDefault, data: elementData, moveToFirstEvent: function(elem, eventType, bindType){ var events = ($._data(elem, 'events') || {})[eventType]; @@ -594,11 +638,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); + $(document).on('updatelayout pageinit collapsibleexpand shown.bs.modal shown.bs.collapse slid.bs.carousel', this.handler); $(window).on('resize', this.handler); (function(){ var oldAnimate = $.fn.animate; var animationTimer; @@ -952,113 +996,71 @@ } else { elem.setAttribute(name, val); } }, -// set current Lang: -// - webshims.activeLang(lang:string); -// get current lang -// - webshims.activeLang(); -// get current lang -// webshims.activeLang({ -// register: moduleName:string, -// callback: callback:function -// }); -// get/set including remoteLang -// - webshims.activeLang({ -// module: moduleName:string, -// callback: callback:function, -// langObj: languageObj:array/object -// }); activeLang: (function(){ - var callbacks = []; - var registeredCallbacks = {}; - var currentLang; - var shortLang; - var notLocal = /:\/\/|^\.*\//; - var loadRemoteLang = function(data, lang, options){ - var langSrc; - if(lang && options && $.inArray(lang, options.availableLangs || options.availabeLangs || []) !== -1){ - data.loading = true; - langSrc = options.langSrc; - if(!notLocal.test(langSrc)){ - langSrc = webshims.cfg.basePath+langSrc; - } - webshims.loader.loadScript(langSrc+lang+'.js', function(){ - if(data.langObj[lang]){ - data.loading = false; - callLang(data, true); - } else { - $(function(){ - if(data.langObj[lang]){ - callLang(data, true); - } - data.loading = false; + var curLang = []; + var langDatas = []; + var loading = {}; + var load = function(src, obj, loadingLang){ + obj._isLoading = true; + if(loading[src]){ + loading[src].push(obj); + } else { + loading[src] = [obj]; + webshims.loader.loadScript(src, function(){ + if(loadingLang == curLang.join()){ + $.each(loading[src], function(i, obj){ + select(obj); }); } + delete loading[src]; }); - return true; } - return false; }; - var callRegister = function(module){ - if(registeredCallbacks[module]){ - registeredCallbacks[module].forEach(function(data){ - data.callback(currentLang, shortLang, ''); - }); - } - }; - var callLang = function(data, _noLoop){ - if(data.activeLang != currentLang && data.activeLang !== shortLang){ - var options = modules[data.module].options; - if( data.langObj[currentLang] || (shortLang && data.langObj[shortLang]) ){ - data.activeLang = currentLang; - data.callback(data.langObj[currentLang] || data.langObj[shortLang], currentLang); - callRegister(data.module); - } else if( !_noLoop && - !loadRemoteLang(data, currentLang, options) && - !loadRemoteLang(data, shortLang, options) && - data.langObj[''] && data.activeLang !== '' ) { - data.activeLang = ''; - data.callback(data.langObj[''], currentLang); - callRegister(data.module); + var select = function(obj){ + var oldLang = obj.__active; + var selectLang = function(i, lang){ + obj._isLoading = false; + if(obj[lang] || obj.availableLangs.indexOf(lang) != -1){ + if(obj[lang]){ + obj.__active = obj[lang]; + } else { + load(obj.langSrc+lang, obj, curLang.join()); + } + return false; } + }; + $.each(curLang, selectLang); + if(!obj.__active){ + obj.__active = obj['']; } + if(oldLang != obj.__active){ + $(obj).trigger('change'); + } }; - - - var activeLang = function(lang){ - - if(typeof lang == 'string' && lang !== currentLang){ - currentLang = lang; - shortLang = currentLang.split('-')[0]; - if(currentLang == shortLang){ - shortLang = false; + return function(lang){ + var shortLang; + if(typeof lang == 'string'){ + if(curLang[0] != lang){ + curLang = [lang]; + shortLang = curLang[0].split('-')[0]; + if(shortLang && shortLang != lang){ + curLang.push(shortLang); + } + langDatas.forEach(select); } - $.each(callbacks, function(i, data){ - callLang(data); - }); } else if(typeof lang == 'object'){ - - if(lang.register){ - if(!registeredCallbacks[lang.register]){ - registeredCallbacks[lang.register] = []; - } - registeredCallbacks[lang.register].push(lang); - lang.callback(currentLang, shortLang, ''); - } else { - if(!lang.activeLang){ - lang.activeLang = ''; - } - callbacks.push(lang); - callLang(lang); + if(!lang.__active){ + langDatas.push(lang); + select(lang); } + return lang.__active; } - return currentLang; + return curLang[0]; }; - - return activeLang; })() }); $.each({ defineNodeNamesProperty: 'defineNodeNameProperty', @@ -1198,43 +1200,69 @@ }); return ret; }; - $.extend($.expr[":"], { - "valid-element": function(elem){ - return rElementsGroup.test(elem.nodeName || '') ? !hasInvalid(elem) :!!($.prop(elem, 'willValidate') && isValid(elem)); - }, - "invalid-element": function(elem){ - return rElementsGroup.test(elem.nodeName || '') ? hasInvalid(elem) : !!($.prop(elem, 'willValidate') && !isValid(elem)); - }, - "required-element": function(elem){ - return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required')); - }, - "user-error": function(elem){ - return ($.prop(elem, 'willValidate') && $(elem).hasClass('user-error')); - }, - "optional-element": function(elem){ - return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required') === false); + var extendSels = function(){ + var exp = $.expr[":"]; + $.extend(exp, { + "valid-element": function(elem){ + return rElementsGroup.test(elem.nodeName || '') ? !hasInvalid(elem) :!!($.prop(elem, 'willValidate') && isValid(elem)); + }, + "invalid-element": function(elem){ + return rElementsGroup.test(elem.nodeName || '') ? hasInvalid(elem) : !!($.prop(elem, 'willValidate') && !isValid(elem)); + }, + "required-element": function(elem){ + return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required')); + }, + "user-error": function(elem){ + return ($.prop(elem, 'willValidate') && $(elem).hasClass('user-error')); + }, + "optional-element": function(elem){ + return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required') === false); + } + }); + + ['valid', 'invalid', 'required', 'optional'].forEach(function(name){ + exp[name] = $.expr[":"][name+"-element"]; + }); + + // sizzle/jQuery has a bug with :disabled/:enabled selectors + if(Modernizr.fieldsetdisabled && !$('<fieldset disabled=""><input /><fieldset>').find('input').is(':disabled')){ + $.extend(exp, { + "enabled": function( elem ) { + return elem.disabled === false && !$(elem).is('fieldset[disabled] *'); + }, + + "disabled": function( elem ) { + return elem.disabled === true || ('disabled' in elem && $(elem).is('fieldset[disabled] *')); + } + }); } - }); - - ['valid', 'invalid', 'required', 'optional'].forEach(function(name){ - $.expr[":"][name] = $.expr.filters[name+"-element"]; - }); - - //bug was partially fixed in 1.10.0 for IE9, but not IE8 (move to es5 as soon as 1.10.2 is used) - var pseudoFocus = $.expr[":"].focus; - $.expr[":"].focus = function(){ - try { - return pseudoFocus.apply(this, arguments); - } catch(e){ - webshims.error(e); + + + //bug was partially fixed in 1.10.0 for IE9, but not IE8 (move to es5 as soon as 1.10.2 is used) + if(typeof document.activeElement == 'unknown'){ + var pseudoFocus = exp.focus; + exp.focus = function(){ + try { + return pseudoFocus.apply(this, arguments); + } catch(e){ + webshims.error(e); + } + return false; + }; } - return false; }; + if($.expr.filters){ + extendSels(); + } else { + webshims.ready('sizzle', extendSels); + } + + webshims.triggerInlineForm = function(elem, event){ $(elem).trigger(event); }; var lazyLoadProxy = function(obj, fn, args){ @@ -1298,11 +1326,14 @@ } }; webshims.getContentValidationMessage = function(elem, validity, key){ - var message = $(elem).data('errormessage') || elem.getAttribute('x-moz-errormessage') || ''; + if(webshims.errorbox && webshims.errorbox.initIvalContentMessage){ + webshims.errorbox.initIvalContentMessage(elem); + } + var message = (webshims.getOptions && webshims.errorbox ? webshims.getOptions(elem, 'errormessage') : $(elem).data('errormessage')) || elem.getAttribute('x-moz-errormessage') || ''; if(key && message[key]){ message = message[key]; } else if(message) { validity = validity || $.prop(elem, 'validity') || {valid: 1}; if(validity.valid){ @@ -1344,11 +1375,11 @@ return message; }; $(document).on('focusin.lazyloadvalidation', function(e){ - if('form' in e.target && (e.target.list || $(e.target).is(':invalid'))){ + if('form' in e.target){ lazyLoad(); } }); webshims.ready('WINDOWLOAD', lazyLoad); @@ -1384,10 +1415,11 @@ rangeOverflow: { defaultMessage: 'Value must be less than or equal to {%max}.' }, stepMismatch: 'Invalid input.', tooLong: 'Please enter at most {%maxlength} character(s). You entered {%valueLen}.', + tooShort: 'Please enter at least {%minlength} character(s). You entered {%valueLen}.', patternMismatch: 'Invalid input. {%title}', valueMissing: { defaultMessage: 'Please fill out this field.', checkbox: 'Please check this box if you want to proceed.' } @@ -1440,10 +1472,11 @@ rangeOverflow: { defaultMessage: '{%value} ist zu hoch. {%max} ist der oberste Wert, den Sie benutzen können.' }, stepMismatch: 'Der Wert {%value} ist in diesem Feld nicht zulässig. Hier sind nur bestimmte Werte zulässig. {%title}', tooLong: 'Der eingegebene Text ist zu lang! Sie haben {%valueLen} Zeichen eingegeben, dabei sind {%maxlength} das Maximum.', + tooShort: 'Der eingegebene Text ist zu kurz! Sie haben {%valueLen} Zeichen eingegeben, dabei sind {%minlength} das Minimum.', patternMismatch: '{%value} hat für dieses Eingabefeld ein falsches Format. {%title}', valueMissing: { defaultMessage: 'Bitte geben Sie einen Wert ein.', checkbox: 'Bitte aktivieren Sie das Kästchen.' } @@ -1491,11 +1524,11 @@ if(!message){ message = getMessageFromObj(validityMessages[''][name], elem) || $.prop(elem, 'validationMessage'); webshims.info('could not find errormessage for: '+ name +' / '+ type +'. in language: '+webshims.activeLang()); } if(message){ - ['value', 'min', 'max', 'title', 'maxlength', 'label'].forEach(function(attr){ + ['value', 'min', 'max', 'title', 'maxlength', 'minlength', 'label'].forEach(function(attr){ if(message.indexOf('{%'+attr) === -1){return;} var val = ((attr == 'label') ? $.trim($('label[for="'+ elem.id +'"]', elem.form).text()).replace(/\*$|:$/, '') : $.prop(elem, attr)) || ''; if(name == 'patternMismatch' && attr == 'title' && !val){ webshims.error('no title for patternMismatch provided. Always add a title attribute.'); } @@ -1521,23 +1554,13 @@ if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){ implementProperties.push('validationMessage'); } - webshims.activeLang({ - langObj: validityMessages, - module: 'form-core', - callback: function(langObj){ - currentValidationMessage = langObj; - } - }); - webshims.activeLang({ - register: 'form-core', - callback: function(val){ - if(validityMessages[val]){ - currentValidationMessage = validityMessages[val]; - } - } + currentValidationMessage = webshims.activeLang(validityMessages); + + $(validityMessages).on('change', function(e, data){ + currentValidationMessage = validityMessages.__active; }); implementProperties.forEach(function(messageProp){ webshims.defineNodeNamesProperty(['fieldset', 'output', 'button'], messageProp, {