vendor/assets/javascripts/webshims/shims/combos/15.js in webshims-rails-1.13.0 vs vendor/assets/javascripts/webshims/shims/combos/15.js in webshims-rails-1.14.1
- old
+ new
@@ -177,12 +177,12 @@
$(evtDel).off(evt, fn);
}
});
return this;
};
-
- var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000));
+ var idCount = 0;
+ var dataID = '_webshims'+ (Math.round(Math.random() * 1000));
var elementData = function(elem, key, val){
elem = elem.jquery ? elem[0] : elem;
if(!elem){return val || {};}
var data = $.data(elem, dataID);
if(val !== undefined){
@@ -209,10 +209,39 @@
}
});
return this.pushStack(elems);
};
});
+
+ function clone(elem, dataAndEvents, uniqueIds){
+ var cloned = $.clone( elem, dataAndEvents, false );
+ $(cloned.querySelectorAll('.'+webshims.shadowClass)).detach();
+ if(uniqueIds){
+ idCount++;
+ $(cloned.querySelectorAll('[id]')).prop('id', function(i, id){
+ return id +idCount;
+ });
+ } else {
+ $(cloned.querySelectorAll('audio[id^="ID-"], video[id^="ID-"], label[id^="ID-"]')).removeAttr('id');
+ }
+ return cloned;
+ }
+
+ $.fn.clonePolyfill = function(dataAndEvents, uniqueIds){
+ dataAndEvents = dataAndEvents || false;
+ return this
+ .map(function() {
+ var cloned = clone( this, dataAndEvents, uniqueIds );
+ setTimeout(function(){
+ if($.contains(document.body, cloned)){
+ $(cloned).updatePolyfill();
+ }
+ });
+ return cloned;
+ })
+ ;
+ };
//add support for $('video').trigger('play') in case extendNative is set to false
if(!webshims.cfg.extendNative && !webshims.cfg.noTriggerOverride){
(function(oldTrigger){
$.event.trigger = function(event, data, elem, onlyHandlers){
@@ -520,10 +549,11 @@
elem.eq(0).prop('id', id);
}
return id;
};
})(),
+ shadowClass: 'wsshadow-'+(Date.now()),
implement: function(elem, type){
var data = elementData(elem, 'implemented') || elementData(elem, 'implemented', {});
if(data[type]){
webshims.warn(type +' already implemented for element #'+elem.id);
return false;
@@ -1331,10 +1361,12 @@
var poCFG = webshims.cfg.wspopover;
addModule('form-validation', $.extend({d: ['form-message']}, formExtras));
addModule('form-validators', $.extend({}, formExtras));
+
+
if($.expr.filters){
extendSels();
} else {
webshims.ready('sizzle', extendSels);
@@ -1452,16 +1484,25 @@
return message;
};
$.event.special.valuevalidation = {
setup: function(){
+ webshims.error('valuevalidation was renamed to validatevalue!');
+ }
+ };
+
+
+ $.event.special.validatevalue = {
+ setup: function(){
var data = $(this).data() || $.data(this, {});
- if(!('valuevalidation' in data)){
- data.valuevalidation = true;
+ if(!('validatevalue' in data)){
+ data.validatevalue = true;
}
}
};
+
+
$(document).on('focusin.lazyloadvalidation', function(e){
if('form' in e.target){
lazyLoad();
}
@@ -1470,28 +1511,52 @@
webshims.ready('WINDOWLOAD', lazyLoad);
if(modules['form-number-date-ui'].loaded && !options.customMessages && (modules['form-number-date-api'].test() || (Modernizr.inputtypes.range && Modernizr.inputtypes.color))){
webshims.isReady('form-number-date-ui', true);
}
+
+ webshims.ready('DOM', function(){
+ if(document.querySelector('.ws-custom-file')){
+ webshims.reTest(['form-validation']);
+ }
+ });
+
+ $(function(){
+ var fileReaderReady = ('FileReader' in window && 'FormData' in window);
+ if(!fileReaderReady){
+ webshims.addReady(function(context){
+ if(!fileReaderReady && !modules.filereader.loaded && !modules.moxie.loaded){
+ if(context.querySelector('input.ws-filereader')){
+ webshims.reTest(['filereader', 'moxie']);
+ fileReaderReady = true;
+ }
+ }
+ });
+ }
+ });
});
;webshims.register('form-shim-extend', function($, webshims, window, document, undefined, options){
"use strict";
webshims.inputTypes = webshims.inputTypes || {};
//some helper-functions
var cfg = webshims.cfg.forms;
var bugs = webshims.bugs;
-
-var isNumber = function(string){
- return (typeof string == 'number' || (string && string == string * 1));
- },
- typeModels = webshims.inputTypes,
+var splitReg = /\s*,\s*/g;
+var typeModels = webshims.inputTypes,
checkTypes = {
radio: 1,
checkbox: 1
},
- getType = function(elem){
- return (elem.getAttribute('type') || elem.type || '').toLowerCase();
+ getType = function(){
+ var elem = this;
+ var type = (elem.getAttribute('type') || '').toLowerCase();
+ return (webshims.inputTypes[type]) ? type : elem.type;
+ },
+ cacheType = function(cache, input){
+ if(!('type' in cache)){
+ cache.type = getType.call(input);
+ }
}
;
(function(){
if('querySelector' in document){
@@ -1567,10 +1632,11 @@
}
return false;
};
var emptyJ = $([]);
+//TODO: cache + perftest
var getGroupElements = function(elem){
elem = $(elem);
var name, form;
var ret = emptyJ;
if(elem[0].type == 'radio'){
@@ -1591,49 +1657,58 @@
var validityRules = {
valueMissing: function(input, val, cache){
if(!input.prop('required')){return false;}
var ret = false;
- if(!('type' in cache)){
- cache.type = getType(input[0]);
- }
+ cacheType(cache, input[0]);
if(cache.nodeName == 'select'){
ret = (!val && (input[0].selectedIndex < 0 || isPlaceholderOptionSelected(input[0]) ));
} else if(checkTypes[cache.type]){
ret = (cache.type == 'checkbox') ? !input.is(':checked') : !getGroupElements(input).filter(':checked')[0];
} else {
ret = !(val);
}
return ret;
},
patternMismatch: function(input, val, cache) {
- if(val === '' || cache.nodeName == 'select'){return false;}
- if(!('type' in cache)){
- cache.type = getType(input[0]);
- }
- if(!patternTypes[cache.type]){return false;}
+ var i;
+ var ret = false;
+ if(val === '' || cache.nodeName == 'select'){return ret;}
+
+ cacheType(cache, input[0]);
+
+ if(!patternTypes[cache.type]){return ret;}
var pattern = input.attr('pattern');
- if(!pattern){return false;}
+ if(!pattern){return ret;}
try {
pattern = new RegExp('^(?:' + pattern + ')$');
} catch(er){
webshims.error('invalid pattern value: "'+ pattern +'" | '+ er);
- pattern = false;
+ pattern = ret;
}
- if(!pattern){return false;}
- return !(pattern.test(val));
+ if(!pattern){return ret;}
+
+ val = cache.type == 'email' && input.prop('multiple') ? val.split(splitReg) : [val];
+
+ for(i = 0; i < val.length; i++){
+ if(!pattern.test(val[i])){
+ ret = true;
+ break;
+ }
+ }
+ return ret;
}
}
;
$.each({tooShort: ['minLength', -1], tooLong: ['maxLength', 1]}, function(name, props){
validityRules[name] = function(input, val, cache){
//defaultValue is not the same as dirty flag, but very similiar
if(cache.nodeName == 'select' || input.prop('defaultValue') == val){return false;}
- if(!('type' in cache)){
- cache.type = getType(input[0]);
- }
+
+ cacheType(cache, input[0]);
+
if(!lengthTypes[cache.type]){return false;}
var prop = input.prop(props[0]);
return ( prop > 0 && prop * props[1] < val.length * props[1] );
};
@@ -1641,13 +1716,12 @@
$.each({typeMismatch: 'mismatch', badInput: 'bad'}, function(name, fn){
validityRules[name] = function (input, val, cache){
if(val === '' || cache.nodeName == 'select'){return false;}
var ret = false;
- if(!('type' in cache)){
- cache.type = getType(input[0]);
- }
+
+ cacheType(cache, input[0]);
if(typeModels[cache.type] && typeModels[cache.type][fn]){
ret = typeModels[cache.type][fn](val, input);
} else if('validity' in input[0] && ('name' in input[0].validity)){
ret = input[0].validity[name] || false;
@@ -1711,28 +1785,30 @@
$('form', this).on('invalid', $.noop);
}
return submitSetup.apply(this, arguments);
}
});
+
webshims.ready('form-shim-extend2 WINDOWLOAD', function(){
$(window).on('invalid', $.noop);
});
webshims.addInputType('email', {
mismatch: (function(){
//taken from http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
var test = cfg.emailReg || /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
- var splitReg = /\s*,\s*/g;
return function(val, input){
+ var i;
var ret = false;
- val = $(input).prop('multiple') ? val.split(splitReg) : [val];
-
- for(var i = 0; i < val.length; i++){
- if(!test.test(val[i])){
- ret = true;
- break;
+ if(val){
+ val = input.prop('multiple') ? val.split(splitReg) : [val];
+ for(i = 0; i < val.length; i++){
+ if(!test.test(val[i])){
+ ret = true;
+ break;
+ }
}
}
return ret;
};
})()
@@ -1741,22 +1817,18 @@
webshims.addInputType('url', {
mismatch: (function(){
//taken from scott gonzales
var test = cfg.urlReg || /^([a-z]([a-z]|\d|\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~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
return function(val){
- return !test.test(val);
+ return val && !test.test(val);
};
})()
});
webshims.defineNodeNameProperty('input', 'type', {
prop: {
- get: function(){
- var elem = this;
- var type = (elem.getAttribute('type') || '').toLowerCase();
- return (webshims.inputTypes[type]) ? type : elem.type;
- }
+ get: getType
}
});
// IDLs for constrain validation API
//ToDo: add object to this list
@@ -2483,10 +2555,10 @@
}
if(message && message.indexOf('{%') != -1){
['value', 'min', 'max', 'maxlength', 'minlength', 'label'].forEach(function(attr){
if(message.indexOf('{%'+attr) === -1){return;}
- var val = ((attr == 'label') ? $.trim($('label[for="'+ elem.id +'"]', elem.form).text()).replace(/\*$|:$/, '') : $.prop(elem, attr)) || '';
+ var val = ((attr == 'label') ? $.trim($('label[for="'+ elem.id +'"]', elem.form).text()).replace(/\*$|:$/, '') : $.prop(elem, attr) || $.attr(elem, attr) || '') || '';
val = ''+val;
val = toLocale(val, elem, attr);