vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.11.1 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.11.2

- old
+ new

@@ -196,11 +196,11 @@ var type = getType(this); if(typeModels[type] && typeModels[type].asNumber){ cache = {type: type}; if(!factor){ factor = 1; - webshims.info("you should always use a factor for stepUp/stepDown"); + webshims.warn("you should always use a factor for stepUp/stepDown"); } factor *= stepFactor; val = $.prop(this, 'valueAsNumber'); @@ -232,17 +232,15 @@ 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'); } - if(dateVal){ - $.prop(this, 'valueAsDate', dateVal); - } else { - $.prop(this, 'valueAsNumber', val); - } - } else if(stepDescriptor.prop && stepDescriptor.prop.value){ - return stepDescriptor.prop.value.apply(this, arguments); + + $.prop(this, 'valueAsNumber', val); + + } else if(stepDescriptor.prop && stepDescriptor.prop._supvalue){ + return stepDescriptor.prop._supvalue.apply(this, arguments); } else { webshims.info("no step method for type: "+ type); throw('invalid state error'); } } @@ -605,22 +603,23 @@ var rangeProto = { _create: function(){ var i; - this.element.addClass('ws-range').attr({role: 'slider'}).append('<span class="ws-range-min" /><span class="ws-range-rail"><span class="ws-range-thumb" /></span>'); - this.trail = $('.ws-range-rail', this.element); - this.range = $('.ws-range-min', this.element); + 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.thumb = $('.ws-range-thumb', this.trail); this.updateMetrics(); this.orig = this.options.orig; for(i = 0; i < createOpts.length; i++){ this[createOpts[i]](this.options[createOpts[i]]); } + this.value = this._value; this.value(this.options.value); this.initDataList(); this.element.data('rangeUi', this); this.addBindings(); @@ -855,11 +854,11 @@ this.updateMetrics(); } } }, addBindings: function(){ - var leftOffset, widgetUnits, hasFocus; + var leftOffset, widgetUnits, hasFocus, isActive; var that = this; var o = this.options; var eventTimer = (function(){ var events = {}; @@ -885,12 +884,32 @@ }, 0); } } }; })(); - + var normalizeTouch = (function(){ + var types = { + touchstart: 1, + touchend: 1, + touchmove: 1 + }; + var normalize = ['pageX', 'pageY']; + return function(e){ + if(types[e.type] && e.originalEvent && e.originalEvent.touches && e.originalEvent.touches.length){ + for(var i = 0; i < normalize.length; i++){ + e[normalize[i]] = e.originalEvent.touches[0][normalize[i]]; + } + + } + return e; + }; + })(); var setValueFromPos = function(e, animate){ + if(e.type == 'touchmove'){ + e.preventDefault(); + normalizeTouch(e); + } var val = that.getStepedValueFromPos((e[that.dirs.mouse] - leftOffset) * widgetUnits); if(val != o.value){ that.value(val, false, animate); eventTimer.call('input', val); @@ -903,45 +922,59 @@ if(e && e.type == 'mouseup'){ eventTimer.call('input', o.value); eventTimer.call('change', o.value); } that.addRemoveClass('ws-active'); - $(document).off('mousemove', setValueFromPos).off('mouseup', remove); + $(document).off('mousemove touchmove', setValueFromPos).off('mouseup touchend', remove); $(window).off('blur', removeWin); + isActive = false; }; var removeWin = function(e){ if(e.target == window){remove();} }; var add = function(e){ var outerWidth; + + if(isActive || (e.type == 'touchstart' && (!e.originalEvent || !e.originalEvent.touches || e.originalEvent.touches.length != 1))){ + return; + } e.preventDefault(); - $(document).off('mousemove', setValueFromPos).off('mouseup', remove); + + $(document).off('mousemove touchmove', setValueFromPos).off('mouseup touchend', remove); $(window).off('blur', removeWin); if(!o.readonly && !o.disabled){ + normalizeTouch(e); that.element.focus(); that.addRemoveClass('ws-active', true); leftOffset = that.element.focus().offset(); widgetUnits = that.element[that.dirs.innerWidth](); if(!widgetUnits || !leftOffset){return;} outerWidth = that.thumb[that.dirs.outerWidth](); leftOffset = leftOffset[that.dirs.pos]; widgetUnits = 100 / widgetUnits; setValueFromPos(e, o.animate); + isActive = true; $(document) - .on({ - mouseup: remove, - mousemove: setValueFromPos - }) + .on(e.type == 'touchstart' ? + { + touchend: remove, + touchmove: setValueFromPos + } : + { + mouseup: remove, + mousemove: setValueFromPos + } + ) ; $(window).on('blur', removeWin); e.stopPropagation(); } }; var elementEvts = { - mousedown: add, + 'touchstart mousedown': add, focus: function(e){ - if(!o.disabled){ + if(!o.disabled && !hasFocus){ eventTimer.init('input', o.value); eventTimer.init('change', o.value); that.addRemoveClass('ws-focus', true); that.updateMetrics(); } @@ -1000,10 +1033,24 @@ }; this.element.on(elementEvts); this.thumb.on({ mousedown: add }); + + if(this.orig){ + $(this.orig).jProp('form').on('reset', function(){ + var val = $.prop(that.orig, 'value'); + that.value(val); + setTimeout(function(){ + var val2 = $.prop(that.orig, 'value'); + if(val != val2){ + that.value(val2); + } + }, 4); + }); + } + if (window.webshims) { webshims.ready('WINDOWLOAD', function(){ webshims.ready('dom-support', function(){ if ($.fn.onWSOff) { that.element.onWSOff('updateshadowdom', function(){ @@ -1105,12 +1152,12 @@ }; var getMonthOptions = (function(){ var str; return function(){ if(!str){ - str = ('<option></option>')+$.map(monthDigits, function(val){ - return '<option>'+val+'</option>'; + str = ('<option value=""></option>')+$.map(monthDigits, function(val){ + return '<option value="'+val+'"]>'+val+'</option>'; }).join(''); } return str; }; })(); @@ -1128,11 +1175,11 @@ _create: function(opts){ var obj = { splits: [$('<input type="text" class="yy" size="4" inputmode="numeric" />')[0]] }; if(opts.monthSelect){ - obj.splits.push($('<select class="mm">'+getMonthOptions()+'</select>')[0]); + 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]); @@ -1163,11 +1210,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()+'</select>')[0]); + obj.splits.push($('<select class="mm ws-spin">'+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}); } @@ -1255,10 +1302,13 @@ d: "dd.mm.yy" }, month: { currentText: 'Aktueller Monat' }, + time: { + currentText: 'Jetzt' + }, date: { close: 'schließen', clear: 'Löschen', prevText: 'Zurück', nextText: 'Vor', @@ -1292,10 +1342,13 @@ }, meridian: ['AM', 'PM'], month: { currentText: 'This month' }, + time: { + "currentText": "Now" + }, date: { "closeText": "Done", clear: 'Clear', "prevText": "Prev", "nextText": "Next", @@ -1354,10 +1407,16 @@ langCfg.colorSigns = '#abcdefABCDEF'; } if(!langCfg['datetime-localSigns']){ langCfg['datetime-localSigns'] = langCfg.dateSigns+langCfg.timeSigns; } + if(!langCfg['datetime-local']){ + langCfg['datetime-local'] = {}; + } + if(!langCfg['datetime-local'].currentText && langCfg.time.currentText){ + langCfg['datetime-local'].currentText = langCfg.time.currentText; + } }; var triggerLocaleChange = function(){ processLangCFG(curCfg); $(document).triggerHandler('wslocalechange'); }; @@ -1421,10 +1480,13 @@ fVal = 1; } else { fVal = 0; } + if(val[0] === '00'){ + val[0] = '12'; + } val = $.trim(val.join(':')) + ' '+ curCfg.meridian[fVal]; } return val; }, 'datetime-local': function(val, o){ @@ -1505,10 +1567,13 @@ return val; }, time: function(val){ var fVal; if(val && curCfg.meridian){ + if(val.substr(0,2) === "12"){ + val = "00" + val.substr(2); + } if(val.indexOf(curCfg.meridian[1]) != -1){ val = val.split(':'); fVal = (val[0] * 1); if(!isNaN(fVal)){ val[0] = fVal + 12; @@ -1590,11 +1655,14 @@ var hintValue = (val || '').split('-'); if(hintValue.length == 2){ hintValue = opts.splitInput ? hintValue : - curCfg.patterns.d.replace('yy', hintValue[0]).replace('mm', hintValue[1]); + curCfg.date.showMonthAfterYear ? + hintValue[0] +' '+hintValue[1] : + + hintValue[1] +' '+ hintValue[0]; } else { hintValue = opts.splitInput ? [val, val] : val; } @@ -1965,14 +2033,22 @@ if (!factor) { factor = 1; } try { that.elemHelper[name](factor); + ret = that.elemHelper.prop('value'); + + } catch (er) { + if(!o.value && that.maxAsNumber >= that.minAsNumber){ + ret = o.defValue; + } + } + if(ret !== false && o.value != ret){ that.value(ret); eventTimer.call('input', ret); - } catch (er) {} + } return ret; } }; }); if(!o.noSpinbtn){ @@ -2034,19 +2110,10 @@ })(); } initChangeEvents(); }, - value: function(val, force){ - if(!this._init || force || val !== this.options.value){ - this.element.val(this.formatValue(val)); - this.options.value = val; - this._propertyChange('value'); - this.mirrorValidity(); - } - - }, required: function(val, boolVal){ this.inputElements.attr({'aria-required': ''+boolVal}); this.mirrorValidity(); }, parseValue: function(noCorrect){ @@ -2059,11 +2126,11 @@ return parseVal[this.type](value, this.options, noCorrect); }, formatValue: function(val, noSplit){ return formatVal[this.type](val, noSplit === false ? false : this.options); }, - createOpts: ['readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'value', 'required'], + createOpts: ['readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'defaultValue', 'value', 'required'], placeholder: function(val){ var options = this.options; options.placeholder = val; var placeholder = val; if(placeholderFormat[this.type]){ @@ -2129,10 +2196,20 @@ this.inputElements.prop('title', this.options.title); } } }; + ['defaultValue', 'value'].forEach(function(name){ + wsWidgetProto[name] = function(val, force){ + if(!this._init || force || val !== this.options[name]){ + this.element.prop(name, this.formatValue(val)); + this.options[name] = val; + this._propertyChange(name); + this.mirrorValidity(); + } + }; + }); ['readonly', 'disabled'].forEach(function(name){ var isDisabled = name == 'disabled'; wsWidgetProto[name] = function(val, boolVal){ var options = this.options; @@ -2182,11 +2259,11 @@ o.max = this.asValue(this.getRelNumber(o.relMax)); $.prop(this.orig, 'max', o.max); } this._init = true; }, - createOpts: ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'value', 'required'], + createOpts: ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'defaultValue', 'value', 'required'], _addSplitInputs: function(){ if(!this.inputElements){ var create = splitInputs[this.type]._create(this.options); this.splits = create.splits; this.inputElements = $(create.elements).prependTo(this.element).filter('input, select'); @@ -2252,13 +2329,51 @@ step: function(val){ var defStep = steps[this.type]; this.options.step = val; this.elemHelper.prop('step', retDefault(val, defStep.step)); this.mirrorValidity(); + }, + _beforeValue: function(val){ + this.valueAsNumber = this.asNumber(val); + this.options.value = val; + + if(isNaN(this.valueAsNumber) || (!isNaN(this.minAsNumber) && this.valueAsNumber < this.minAsNumber) || (!isNaN(this.maxAsNumber) && this.valueAsNumber > this.maxAsNumber)){ + this._setStartInRange(); + } else { + this.elemHelper.prop('value', val); + this.options.defValue = ""; + } } }); + ['defaultValue', 'value'].forEach(function(name){ + var isValue = name == 'value'; + spinBtnProto[name] = function(val, force){ + if(!this._init || force || this.options[name] !== val){ + if(isValue){ + this._beforeValue(val); + } + + val = formatVal[this.type](val, this.options); + if(this.options.splitInput){ + $.each(this.splits, function(i, elem){ + var setOption; + if(!(name in elem) && !isValue && $.nodeName(elem, 'select')){ + $('option[value="'+ val[i] +'"]', elem).prop('defaultSelected', true); + } else { + $.prop(elem, name, val[i]); + } + }); + } else { + this.element.prop(name, val); + } + this._propertyChange(name); + this.mirrorValidity(); + } + }; + }); + $.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); @@ -2658,14 +2773,16 @@ var modernizrInputTypes = Modernizr.inputtypes; var inputTypes = { }; + var boolAttrs = {disabled: 1, required: 1, readonly: 1}; var copyProps = [ 'disabled', 'readonly', 'value', + 'defaultValue', 'min', 'max', 'step', 'title', 'required', @@ -2679,25 +2796,43 @@ var fnName = name.replace(/^data\-/, ''); webshims.onNodeNamesPropertyModify('input', name, function(val, boolVal){ if(!stopCircular){ var shadowData = webshims.data(this, 'shadowData'); if(shadowData && shadowData.data && shadowData.nativeElement === this && shadowData.data[fnName]){ - shadowData.data[fnName](val, boolVal); + if(boolAttrs[fnName]){ + shadowData.data[fnName](val, boolVal); + } else { + shadowData.data[fnName](val); + } } } }); }); if(options.replaceUI && 'valueAsNumber' in document.createElement('input')){ - var reflectFn = function(val){ + var reflectFn = function(){ if(webshims.data(this, 'hasShadow')){ $.prop(this, 'value', $.prop(this, 'value')); } }; webshims.onNodeNamesPropertyModify('input', 'valueAsNumber', reflectFn); webshims.onNodeNamesPropertyModify('input', 'valueAsDate', reflectFn); + $.each({stepUp: 1, stepDown: -1}, function(name, stepFactor){ + var stepDescriptor = webshims.defineNodeNameProperty('input', name, { + prop: { + value: function(){ + var ret; + if(stepDescriptor.prop && stepDescriptor.prop._supvalue){ + ret = stepDescriptor.prop._supvalue.apply(this, arguments); + reflectFn.apply(this, arguments); + } + return ret; + } + } + }); + }); } var extendType = (function(){ return function(name, data){ inputTypes[name] = data; @@ -2713,11 +2848,11 @@ var init; var updateStyles = function(){ $(data.orig).removeClass('ws-important-hide'); $.style( data.orig, 'display', '' ); var hasButtons, marginR, marginL; - var correctWidth = 0.6; + var correctWidth = 0.8; if(!init || data.orig.offsetWidth){ hasButtons = data.buttonWrapper && data.buttonWrapper.filter(isVisible).length; marginR = $.css( data.orig, 'marginRight'); data.element.css({ marginLeft: $.css( data.orig, 'marginLeft'), @@ -2737,11 +2872,11 @@ paddingRight: (parseInt( data.element.css('paddingRight'), 10) || 0) + data.buttonWrapper.outerWidth() }) ; } else { data.buttonWrapper.css('marginRight', marginR); - correctWidth = data.buttonWrapper.outerWidth(true) + 0.6; + correctWidth = data.buttonWrapper.outerWidth(true) + correctWidth; } } data.element.outerWidth( $(data.orig).outerWidth() - correctWidth ); } @@ -2895,21 +3030,43 @@ } }); }); } - if(!modernizrInputTypes.range || options.replaceUI){ + var replace = {}; + + + if(options.replaceUI){ + if( $.isPlainObject(options.replaceUI) ){ + $.extend(replace, options.replaceUI); + } else { + $.extend(replace, { + 'range': 1, + 'number': 1, + 'time': 1, + 'month': 1, + 'date': 1, + 'color': 1, + 'datetime-local': 1 + }); + } + } + if(modernizrInputTypes.number && navigator.userAgent.indexOf('Touch') == -1 && ((/MSIE 1[0|1]\.\d/.test(navigator.userAgent)) || (/Trident\/7\.0/.test(navigator.userAgent)))){ + replace.number = 1; + } + + if(!modernizrInputTypes.range || replace.range){ extendType('range', { _create: function(opts, set){ var data = $('<span />').insertAfter(opts.orig).rangeUI(opts).data('rangeUi'); return data; } }); } - var isStupid = modernizrInputTypes.number && navigator.userAgent.indexOf('Touch') == -1 && ((/MSIE 1[0|1]\.\d/.test(navigator.userAgent)) || (/Trident\/7\.0/.test(navigator.userAgent))); + ['number', 'time', 'month', 'date', 'color', 'datetime-local'].forEach(function(name){ - if(!modernizrInputTypes[name] || options.replaceUI || (name == 'number' && isStupid)){ + if(!modernizrInputTypes[name] || replace[name]){ extendType(name, { _create: function(opts, set){ if(opts.monthSelect){ opts.splitInput = true; }