vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.10.9 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.10.10

- old
+ new

@@ -60,11 +60,11 @@ webshims.addValidityRule('stepMismatch', function(input, val, cache, validityState){ if(val === ''){return false;} if(!('type' in cache)){ cache.type = getType(input[0]); } - + if(cache.type == 'week'){return false;} var ret = (validityState || {}).stepMismatch || false, base; if(typeModels[cache.type] && typeModels[cache.type].step){ if( !('step' in cache) ){ cache.step = webshims.getStep(input[0], cache.type); } @@ -248,10 +248,33 @@ } } }); }); + /* + * ToDO: WEEK + */ +// var getWeek = function(date){ +// var time; +// var checkDate = new Date(date.getTime()); +// +// checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7)); +// +// time = checkDate.getTime(); +// checkDate.setMonth(0); +// checkDate.setDate(1); +// return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1; +// }; +// +// var setWeek = function(year, week){ +// var date = new Date(year, 0, 1); +// +// week = (week - 1) * 86400000 * 7; +// date = new Date(date.getTime() + week); +// date.setDate(date.getDate() + 1 - (date.getDay() || 7)); +// return date; +// }; var typeProtos = { number: { mismatch: function(val){ @@ -324,10 +347,60 @@ }, dateToString: function(date){ return (date && date.getFullYear) ? addleadingZero(date.getUTCFullYear(), 4) +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false; } }, + /* + * ToDO: WEEK + */ +// week: { +// mismatch: function(val){ +// if(!val || !val.split){return true;} +// var valA = val.split('-W'); +// var ret = true; +// if(valA.length == 2 && valA[0].length > 3 && valA.length == 2){ +// ret = this.dateToString(setWeek(valA[0], valA[1])) != val; +// } +// return ret; +// }, +// step: 1, +// stepScaleFactor: 604800000, +// stepBase: -259200000, +// asDate: function(str, _noMismatch){ +// var ret = null; +// if(_noMismatch || !this.mismatch(str)){ +// ret = str.split('-W'); +// ret = setWeek(ret[0], ret[1]); +// } +// return ret; +// }, +// asNumber: function(str, _noMismatch){ +// var ret = nan; +// var date = this.asDate(str, _noMismatch); +// if(date && date.getUTCFullYear){ +// ret = date.getTime(); +// } +// return ret; +// }, +// dateToString: function(date){ +// var week, checkDate; +// var ret = false; +// if(date && date.getFullYear){ +// week = getWeek(date); +// if(week == 1){ +// checkDate = new Date(date.getTime()); +// checkDate.setDate(checkDate.getDate() + 7); +// date.setUTCFullYear(checkDate.getUTCFullYear()); +// } +// ret = addleadingZero(date.getUTCFullYear(), 4) +'-W'+addleadingZero(week, 2); +// } +// return ret; +// }, +// numberToString: function(num){ +// return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false; +// } +// }, time: { mismatch: function(val, _getParsed){ if(!val || !val.split || !(/\d$/.test(val))){return true;} val = val.split(/\u003A/); if(val.length < 2 || val.length > 3){return true;} @@ -482,12 +555,10 @@ typeProtos.time = $.extend({}, typeProtos.date, typeProtos.time); typeProtos.month = $.extend({}, typeProtos.date, typeProtos.month); // typeProtos['datetime-local'] = $.extend({}, typeProtos.date, typeProtos.time, typeProtos['datetime-local']); } - - //'datetime-local' ['number', 'month', 'range', 'date', 'time', 'color'].forEach(function(type){ if(typeBugs || !supportsType(type)){ webshims.addInputType(type, typeProtos[type]); } @@ -1011,18 +1082,18 @@ }); if(webshims._polyfill){ webshims._polyfill(['es5']); } } -})(jQuery); +})(window.webshims ? webshims.$ : jQuery); webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){ "use strict"; var curCfg; var formcfg = webshims.formcfg; var stopPropagation = function(e){ - e.stopImmediatePropagation(e); + e.stopImmediatePropagation(); }; var createFormat = function(name){ if(!curCfg.patterns[name+'Obj']){ var obj = {}; $.each(curCfg.patterns[name].split(curCfg[name+'Format']), function(i, name){ @@ -1089,10 +1160,14 @@ var nowDate = new Date().getTime() - (new Date().getTimezoneOffset() * 60 * 1000 ); var steps = { number: { step: 1 }, +// week: { +// step: 1, +// start: new Date(nowDate) +// }, time: { step: 60 }, month: { step: 1, @@ -1291,10 +1366,13 @@ return (val+'').replace(/\,/g, '').replace(/\./, curCfg.numberFormat['.']); }, time: function(val){ return val; }, + week: function(val){ + return val; + }, //todo empty val for month/split month: function(val, options){ var names; var p = val.split('-'); if(p[0] && p[1]){ @@ -1340,10 +1418,13 @@ var parseVal = { number: function(val){ return (val+'').replace(curCfg.numberFormat[','], '').replace(curCfg.numberFormat['.'], '.'); }, +// week: function(val){ +// return val; +// }, time: function(val){ return val; }, month: function(val, opts, noCorrect){ @@ -1476,10 +1557,14 @@ if( steps[this.type] && typeof steps[this.type].start == 'object'){ steps[this.type].start = this.asNumber(steps[this.type].start); } + if(!webshims.picker[this.type]){ + o.buttonOnly = false; + } + for(i = 0; i < createOpts.length; i++){ if(o[createOpts[i]] != null){ this[createOpts[i]](o[createOpts[i]], o[createOpts[i]]); } } @@ -1487,10 +1572,15 @@ this.inputElements.prop('maxLength', 7); } this.addBindings(); $(this.element).data('wsWidget'+o.type, this); + + if(o.buttonOnly){ + this.inputElements.prop({readOnly: true}); + } + this._init = true; if(o.mirrorValidity){ that = this; timedMirror = function(){ @@ -1567,11 +1657,11 @@ var preventBlur = function(e){ if(preventBlur.prevent){ e.preventDefault(); (isFocused || that.element.getShadowFocusElement()).focus(); - e.stopImmediatePropagation(); + stopPropagation(e); return true; } }; var callSplitChange = (function(){ var timer; @@ -1939,16 +2029,22 @@ ['readonly', 'disabled'].forEach(function(name){ var isDisabled = name == 'disabled'; wsWidgetProto[name] = function(val, boolVal){ - if(this.options[name] != boolVal || !this._init){ - this.options[name] = !!boolVal; - this.inputElements.prop(name, this.options[name]); - this.buttonWrapper[this.options[name] ? 'addClass' : 'removeClass']('ws-'+name); + var options = this.options; + if(options[name] != boolVal || !this._init){ + options[name] = !!boolVal; + + if(!isDisabled && options.buttonOnly){ + this.inputElements.attr({'aria-readonly': options[name]}); + } else { + this.inputElements.prop(name, options[name]); + } + this.buttonWrapper[options[name] ? 'addClass' : 'removeClass']('ws-'+name); if(isDisabled){ - $('button', this.buttonWrapper).prop('disabled', this.options[name]); + $('button', this.buttonWrapper).prop('disabled', options[name]); } } }; }); @@ -2231,14 +2327,15 @@ }); }; picker._common = function(data){ - var popover = webshims.objectCreate(webshims.wsPopover, {}, {prepareFor: data.element}); - var opener = $('<button type="button" class="ws-popover-opener"><span /></button>').appendTo(data.buttonWrapper); var options = data.options; + var popover = webshims.objectCreate(webshims.wsPopover, {}, {prepareFor: data.element, position: options.widgetPosition}); + var opener = $('<button type="button" class="ws-popover-opener"><span /></button>').appendTo(data.buttonWrapper); + var showPickerContent = function(){ (picker[data.type].showPickerContent || picker.showPickerContent)(data, popover); }; var show = function(){ var type = loadPicker(data.type, 'DOM'); @@ -2322,42 +2419,52 @@ var resetMouseFocus = function(){ mouseFocus = false; }; data.inputElements.on({ focus: function(){ - if(!popover.stopOpen && (data.options.openOnFocus || (mouseFocus && options.openOnMouseFocus))){ - popover.openedByFocus = !options.noInput; + if(!popover.stopOpen && (options.buttonOnly || options.openOnFocus || (mouseFocus && options.openOnMouseFocus))){ + popover.openedByFocus = options.buttonOnly ? false : !options.noInput; show(); } else { popover.preventBlur(); } }, mousedown: function(){ mouseFocus = true; setTimeout(resetMouseFocus, 9); + if(options.buttonOnly && popover.isVisible && popover.activeElement){ + popover.openedByFocus = false; + setTimeout(function(){ + popover.openedByFocus = false; + popover.activeElement.focus(); + }, 4); + } if(data.element.is(':focus')){ - popover.openedByFocus = !options.noInput; + popover.openedByFocus = options.buttonOnly ? false : !options.noInput; show(); } popover.preventBlur(); } }); })(); data.popover = popover; data.opener = opener; $(data.orig).on('remove', function(e){ if(!e.originalEvent){ - opener.remove(); - popover.element.remove(); + setTimeout(function(){ + opener.remove(); + popover.element.remove(); + }, 4); } }); loadPicker(data.type, 'WINDOWLOAD'); }; picker.month = picker._common; picker.date = picker._common; +// picker.week = picker._common; picker.color = function(data){ var ret = picker._common.apply(this, arguments); var alpha = $(data.orig).data('alphacontrol'); var colorIndicator = data.opener .prepend('<span class="ws-color-indicator-bg"><span class="ws-color-indicator" /></span>') @@ -2605,13 +2712,15 @@ if(data.shim.buttonWrapper && data.shim.buttonWrapper.filter(isVisible).length){ data.shim.element.addClass('has-input-buttons'); } + data.shim.element.addClass($.prop(this, 'className')); + if(opts.calculateWidth){ sizeInput(data.shim); } else { - $(this).css({display: 'none'}); + $(this).addClass('ws-important-hide'); } } };