vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.12.7 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.13.0

- old
+ new

@@ -196,37 +196,48 @@ $.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, base, attrVal; + var step, val, valModStep, alignValue, cache, base, attrVal; var type = getType(this); if(typeModels[type] && typeModels[type].asNumber){ cache = {type: type}; if(!factor){ factor = 1; webshims.warn("you should always use a factor for stepUp/stepDown"); } factor *= stepFactor; - val = $.prop(this, 'valueAsNumber'); + - if(isNaN(val)){ - webshims.info("valueAsNumber is NaN can't apply stepUp/stepDown "); - throw('invalid state error'); - } + step = webshims.getStep(this, type); if(step == 'any'){ webshims.info("step is 'any' can't apply stepUp/stepDown"); throw('invalid state error'); } webshims.addMinMaxNumberToCache('min', $(this), cache); webshims.addMinMaxNumberToCache('max', $(this), cache); - + + val = $.prop(this, 'valueAsNumber'); + + if(factor > 0 && !isNaN(cache.minAsNumber) && (isNaN(val) || cache.minAsNumber > val)){ + $.prop(this, 'valueAsNumber', cache.minAsNumber); + return; + } else if(factor < 0 && !isNaN(cache.maxAsNumber) && (isNaN(val) || cache.maxAsNumber < val)){ + $.prop(this, 'valueAsNumber', cache.maxAsNumber); + return; + } + + if(isNaN(val)){ + val = 0; + } + base = cache.minAsNumber; if(isNaN(base) && (attrVal = $.prop(this, 'defaultValue'))){ base = typeModels[type].asNumber( attrVal ); } @@ -247,11 +258,11 @@ val = alignValue.toFixed(5) * 1; } if( (!isNaN(cache.maxAsNumber) && val > cache.maxAsNumber) || (!isNaN(cache.minAsNumber) && val < cache.minAsNumber) ){ webshims.info("max/min overflow can't apply stepUp/stepDown"); - throw('invalid state error'); + return; } $.prop(this, 'valueAsNumber', val); } else if(stepDescriptor.prop && stepDescriptor.prop._supvalue){ @@ -601,11 +612,12 @@ writeable: false } }); } -});;(function($){ +}); +;(function($){ "use strict"; var isNumber = function(string){ return (typeof string == 'number' || (string && string == string * 1)); }; @@ -2181,11 +2193,10 @@ } else if(!isNaN(this.maxAsNumber) && start > this.maxAsNumber){ start = this.maxAsNumber; } this.elemHelper.prop('valueAsNumber', start); this.options.defValue = this.elemHelper.prop('value'); - }, reorderInputs: function(){ if(splitInputs[this.type]){ var element = this.element.attr('dir', curCfg.date.isRTL ? 'rtl' : 'ltr'); splitInputs[this.type].sort(element, this.options); @@ -2248,11 +2259,11 @@ val = this.toFixed(val); if(isLive && this._getSelectionEnd){ selectionEnd = this._getSelectionEnd(val); } this.element.prop(name, val); - if(selectionEnd){ + if(selectionEnd != null){ this.element.prop('selectionEnd', selectionEnd); } } this._propertyChange(name); this.mirrorValidity(); @@ -2263,10 +2274,11 @@ $.each({min: 1, max: -1}, function(name, factor){ var numName = name +'AsNumber'; spinBtnProto[name] = function(val){ this.elemHelper.prop(name, val); this[numName] = this.asNumber(val); + if(this.valueAsNumber != null && (isNaN(this.valueAsNumber) || (!isNaN(this[numName]) && (this.valueAsNumber * factor) < (this[numName] * factor)))){ this._setStartInRange(); } this.options[name] = val; if(this._init){ @@ -2899,15 +2911,15 @@ var implementType = function(){ var type = $.prop(this, 'type'); - var i, opts, data, optsName, labels, cNames; + var i, opts, data, optsName, labels, cNames, hasInitialFocus; if(inputTypes[type] && webshims.implement(this, 'inputwidgets')){ data = {}; optsName = type; - + hasInitialFocus = $(this).is(':focus'); labels = $(this).jProp('labels'); opts = $.extend(webshims.getOptions(this, type, [options.widgets, options[type], $($.prop(this, 'form')).data(type)]), { orig: this, type: type, labels: labels, @@ -3027,9 +3039,12 @@ if(opts.calculateWidth){ sizeInput(data.shim); } else { $(this).css('display', 'none'); + } + if(hasInitialFocus){ + $(this).getShadowFocusElement().trigger('focus'); } } };