vendor/assets/javascripts/webshims/shims/combos/11.js in webshims-rails-1.10.6 vs vendor/assets/javascripts/webshims/shims/combos/11.js in webshims-rails-1.10.9

- old
+ new

@@ -399,20 +399,24 @@ }; this.element.on(elementEvts); this.thumb.on({ mousedown: add }); - $(function(){ - webshims.ready('dom-support', function(){ - that.element.onWSOff('updateshadowdom', function(){ - that.updateMetrics(); + if (window.webshims) { + webshims.ready('WINDOWLOAD', function(){ + webshims.ready('dom-support', function(){ + if ($.fn.onWSOff) { + that.element.onWSOff('updateshadowdom', function(){ + that.updateMetrics(); + }); + } }); + if (!$.fn.onWSOff && webshims._polyfill) { + webshims._polyfill(['dom-support']); + } }); - if(!$.fn.onWSOff){ - webshims._polyfill(['dom-support']); - } - }); + } }, posCenter: function(elem, outerWidth){ var temp; if(this.options.calcCenter && (!this._init || this.element[0].offsetWidth)){ if(!elem){ @@ -450,10 +454,16 @@ ; this.posCenter(); } }; + var oCreate = function (o) { + function F() {} + F.prototype = o; + return new F(); + }; + $.fn.rangeUI = function(opts){ opts = $.extend({ readonly: false, disabled: false, tabindex: 0, @@ -468,18 +478,23 @@ options: {}, calcCenter: true, calcTrail: true }, opts); return this.each(function(){ - webshims.objectCreate(rangeProto, { - element: { - value: $(this) - } - }, opts); + var obj = $.extend(oCreate(rangeProto), {element: $(this)}); + obj.options = opts; + obj._create.call(obj); }); }; - webshims.isReady('range-ui', true); + if(window.webshims && webshims.isReady){ + webshims.ready('es5', function(){ + webshims.isReady('range-ui', true); + }); + if(webshims._polyfill){ + webshims._polyfill(['es5']); + } + } })(jQuery); webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){ "use strict"; var curCfg; var formcfg = webshims.formcfg; @@ -522,14 +537,18 @@ } }); } }, month: { - _create: function(){ + _create: function(opts){ + var obj = { splits: [$('<input type="text" class="yy" inputmode="numeric" size="4" />')[0], $('<input type="text" class="mm ws-spin" />')[0]] }; + if(opts.onlyMonthDigits){ + $(obj.splits[1]).attr({inputmode: 'numeric', size: 2, maxlength: 2}); + } obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1]]; return obj; }, sort: function(element){ var seperator = $('.ws-input-seperator', element).html(curCfg.dFormat); @@ -545,24 +564,25 @@ seperator[action](mm); } } }; + var nowDate = new Date().getTime() - (new Date().getTimezoneOffset() * 60 * 1000 ); var steps = { number: { step: 1 }, time: { step: 60 }, month: { step: 1, - start: new Date() + start: new Date(nowDate) }, date: { step: 1, - start: new Date() + start: new Date(nowDate) } }; var labelWidth = (function(){ var getId = function(){ return webshims.getID(this); @@ -654,14 +674,24 @@ "firstDay": 0, "isRTL": false, "showMonthAfterYear": false, "yearSuffix": "" } - }, formcfg['en'] || {}); + }, formcfg.en || {}); + if(!formcfg['en-US']){ - formcfg['en-US'] = formcfg['en']; + formcfg['en-US'] = $.extend(true, {}, formcfg['en']); } + if(!formcfg['en-GB']){ + formcfg['en-GB'] = $.extend(true, {}, formcfg.en, { + date: {firstDay: 1}, + patterns: {d: "dd/mm/yy"} + }); + } + if(!formcfg['en-AU']){ + formcfg['en-AU'] = $.extend(true, {}, formcfg['en-GB']); + } if(!formcfg['']){ formcfg[''] = formcfg['en-US']; } curCfg = formcfg['']; @@ -684,26 +714,41 @@ } if(!langCfg.colorSigns){ langCfg.colorSigns = '#abcdefABCDEF'; } }; + var triggerLocaleChange = function(){ + processLangCFG(curCfg); + $(document).triggerHandler('wslocalechange'); + }; - processLangCFG(curCfg); + triggerLocaleChange(); - $.webshims.activeLang({ - register: 'form-core', + webshims.activeLang({ + register: 'form-core', callback: function(){ $.each(arguments, function(i, val){ if(formcfg[val]){ - curCfg = formcfg[val]; - processLangCFG(curCfg); - $(document).triggerHandler('wslocalechange'); + if(formcfg[val] != curCfg){ + curCfg = formcfg[val]; + triggerLocaleChange(); + } return false; } }); } }); + webshims.activeLang({ + langObj: formcfg, + module: 'form-core', + callback: function(val){ + if(curCfg != val){ + curCfg = val; + triggerLocaleChange(); + } + } + }); })(); (function(){ @@ -738,10 +783,12 @@ if(options && options.splitInput){ val = [p[0] || '', p[1] || '']; } else if(p[1]){ val = curCfg.date.showMonthAfterYear ? p.join(' ') : p[1]+' '+p[0]; } + } else if(options && options.splitInput){ + val = [p[0] || '', p[1] || '']; } return val; }, date: function(val, opts){ var p = (val+'').split('-'); @@ -776,41 +823,41 @@ return (val+'').replace(curCfg.numberFormat[','], '').replace(curCfg.numberFormat['.'], '.'); }, time: function(val){ return val; }, - month: function(val, opts){ + month: function(val, opts, noCorrect){ var p = (!opts.splitInput) ? val.trim().split(/[\.\s-\/\\]+/) : val; if(p.length == 2 && p[0] && p[1]){ - p[0] = curCfg.date.monthkeys[p[0]] || p[0]; - p[1] = curCfg.date.monthkeys[p[1]] || p[1]; - if(p[1].length == 2){ + p[0] = !noCorrect && curCfg.date.monthkeys[p[0]] || p[0]; + p[1] = !noCorrect && curCfg.date.monthkeys[p[1]] || p[1]; + if(p[1].length == 2 && p[0].length > 3){ val = p[0]+'-'+p[1]; - } else if(p[0].length == 2){ + } else if(p[0].length == 2 && p[1].length > 3){ val = p[1]+'-'+p[0]; } else { val = ''; } } else if(opts.splitInput) { val = ''; } return val; }, - date: function(val, opts){ + date: function(val, opts, noCorrect){ createFormat('d'); var i; var obj; 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]) ? + 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('-') : '' ; }, color: function(val, opts){ @@ -864,11 +911,11 @@ var createHelper = (function(){ var types = {}; return function(type){ var input; if(!types[type]){ - input = $('<input type="'+type+'" />'); + input = $('<input type="'+type+'" step="any" />'); types[type] = { asNumber: function(val){ var type = (typeof val == 'object') ? 'valueAsDate' : 'value'; return input.prop(type, val).prop('valueAsNumber'); }, @@ -1093,10 +1140,26 @@ } if(stepped){ e.preventDefault(); } }, + input: (this.type == 'color' && this.isValid) ? + $.noop : + (function(){ + var timer; + var check = function(){ + var val = that.parseValue(true); + if(val && that.isValid(val)){ + that.setInput(val); + } + + }; + return function(){ + clearTimeout(timer); + timer = setTimeout(check, 200); + }; + })(), 'input keydown keypress': (function(){ var timer; var isStopped = false; var releaseTab = function(){ if(isStopped === true){ @@ -1110,12 +1173,16 @@ isStopped = true; clearTimeout(timer); timer = setTimeout(releaseTab, 300); }; var select = function(){ - this.focus(); - this.select(); + var elem = this; + setTimeout(function(){ + elem.focus(); + elem.select(); + }, 4); + stopTab(); }; return function(e){ if(o.splitInput && o.jumpInputs){ @@ -1232,12 +1299,13 @@ if(this.type != 'color'){ (function(){ var localeChange ; if(!o.splitInput){ localeChange = function(){ + if(o.value){ - that.value(o.value); + that.value(o.value, true); } if(placeholderFormat[that.type] && o.placeholder){ that.placeholder(o.placeholder); } @@ -1252,12 +1320,12 @@ })(); } initChangeEvents(); }, - value: function(val){ - if(!this._init || val !== this.options.value){ + 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(); } @@ -1265,18 +1333,18 @@ }, required: function(val, boolVal){ this.inputElements.attr({'aria-required': ''+boolVal}); this.mirrorValidity(); }, - parseValue: function(){ + parseValue: function(noCorrect){ var value = this.inputElements.map(function(){ return $.prop(this, 'value'); }).get(); if(!this.options.splitInput){ value = value[0]; } - return parseVal[this.type](value, this.options); + 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'], @@ -1370,11 +1438,13 @@ var helper = createHelper(o.type); this.elemHelper = $('<input type="'+ o.type+'" />'); this.asNumber = helper.asNumber; this.asValue = helper.asValue; + this.isValid = helper.isValid; + wsWidgetProto._create.apply(this, arguments); this._init = false; this.buttonWrapper.html('<span unselectable="on" class="step-controls"><span class="step-up"></span><span class="step-down"></span></span>'); @@ -1395,11 +1465,11 @@ this._init = true; }, createOpts: ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'value', 'required'], _addSplitInputs: function(){ if(!this.inputElements){ - var create = splitInputs[this.type]._create(); + var create = splitInputs[this.type]._create(this.options); this.splits = create.splits; this.inputElements = $(create.elements).prependTo(this.element).filter('input'); } }, @@ -1432,13 +1502,13 @@ data.shadowData.shadowFocusElement = element.find('input')[0] || element[0]; } }, 9); } }, - value: function(val){ + value: function(val, force){ - if(!this._init || this.options.value !== val){ + if(!this._init || force || this.options.value !== 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(); @@ -1946,10 +2016,12 @@ optsName = copyAttrs[i].replace(/^data\-/, ''); if(optsName == 'placeholder' || !opts[optsName]){ opts[optsName] = $.attr(this, copyAttrs[i]) || opts[optsName]; } } - + if(opts.onlyMonthDigits){ + opts.formatMonthNames = 'monthDigits'; + } data.shim = inputTypes[type]._create(opts); webshims.addShadowDom(this, data.shim.element, { data: data.shim || {} });