webshim
Version:
modular capability-based polyfill loading libary, which extends jQuery with HTML5 features in legacy browsers
1,782 lines (1,610 loc) • 96.9 kB
JavaScript
webshims.register('form-native-extend', function($, webshims, window, doc, undefined, options){
"use strict";
var support = webshims.support;
if(!support.formvalidation || webshims.bugs.bustedValidity){return;}
var typeModels = webshims.inputTypes;
var runTest = false;
var validityRules = {};
var updateValidity = (function(){
var timer;
var getValidity = function(){
$(this).prop('validity');
};
var update = function(){
$('input').each(getValidity);
};
return function(){
clearTimeout(timer);
timer = setTimeout(update, 9);
};
})();
webshims.addInputType = function(type, obj){
typeModels[type] = obj;
runTest = true;
//update validity of all implemented input types
if($.isDOMReady && support.formvalidation && !webshims.bugs.bustedValidity){
updateValidity();
}
};
webshims.addValidityRule = function(type, fn){
validityRules[type] = fn;
};
$.each({typeMismatch: 'mismatch', badInput: 'bad'}, function(name, fn){
webshims.addValidityRule(name, function (input, val, cache, validityState){
if(val === ''){return false;}
var ret = validityState[name];
if(!('type' in cache)){
cache.type = (input[0].getAttribute('type') || '').toLowerCase();
}
if(typeModels[cache.type] && typeModels[cache.type][fn]){
ret = typeModels[cache.type][fn](val, input);
}
return ret || false;
});
});
var formsExtModule = webshims.modules['form-number-date-api'];
var overrideValidity = formsExtModule.loaded && !formsExtModule.test();
var validityProps = ['customError', 'badInput','typeMismatch','rangeUnderflow','rangeOverflow','stepMismatch','tooLong', 'tooShort','patternMismatch','valueMissing','valid'];
var validityChanger = ['value'];
var validityElements = [];
var testValidity = function(elem, init){
if(!elem && !runTest){return;}
var type = (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase();
if(typeModels[type]){
$.prop(elem, 'validity');
}
};
var oldSetCustomValidity = {};
['input', 'textarea', 'select'].forEach(function(name){
var desc = webshims.defineNodeNameProperty(name, 'setCustomValidity', {
prop: {
value: function(error){
error = error+'';
var elem = (name == 'input') ? $(this).getNativeElement()[0] : this;
desc.prop._supvalue.call(elem, error);
if(overrideValidity){
webshims.data(elem, 'hasCustomError', !!(error));
testValidity(elem);
}
}
}
});
oldSetCustomValidity[name] = desc.prop._supvalue;
});
if(overrideValidity){
validityChanger.push('min');
validityChanger.push('max');
validityChanger.push('step');
validityElements.push('input');
}
if(overrideValidity){
var stopValidity;
validityElements.forEach(function(nodeName){
var oldDesc = webshims.defineNodeNameProperty(nodeName, 'validity', {
prop: {
get: function(){
if(stopValidity){return;}
var elem = (nodeName == 'input') ? $(this).getNativeElement()[0] : this;
var validity = oldDesc.prop._supget.call(elem);
if(!validity){
return validity;
}
var validityState = {};
validityProps.forEach(function(prop){
validityState[prop] = validity[prop] || false;
});
if( !$.prop(elem, 'willValidate') ){
return validityState;
}
stopValidity = true;
var jElm = $(elem),
cache = {type: (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase(), nodeName: (elem.nodeName || '').toLowerCase()},
val = jElm.val(),
customError = !!(webshims.data(elem, 'hasCustomError')),
setCustomMessage
;
stopValidity = false;
validityState.customError = customError;
if( validityState.valid && validityState.customError ){
validityState.valid = false;
} else if(!validityState.valid) {
var allFalse = true;
$.each(validityState, function(name, prop){
if(prop){
allFalse = false;
return false;
}
});
if(allFalse){
validityState.valid = true;
}
}
$.each(validityRules, function(rule, fn){
validityState[rule] = fn(jElm, val, cache, validityState);
if( validityState[rule] && (validityState.valid || !setCustomMessage) && ((typeModels[cache.type])) ) {
oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, rule));
validityState.valid = false;
setCustomMessage = true;
}
});
if(validityState.valid){
oldSetCustomValidity[nodeName].call(elem, '');
webshims.data(elem, 'hasCustomError', false);
}
return validityState;
},
writeable: false
}
});
});
validityChanger.forEach(function(prop){
webshims.onNodeNamesPropertyModify(validityElements, prop, function(s){
testValidity(this);
});
});
if(doc.addEventListener){
var inputThrottle;
var testPassValidity = function(e){
if(!('form' in e.target)){return;}
clearTimeout(inputThrottle);
testValidity(e.target);
};
doc.addEventListener('change', testPassValidity, true);
doc.addEventListener('input', function(e){
clearTimeout(inputThrottle);
inputThrottle = setTimeout(function(){
testValidity(e.target);
}, 290);
}, true);
}
var validityElementsSel = validityElements.join(',');
webshims.addReady(function(context, elem){
if(runTest){
$(validityElementsSel, context).add(elem.filter(validityElementsSel)).each(function(){
testValidity(this);
});
}
});
} //end: overrideValidity
webshims.defineNodeNameProperty('input', 'type', {
prop: {
get: function(){
var elem = this;
var type = (elem.getAttribute && elem.getAttribute('type') || '').toLowerCase();
return (webshims.inputTypes[type]) ? type : elem.type;
}
}
});
});
;webshims.register('form-number-date-api', function($, webshims, window, document, undefined, options){
"use strict";
if(!webshims.addInputType){
webshims.error("you can not call forms-ext feature after calling forms feature. call both at once instead: $.webshims.polyfill('forms forms-ext')");
}
if(!webshims.getStep){
webshims.getStep = function(elem, type){
var step = $.attr(elem, 'step');
if(step === 'any'){
return step;
}
type = type || getType(elem);
if(!typeModels[type] || !typeModels[type].step){
return step;
}
step = typeProtos.number.asNumber(step);
return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * (typeModels[type].stepScaleFactor || 1);
};
}
if(!webshims.addMinMaxNumberToCache){
webshims.addMinMaxNumberToCache = function(attr, elem, cache){
if (!(attr+'AsNumber' in cache)) {
cache[attr+'AsNumber'] = typeModels[cache.type].asNumber(elem.attr(attr));
if(isNaN(cache[attr+'AsNumber']) && (attr+'Default' in typeModels[cache.type])){
cache[attr+'AsNumber'] = typeModels[cache.type][attr+'Default'];
}
}
};
}
var nan = parseInt('NaN', 10),
typeModels = webshims.inputTypes,
isNumber = function(string){
return (typeof string == 'number' || (string && string == string * 1));
},
supportsType = function(type){
return ($('<input type="'+type+'" />').prop('type') === type);
},
getType = function(elem){
return (elem.getAttribute('type') || '').toLowerCase();
},
isDateTimePart = function(string){
return (string && !(isNaN(string * 1)));
},
addMinMaxNumberToCache = webshims.addMinMaxNumberToCache,
addleadingZero = function(val, len){
val = ''+val;
len = len - val.length;
for(var i = 0; i < len; i++){
val = '0'+val;
}
return val;
},
EPS = 1e-7,
typeBugs = webshims.bugs.bustedValidity
;
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 base, attrVal;
var ret = (validityState || {}).stepMismatch || false;
if(typeModels[cache.type] && typeModels[cache.type].step){
if( !('step' in cache) ){
cache.step = webshims.getStep(input[0], cache.type);
}
if(cache.step == 'any'){return false;}
if(!('valueAsNumber' in cache)){
cache.valueAsNumber = typeModels[cache.type].asNumber( val );
}
if(isNaN(cache.valueAsNumber)){return false;}
addMinMaxNumberToCache('min', input, cache);
base = cache.minAsNumber;
if(isNaN(base) && (attrVal = input.prop('defaultValue'))){
base = typeModels[cache.type].asNumber( attrVal );
}
if(isNaN(base)){
base = typeModels[cache.type].stepBase || 0;
}
ret = Math.abs((cache.valueAsNumber - base) % cache.step);
ret = !( ret <= EPS || Math.abs(ret - cache.step) <= EPS );
}
return ret;
});
[{name: 'rangeOverflow', attr: 'max', factor: 1}, {name: 'rangeUnderflow', attr: 'min', factor: -1}].forEach(function(data, i){
webshims.addValidityRule(data.name, function(input, val, cache, validityState) {
var ret = (validityState || {})[data.name] || false;
if(val === ''){return ret;}
if (!('type' in cache)) {
cache.type = getType(input[0]);
}
if (typeModels[cache.type] && typeModels[cache.type].asNumber) {
if(!('valueAsNumber' in cache)){
cache.valueAsNumber = typeModels[cache.type].asNumber( val );
}
if(isNaN(cache.valueAsNumber)){
return false;
}
addMinMaxNumberToCache(data.attr, input, cache);
if(isNaN(cache[data.attr+'AsNumber'])){
return ret;
}
ret = ( cache[data.attr+'AsNumber'] * data.factor < cache.valueAsNumber * data.factor - EPS );
}
return ret;
});
});
webshims.reflectProperties(['input'], ['max', 'min', 'step']);
//IDLs and methods, that aren't part of constrain validation, but strongly tight to it
var valueAsNumberDescriptor = webshims.defineNodeNameProperty('input', 'valueAsNumber', {
prop: {
get: function(){
var elem = this;
var type = getType(elem);
var ret = (typeModels[type] && typeModels[type].asNumber) ?
typeModels[type].asNumber($.prop(elem, 'value')) :
(valueAsNumberDescriptor.prop._supget && valueAsNumberDescriptor.prop._supget.apply(elem, arguments));
if(ret == null){
ret = nan;
}
return ret;
},
set: function(val){
var elem = this;
var type = getType(elem);
if(typeModels[type] && typeModels[type].numberToString){
//is NaN a number?
if(isNaN(val)){
$.prop(elem, 'value', '');
return;
}
var set = typeModels[type].numberToString(val);
if(set !== false){
$.prop(elem, 'value', set);
} else {
webshims.error('INVALID_STATE_ERR: DOM Exception 11');
}
} else if(valueAsNumberDescriptor.prop._supset) {
valueAsNumberDescriptor.prop._supset.apply(elem, arguments);
}
}
}
});
var valueAsDateDescriptor = webshims.defineNodeNameProperty('input', 'valueAsDate', {
prop: {
get: function(){
var elem = this;
var type = getType(elem);
return (typeModels[type] && typeModels[type].asDate && !typeModels[type].noAsDate) ?
typeModels[type].asDate($.prop(elem, 'value')) :
valueAsDateDescriptor.prop._supget && valueAsDateDescriptor.prop._supget.call(elem) || null;
},
set: function(value){
var elem = this;
var type = getType(elem);
if(typeModels[type] && typeModels[type].dateToString && !typeModels[type].noAsDate){
if(value === null){
$.prop(elem, 'value', '');
return '';
}
var set = typeModels[type].dateToString(value);
if(set !== false){
$.prop(elem, 'value', set);
return set;
} else {
webshims.error('INVALID_STATE_ERR: DOM Exception 11');
}
} else {
return valueAsDateDescriptor.prop._supset && valueAsDateDescriptor.prop._supset.apply(elem, arguments) || null;
}
}
}
});
$.each({stepUp: 1, stepDown: -1}, function(name, stepFactor){
var stepDescriptor = webshims.defineNodeNameProperty('input', name, {
prop: {
value: function(factor){
var step, val, valModStep, alignValue, cache, base, attrVal;
var type = getType(this);
if(typeModels[type] && typeModels[type].asNumber){
cache = {type: type};
if(!factor){
factor = 1;
webshims.warn("you should always use a factor for stepUp/stepDown");
}
factor *= stepFactor;
step = webshims.getStep(this, type);
if(step == 'any'){
webshims.info("step is 'any' can't apply stepUp/stepDown");
throw('invalid state error');
}
webshims.addMinMaxNumberToCache('min', $(this), cache);
webshims.addMinMaxNumberToCache('max', $(this), cache);
val = $.prop(this, 'valueAsNumber');
if(factor > 0 && !isNaN(cache.minAsNumber) && (isNaN(val) || cache.minAsNumber > val)){
$.prop(this, 'valueAsNumber', cache.minAsNumber);
return;
} else if(factor < 0 && !isNaN(cache.maxAsNumber) && (isNaN(val) || cache.maxAsNumber < val)){
$.prop(this, 'valueAsNumber', cache.maxAsNumber);
return;
}
if(isNaN(val)){
val = 0;
}
base = cache.minAsNumber;
if(isNaN(base) && (attrVal = $.prop(this, 'defaultValue'))){
base = typeModels[type].asNumber( attrVal );
}
if(!base){
base = 0;
}
step *= factor;
val = (val + step).toFixed(5) * 1;
valModStep = (val - base) % step;
if ( valModStep && (Math.abs(valModStep) > EPS) ) {
alignValue = val - valModStep;
alignValue += ( valModStep > 0 ) ? step : ( -step );
val = alignValue.toFixed(5) * 1;
}
if( (!isNaN(cache.maxAsNumber) && val > cache.maxAsNumber) || (!isNaN(cache.minAsNumber) && val < cache.minAsNumber) ){
webshims.info("max/min overflow can't apply stepUp/stepDown");
return;
}
$.prop(this, 'valueAsNumber', val);
} else if(stepDescriptor.prop && stepDescriptor.prop._supvalue){
return stepDescriptor.prop._supvalue.apply(this, arguments);
} else {
webshims.info("no step method for type: "+ type);
throw('invalid state error');
}
}
}
});
});
/*
* 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: {
bad: function(val){
return !(isNumber(val));
},
step: 1,
//stepBase: 0, 0 = default
stepScaleFactor: 1,
asNumber: function(str){
return (isNumber(str)) ? str * 1 : nan;
},
numberToString: function(num){
return (isNumber(num)) ? num : false;
}
},
range: {
minDefault: 0,
maxDefault: 100
},
color: {
bad: (function(){
var cReg = /^\u0023[a-f0-9]{6}$/;
return function(val){
return (!val || val.length != 7 || !(cReg.test(val)));
};
})()
},
date: {
bad: function(val){
if(!val || !val.split || !(/\d$/.test(val))){return true;}
var i;
var valA = val.split(/\u002D/);
if(valA.length !== 3){return true;}
var ret = false;
if(valA[0].length < 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
ret = true;
} else {
for(i = 0; i < 3; i++){
if(!isDateTimePart(valA[i])){
ret = true;
break;
}
}
}
return ret || (val !== this.dateToString( this.asDate(val, true) ) );
},
step: 1,
//stepBase: 0, 0 = default
stepScaleFactor: 86400000,
asDate: function(val, _noMismatch){
if(!_noMismatch && this.bad(val)){
return null;
}
return new Date(this.asNumber(val, true));
},
asNumber: function(str, _noMismatch){
var ret = nan;
if(_noMismatch || !this.bad(str)){
str = str.split(/\u002D/);
ret = Date.UTC(str[0], str[1] - 1, str[2]);
}
return ret;
},
numberToString: function(num){
return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false;
},
dateToString: function(date){
return (date && date.getFullYear) ? addleadingZero(date.getUTCFullYear(), 4) +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
}
},
/*
* ToDO: WEEK
*/
// week: {
// bad: 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.bad(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: {
bad: 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;}
var ret = false,
sFraction;
if(val[2]){
val[2] = val[2].split(/\u002E/);
sFraction = parseInt(val[2][1], 10);
val[2] = val[2][0];
}
$.each(val, function(i, part){
if(!isDateTimePart(part) || part.length !== 2){
ret = true;
return false;
}
});
if(ret){return true;}
if(val[0] > 23 || val[0] < 0 || val[1] > 59 || val[1] < 0){
return true;
}
if(val[2] && (val[2] > 59 || val[2] < 0 )){
return true;
}
if(sFraction && isNaN(sFraction)){
return true;
}
if(sFraction){
if(sFraction < 100){
sFraction *= 100;
} else if(sFraction < 10){
sFraction *= 10;
}
}
return (_getParsed === true) ? [val, sFraction] : false;
},
step: 60,
stepBase: 0,
stepScaleFactor: 1000,
asDate: function(val){
val = new Date(this.asNumber(val));
return (isNaN(val)) ? null : val;
},
asNumber: function(val){
var ret = nan;
val = this.bad(val, true);
if(val !== true){
ret = Date.UTC('1970', 0, 1, val[0][0], val[0][1], val[0][2] || 0);
if(val[1]){
ret += val[1];
}
}
return ret;
},
dateToString: function(date){
if(date && date.getUTCHours){
var str = addleadingZero(date.getUTCHours(), 2) +':'+ addleadingZero(date.getUTCMinutes(), 2),
tmp = date.getSeconds()
;
if(tmp != "0"){
str += ':'+ addleadingZero(tmp, 2);
}
tmp = date.getUTCMilliseconds();
if(tmp != "0"){
str += '.'+ addleadingZero(tmp, 3);
}
return str;
} else {
return false;
}
}
},
month: {
bad: function(val){
return typeProtos.date.bad(val+'-01');
},
step: 1,
stepScaleFactor: false,
//stepBase: 0, 0 = default
asDate: function(val){
return new Date(typeProtos.date.asNumber(val+'-01'));
},
asNumber: function(val){
//1970-01
var ret = nan;
if(val && !this.bad(val)){
val = val.split(/\u002D/);
val[0] = (val[0] * 1) - 1970;
val[1] = (val[1] * 1) - 1;
ret = (val[0] * 12) + val[1];
}
return ret;
},
numberToString: function(num){
var mod;
var ret = false;
if(isNumber(num)){
mod = (num % 12);
num = ((num - mod) / 12) + 1970;
mod += 1;
if(mod < 1){
num -= 1;
mod += 12;
}
ret = addleadingZero(num, 4)+'-'+addleadingZero(mod, 2);
}
return ret;
},
dateToString: function(date){
if(date && date.getUTCHours){
var str = typeProtos.date.dateToString(date);
return (str.split && (str = str.split(/\u002D/))) ? str[0]+'-'+str[1] : false;
} else {
return false;
}
}
}
,'datetime-local': {
bad: function(val, _getParsed){
if(!val || !val.split || (val+'special').split(/\u0054/).length !== 2){return true;}
val = val.split(/\u0054/);
return ( typeProtos.date.bad(val[0]) || typeProtos.time.bad(val[1], _getParsed) );
},
noAsDate: true,
asDate: function(val){
val = new Date(this.asNumber(val));
return (isNaN(val)) ? null : val;
},
asNumber: function(val){
var ret = nan;
var time = this.bad(val, true);
if(time !== true){
val = val.split(/\u0054/)[0].split(/\u002D/);
ret = Date.UTC(val[0], val[1] - 1, val[2], time[0][0], time[0][1], time[0][2] || 0);
if(time[1]){
ret += time[1];
}
}
return ret;
},
dateToString: function(date, _getParsed){
return typeProtos.date.dateToString(date) +'T'+ typeProtos.time.dateToString(date, _getParsed);
}
}
};
if(typeBugs || !supportsType('range') || !supportsType('time') || !supportsType('month') || !supportsType('datetime-local')){
typeProtos.range = $.extend({}, typeProtos.number, typeProtos.range);
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']);
}
//
['number', 'month', 'range', 'date', 'time', 'color', 'datetime-local'].forEach(function(type){
if(typeBugs || !supportsType(type)){
webshims.addInputType(type, typeProtos[type]);
}
});
if($('<input />').prop('labels') == null){
webshims.defineNodeNamesProperty('button, input, keygen, meter, output, progress, select, textarea', 'labels', {
prop: {
get: function(){
if(this.type == 'hidden'){return null;}
var id = this.id;
var labels = $(this)
.closest('label')
.filter(function(){
var hFor = (this.attributes['for'] || {});
return (!hFor.specified || hFor.value == id);
})
;
if(id) {
labels = labels.add('label[for="'+ id +'"]');
}
return labels.get();
},
writeable: false
}
});
}
});
;(function($){
"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))){
return def;
}
return val * 1;
};
var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex'];
var normalizeTouch = (function(){
var types = {
touchstart: 1,
touchend: 1,
touchmove: 1
};
var normalize = ['pageX', 'pageY'];
return function(e){
if(types[e.type] && e.originalEvent && e.originalEvent.touches && e.originalEvent.touches.length){
for(var i = 0; i < normalize.length; i++){
e[normalize[i]] = e.originalEvent.touches[0][normalize[i]];
}
}
return e;
};
})();
var rangeProto = {
_create: function(){
var i;
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;
for(i = 0; i < createOpts.length; i++){
this[createOpts[i]](this.options[createOpts[i]]);
}
this.value = this._value;
this.value(this.options.value);
this.initDataList();
this.element.data('rangeUi', this);
this.addBindings();
this._init = true;
},
value: $.noop,
_value: function(val, _noNormalize, animate){
var left, posDif;
var o = this.options;
var oVal = val;
var thumbStyle = {};
var rangeStyle = {};
if(!_noNormalize && parseFloat(val, 10) != val){
val = o.min + ((o.max - o.min) / 2);
}
if(!_noNormalize){
val = this.normalizeVal(val);
}
left = 100 * ((val - o.min) / (o.max - o.min));
if(this._init && val == o.value && oVal == val){return;}
o.value = val;
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 || !$.fn.animate){
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);
}
if(!animate.duration){
posDif = Math.abs(left - parseInt(this.thumb[0].style[this.dirs.left] || 50, 10));
animate.duration = Math.max(Math.min(999, posDif * 5), 99);
}
this.thumb.animate(thumbStyle, animate);
this.range.animate(rangeStyle, animate);
}
if(this.orig && (oVal != val || (!this._init && this.orig.value != val)) ){
this.options._change(val);
}
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[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', this.trail).addClass('ws-selected-option');
}
},
initDataList: function(){
if(this.orig){
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).on('listdatalistchange', updateList);
this.list();
}
},
list: function(opts){
var o = this.options;
var min = o.min;
var max = o.max;
var trail = this.trail;
var that = this;
this.element.attr({'aria-valuetext': o.options[o.value] || o.value});
$('.ws-range-ticks', trail).remove();
$(this.orig).jProp('list').find('option:not([disabled])').each(function(){
o.options[$.prop(this, 'value')] = $.prop(this, 'label') || '';
});
$.each(o.options, function(val, label){
if(!isNumber(val) || val < min || val > max){return;}
var left = 100 * ((val - min) / (max - min));
var attr = 'data-value="'+val+'"';
if(label){
attr += ' data-label="'+label+'"';
if(o.showLabels){
attr += ' title="'+label+'"';
}
}
if(that.vertical){
left = Math.abs(left - 100);
}
that.posCenter(
$('<span class="ws-range-ticks"'+ attr +' style="'+(that.dirs.left)+': '+left+'%;" />').appendTo(trail)
);
});
if(o.value in o.options){
this._setValueMarkup();
}
},
readonly: function(val){
val = !!val;
this.options.readonly = val;
this.element.attr('aria-readonly', ''+val);
if(this._init){
this.updateMetrics();
}
},
disabled: function(val){
val = !!val;
this.options.disabled = val;
if(val){
this.element.attr({tabindex: -1, 'aria-disabled': 'true'});
} else {
this.element.attr({tabindex: this.options.tabindex, 'aria-disabled': 'false'});
}
if(this._init){
this.updateMetrics();
}
},
tabindex: function(val){
this.options.tabindex = val;
if(!this.options.disabled){
this.element.attr({tabindex: val});
}
},
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);
if(o.stepping){
webshims.error('stepping was removed. Use stepfactor instead.');
}
if(o.stepfactor && step != 'any'){
step *= o.stepfactor;
}
o.step = step;
this.value(this.options.value);
},
normalizeVal: function(val){
var valModStep, alignValue, step;
var o = this.options;
if(val <= o.min){
val = o.min;
} else if(val >= o.max) {
val = o.max;
} else if(o.step != 'any'){
step = o.step;
valModStep = (val - o.min) % step;
alignValue = val - valModStep;
if ( Math.abs(valModStep) * 2 >= step ) {
alignValue += ( valModStep > 0 ) ? step : ( -step );
}
val = alignValue.toFixed(5) * 1;
}
return val;
},
doStep: function(factor, animate){
var step = retDefault(this.options.step, 1);
if(this.options.step == 'any'){
step = Math.min(step, (this.options.max - this.options.min) / 10);
}
this.value( this.options.value + (step * factor), false, animate );
},
getStepedValueFromPos: function(pos){
var val, valModStep, alignValue, step;
if(pos <= 0){
val = this.options[this.dirs[this.isRtl ? 'max' : 'min']];
} else if(pos > 100) {
val = this.options[this.dirs[this.isRtl ? 'min' : 'max']];
} else {
if(this.vertical || this.isRtl){
pos = Math.abs(pos - 100);
}
val = ((this.options.max - this.options.min) * (pos / 100)) + this.options.min;
step = this.options.step;
if(step != 'any'){
valModStep = (val - this.options.min) % step;
alignValue = val - valModStep;
if ( Math.abs(valModStep) * 2 >= step ) {
alignValue += ( valModStep > 0 ) ? step : ( -step );
}
val = ((alignValue).toFixed(5)) * 1;
}
}
return val;
},
addRemoveClass: function(cName, add){
var isIn = this.element.prop('className').indexOf(cName) != -1;
var action;
if(!add && isIn){
action = 'removeClass';
this.element.removeClass(cName);
this.updateMetrics();
} else if(add && !isIn){
action = 'addClass';
}
if(action){
this.element[action](cName);
if(this._init){
this.updateMetrics();
}
}
},
addBindings: function(){
var leftOffset, widgetUnits, hasFocus, isActive;
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};
if(that.orig){
$(that.orig).on(name, function(){
events[name].val = $.prop(that.orig, 'value');
});
}
}
events[name].val = curVal;
},
call: function(name, val){
if(events[name].val != val){
clearTimeout(events[name].timer);
events[name].val = val;
events[name].timer = setTimeout(function(){
events[name].fn(val, that);
}, 0);
}
}
};
})();
var updateValue = function(val, animate){
if(val != o.value){
that.value(val, false, animate);
eventTimer.call('input', val);
}
};
var setValueFromPos = function(e, animate){
if(e.type == 'touchmove'){
e.preventDefault();
normalizeTouch(e);
}
updateValue(that.getStepedValueFromPos((e[that.dirs.mouse] - leftOffset) * widgetUnits), animate);
if(e && e.type == 'mousemove'){
e.preventDefault();
}
};
var remove = function(e){
if(e && (e.type == 'mouseup' || e.type == 'touchend')){
eventTimer.call('input', o.value);
eventTimer.call('change', o.value);
}
that.addRemoveClass('ws-active');
$(document).off('mousemove touchmove', setValueFromPos).off('mouseup touchend', remove);
$(window).off('blur', removeWin);
isActive = false;
};
var removeWin = function(e){
if(e.target == window){remove();}
};
var add = function(e){
if(isActive || (e.type == 'touchstart' && (!e.originalEvent || !e.originalEvent.touches || e.originalEvent.touches.length != 1))){
return;
}
e.preventDefault();
$(document).off('mousemove touchmove', setValueFromPos).off('mouseup touchend', remove);
$(window).off('blur', removeWin);
if(!o.readonly && !o.disabled){
eventTimer.init('input', o.value);
eventTimer.init('change', o.value);
normalizeTouch(e);
that.element.trigger('focus');
that.addRemoveClass('ws-active', true);
leftOffset = that.element.offset();
widgetUnits = that.element[that.dirs.innerWidth]();
if(!widgetUnits || !leftOffset){return;}
leftOffset = leftOffset[that.dirs.pos];
widgetUnits = 100 / widgetUnits;
if(e.target.className == 'ws-range-ticks'){
updateValue(e.target.getAttribute('data-value'), o.animate);
} else {
setValueFromPos(e, o.animate);
}
isActive = true;
$(document)
.on(e.type == 'touchstart' ?
{
touchend: remove,
touchmove: setValueFromPos
} :
{
mouseup: remove,
mousemove: setValueFromPos
}
)
;
$(window).on('blur', removeWin);
e.stopPropagation();
}
};
var elementEvts = {
'touchstart mousedown': add,
focus: function(e){
if(!o.disabled && !hasFocus){
if(!isActive){
eventTimer.init('input', o.value);
eventTimer.init('change', o.value);
}
that.addRemoveClass('ws-focus', true);
that.updateMetrics();
}
hasFocus = true;
},
blur: function(e){
that.element.removeClass('ws-focus ws-active');
that.updateMetrics();
hasFocus = false;
eventTimer.init('input', o.value);
eventTimer.call('change', o.value);
},
keyup: function(){
that.addRemoveClass('ws-active');
eventTimer.call('input', o.value);
eventTimer.call('change', o.value);
},
keydown: function(e){
var step = true;
var code = e.keyCode;
if(!o.readonly && !o.disabled){
if(that.isRtl){
if(code == 39){
code = 37;
} else if(code == 37){
code = 39;
}
}
if (code == 39 || code == 38) {
that.doStep(1);
} else if (code == 37 || code == 40) {
that.doStep(-1);
} else if (code == 33) {
that.doStep(10, o.animate);
} else if (code == 34) {
that.doStep(-10, o.animate);
} else if (code == 36) {
that.value(that.options.max, false, o.animate);
} else if (code == 35) {
that.value(that.options.min, false, o.animate);
} else {
step = false;
}
if (step) {
that.addRemoveClass('ws-active', true);
eventTimer.call('input', o.value);
e.preventDefault();
}
}
}
};
eventTimer.init('input', o.value, this.options.input);
eventTimer.init('change', o.value, this.options.change);
elementEvts[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
if(delta && hasFocus && !o.readonly && !o.disabled){
that.doStep(delta);
e.preventDefault();
eventTimer.call('input', o.value);
}
};
this.element.on(elementEvts);
this.thumb.on({
mousedown: add
});
if(this.orig){
$(this.orig).jProp('form').on('reset', function(){
var val = $.prop(that.orig, 'value');
that.value(val);
setTimeout(function(){
var val2 = $.prop(that.orig, 'value');
if(val != val2){
that.value(val2);
}
}, 4);
});
}
if (window.webshims) {
webshims.ready('WINDOWLOAD', function(){
webshims.ready('dom-support', function(){
if ($.fn.onWSOff) {
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, 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;
eS[this.dirs.marginLeft] = outerWidth +'px';
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', 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')
;
this.updateMetrics = this.posCenter;
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,
min: 0,
step: 1,
max: 100,
value: 50,
input: $.noop,
change: $.noop,
_change: $.noop,
showLabels: true,
options: {},
calcCenter: true,
calcTrail: true
}, opts);
return this.each(function(){
var obj = $.extend(oCreate(rangeProto), {element: $(this)});
obj.options = opts;
obj._create.call(obj);
});
};
$.fn.rangeUI.normalizeTouch = normalizeTouch;
if(window.webshims && webshims.isReady){
webshims.isReady('range-ui', true);
}
})(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 hasFormValidation = webshims.support.formvalidation && !webshims.bugs.bustedValidity;
var monthDigits = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
var stopPropagation = function(e){
e.stopImmediatePropagation();
};
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>';
}).join('');
}
return curCfg[selectName];
};
var daySelect = '<select class="dd"><option value=""></option>'+ (function(){
var i = 1;
var opts = [];
while(i < 32){
opts.push('<option>'+ ((i < 10) ? '0'+ i : i) +'</option>' );
i++;
}
return opts.join('');
})() +'</select>';
var createFormat = function(name){
if(!curCfg.patterns[name+'Obj']){
var obj = {};
$.each(curCfg.patterns[name].split(curCfg[name+'Format']), function(i, name){
obj[name] = i;
});
curCfg.patterns[name+'Obj'] = obj;
}
};
var createYearSelect = function(obj, opts){
var options, nowY, max, min;
if(opts.yearSelect){
nowY = parseInt(opts.value.split('-')[0], 10);
max = opts.max.split('-');
min = opts.min.split('-');
options = webshims.picker.createYearSelect(nowY || parseInt(min[0], 10) || parseInt(max[0], 10) || nowYear, max, min);
options.unshift('<option />');
$(obj.elements)
.filter('select.yy')
.html(options.join(''))
.each(function(){
if(!nowY){
$('option[selected]', this).removeAttr('selected');
$(this).val();
}
})
;
}
};
var numericType = webshims.support.inputtypes.tel && navigator.userAgent.indexOf('Mobile') != -1 && !('inputMode' in document.createElement('input') && !('inputmode' in document.createElement('input'))) ?
'tel' : 'text';
var splitInputs = {
date: {
_create: function(opts){
var obj = {
splits: []
};
if(opts.yearSelect){
obj.splits.push($('<select class="yy"></select>')[0]);
} else {
obj.splits.push($('<input type="'+ numericType +'" class="yy" size="4" inputmode="numeric" maxlength="4" />')[0]);
}
if(opts.monthSelect){
obj.splits.push($('<select class="mm">'+getMonthOptions(opts)+'</select>')[0]);
} else {
obj.splits.push($('<input type="'+ numericType +'" class="mm" inputmode="numeric" maxlength="2" size="2" />')[0]);
}
if(opts.daySelect){
obj.splits.push($(daySelect)[0]);
} else {
obj.splits.push($('<input type="'+ numericType +'" class="dd ws-spin" inputmode="numeric" maxlength="2" size="2" />')[0]);
}
obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1], $('<span class="ws-input-seperator" />')[0], obj.splits[2]];
createYearSelect(obj, opts);
return obj;
},
sort: function(element){
createFormat('d');
var i = 0;
var seperators = $('.ws-input-seperator', element).html(curCfg.dFormat);
var inputs = $('input, select', element);
$.each(curCfg.patterns.dObj, function(name, value){
var input = inputs.filter('.'+ name);
if(input[0]){
input.appendTo(element);
if(i < seperators.length){
seperators.eq(i).insertAfter(input);
}
i++;
}
});
}
},
month: {
_create: function(opts){
var obj = {
splits: []
};
if(opts.yearSelect){
obj.splits.push($('<select class="yy"></select>')[0]);
} else {
obj.splits.push($('<input type="'+ numericType +'" class="yy" size="4" inputmode="numeric" maxlength="4" />')[0]);
}
if(opts.monthSelect){
obj.splits.push($('<select class="mm">'+getMonthOptions(opts)+'</select>')[0]);
} else {
obj.splits.push($('<input type="text" class="mm ws-spin" />')[0]);
if(opts.onlyMonthDigits){
$().attr({inputmode: 'numeric', size: 2, maxlength: 2});
try {
obj.splits[1].setAttribute('type', numericType);
} catch(e){}
}
}
obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1]];
createYearSelect(obj, opts);
return obj;
},
sort: function(element){
var seperator = $('.ws-input-seperator', element).html(curCfg.dFormat);
var mm = $('input.mm, select.mm', element);
var action;
if(curCfg.date.showMonthAfterYear){
mm.appendTo(element);
action = 'insertBefore';
} else {
mm.prependTo(element);
action = 'insertAfter';
}
seperator[action](mm);
}
}
};
var nowDate = new Date(new Date().getTime() - (new Date().getTimezoneOffset() * 60 * 1000 ));
var nowYear = nowDate.getFullYear();
nowDate = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), nowDate.getHours()).getTime();
var steps = {
number: {
step: 1
},
// week: {
// step: 1,
// start: new Date(nowDate)
// },
'datetime-local': {
step: 60,
start: new Date(nowDate).getTime()
},
time: {
step: 60
},
month: {
step: 1,
start: new Date(nowDate)
},
date: {
step: 1,
start: new Date(nowDate)
}
};
var labelWidth = (function(){
var getId = function(){
return webshims.getID(this);
};
return function(element, labels, noFocus){
$(element).attr({'aria-labelledby': labels.map(getId).get().join(' ')});
if(!noFocus){
labels.on('click', function(e){
if(!e.isDefaultPrevented()){
element.getShadowFocusElement().focus();
e.preventDefault();
return false;
}
});
}
};
})();
var addZero = function(val){
val = val+'';
if(!val){return "";}
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,
css: 'styles/forms-picker.css',
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: {
",": ".",
".": ","
},
timeSigns: ":. ",
numberSigns: ',',
dateSigns: '.',
dFormat: ".",
patterns: {
d: "dd.mm.yy"
},
month: {
currentText: 'Aktueller Monat'
},
time: {
currentText: 'Jetzt'
},
date: {
close: 'schließen',
clear: 'Löschen',
prevText: 'Zurück',
nextText: 'Vor',
currentText: 'Heute',
monthNames: ['Januar','Februar','März','April','Mai','Juni',
'Juli','August','September','Oktober','November','Dezember'],
monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
'Jul','Aug','Sep','Okt','Nov','Dez'],
dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
weekHeader: 'KW',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''
}
}, formcfg.de || {});
formcfg.en = $.extend(true, {
numberFormat: {
".": ".",
",": ","
},
numberSigns: '.',
dateSigns: '-',
timeSigns: ":. ",
dFormat: "-",
patterns: {
d: "yy-mm-dd"
},
month: {
currentText: 'This month'
},
time: {
"currentText": "Now"
},
date: {
"closeText": "Done",
clear: 'Clear',
"prevText": "Prev",
"nextText": "Next",
"currentText": "Today",
"monthNames": ["January","February","March","April","May","June","July","August","September","October","November","December"],
"monthNamesShort": ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
"dayNames": ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
"dayNamesShort": ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
"dayNamesMin": ["Su","Mo","Tu","We","Th","Fr","Sa"],
"weekHeader": "Wk",
"firstDay": 1,
"isRTL": false,
"showMonthAfterYear": false,
"yearSuffix": ""
}
}, formcfg.en || {});
if(!formcfg['en-US']){
formcfg['en-US'] = $.extend(true, {}, formcfg.en, {
date: {firstDay: 0},
patterns: {d: "mm/dd/yy"},
dateSigns: '/',
dFormat: "/",
meridian: ['AM', 'PM']
});
}
if(!formcfg['en-GB']){
formcfg['en-GB'] = $.extend(true, {}, formcfg.en, {
date: {firstDay: 1},
patterns: {d: "dd/mm/yy"},
dateSigns: '/',
dFormat: "/",
meridian: ['AM', 'PM']
});
}
if(!formcfg['en-AU']){
formcfg['en-AU'] = $.extend(true, {}, formcfg['en-GB']);
}
if(!formcfg['']){
formcfg[''] = formcfg['en'];
}
curCfg = formcfg[''];
var