vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.12.3 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.12.5

- old
+ new

@@ -602,12 +602,12 @@ } }); } });;(function($){ - - var id = 0; + "use strict"; + var isNumber = function(string){ return (typeof string == 'number' || (string && string == string * 1)); }; var retDefault = function(val, def){ if(!(typeof val == 'number' || (val && val == val * 1))){ @@ -618,11 +618,11 @@ var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex']; var rangeProto = { _create: function(){ 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><span data-value="" data-valuetext="" /></span></span></span>'); + 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.trail = $('.ws-range-track', this.element); this.range = $('.ws-range-progress', this.element); this.thumb = $('.ws-range-thumb', this.trail); this.updateMetrics(); @@ -803,14 +803,16 @@ title: function(val){ this.element.prop('title', val); }, min: function(val){ this.options.min = retDefault(val, 0); + this.element.attr('aria-valuemin', this.options.min); this.value(this.options.value, true); }, max: function(val){ this.options.max = retDefault(val, 100); + this.element.attr('aria-valuemax', this.options.max); this.value(this.options.value, true); }, step: function(val){ var o = this.options; var step = val == 'any' ? 'any' : retDefault(val, 1); @@ -979,12 +981,10 @@ }; 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(); @@ -995,11 +995,10 @@ that.element.trigger('focus'); that.addRemoveClass('ws-active', true); leftOffset = that.element.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; if(e.target.className == 'ws-range-ticks'){ updateValue(e.target.getAttribute('data-value'), o.animate); @@ -1112,42 +1111,47 @@ if (window.webshims) { webshims.ready('WINDOWLOAD', function(){ webshims.ready('dom-support', function(){ if ($.fn.onWSOff) { - that.element.onWSOff('updateshadowdom', function(){ + var timer; + var update = function(){ that.updateMetrics(); + }; + that.element.onWSOff('updateshadowdom', function(){ + clearTimeout(timer); + timer = setTimeout(update, 100); }); } }); if (!$.fn.onWSOff && webshims._polyfill) { webshims._polyfill(['dom-support']); } }); } }, posCenter: function(elem, outerWidth){ - var temp; + var temp, eS; + if(this.options.calcCenter && (!this._init || this.element[0].offsetWidth)){ if(!elem){ elem = this.thumb; } + eS = elem[0].style; if(!outerWidth){ outerWidth = elem[this.dirs.outerWidth](); } outerWidth = outerWidth / -2; - elem.css(this.dirs.marginLeft, outerWidth); - + eS[this.dirs.marginLeft] = outerWidth +'px'; + if(this.options.calcTrail && elem[0] == this.thumb[0]){ temp = this.element[this.dirs.innerHeight](); - elem.css(this.dirs.marginTop, (elem[this.dirs.outerHeight]() - temp) / -2); - this.range.css(this.dirs.marginTop, (this.range[this.dirs.outerHeight]() - temp) / -2 ); + 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'; outerWidth *= -1; - this.trail - .css(this.dirs.left, outerWidth) - .css(this.dirs.right, outerWidth) - ; + 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(); @@ -1187,11 +1191,11 @@ step: 1, max: 100, value: 50, input: $.noop, change: $.noop, - _change: $.noop, + _change: $.noop, showLabels: true, options: {}, calcCenter: true, calcTrail: true }, opts); @@ -1217,11 +1221,11 @@ var getMonthOptions = function(opts){ var selectName = 'monthSelect'+opts.monthNames; if(!curCfg[selectName]){ var labels = curCfg.date[opts.monthNames] || monthDigits; curCfg[selectName] = ('<option value=""></option>')+$.map(monthDigits, function(val, i){ - return '<option value="'+val+'"]>'+labels[i]+'</option>'; + return '<option value="'+val+'">'+labels[i]+'</option>'; }).join(''); } return curCfg[selectName]; }; var daySelect = '<select class="dd"><option value=""></option>'+ (function(){ @@ -1621,12 +1625,16 @@ //todo empty val for month/split month: function(val, options){ var names; var p = val.split('-'); if(p[0] && p[1]){ - names = curCfg.date[options.monthNames] || curCfg.date.monthNames; - p[1] = names[(p[1] * 1) - 1]; + + if(!options || !options.monthSelect){ + names = curCfg.date[options.monthNames] || curCfg.date.monthNames; + p[1] = names[(p[1] * 1) - 1]; + } + if(options && options.splitInput){ val = [p[0] || '', p[1] || '']; } else if(p[1]){ val = curCfg.date.showMonthAfterYear ? p.join(' ') : p[1]+' '+p[0]; } @@ -1815,10 +1823,14 @@ }, asValue: function(val){ var type = (typeof val == 'object') ? 'valueAsDate' : 'valueAsNumber'; return input.prop(type, val).prop('value'); }, + asDate: function(val){ + var type = (typeof val == 'number') ? 'valueAsNumber' : 'value'; + return input.prop(type, val).prop('valueAsDate'); + }, isValid: function(val, attrs){ if(attrs && (attrs.nodeName || attrs.jquery)){ attrs = { min: $(attrs).prop('min') || '', max: $(attrs).prop('max') || '', @@ -2088,10 +2100,11 @@ this.elemHelper = $('<input type="'+ o.type+'" />'); this.asNumber = helper.asNumber; this.asValue = helper.asValue; this.isValid = helper.isValid; + this.asDate = helper.asDate; wsWidgetProto._create.apply(this, arguments); this._init = false; @@ -2686,57 +2699,79 @@ var isVisible = function(){ return $.css(this, 'display') != 'none'; }; var sizeInput = function(data){ - var init; + var init, parent, lastWidth, left, right, isRtl, hasButtons; + var oriStyleO = data.orig.style; + var styleO = data.element[0].style; + if($.support.boxSizing == null && !$.isReady){ + $(function(){ + parent = data.orig.parentNode; + }); + } else { + parent = data.orig.parentNode; + } var updateStyles = function(){ - $(data.orig).removeClass('ws-important-hide'); - $.style( data.orig, 'display', '' ); - var hasButtons, marginR, marginL, left, right, isRtl; + var curWidth, marginR, marginL, assignWidth; var correctWidth = 0.8; - if(!init || data.orig.offsetWidth){ - hasButtons = data.buttonWrapper && data.buttonWrapper.filter(isVisible).length; - - isRtl = hasButtons && data.buttonWrapper.css('direction') == 'rtl'; - if(isRtl){ - left = 'Right'; - right = 'Left'; - } else { - left = 'Left'; - right = 'Right'; + + if(parent){ + curWidth = parent.offsetWidth; + } + + if(!init || (curWidth && curWidth != lastWidth)){ + lastWidth = curWidth; + oriStyleO.display = ''; + styleO.display = 'none'; + + if(!init){ + hasButtons = data.buttonWrapper && data.buttonWrapper.filter(isVisible).length; + isRtl = hasButtons && data.buttonWrapper.css('direction') == 'rtl'; + if(isRtl){ + left = 'Right'; + right = 'Left'; + } else { + left = 'Left'; + right = 'Right'; + } + if(hasButtons){ + data.buttonWrapper[isRtl ? 'addClass' : 'removeClass']('ws-is-rtl'); + } } - + marginR = $.css( data.orig, 'margin'+right); + + styleO['margin'+left] = $.css( data.orig, 'margin'+left); + styleO['margin'+right] = hasButtons ? '0px' : marginR; + - data.element - .css('margin'+left, $.css( data.orig, 'margin'+left)) - .css('margin'+right, hasButtons ? 0 : marginR) - ; - if(hasButtons){ - data.buttonWrapper[isRtl ? 'addClass' : 'removeClass']('ws-is-rtl'); + marginL = (parseInt(data.buttonWrapper.css('margin'+left), 10) || 0); - data.element.css('padding'+right, ''); - + styleO['padding'+right] = ''; + if(marginL < 0){ marginR = (parseInt(marginR, 10) || 0) + ((data.buttonWrapper.outerWidth() + marginL) * -1); - data.buttonWrapper.css('margin'+right, marginR); - data.element - .css('padding'+right, '') - .css('padding'+right, (parseInt( data.element.css('padding'+right), 10) || 0) + data.buttonWrapper.outerWidth()) - ; + data.buttonWrapper[0].style['margin'+right] = marginR+'px'; + + styleO['padding'+right] = ((parseInt( data.element.css('padding'+right), 10) || 0) + data.buttonWrapper.outerWidth()) +'px'; + } else { - data.buttonWrapper.css('margin'+right, marginR); + data.buttonWrapper[0].style['margin'+right] = marginR; correctWidth = data.buttonWrapper.outerWidth(true) + correctWidth; } } - - data.element.outerWidth( $(data.orig).outerWidth() - correctWidth ); + + assignWidth = $(data.orig).outerWidth() - correctWidth; + + styleO.display = ''; + data.element.outerWidth(assignWidth); + oriStyleO.display = 'none'; + init = true; } - init = true; - $(data.orig).addClass('ws-important-hide'); + }; data.element.onWSOff('updateshadowdom', updateStyles, true); }; @@ -2796,10 +2831,11 @@ data.shim.options.containerElements.push(data.shim.element[0]); cNames = $.prop(this, 'className'); if(opts.classes){ cNames += ' '+opts.classes; + $(this).addClass(opts.classes); } if(opts.splitInput || type == 'range'){ cNames = cNames.replace('form-control', ''); } @@ -2868,10 +2904,10 @@ } if(opts.calculateWidth){ sizeInput(data.shim); } else { - $(this).addClass('ws-important-hide'); + $(this).css('display', 'none'); } } };