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

- old
+ new

@@ -13,14 +13,15 @@ var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex']; var rangeProto = { _create: function(){ var i; - this.element.addClass(this.options.baseClass || '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><span data-value="" data-valuetext="" /></span></span></span>'); + this.element.addClass(this.options.baseClass || 'ws-range ws-input').attr({role: 'slider'}).append('<span class="ws-range-rail ws-range-track"><span class="ws-range-min ws-range-progress" /><span class="ws-range-thumb"><span><span data-value="" data-valuetext="" /></span></span></span>'); this.trail = $('.ws-range-track', this.element); this.range = $('.ws-range-progress', this.element); this.thumb = $('.ws-range-thumb', this.trail); + this.thumbValue = $('span[data-value]', this.thumb); this.updateMetrics(); this.orig = this.options.orig; @@ -67,12 +68,12 @@ } thumbStyle[this.dirs.left] = left+'%'; if(!animate || !$.fn.animate){ - this.thumb.css(thumbStyle); - this.range.css(rangeStyle); + this.thumb[0].style[this.dirs.left] = thumbStyle[this.dirs.left]; + this.range[0].style[this.dirs.width] = rangeStyle[this.dirs.width]; } else { if(typeof animate != 'object'){ animate = {}; } else { animate = $.extend({}, animate); @@ -91,24 +92,23 @@ this._setValueMarkup(); }, _setValueMarkup: function(){ var o = this.options; var textValue = o.textValue ? o.textValue(this.options.value) : o.options[o.value] || o.value; - this.element.attr({ - 'aria-valuenow': this.options.value, - 'aria-valuetext': textValue - }); - $('span[data-value]', this.thumb).attr({ - 'data-value': this.options.value, - 'data-valuetext': textValue - }); + + this.element[0].setAttribute('aria-valuenow', this.options.value); + this.element[0].setAttribute('aria-valuetext', textValue); + + this.thumbValue[0].setAttribute('data-value', this.options.value); + this.thumbValue[0].setAttribute('data-valuetext', textValue); + if(o.selectedOption){ $(o.selectedOption).removeClass('ws-selected-option'); o.selectedOption = null; } if(o.value in o.options){ - o.selectedOption = $('[data-value="'+o.value+'"].ws-range-ticks').addClass('ws-selected-option'); + o.selectedOption = $('[data-value="'+o.value+'"].ws-range-ticks', this.trail).addClass('ws-selected-option'); } }, initDataList: function(){ if(this.orig){ var listTimer; @@ -540,29 +540,37 @@ if(this.options.calcTrail && elem[0] == this.thumb[0]){ temp = this.element[this.dirs.innerHeight](); eS[this.dirs.marginTop] = ((elem[this.dirs.outerHeight]() - temp) / -2) + 'px'; this.range[0].style[this.dirs.marginTop] = ((this.range[this.dirs.outerHeight]() - temp) / -2 ) +'px'; + + this.range[0].style[this.dirs.posLeft] = outerWidth +'px'; + outerWidth *= -1; + + this.range[0].style[this.dirs.paddingRight] = outerWidth +'px'; this.trail[0].style[this.dirs.left] = outerWidth +'px'; this.trail[0].style[this.dirs.right] = outerWidth +'px'; + + } } }, updateMetrics: function(){ var width = this.element.innerWidth(); this.vertical = (width && this.element.innerHeight() - width > 10); this.dirs = this.vertical ? - {mouse: 'pageY', pos: 'top', min: 'max', max: 'min', left: 'top', right: 'bottom', width: 'height', innerWidth: 'innerHeight', innerHeight: 'innerWidth', outerWidth: 'outerHeight', outerHeight: 'outerWidth', marginTop: 'marginLeft', marginLeft: 'marginTop'} : - {mouse: 'pageX', pos: 'left', min: 'min', max: 'max', left: 'left', right: 'right', width: 'width', innerWidth: 'innerWidth', innerHeight: 'innerHeight', outerWidth: 'outerWidth', outerHeight: 'outerHeight', marginTop: 'marginTop', marginLeft: 'marginLeft'} + {mouse: 'pageY', pos: 'top', posLeft: 'bottom', paddingRight: 'paddingTop', min: 'max', max: 'min', left: 'top', right: 'bottom', width: 'height', innerWidth: 'innerHeight', innerHeight: 'innerWidth', outerWidth: 'outerHeight', outerHeight: 'outerWidth', marginTop: 'marginLeft', marginLeft: 'marginTop'} : + {mouse: 'pageX', pos: 'left', posLeft: 'left', paddingRight: 'paddingRight', min: 'min', max: 'max', left: 'left', right: 'right', width: 'width', innerWidth: 'innerWidth', innerHeight: 'innerHeight', outerWidth: 'outerWidth', outerHeight: 'outerHeight', marginTop: 'marginTop', marginLeft: 'marginLeft'} ; if(!this.vertical && this.element.css('direction') == 'rtl'){ this.isRtl = true; this.dirs.left = 'right'; this.dirs.right = 'left'; this.dirs.marginLeft = 'marginRight'; + this.dirs.posLeft = 'right'; } this.element [this.vertical ? 'addClass' : 'removeClass']('vertical-range') [this.isRtl ? 'addClass' : 'removeClass']('ws-is-rtl') ; @@ -811,10 +819,11 @@ options.addZero = addZero; webshims.loader.addModule('forms-picker', { noAutoCallback: true, + css: 'styles/forms-picker.css', options: options }); webshims.loader.addModule('color-picker', { noAutoCallback: true, css: 'jpicker/jpicker.css', @@ -983,12 +992,44 @@ return val * 1; }; var formatVal = { - number: function(val, o){ - return (val+'').replace(/\,/g, '').replace(/\./, curCfg.numberFormat['.']); + number: function(val, o, noCorrect){ + var parts, len, i, isNegative; + if(o && o.nogrouping){ + return (val+'').replace(/\,/g, '').replace(/\./, curCfg.numberFormat['.']); + } + + val += ''; + + if(val.charAt(0) == '-'){ + isNegative = true; + val = val.replace('-', ''); + } + parts = val.split('.'); + len = parts[0].length; + i = len - 1; + + val = ""; + while(i >= 0) { + val = parts[0].charAt(i) + val; + if (i > 0 && (len - i) % 3 === 0) { + val = curCfg.numberFormat[','] + val; + } + --i; + } + if(parts[1] != null){ + if(!noCorrect){ + parts[1] = parts[1].replace(/\-/g, '0'); + } + val += curCfg.numberFormat['.'] + parts[1]; + } + if(isNegative){ + val = '-'+val; + } + return val; }, time: function(val){ var fVal; if(val && curCfg.meridian){ val = val.split(':'); @@ -1063,14 +1104,14 @@ } } return ret; } }; - + var parseVal = { number: function(val){ - return (val+'').replace(curCfg.numberFormat[','], '').replace(curCfg.numberFormat['.'], '.'); + return (val+'').split(curCfg.numberFormat[',']).join('').replace(curCfg.numberFormat['.'], '.'); }, // week: function(val){ // return val; // }, 'datetime-local': function(val, o){ @@ -1135,11 +1176,11 @@ } else { obj = curCfg.patterns.dObj; val = val.split(curCfg.dFormat); } 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){ + if(!opts.noDayMonthSwitch && 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){ @@ -1568,20 +1609,21 @@ this.options.defValue = ""; } }, toFixed: function(val, force){ var o = this.options; - if(o.toFixed && o.type == 'number' && val && this.valueAsNumber && (force || !this.element.is(':focus')) && (!o.fixOnlyFloat || (this.valueAsNumber % 1)) && !$(this.orig).is(':invalid')){ + if(o.toFixed && o.type == 'number' && val && !isNaN(this.valueAsNumber) && (force || !this.element.is(':focus')) && (!o.fixOnlyFloat || (this.valueAsNumber % 1))){ val = formatVal[this.type](this.valueAsNumber.toFixed(o.toFixed), this.options); } return val; } }); ['defaultValue', 'value'].forEach(function(name){ var isValue = name == 'value'; - spinBtnProto[name] = function(val, force){ + spinBtnProto[name] = function(val, force, isLive){ + var selectionEnd; if(!this._init || force || this.options[name] !== val){ if(isValue){ this._beforeValue(val); } else { this.elemHelper.prop(name, val); @@ -1596,11 +1638,18 @@ } else { $.prop(elem, name, val[i]); } }); } else { - this.element.prop(name, this.toFixed(val)); + val = this.toFixed(val); + if(isLive && this._getSelectionEnd){ + selectionEnd = this._getSelectionEnd(val); + } + this.element.prop(name, val); + if(selectionEnd){ + this.element.prop('selectionEnd', selectionEnd); + } } this._propertyChange(name); this.mirrorValidity(); } }; @@ -1624,11 +1673,11 @@ }); $.fn.wsBaseWidget = function(opts){ opts = $.extend({}, opts); return this.each(function(){ - $.webshims.objectCreate(wsWidgetProto, { + webshims.objectCreate(wsWidgetProto, { element: { value: $(this) } }, opts); }); @@ -1639,25 +1688,93 @@ $.fn.spinbtnUI = function(opts){ opts = $.extend({ monthNames: 'monthNamesShort' }, opts); return this.each(function(){ - $.webshims.objectCreate(spinBtnProto, { + webshims.objectCreate(spinBtnProto, { element: { value: $(this) } }, opts); }); }; $.fn.spinbtnUI.wsProto = spinBtnProto; + + webshims._format = formatVal; })(); - + + + $.fn.wsTouchClick = (function(){ + var supportsTouchaction = ('touchAction' in document.documentElement.style); + var addTouch = !supportsTouchaction && ('ontouchstart' in window) && document.addEventListener; + return function(target, handler){ + var touchData, touchEnd, touchStart; + + if(addTouch){ + + touchEnd = function(e){ + var ret, touch; + e = e.originalEvent || {}; + $(this).off('touchend', touchEnd); + var changedTouches = e.changedTouches || e.touches; + if(!touchData || !changedTouches || changedTouches.length != 1){ + return; + } + + touch = changedTouches[0]; + if(Math.abs(touchData.x - touch.pageX) > 40 || Math.abs(touchData.y - touch.pageY) > 40 || Date.now() - touchData.now > 600){ + return; + } + e.preventDefault(); + ret = handler.apply(this, arguments); + + return ret; + }; + + touchStart = function(e){ + var touch, elemTarget; + + + if((!e || e.touches.length != 1)){ + return; + } + touch = e.touches[0]; + elemTarget = target ? $(touch.target).closest(target) : $(this); + if(!elemTarget.length){ + return; + } + touchData = { + x: touch.pageX, + y: touch.pageY, + now: Date.now() + }; + elemTarget.on('touchend', touchEnd); + }; + + this.each(function(){ + this.addEventListener('touchstart', touchStart, true); + }); + } else if(supportsTouchaction){ + this.css('touch-action', 'manipulation'); + } + + if($.isFunction(target)){ + handler = target; + target = false; + this.on('click', handler); + } else { + this.on('click', target, handler); + } + return this; + }; + })(); + (function(){ var picker = {}; - + var assumeVirtualKeyBoard = Modernizr.touchevents || Modernizr.touch || (/android|iphone|ipad|ipod|blackberry|iemobile/i.test(navigator.userAgent.toLowerCase())); webshims.inlinePopover = { _create: function(){ this.element = $('<div class="ws-inline-picker"><div class="ws-po-box" /></div>').data('wspopover', this); this.contentElement = $('.ws-po-box', this.element); this.element.insertAfter(this.options.prepareFor); @@ -1744,11 +1861,15 @@ data.setChange(val); }, cancel: function(val, popover, data){ if(!data.options.inlinePicker){ popover.stopOpen = true; - data.element.getShadowFocusElement().trigger('focus'); + if(assumeVirtualKeyBoard){ + $('button', data.buttonWrapper).trigger('focus'); + } else { + data.element.getShadowFocusElement().trigger('focus'); + } setTimeout(function(){ popover.stopOpen = false; }, 9); popover.hide(); } @@ -1835,10 +1956,11 @@ }); }; picker._common = function(data){ + if(data.options.nopicker){return;} var options = data.options; var popover = webshims.objectCreate(options.inlinePicker ? webshims.inlinePopover : webshims.wsPopover, {}, $.extend(options.popover || {}, {prepareFor: options.inlinePicker ? data.buttonWrapper : data.element})); var opener = $('<button type="button" class="ws-popover-opener"><span /></button>').appendTo(data.buttonWrapper); if(options.widgetPosition){ @@ -1904,11 +2026,11 @@ if(options.disabled){ opener.prop({disabled: true}); } - opener.on({click: open}); + opener.wsTouchClick(open); if(options.inlinePicker){ popover.openedByFocus = true; } else { opener @@ -2097,10 +2219,10 @@ }; var sizeInput = function(data){ var init, parent, lastWidth, left, right, isRtl, hasButtons; var oriStyleO = data.orig.style; var styleO = data.element[0].style; - if($.support.boxSizing == null && !$.isReady){ + if($.support.boxSizing == null){ $(function(){ parent = data.orig.parentNode; }); } else { parent = data.orig.parentNode;