vendor/assets/javascripts/webshims/shims/combos/3.js in webshims-rails-1.12.5 vs vendor/assets/javascripts/webshims/shims/combos/3.js in webshims-rails-1.12.7

- old
+ new

@@ -1,5 +1,63 @@ + +//this might was already extended by ES5 shim feature +(function($){ + "use strict"; + var webshims = window.webshims; + if(webshims.defineProperties){return;} + var defineProperty = 'defineProperty'; + var has = Object.prototype.hasOwnProperty; + var descProps = ['configurable', 'enumerable', 'writable']; + var extendUndefined = function(prop){ + for(var i = 0; i < 3; i++){ + if(prop[descProps[i]] === undefined && (descProps[i] !== 'writable' || prop.value !== undefined)){ + prop[descProps[i]] = true; + } + } + }; + + var extendProps = function(props){ + if(props){ + for(var i in props){ + if(has.call(props, i)){ + extendUndefined(props[i]); + } + } + } + }; + + if(Object.create){ + webshims.objectCreate = function(proto, props, opts){ + extendProps(props); + var o = Object.create(proto, props); + if(opts){ + o.options = $.extend(true, {}, o.options || {}, opts); + opts = o.options; + } + if(o._create && $.isFunction(o._create)){ + o._create(opts); + } + return o; + }; + } + + if(Object[defineProperty]){ + webshims[defineProperty] = function(obj, prop, desc){ + extendUndefined(desc); + return Object[defineProperty](obj, prop, desc); + }; + } + if(Object.defineProperties){ + webshims.defineProperties = function(obj, props){ + extendProps(props); + return Object.defineProperties(obj, props); + }; + } + webshims.getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + + webshims.getPrototypeOf = Object.getPrototypeOf; +})(window.webshims.$); //DOM-Extension helper webshims.register('dom-extend', function($, webshims, window, document, undefined){ "use strict"; var supportHrefNormalized = !('hrefNormalized' in $.support) || $.support.hrefNormalized; var supportGetSetAttribute = !('getSetAttribute' in $.support) || $.support.getSetAttribute; @@ -631,10 +689,17 @@ this._create(); this.height = docObserve.getHeight(); this.width = docObserve.getWidth(); setInterval(this.test, 999); $(this.test); + if($.support.boxSizing == null){ + $(function(){ + if($.support.boxSizing){ + docObserve.handler({type: 'boxsizing'}); + } + }); + } webshims.ready('WINDOWLOAD', this.test); $(document).on('updatelayout.webshim pageinit popupafteropen panelbeforeopen tabsactivate collapsibleexpand shown.bs.modal shown.bs.collapse slid.bs.carousel', this.handler); $(window).on('resize', this.handler); } } @@ -642,17 +707,11 @@ webshims.docObserve = function(){ webshims.ready('DOM', function(){ docObserve.start(); - if($.support.boxSizing == null){ - $(function(){ - if($.support.boxSizing){ - docObserve.handler({type: 'boxsizing'}); - } - }); - } + }); }; return function(nativeElem, shadowElem, opts){ if(nativeElem && shadowElem){ opts = opts || {}; @@ -1179,31 +1238,31 @@ $(document).off('.lazyloadvalidation'); }; /* * Selectors for all browsers */ - var rElementsGroup = /^(?:form|fieldset)$/i; - var hasInvalid = function(elem){ - var ret = false; - $(elem).jProp('elements').each(function(){ - if(!rElementsGroup.test(this.nodeName || '')){ - ret = $(this).is(':invalid'); - if(ret){ - return false; - } - } - - }); - return ret; - }; var extendSels = function(){ var matches, matchesOverride; var exp = $.expr[":"]; + var rElementsGroup = /^(?:form|fieldset)$/i; + var hasInvalid = function(elem){ + var ret = false; + $(elem).jProp('elements').each(function(){ + if(!rElementsGroup.test(this.nodeName || '')){ + ret = exp.invalid(this); + if(ret){ + return false; + } + } + + }); + return ret; + }; $.extend(exp, { "valid-element": function(elem){ - return rElementsGroup.test(elem.nodeName || '') ? !hasInvalid(elem) :!!($.prop(elem, 'willValidate') && isValid(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){ @@ -1254,31 +1313,40 @@ } return false; }; } }; + var formExtras = { + noAutoCallback: true, + options: options + }; + var addModule = webshims.loader.addModule; + var lazyLoadProxy = function(obj, fn, args){ + lazyLoad(); + webshims.ready('form-validation', function(){ + obj[fn].apply(obj, args); + }); + }; + + var transClass = ('transitionDelay' in document.documentElement.style) ? '' : ' no-transition'; + var poCFG = webshims.cfg.wspopover; + + addModule('form-validation', $.extend({d: ['form-message']}, formExtras)); + + addModule('form-validators', $.extend({}, formExtras)); if($.expr.filters){ extendSels(); } else { webshims.ready('sizzle', extendSels); } - - + webshims.triggerInlineForm = function(elem, event){ $(elem).trigger(event); }; - var lazyLoadProxy = function(obj, fn, args){ - lazyLoad(); - webshims.ready('form-validation', function(){ - obj[fn].apply(obj, args); - }); - }; - - var transClass = ('transitionDelay' in document.documentElement.style) ? '' : ' no-transition'; - var poCFG = webshims.cfg.wspopover; + if(!poCFG.position && poCFG.position !== false){ poCFG.position = { at: 'left bottom', my: 'left top', collision: 'fit flip' @@ -1396,11 +1464,11 @@ } }); webshims.ready('WINDOWLOAD', lazyLoad); - if(modules['form-number-date-ui'].loaded && modules['form-number-date-api'].test()){ + if(modules['form-number-date-ui'].loaded && !options.customMessages && (modules['form-number-date-api'].test() || (Modernizr.inputtypes.range && Modernizr.inputtypes.color))){ webshims.isReady('form-number-date-ui', true); } }); ;webshims.register('form-message', function($, webshims, window, document, undefined, options){ "use strict"; @@ -1527,29 +1595,106 @@ var valueVals = { value: 1, min: 1, max: 1 }; + var toLocale = (function(){ + var monthFormatter; + var transforms = { + number: function(val){ + var num = val * 1; + if(num.toLocaleString && !isNaN(num)){ + val = num.toLocaleString() || val; + } + return val; + } + }; + var _toLocale = function(val, elem, attr){ + var type, widget; + if(valueVals[attr]){ + type = $.prop(elem, 'type'); + widget = $(elem).getShadowElement().data('wsWidget'+ type ); + if(widget && widget.formatValue){ + val = widget.formatValue(val, false); + } else if(transforms[type]){ + val = transforms[type](val); + } + } + return val; + }; + [{n: 'date', f: 'toLocaleDateString'}, {n: 'time', f: 'toLocaleTimeString'}, {n: 'datetime-local', f: 'toLocaleString'}].forEach(function(desc){ + transforms[desc.n] = function(val){ + var date = new Date(val); + if(date && date[desc.f]){ + val = date[desc.f]() || val; + } + return val; + }; + }); + + if(window.Intl && Intl.DateTimeFormat){ + monthFormatter = new Intl.DateTimeFormat(navigator.browserLanguage || navigator.language, {year: "numeric", month: "2-digit"}).format(new Date()); + if(monthFormatter && monthFormatter.format){ + transforms.month = function(val){ + var date = new Date(val); + if(date){ + val = monthFormatter.format(date) || val; + } + return val; + }; + } + } + + webshims.format = {}; + + ['date', 'number', 'month', 'time', 'datetime-local'].forEach(function(name){ + webshims.format[name] = function(val, opts){ + if(opts && opts.nodeType){ + return _toLocale(val, opts, name); + } + if(name == 'number' && opts && opts.toFixed ){ + val = (val * 1); + if(!opts.fixOnlyFloat || val % 1){ + val = val.toFixed(opts.toFixed); + } + } + if(webshims._format && webshims._format[name]){ + return webshims._format[name](val, opts); + } + return transforms[name](val); + }; + }); + + return _toLocale; + })(); + webshims.replaceValidationplaceholder = function(elem, message, name){ - var type, widget; + var val = $.prop(elem, 'title'); + if(message){ + if(name == 'patternMismatch' && !val){ + webshims.error('no title for patternMismatch provided. Always add a title attribute.'); + } + if(val){ + val = '<span class="ws-titlevalue">'+ val.replace(lReg, '&lt;').replace(gReg, '&gt;') +'</span>'; + } + + if(message.indexOf('{%title}') != -1){ + message = message.replace('{%title}', val); + } else if(val) { + message = message+' '+val; + } + } + if(message && message.indexOf('{%') != -1){ - ['value', 'min', 'max', 'title', 'maxlength', 'minlength', 'label'].forEach(function(attr){ + ['value', 'min', 'max', '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)) || ''; val = ''+val; - if(name == 'patternMismatch' && attr == 'title' && !val){ - webshims.error('no title for patternMismatch provided. Always add a title attribute.'); - } - if(valueVals[attr]){ - if(!widget){ - widget = $(elem).getShadowElement().data('wsWidget'+ (type = $.prop(elem, 'type'))); - } - if(widget && widget.formatValue){ - val = widget.formatValue(val, false); - } - } + + val = toLocale(val, elem, attr); + message = message.replace('{%'+ attr +'}', val.replace(lReg, '&lt;').replace(gReg, '&gt;')); if('value' == attr){ message = message.replace('{%valueLen}', val.length); }