vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.11.6.1 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.12.0

- old
+ new

@@ -61,11 +61,12 @@ if(val === ''){return false;} if(!('type' in cache)){ cache.type = getType(input[0]); } if(cache.type == 'week'){return false;} - var ret = (validityState || {}).stepMismatch || false, base; + var base, attrVal; + var ret = (validityState || {}).stepMismatch || false; if(typeModels[cache.type] && typeModels[cache.type].step){ if( !('step' in cache) ){ cache.step = webshims.getStep(input[0], cache.type); } @@ -76,10 +77,15 @@ } if(isNaN(cache.valueAsNumber)){return false;} addMinMaxNumberToCache('min', input, cache); base = cache.minAsNumber; + + if(isNaN(base) && (attrVal = input.prop('defaultValue'))){ + base = typeModels[cache.type].asNumber( attrVal ); + } + if(isNaN(base)){ base = typeModels[cache.type].stepBase || 0; } ret = Math.abs((cache.valueAsNumber - base) % cache.step); @@ -190,11 +196,11 @@ $.each({stepUp: 1, stepDown: -1}, function(name, stepFactor){ var stepDescriptor = webshims.defineNodeNameProperty('input', name, { prop: { value: function(factor){ - var step, val, dateVal, valModStep, alignValue, cache; + var step, val, dateVal, valModStep, alignValue, cache, base, attrVal; var type = getType(this); if(typeModels[type] && typeModels[type].asNumber){ cache = {type: type}; if(!factor){ factor = 1; @@ -217,15 +223,26 @@ } webshims.addMinMaxNumberToCache('min', $(this), cache); webshims.addMinMaxNumberToCache('max', $(this), cache); + base = cache.minAsNumber; + + if(isNaN(base) && (attrVal = $.prop(this, 'defaultValue'))){ + base = typeModels[type].asNumber( attrVal ); + } + + if(!base){ + base = 0; + } + step *= factor; val = (val + step).toFixed(5) * 1; - valModStep = (val - (cache.minAsNumber || 0)) % step; + valModStep = (val - base) % step; + if ( valModStep && (Math.abs(valModStep) > EPS) ) { alignValue = val - valModStep; alignValue += ( valModStep > 0 ) ? step : ( -step ); val = alignValue.toFixed(5) * 1; } @@ -584,12 +601,11 @@ writeable: false } }); } -}); -(function($){ +});;(function($){ var id = 0; var isNumber = function(string){ return (typeof string == 'number' || (string && string == string * 1)); }; @@ -605,11 +621,11 @@ var i; this.element.addClass('ws-range').attr({role: 'slider'}).append('<span class="ws-range-min ws-range-progress" /><span class="ws-range-rail ws-range-track"><span class="ws-range-thumb" /></span>'); this.trail = $('.ws-range-track', this.element); - this.range = $('.ws-range-progress ', this.element); + this.range = $('.ws-range-progress', this.element); this.thumb = $('.ws-range-thumb', this.trail); this.updateMetrics(); this.orig = this.options.orig; @@ -625,11 +641,11 @@ this.addBindings(); this._init = true; }, value: $.noop, _value: function(val, _noNormalize, animate){ - var left, posDif; + var left, posDif, textValue; var o = this.options; var oVal = val; var thumbStyle = {}; var rangeStyle = {}; @@ -674,14 +690,20 @@ this.range.animate(rangeStyle, animate); } if(this.orig && (oVal != val || (!this._init && this.orig.value != val)) ){ this.options._change(val); } + + textValue = this.options.textValue ? this.options.textValue(this.options.value) : this.options.options[this.options.value] || this.options.value; this.element.attr({ 'aria-valuenow': this.options.value, - 'aria-valuetext': this.options.textValue ? this.options.textValue(this.options.value) : this.options.options[this.options.value] || this.options.value + 'aria-valuetext': textValue }); + this.thumb.attr({ + 'data-value': this.options.value, + 'data-valuetext': textValue + }); }, initDataList: function(){ if(this.orig){ var listTimer; var that = this; @@ -720,17 +742,23 @@ }); $.each(o.options, function(val, label){ if(!isNumber(val) || val < min || val > max){return;} var left = 100 * ((val - min) / (max - min)); - var title = o.showLabels && label ? ' title="'+ label +'"' : ''; + var attr = ''; + if(label){ + attr += 'data-label="'+label+'"'; + if(o.showLabels){ + attr += ' title="'+label+'"'; + } + } if(that.vertical){ left = Math.abs(left - 100); } that.posCenter( - $('<span class="ws-range-ticks"'+ title +' data-label="'+label+'" style="'+(that.dirs.left)+': '+left+'%;" />').appendTo(trail) + $('<span class="ws-range-ticks"'+ attr +' style="'+(that.dirs.left)+': '+left+'%;" />').appendTo(trail) ); }); }, readonly: function(val){ val = !!val; @@ -1135,37 +1163,40 @@ obj.options = opts; obj._create.call(obj); }); }; if(window.webshims && webshims.isReady){ - webshims.ready('es5', function(){ - webshims.isReady('range-ui', true); - }); - if(webshims._polyfill){ - webshims._polyfill(['es5']); - } + webshims.isReady('range-ui', true); } -})(window.webshims ? webshims.$ : jQuery); -webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){ +})(window.webshims ? webshims.$ : jQuery);;webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){ "use strict"; var curCfg; var formcfg = webshims.formcfg; + var hasFormValidation = Modernizr.formvalidation && !webshims.bugs.bustedValidity; var monthDigits = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']; var stopPropagation = function(e){ e.stopImmediatePropagation(); }; - var getMonthOptions = (function(){ - var str; - return function(){ - if(!str){ - str = ('<option value=""></option>')+$.map(monthDigits, function(val){ - return '<option value="'+val+'"]>'+val+'</option>'; - }).join(''); - } - return str; - }; - })(); + var getMonthOptions = function(opts){ + var selectName = 'monthSelect'+opts.formatMonthNames; + if(!curCfg[selectName]){ + var labels = curCfg.date[opts.formatMonthNames] || monthDigits; + curCfg[selectName] = ('<option value=""></option>')+$.map(monthDigits, function(val, i){ + return '<option value="'+val+'"]>'+labels[i]+'</option>'; + }).join(''); + } + return curCfg[selectName]; + }; + var daySelect = '<select class="dd"><option value=""></option>'+ (function(){ + var i = 1; + var opts = []; + while(i < 32){ + opts.push('<option>'+ ((i < 10) ? '0'+ i : i) +'</option>' ); + i++; + } + return opts.join(''); + })() +'</select>'; var createFormat = function(name){ if(!curCfg.patterns[name+'Obj']){ var obj = {}; $.each(curCfg.patterns[name].split(curCfg[name+'Format']), function(i, name){ obj[name] = i; @@ -1175,20 +1206,24 @@ }; var splitInputs = { date: { _create: function(opts){ var obj = { - splits: [$('<input type="text" class="yy" size="4" inputmode="numeric" />')[0]] + splits: [$('<input type="text" class="yy" size="4" inputmode="numeric" maxlength="4" />')[0]] }; + if(opts.monthSelect){ obj.splits.push($('<select class="mm">'+getMonthOptions(opts)+'</select>')[0]); } else { obj.splits.push($('<input type="text" class="mm" inputmode="numeric" maxlength="2" size="2" />')[0]); } - obj.splits.push($('<input type="text" class="dd ws-spin" inputmode="numeric" maxlength="2" size="2" />')[0]); + if(opts.daySelect){ + obj.splits.push($(daySelect)[0]); + } else { + obj.splits.push($('<input type="text" class="dd ws-spin" inputmode="numeric" maxlength="2" size="2" />')[0]); + } - obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1], $('<span class="ws-input-seperator" />')[0], obj.splits[2]]; return obj; }, sort: function(element){ createFormat('d'); @@ -1213,11 +1248,11 @@ var obj = { splits: [$('<input type="text" class="yy" inputmode="numeric" size="4" />')[0]] }; if(opts.monthSelect){ - obj.splits.push($('<select class="mm ws-spin">'+getMonthOptions(opts)+'</select>')[0]); + obj.splits.push($('<select class="mm">'+getMonthOptions(opts)+'</select>')[0]); } else { obj.splits.push($('<input type="text" class="mm ws-spin" />')[0]); if(opts.onlyMonthDigits){ $(obj.splits[1]).attr({inputmode: 'numeric', size: 2, maxlength: 2}); } @@ -1617,22 +1652,34 @@ } return val; }, date: function(val, opts, noCorrect){ createFormat('d'); - var i; - var obj; + var tmp, obj; + var ret = ''; if(opts.splitInput){ obj = {yy: 0, mm: 1, dd: 2}; } else { obj = curCfg.patterns.dObj; val = val.split(curCfg.dFormat); } - - return (val.length == 3 && val[0] && val[1] && val[2] && (!noCorrect || (val[obj.yy].length > 3 && val[obj.mm].length == 2 && val[obj.dd].length == 2))) ? - ([addZero(val[obj.yy]), addZero(val[obj.mm]), addZero(val[obj.dd])]).join('-') : - '' + if(val.length == 3 && val[0] && val[1] && val[2] && (!noCorrect || (val[obj.yy].length > 3 && val[obj.mm].length == 2 && val[obj.dd].length == 2))){ + if(val[obj.mm] > 12 && val[obj.dd] < 13){ + tmp = val[obj.dd]; + val[obj.dd] = val[obj.mm]; + val[obj.mm] = tmp; + } + if(val[obj.yy].length < 4){ + tmp = ((new Date()).getFullYear() +'').substr(0, 4 - val[obj.yy].length); + if(val[obj.yy] > 50){ + tmp--; + } + val[obj.yy] = tmp + val[obj.yy]; + } + ret = ([addZero(val[obj.yy]), addZero(val[obj.mm]), addZero(val[obj.dd])]).join('-'); + } + return ret ; }, color: function(val, opts){ var ret = '#000000'; if(val){ @@ -1728,11 +1775,11 @@ this.orig = o.orig; this.buttonWrapper = $('<span class="input-buttons '+this.type+'-input-buttons"></span>').insertAfter(this.element); this.options.containerElements.push(this.buttonWrapper[0]); - o.mirrorValidity = o.mirrorValidity && this.orig && Modernizr.formvalidation && !webshims.bugs.bustedValidity; + o.mirrorValidity = o.mirrorValidity && this.orig && hasFormValidation; if(o.splitInput && this._addSplitInputs){ if(o.monthSelect){ this.element.addClass('ws-month-select'); } @@ -1832,11 +1879,11 @@ ; if(this.type != 'color'){ (function(){ - var localeChange ; + var localeChange, select, selectVal; if(!o.splitInput){ localeChange = function(){ if(o.value){ that.value(o.value, true); @@ -1847,10 +1894,16 @@ } }; } else { localeChange = function(){ that.reorderInputs(); + if(o.monthSelect){ + select = that.inputElements.filter('select.mm'); + selectVal = select.prop('value'); + select.html(getMonthOptions(o)); + select.prop('value', selectVal); + } }; that.reorderInputs(); } $(that.orig).onWSOff('wslocalechange', localeChange); })(); @@ -1880,11 +1933,15 @@ if(placeholderFormat[this.type]){ placeholder = placeholderFormat[this.type](val, this.options); } if(options.splitInput && typeof placeholder == 'object'){ $.each(this.splits, function(i, elem){ - $.prop(elem, 'placeholder', placeholder[i]); + if($.nodeName(elem, 'select')){ + $(elem).children('option:first-child').text(placeholder[i]); + } else { + $.prop(elem, 'placeholder', placeholder[i]); + } }); } else { this.element.prop('placeholder', placeholder); } }, @@ -1964,18 +2021,13 @@ if(this.type == 'number'){ this.inputElements.attr('inputmode', 'numeric'); } - if(!o.min && typeof o.relMin == 'number'){ - o.min = this.asValue(this.getRelNumber(o.relMin)); - $.prop(this.orig, 'min', o.min); - } - if(!o.max && typeof o.relMax == 'number'){ - o.max = this.asValue(this.getRelNumber(o.relMax)); - $.prop(this.orig, 'max', o.max); + if((!o.max && typeof o.relMax == 'number') || (!o.min && typeof o.relMin == 'number')){ + webshims.error('relMax/relMin are not supported anymore') } this._init = true; }, createOpts: ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'defaultValue', 'value', 'required'], _addSplitInputs: function(){ @@ -2040,10 +2092,12 @@ var isValue = name == 'value'; spinBtnProto[name] = function(val, force){ if(!this._init || force || this.options[name] !== val){ if(isValue){ this._beforeValue(val); + } else { + this.elemHelper.prop(name, val); } val = formatVal[this.type](val, this.options); if(this.options.splitInput){ $.each(this.splits, function(i, elem){ @@ -2090,13 +2144,11 @@ $.fn.wsBaseWidget.wsProto = wsWidgetProto; $.fn.spinbtnUI = function(opts){ opts = $.extend({ - monthNames: 'monthNames', - size: 1, - startView: 0 + monthNames: 'monthNames' }, opts); return this.each(function(){ $.webshims.objectCreate(spinBtnProto, { element: { value: $(this) @@ -2164,14 +2216,16 @@ } }; picker.commonInit = function(data, popover){ + if(data._commonInit){return;} + data._commonInit = true; var tabbable; popover.isDirty = true; - + popover.element.on('updatepickercontent pickerchange', function(){ tabbable = false; }); if(!data.options.inlinePicker){ @@ -2207,10 +2261,11 @@ } }; return function(prop){ if(prop == 'value' && !data.options.inlinePicker){return;} popover.isDirty = true; + if(popover.isVisible){ clearTimeout(timer); timer = setTimeout(update, 9); } }; @@ -2274,34 +2329,10 @@ }; options.containerElements.push(popover.element[0]); - if(data.type != 'color'){ - if(options.yearButtons){ - options.startView = 2; - } - if(!options.startView){ - options.startView = 0; - } - - if(data.type == 'time'){ - options.minView = 3; - options.startView = 3; - } - if(!options.minView){ - options.minView = 0; - } - if(options.startView < options.minView){ - options.startView = options.minView; - webshims.warn("wrong config for minView/startView."); - } - if(!options.size){ - options.size = 1; - } - } - popover.element .addClass(data.type+'-popover input-picker') .attr({role: 'application'}) .on({ wspopoverhide: function(){ @@ -2358,16 +2389,16 @@ var resetMouseFocus = function(){ mouseFocus = false; }; data.inputElements.on({ keydown: function(e){ - if(e.keyCode == 40 && e.altKey){ + if(e.keyCode == 40 && e.altKey && !$.nodeName(e.target, 'select')){ open(); } }, - focus: function(){ - if(!popover.stopOpen && (options.buttonOnly || options.openOnFocus || (mouseFocus && options.openOnMouseFocus))){ + focus: function(e){ + if(!popover.stopOpen && (options.buttonOnly || options.openOnFocus || (mouseFocus && options.openOnMouseFocus)) && !$.nodeName(e.target, 'select')){ popover.openedByFocus = options.buttonOnly ? false : !options.noInput; show(); } else { popover.preventBlur(); } @@ -2380,11 +2411,11 @@ setTimeout(function(){ popover.openedByFocus = false; popover.activeElement.focus(); }, 4); } - if(data.element.is(':focus')){ + if(data.element.is(':focus') && !$.nodeName(e.target, 'select')){ popover.openedByFocus = options.buttonOnly ? false : !options.noInput; show(); } popover.preventBlur(); } @@ -2608,14 +2639,12 @@ optsName = copyAttrs[i].replace(/^data\-/, ''); if(optsName == 'placeholder' || !opts[optsName]){ opts[optsName] = $.attr(this, copyAttrs[i]) || opts[optsName]; } } - if(opts.monthSelect){ - opts.onlyMonthDigits = true; - } - if(opts.onlyMonthDigits){ + + if(opts.onlyMonthDigits || (!opts.formatMonthNames && opts.monthSelect)){ opts.formatMonthNames = 'monthDigits'; } data.shim = inputTypes[type]._create(opts); webshims.addShadowDom(this, data.shim.element, { @@ -2661,15 +2690,15 @@ })(); data.shim.element.on('change input', stopPropagation); - if(Modernizr.formvalidation){ + if(hasFormValidation){ $(opts.orig).on('firstinvalid', function(e){ if(!webshims.fromSubmit && isCheckValidity){return;} $(opts.orig).off('invalid.replacedwidgetbubble').on('invalid.replacedwidgetbubble', function(evt){ - if(!e.isInvalidUIPrevented() && !evt.isDefaultPrevented()){ + if(!evt.isDefaultPrevented()){ webshims.validityAlert.showFor( e.target ); e.preventDefault(); evt.preventDefault(); } $(opts.orig).off('invalid.replacedwidgetbubble'); @@ -2692,11 +2721,11 @@ } }; - if(Modernizr.formvalidation){ + if(hasFormValidation){ ['input', 'form'].forEach(function(name){ var desc = webshims.defineNodeNameProperty(name, 'checkValidity', { prop: { value: function(){ isCheckValidity = true; @@ -2743,10 +2772,10 @@ ['number', 'time', 'month', 'date', 'color', 'datetime-local'].forEach(function(name){ if(!modernizrInputTypes[name] || replace[name]){ extendType(name, { _create: function(opts, set){ - if(opts.monthSelect){ + if(opts.monthSelect || opts.daySelect){ opts.splitInput = true; } if(opts.splitInput && !splitInputs[name]){ webshims.warn('splitInput not supported for '+ name); opts.splitInput = false;