vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.11.3.1 vs vendor/assets/javascripts/webshims/shims/combos/17.js in webshims-rails-1.11.6
- old
+ new
@@ -642,21 +642,24 @@
}
left = 100 * ((val - o.min) / (o.max - o.min));
if(this._init && val == o.value && oVal == val){return;}
this.options.value = val;
- this.thumb.stop();
- this.range.stop();
+ if($.fn.stop){
+ this.thumb.stop();
+ this.range.stop();
+ }
+
rangeStyle[this.dirs.width] = left+'%';
if(this.vertical){
left = Math.abs(left - 100);
}
thumbStyle[this.dirs.left] = left+'%';
- if(!animate){
+ if(!animate || !$.fn.animate){
this.thumb.css(thumbStyle);
this.range.css(rangeStyle);
} else {
if(typeof animate != 'object'){
animate = {};
@@ -941,13 +944,13 @@
$(document).off('mousemove touchmove', setValueFromPos).off('mouseup touchend', remove);
$(window).off('blur', removeWin);
if(!o.readonly && !o.disabled){
normalizeTouch(e);
- that.element.focus();
+ that.element.trigger('focus');
that.addRemoveClass('ws-active', true);
- leftOffset = that.element.focus().offset();
+ 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;
@@ -1284,10 +1287,36 @@
if(!val){return "";}
val = val+'';
return val.length == 1 ? '0'+val : val;
};
+ var loadPicker = function(type, name){
+ type = (type == 'color' ? 'color' : 'forms')+'-picker';
+ if(!loadPicker[name+'Loaded'+type]){
+ loadPicker[name+'Loaded'+type] = true;
+ webshims.ready(name, function(){
+ webshims.loader.loadList([type]);
+
+ });
+ }
+ return type;
+ };
+
+
+ options.addZero = addZero;
+ webshims.loader.addModule('forms-picker', {
+ noAutoCallback: true,
+ options: options
+ });
+ webshims.loader.addModule('color-picker', {
+ noAutoCallback: true,
+ css: 'jpicker/jpicker.css',
+ options: options,
+ d: ['forms-picker']
+ });
+
+ options.steps = steps;
(function(){
formcfg.de = $.extend(true, {
numberFormat: {
@@ -1396,11 +1425,11 @@
};
langCfg.date.monthkeys = {};
langCfg.date.monthDigits = monthDigits;
langCfg.numberSigns += '-';
if(langCfg.meridian){
- langCfg.timeSigns += langCfg.meridian[0] + langCfg.meridian[1];
+ langCfg.timeSigns += langCfg.meridian[0] + langCfg.meridian[1] + langCfg.meridian[0].toLowerCase() + langCfg.meridian[1].toLowerCase();
}
$.each(langCfg.date.monthNames, create);
$.each(langCfg.date.monthNamesShort, create);
}
if(!langCfg.colorSigns){
@@ -1422,47 +1451,28 @@
var triggerLocaleChange = function(){
processLangCFG(curCfg);
$(document).triggerHandler('wslocalechange');
};
- triggerLocaleChange();
- webshims.activeLang({
- register: 'form-core',
- callback: function(){
- $.each(arguments, function(i, val){
- if(formcfg[val]){
- if(formcfg[val] != curCfg){
- curCfg = formcfg[val];
- triggerLocaleChange();
- }
- return false;
- }
- });
- }
+
+
+ curCfg = webshims.activeLang(formcfg);
+
+ triggerLocaleChange();
+
+ $(formcfg).on('change', function(){
+ curCfg = formcfg.__active;
+ triggerLocaleChange();
});
- webshims.activeLang({
- langObj: formcfg,
- module: 'form-core',
- callback: function(val){
- if(curCfg != val){
- curCfg = val;
- triggerLocaleChange();
- }
- }
- });
+
})();
(function(){
-
- var mousePress = function(e){
- $(this)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
- };
-
var retDefault = function(val, def){
if(!(typeof val == 'number' || (val && val == val * 1))){
return def;
}
return val * 1;
@@ -1570,10 +1580,11 @@
return val;
},
time: function(val){
var fVal;
if(val && curCfg.meridian){
+ val = val.toUpperCase();
if(val.substr(0,2) === "12"){
val = "00" + val.substr(2);
}
if(val.indexOf(curCfg.meridian[1]) != -1){
val = val.split(':');
@@ -1793,304 +1804,36 @@
this.lastErrorMessage = message;
}
}
},
addBindings: function(){
- var isFocused;
-
var that = this;
var o = this.options;
-
- var eventTimer = (function(){
- var events = {};
- return {
- init: function(name, curVal, fn){
- if(!events[name]){
- events[name] = {fn: fn};
- $(that.orig).on(name, function(){
- events[name].val = $.prop(that.orig, 'value');
- });
- }
- events[name].val = curVal;
- },
- call: function(name, val){
- if(events[name] && events[name].val != val){
- clearTimeout(events[name].timer);
- events[name].val = val;
- events[name].timer = setTimeout(function(){
- events[name].fn(val, that);
- }, 9);
- }
- }
- };
- })();
- var initChangeEvents = function(){
- eventTimer.init('input', $.prop(that.orig, 'value'), that.options.input);
- eventTimer.init('change', $.prop(that.orig, 'value'), that.options.change);
+ var run = function(){
+ that._addBindings();
};
+ if(this._addBindings){
+ run();
+ } else {
+ webshims.ready('forms-picker', run);
+ loadPicker(this.type, 'WINDOWLOAD');
+ }
- var step = {};
-
- var preventBlur = function(e){
- if(preventBlur.prevent){
- e.preventDefault();
- (isFocused || that.element.getShadowFocusElement()).focus();
- stopPropagation(e);
- return true;
- }
- };
- var callSplitChange = (function(){
- var timer;
-
- var call = function(e){
- var val;
- clearTimeout(timer);
- val = that.parseValue();
- if(that.type == 'color'){
- that.inputElements.val(val);
+ this.inputElements
+ .add(this.buttonWrapper)
+ .add(this.element)
+ .one('mousedown focusin', function(e){
+ loadPicker(that.type, 'DOM');
+ })
+ .on({
+ 'change input focus focusin blur focusout': function(e){
+ $(e.target).trigger('ws__'+e.type);
}
- $.prop(that.orig, 'value', val);
- eventTimer.call('input', val);
- if(!e || e.type != 'wsupdatevalue'){
- eventTimer.call('change', val);
- }
- };
+ })
- var onFocus = function(){
- clearTimeout(timer);
- };
- var onBlur = function(e){
- clearTimeout(timer);
- timer = setTimeout(call, 0);
-
- if(e.type == 'change'){
- stopPropagation(e);
- if(!o.splitInput){
- call();
- }
- }
- };
-
- that.element.on('wsupdatevalue', call);
-
- that.inputElements
- .add(that.buttonWrapper)
- .add(that.element)
- .on(
- {
- 'focus focusin': onFocus,
- 'blur focusout change': onBlur
- }
- )
- ;
- setTimeout(function(){
- if(that.popover){
- that.popover.element.on('wspopoverhide', onBlur);
- $('> *', that.popover.element)
- .on({
- 'focusin': onFocus,
- 'focusout': onBlur
- })
- ;
- }
- }, 0);
- })();
+ ;
- var spinEvents = {};
- var spinElement = o.splitInput ? this.inputElements.filter('.ws-spin') : this.inputElements.eq(0);
- var elementEvts = {
- blur: function(e){
- if(!preventBlur(e) && !o.disabled && !o.readonly){
- if(!preventBlur.prevent){
- isFocused = false;
- }
- }
- stopPropagation(e);
- },
- focus: function(e){
- if(!isFocused){
- initChangeEvents();
- isFocused = this;
- }
- },
- keypress: function(e){
- if(e.isDefaultPrevented()){return;}
- var chr;
- var stepped = true;
- var code = e.keyCode;
- if(!e.ctrlKey && !e.metaKey && curCfg[that.type+'Signs']){
- chr = String.fromCharCode(e.charCode == null ? code : e.charCode);
- stepped = !(chr < " " || (curCfg[that.type+'Signs']+'0123456789').indexOf(chr) > -1);
- } else {
- stepped = false;
- }
- 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){
- isStopped = 'semi';
- timer = setTimeout(releaseTab, 250);
- } else {
- isStopped = false;
- }
- };
- var stopTab = function(){
- isStopped = true;
- clearTimeout(timer);
- timer = setTimeout(releaseTab, 300);
- };
- var select = function(){
- var elem = this;
- setTimeout(function(){
- elem.focus();
- elem.select();
- }, 4);
-
- stopTab();
- };
-
- return function(e){
- if(o.splitInput && o.jumpInputs){
- if(e.type == 'input'){
- if($.prop(this, 'value').length === $.prop(this, 'maxLength')){
- try {
- $(this)
- .next()
- .next('input, select')
- .each(select)
- ;
- } catch(er){}
- }
- } else if(!e.shiftKey && !e.crtlKey && e.keyCode == 9 && (isStopped === true || (isStopped && !$.prop(this, 'value')))){
- e.preventDefault();
- }
- }
- };
- })()
- };
- var mouseDownInit = function(){
- if(!o.disabled && !isFocused){
- that.element.getShadowFocusElement().focus();
- }
- preventBlur.set();
-
- return false;
- };
-
- preventBlur.set = (function(){
- var timer;
- var reset = function(){
- preventBlur.prevent = false;
- };
- return function(){
- clearTimeout(timer);
- preventBlur.prevent = true;
- setTimeout(reset, 9);
- };
- })();
-
-
- this.buttonWrapper.on('mousedown', mouseDownInit);
-
- this.setInput = function(value){
- that.value(value);
- eventTimer.call('input', value);
- };
- this.setChange = function(value){
- that.setInput(value);
- eventTimer.call('change', value);
- };
-
-
-
- this.inputElements.on(elementEvts);
-
- if(steps[this.type]){
- ['stepUp', 'stepDown'].forEach(function(name){
- step[name] = function(factor){
- if(!o.disabled && !o.readonly){
- if(!isFocused){
- mouseDownInit();
- }
- var ret = false;
- 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);
- }
- return ret;
- }
- };
- });
- if(!o.noSpinbtn){
- spinEvents[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
- if(delta && isFocused && !o.disabled){
- step[delta > 0 ? 'stepUp' : 'stepDown']();
- e.preventDefault();
- }
- };
- spinEvents.keydown = function(e){
- if(o.list || e.isDefaultPrevented() || (e.altKey && e.keyCode == 40) || $.attr(this, 'list')){return;}
- var stepped = true;
- var code = e.keyCode;
- if (code == 38) {
- step.stepUp();
- } else if (code == 40) {
- step.stepDown();
- } else {
- stepped = false;
- }
- if(stepped){
- e.preventDefault();
- }
- };
-
- spinElement.attr({'autocomplete': 'off', role: 'spinbutton'}).on(spinEvents);
- }
- $(this.buttonWrapper)
- .on('mousepressstart mousepressend', '.step-up, .step-down', mousePress)
- .on('mousedown mousepress', '.step-up', function(e){
- step.stepUp();
- })
- .on('mousedown mousepress', '.step-down', function(e){
- step.stepDown();
- })
- ;
- }
if(this.type != 'color'){
(function(){
var localeChange ;
if(!o.splitInput){
localeChange = function(){
@@ -2110,12 +1853,10 @@
that.reorderInputs();
}
$(that.orig).onWSOff('wslocalechange', localeChange);
})();
}
-
- initChangeEvents();
},
required: function(val, boolVal){
this.inputElements.attr({'aria-required': ''+boolVal});
this.mirrorValidity();
},
@@ -2145,38 +1886,10 @@
});
} else {
this.element.prop('placeholder', placeholder);
}
},
- initDataList: function(){
- var listTimer;
- var that = this;
- var updateList = function(){
- $(that.orig)
- .jProp('list')
- .off('updateDatalist', updateList)
- .on('updateDatalist', updateList)
- ;
- clearTimeout(listTimer);
- listTimer = setTimeout(function(){
- if(that.list){
- that.list();
- }
- }, 9);
-
- };
-
- $(this.orig).onTrigger('listdatalistchange', updateList);
- },
- getOptions: function(){
- var options = {};
- var datalist = $(this.orig).jProp('list');
- datalist.find('option').each(function(){
- options[$.prop(this, 'value')] = $.prop(this, 'label');
- });
- return [options, datalist.data('label')];
- },
list: function(val){
if(this.type == 'number'){
this.element.attr('list', $.attr(this.orig, 'list'));
}
this.options.list = val;
@@ -2302,35 +2015,10 @@
data.shadowData.shadowFocusElement = element.find('input, select')[0] || element[0];
}
}, 9);
}
},
- value: function(val, force){
-
- 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();
- } else {
- this.elemHelper.prop('value', val);
- this.options.defValue = "";
- }
-
- val = formatVal[this.type](val, this.options);
- if(this.options.splitInput){
- $.each(this.splits, function(i, elem){
- $.prop(elem, 'value', val[i]);
- });
- } else {
- this.element.prop('value', val);
- }
- this._propertyChange('value');
- this.mirrorValidity();
- }
- },
step: function(val){
var defStep = steps[this.type];
this.options.step = val;
this.elemHelper.prop('step', retDefault(val, defStep.step));
this.mirrorValidity();
@@ -2398,10 +2086,12 @@
}
}, opts);
});
};
+ $.fn.wsBaseWidget.wsProto = wsWidgetProto;
+
$.fn.spinbtnUI = function(opts){
opts = $.extend({
monthNames: 'monthNames',
size: 1,
startView: 0
@@ -2412,36 +2102,18 @@
value: $(this)
}
}, opts);
});
};
+
+ $.fn.spinbtnUI.wsProto = spinBtnProto;
+
})();
(function(){
var picker = {};
- var loadPicker = function(type, name){
- type = (type == 'color' ? 'color' : 'forms')+'-picker';
- if(!loadPicker[name+'Loaded'+type]){
- loadPicker[name+'Loaded'+type] = true;
- webshims.ready(name, function(){
- webshims.loader.loadList([type]);
- });
- }
- return type;
- };
- options.addZero = addZero;
- webshims.loader.addModule('forms-picker', {
- noAutoCallback: true,
- options: options
- });
- webshims.loader.addModule('color-picker', {
- noAutoCallback: true,
- css: 'jpicker/jpicker.css',
- options: options
- });
-
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);
@@ -2481,11 +2153,11 @@
data.setChange(val);
},
cancel: function(val, popover, data){
if(!data.options.inlinePicker){
popover.stopOpen = true;
- data.element.getShadowFocusElement().focus();
+ data.element.getShadowFocusElement().trigger('focus');
setTimeout(function(){
popover.stopOpen = false;
}, 9);
popover.hide();
}
@@ -2570,14 +2242,21 @@
};
picker._common = function(data){
var options = data.options;
- var popover = webshims.objectCreate(options.inlinePicker ? webshims.inlinePopover : webshims.wsPopover, {}, {prepareFor: options.inlinePicker ? data.buttonWrapper : data.element, position: options.widgetPosition});
+ 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){
+ webshims.error('options.widgetPosition was removed use options.popover.position instead');
+ }
+ if(options.openOnFocus && popover.options && (popover.options.appendTo == 'auto' || popover.options.appendTo == 'element')){
+ webshims.error('openOnFocus and popover.appendTo "auto/element" can prduce a11y problems try to change appendTo to body or similiar or use openOnMouseFocus instead');
+ }
+
var showPickerContent = function(){
(picker[data.type].showPickerContent || picker.showPickerContent)(data, popover);
};
var show = function(){
var type = loadPicker(data.type, 'DOM');
@@ -2724,11 +2403,10 @@
}
});
if(options.inlinePicker){
show();
}
- loadPicker(data.type, 'WINDOWLOAD');
};
picker.month = picker._common;
picker.date = picker._common;
picker.time = picker._common;
@@ -2740,11 +2418,11 @@
var colorIndicator = data.opener
.prepend('<span class="ws-color-indicator-bg"><span class="ws-color-indicator" /></span>')
.find('.ws-color-indicator')
;
var showColor = function(){
- colorIndicator.css({backgroundColor: $.prop(this, 'value') || '#000'})
+ colorIndicator.css({backgroundColor: $.prop(this, 'value') || '#000000'});
};
var showOpacity = (function(){
var timer;
var show = function(){
try {
@@ -2897,15 +2575,12 @@
var i, opts, data, optsName, labels;
if(inputTypes[type] && webshims.implement(this, 'inputwidgets')){
data = {};
optsName = type;
- //todo: do we need deep extend?
-
labels = $(this).jProp('labels');
-
- opts = $.extend({}, options.widgets, options[type], $($.prop(this, 'form')).data(type) || {}, $(this).data(type) || {}, {
+ opts = $.extend(webshims.getOptions(this, type, [options.widgets, options[type], $($.prop(this, 'form')).data(type)]), {
orig: this,
type: type,
labels: labels,
options: {},
input: function(val){
@@ -2923,11 +2598,10 @@
}
},
containerElements: []
});
-
for(i = 0; i < copyProps.length; i++){
opts[copyProps[i]] = $.prop(this, copyProps[i]);
}
for(i = 0; i < copyAttrs.length; i++){
@@ -3077,12 +2751,12 @@
if(opts.splitInput && !splitInputs[name]){
webshims.warn('splitInput not supported for '+ name);
opts.splitInput = false;
}
var markup = opts.splitInput ?
- '<span class="ws-'+name+' ws-input" role="group"></span>' :
- '<input class="ws-'+name+'" type="text" />';
+ '<span class="ws-'+name+' ws-input ws-inputreplace" role="group"></span>' :
+ '<input class="ws-'+name+' ws-inputreplace" type="text" />';
var data = $(markup).insertAfter(opts.orig);
if(steps[name]){
data = data.spinbtnUI(opts).data('wsWidget'+name);
} else {
data = data.wsBaseWidget(opts).data('wsWidget'+name);
@@ -3095,15 +2769,22 @@
}
});
}
});
+ var init = function(){
+ webshims.addReady(function(context, contextElem){
+ $('input', context)
+ .add(contextElem.filter('input'))
+ .each(implementType)
+ ;
+ });
+ };
+ if(formcfg._isLoading){
+ $(formcfg).one('change', init);
+ } else {
+ init();
+ }
- webshims.addReady(function(context, contextElem){
- $('input', context)
- .add(contextElem.filter('input'))
- .each(implementType)
- ;
- });
})();
});