webshims-rails 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/webshims-rails/version.rb +2 -2
- data/vendor/assets/javascripts/webshims/extras/custom-validity.js +253 -253
- data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +534 -534
- data/vendor/assets/javascripts/webshims/extras/mousepress.js +60 -60
- data/vendor/assets/javascripts/webshims/minified/polyfiller.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/form-message.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +33 -33
- data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +34 -34
- data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +1 -1
- data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
- data/vendor/assets/javascripts/webshims/polyfiller.js +1188 -1188
- data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +82 -82
- data/vendor/assets/javascripts/webshims/shims/combos/1.js +1752 -1752
- data/vendor/assets/javascripts/webshims/shims/combos/10.js +3310 -3311
- data/vendor/assets/javascripts/webshims/shims/combos/11.js +1631 -1631
- data/vendor/assets/javascripts/webshims/shims/combos/12.js +1695 -1696
- data/vendor/assets/javascripts/webshims/shims/combos/13.js +1098 -1098
- data/vendor/assets/javascripts/webshims/shims/combos/14.js +477 -477
- data/vendor/assets/javascripts/webshims/shims/combos/15.js +317 -317
- data/vendor/assets/javascripts/webshims/shims/combos/16.js +2177 -2154
- data/vendor/assets/javascripts/webshims/shims/combos/17.js +2354 -2319
- data/vendor/assets/javascripts/webshims/shims/combos/18.js +1322 -1322
- data/vendor/assets/javascripts/webshims/shims/combos/19.js +2262 -2238
- data/vendor/assets/javascripts/webshims/shims/combos/2.js +2376 -2340
- data/vendor/assets/javascripts/webshims/shims/combos/20.js +1557 -1558
- data/vendor/assets/javascripts/webshims/shims/combos/21.js +1745 -1733
- data/vendor/assets/javascripts/webshims/shims/combos/22.js +2360 -2361
- data/vendor/assets/javascripts/webshims/shims/combos/23.js +2342 -2331
- data/vendor/assets/javascripts/webshims/shims/combos/24.js +2859 -2836
- data/vendor/assets/javascripts/webshims/shims/combos/25.js +1547 -1548
- data/vendor/assets/javascripts/webshims/shims/combos/26.js +2178 -2155
- data/vendor/assets/javascripts/webshims/shims/combos/27.js +3311 -3312
- data/vendor/assets/javascripts/webshims/shims/combos/3.js +3058 -3022
- data/vendor/assets/javascripts/webshims/shims/combos/4.js +807 -771
- data/vendor/assets/javascripts/webshims/shims/combos/5.js +1063 -1027
- data/vendor/assets/javascripts/webshims/shims/combos/59.js +1745 -1709
- data/vendor/assets/javascripts/webshims/shims/combos/6.js +384 -384
- data/vendor/assets/javascripts/webshims/shims/combos/7.js +640 -640
- data/vendor/assets/javascripts/webshims/shims/combos/8.js +1546 -1547
- data/vendor/assets/javascripts/webshims/shims/combos/9.js +2507 -2508
- data/vendor/assets/javascripts/webshims/shims/details.js +148 -148
- data/vendor/assets/javascripts/webshims/shims/dom-extend.js +949 -949
- data/vendor/assets/javascripts/webshims/shims/es5.js +802 -802
- data/vendor/assets/javascripts/webshims/shims/excanvas.js +924 -924
- data/vendor/assets/javascripts/webshims/shims/form-core.js +630 -606
- data/vendor/assets/javascripts/webshims/shims/form-datalist.js +681 -681
- data/vendor/assets/javascripts/webshims/shims/form-message.js +176 -164
- data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +255 -255
- data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +383 -383
- data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1568 -1568
- data/vendor/assets/javascripts/webshims/shims/geolocation.js +168 -168
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ar.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ch-ZN.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-de.txt +33 -33
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-el.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-en.txt +34 -34
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-es.js +31 -31
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-fr.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-he.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hi.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hu.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-it.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ja.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-nl.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-pt-PT.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ru.js +31 -31
- data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-sv.js +32 -32
- data/vendor/assets/javascripts/webshims/shims/json-storage.js +308 -308
- data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +596 -597
- data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +891 -891
- data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +98 -98
- data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +960 -960
- data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +543 -543
- data/vendor/assets/javascripts/webshims/shims/styles/shim.css +697 -697
- data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
- metadata +2 -4
- data/vendor/assets/javascripts/webshims/minified/shims/range-ui.js +0 -1
- data/vendor/assets/javascripts/webshims/shims/range-ui.js +0 -66
@@ -1,1734 +1,1746 @@
|
|
1
|
-
if(!Modernizr.formvalidation || jQuery.webshims.bugs.bustedValidity){
|
2
|
-
jQuery.webshims.register('form-shim-extend', function($, webshims, window, document){
|
3
|
-
"use strict";
|
4
|
-
webshims.inputTypes = webshims.inputTypes || {};
|
5
|
-
//some helper-functions
|
6
|
-
var cfg = webshims.cfg.forms;
|
7
|
-
var isSubmit;
|
8
|
-
|
9
|
-
var isNumber = function(string){
|
10
|
-
return (typeof string == 'number' || (string && string == string * 1));
|
11
|
-
},
|
12
|
-
typeModels = webshims.inputTypes,
|
13
|
-
checkTypes = {
|
14
|
-
radio: 1,
|
15
|
-
checkbox: 1
|
16
|
-
},
|
17
|
-
getType = function(elem){
|
18
|
-
return (elem.getAttribute('type') || elem.type || '').toLowerCase();
|
19
|
-
}
|
20
|
-
;
|
21
|
-
|
22
|
-
//API to add new input types
|
23
|
-
webshims.addInputType = function(type, obj){
|
24
|
-
typeModels[type] = obj;
|
25
|
-
};
|
26
|
-
|
27
|
-
//contsrain-validation-api
|
28
|
-
var validityPrototype = {
|
29
|
-
customError: false,
|
30
|
-
|
31
|
-
typeMismatch: false,
|
32
|
-
rangeUnderflow: false,
|
33
|
-
rangeOverflow: false,
|
34
|
-
stepMismatch: false,
|
35
|
-
tooLong: false,
|
36
|
-
patternMismatch: false,
|
37
|
-
valueMissing: false,
|
38
|
-
|
39
|
-
valid: true
|
40
|
-
};
|
41
|
-
|
42
|
-
var isPlaceholderOptionSelected = function(select){
|
43
|
-
if(select.type == 'select-one' && select.size < 2){
|
44
|
-
var option = $('> option:first-child', select);
|
45
|
-
return !!option.prop('selected');
|
46
|
-
}
|
47
|
-
return false;
|
48
|
-
};
|
49
|
-
|
50
|
-
var validityRules = {
|
51
|
-
valueMissing: function(input, val, cache){
|
52
|
-
if(!input.prop('required')){return false;}
|
53
|
-
var ret = false;
|
54
|
-
if(!('type' in cache)){
|
55
|
-
cache.type = getType(input[0]);
|
56
|
-
}
|
57
|
-
if(cache.nodeName == 'select'){
|
58
|
-
ret = (!val && (input[0].selectedIndex < 0 || isPlaceholderOptionSelected(input[0]) ));
|
59
|
-
} else if(checkTypes[cache.type]){
|
60
|
-
ret = (cache.type == 'checkbox') ? !input.is(':checked') : !webshims.modules["form-core"].getGroupElements(input).filter(':checked')[0];
|
61
|
-
} else {
|
62
|
-
ret = !(val);
|
63
|
-
}
|
64
|
-
return ret;
|
65
|
-
},
|
66
|
-
tooLong: function(){
|
67
|
-
return false;
|
68
|
-
},
|
69
|
-
typeMismatch: function (input, val, cache){
|
70
|
-
if(val === '' || cache.nodeName == 'select'){return false;}
|
71
|
-
var ret = false;
|
72
|
-
if(!('type' in cache)){
|
73
|
-
cache.type = getType(input[0]);
|
74
|
-
}
|
75
|
-
|
76
|
-
if(typeModels[cache.type] && typeModels[cache.type].mismatch){
|
77
|
-
ret = typeModels[cache.type].mismatch(val, input);
|
78
|
-
} else if('validity' in input[0]){
|
79
|
-
ret = input[0].validity.typeMismatch;
|
80
|
-
}
|
81
|
-
return ret;
|
82
|
-
},
|
83
|
-
patternMismatch: function(input, val, cache) {
|
84
|
-
if(val === '' || cache.nodeName == 'select'){return false;}
|
85
|
-
var pattern = input.attr('pattern');
|
86
|
-
if(!pattern){return false;}
|
87
|
-
try {
|
88
|
-
pattern = new RegExp('^(?:' + pattern + ')$');
|
89
|
-
} catch(er){
|
90
|
-
webshims.error('invalid pattern value: "'+ pattern +'" | '+ er);
|
91
|
-
pattern = false;
|
92
|
-
}
|
93
|
-
if(!pattern){return false;}
|
94
|
-
return !(pattern.test(val));
|
95
|
-
}
|
96
|
-
}
|
97
|
-
;
|
98
|
-
|
99
|
-
webshims.addValidityRule = function(type, fn){
|
100
|
-
validityRules[type] = fn;
|
101
|
-
};
|
102
|
-
|
103
|
-
$.event.special.invalid = {
|
104
|
-
add: function(){
|
105
|
-
$.event.special.invalid.setup.call(this.form || this);
|
106
|
-
},
|
107
|
-
setup: function(){
|
108
|
-
var form = this.form || this;
|
109
|
-
if( $.data(form, 'invalidEventShim') ){
|
110
|
-
form = null;
|
111
|
-
return;
|
112
|
-
}
|
113
|
-
$(form)
|
114
|
-
.data('invalidEventShim', true)
|
115
|
-
.on('submit', $.event.special.invalid.handler)
|
116
|
-
;
|
117
|
-
webshims.moveToFirstEvent(form, 'submit');
|
118
|
-
if(webshims.bugs.bustedValidity && $.nodeName(form, 'form')){
|
119
|
-
(function(){
|
120
|
-
var noValidate = form.getAttribute('novalidate');
|
121
|
-
form.setAttribute('novalidate', 'novalidate');
|
122
|
-
webshims.data(form, 'bustedNoValidate', (noValidate == null) ? null : noValidate);
|
123
|
-
})();
|
124
|
-
}
|
125
|
-
form = null;
|
126
|
-
},
|
127
|
-
teardown: $.noop,
|
128
|
-
handler: function(e, d){
|
129
|
-
|
130
|
-
if( e.type != 'submit' || e.testedValidity || !e.originalEvent || !$.nodeName(e.target, 'form') || $.prop(e.target, 'noValidate') ){return;}
|
131
|
-
|
132
|
-
isSubmit = true;
|
133
|
-
e.testedValidity = true;
|
134
|
-
var notValid = !($(e.target).checkValidity());
|
135
|
-
if(notValid){
|
136
|
-
e.stopImmediatePropagation();
|
137
|
-
isSubmit = false;
|
138
|
-
return false;
|
139
|
-
}
|
140
|
-
isSubmit = false;
|
141
|
-
}
|
142
|
-
};
|
143
|
-
|
144
|
-
var addSubmitBubbles = function(form){
|
145
|
-
if (!$.support.submitBubbles && form && typeof form == 'object' && !form._submit_attached ) {
|
146
|
-
|
147
|
-
$.event.add( form, 'submit._submit', function( event ) {
|
148
|
-
event._submit_bubble = true;
|
149
|
-
});
|
150
|
-
|
151
|
-
form._submit_attached = true;
|
152
|
-
}
|
153
|
-
};
|
154
|
-
if(!$.support.submitBubbles && $.event.special.submit){
|
155
|
-
$.event.special.submit.setup = function() {
|
156
|
-
// Only need this for delegated form submit events
|
157
|
-
if ( $.nodeName( this, "form" ) ) {
|
158
|
-
return false;
|
159
|
-
}
|
160
|
-
|
161
|
-
// Lazy-add a submit handler when a descendant form may potentially be submitted
|
162
|
-
$.event.add( this, "click._submit keypress._submit", function( e ) {
|
163
|
-
// Node name check avoids a VML-related crash in IE (#9807)
|
164
|
-
var elem = e.target,
|
165
|
-
form = $.nodeName( elem, 'input' ) || $.nodeName( elem, 'button' ) ? $.prop(elem, 'form') : undefined;
|
166
|
-
addSubmitBubbles(form);
|
167
|
-
|
168
|
-
});
|
169
|
-
// return undefined since we don't need an event listener
|
170
|
-
};
|
171
|
-
}
|
172
|
-
|
173
|
-
$.event.special.submit = $.event.special.submit || {setup: function(){return false;}};
|
174
|
-
var submitSetup = $.event.special.submit.setup;
|
175
|
-
$.extend($.event.special.submit, {
|
176
|
-
setup: function(){
|
177
|
-
if($.nodeName(this, 'form')){
|
178
|
-
$(this).on('invalid', $.noop);
|
179
|
-
} else {
|
180
|
-
$('form', this).on('invalid', $.noop);
|
181
|
-
}
|
182
|
-
return submitSetup.apply(this, arguments);
|
183
|
-
}
|
184
|
-
});
|
185
|
-
|
186
|
-
$(window).on('invalid', $.noop);
|
187
|
-
|
188
|
-
|
189
|
-
webshims.addInputType('email', {
|
190
|
-
mismatch: (function(){
|
191
|
-
//taken from http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
|
192
|
-
var test = cfg.emailReg || /^[a-zA-Z0-9.!#$%&'*+-\/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
193
|
-
return function(val){
|
194
|
-
return !test.test(val);
|
195
|
-
};
|
196
|
-
})()
|
197
|
-
});
|
198
|
-
|
199
|
-
webshims.addInputType('url', {
|
200
|
-
mismatch: (function(){
|
201
|
-
//taken from scott gonzales
|
202
|
-
var test = cfg.urlReg || /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
|
203
|
-
return function(val){
|
204
|
-
return !test.test(val);
|
205
|
-
};
|
206
|
-
})()
|
207
|
-
});
|
208
|
-
|
209
|
-
webshims.defineNodeNameProperty('input', 'type', {
|
210
|
-
prop: {
|
211
|
-
get: function(){
|
212
|
-
var elem = this;
|
213
|
-
var type = (elem.getAttribute('type') || '').toLowerCase();
|
214
|
-
return (webshims.inputTypes[type]) ? type : elem.type;
|
215
|
-
}
|
216
|
-
}
|
217
|
-
});
|
218
|
-
|
219
|
-
// IDLs for constrain validation API
|
220
|
-
//ToDo: add object to this list
|
221
|
-
webshims.defineNodeNamesProperties(['button', 'fieldset', 'output'], {
|
222
|
-
checkValidity: {
|
223
|
-
value: function(){return true;}
|
224
|
-
},
|
225
|
-
willValidate: {
|
226
|
-
value: false
|
227
|
-
},
|
228
|
-
setCustomValidity: {
|
229
|
-
value: $.noop
|
230
|
-
},
|
231
|
-
validity: {
|
232
|
-
writeable: false,
|
233
|
-
get: function(){
|
234
|
-
return $.extend({}, validityPrototype);
|
235
|
-
}
|
236
|
-
}
|
237
|
-
}, 'prop');
|
238
|
-
|
239
|
-
var baseCheckValidity = function(elem){
|
240
|
-
var e,
|
241
|
-
v = $.prop(elem, 'validity')
|
242
|
-
;
|
243
|
-
if(v){
|
244
|
-
$.data(elem, 'cachedValidity', v);
|
245
|
-
} else {
|
246
|
-
return true;
|
247
|
-
}
|
248
|
-
if( !v.valid ){
|
249
|
-
e = $.Event('invalid');
|
250
|
-
var jElm = $(elem).trigger(e);
|
251
|
-
if(isSubmit && !baseCheckValidity.unhandledInvalids && !e.isDefaultPrevented()){
|
252
|
-
webshims.validityAlert.showFor(jElm);
|
253
|
-
baseCheckValidity.unhandledInvalids = true;
|
254
|
-
}
|
255
|
-
}
|
256
|
-
$.removeData(elem, 'cachedValidity');
|
257
|
-
return v.valid;
|
258
|
-
};
|
259
|
-
var rsubmittable = /^(?:select|textarea|input)/i;
|
260
|
-
webshims.defineNodeNameProperty('form', 'checkValidity', {
|
261
|
-
prop: {
|
262
|
-
value: function(){
|
263
|
-
|
264
|
-
var ret = true,
|
265
|
-
elems = $($.prop(this, 'elements')).filter(function(){
|
266
|
-
if(!rsubmittable.test(this.nodeName)){return false;}
|
267
|
-
var shadowData = webshims.data(this, 'shadowData');
|
268
|
-
return !shadowData || !shadowData.nativeElement || shadowData.nativeElement === this;
|
269
|
-
})
|
270
|
-
;
|
271
|
-
|
272
|
-
baseCheckValidity.unhandledInvalids = false;
|
273
|
-
for(var i = 0, len = elems.length; i < len; i++){
|
274
|
-
if( !baseCheckValidity(elems[i]) ){
|
275
|
-
ret = false;
|
276
|
-
}
|
277
|
-
}
|
278
|
-
return ret;
|
279
|
-
}
|
280
|
-
}
|
281
|
-
});
|
282
|
-
|
283
|
-
webshims.defineNodeNamesProperties(['input', 'textarea', 'select'], {
|
284
|
-
checkValidity: {
|
285
|
-
value: function(){
|
286
|
-
baseCheckValidity.unhandledInvalids = false;
|
287
|
-
return baseCheckValidity($(this).getNativeElement()[0]);
|
288
|
-
}
|
289
|
-
},
|
290
|
-
setCustomValidity: {
|
291
|
-
value: function(error){
|
292
|
-
$.removeData(this, 'cachedValidity');
|
293
|
-
webshims.data(this, 'customvalidationMessage', ''+error);
|
294
|
-
}
|
295
|
-
},
|
296
|
-
willValidate: {
|
297
|
-
writeable: false,
|
298
|
-
get: (function(){
|
299
|
-
var types = {
|
300
|
-
button: 1,
|
301
|
-
reset: 1,
|
302
|
-
hidden: 1,
|
303
|
-
image: 1
|
304
|
-
}
|
305
|
-
;
|
306
|
-
return function(){
|
307
|
-
var elem = $(this).getNativeElement()[0];
|
308
|
-
//elem.name && <- we don't use to make it easier for developers
|
309
|
-
return !!(!elem.disabled && !elem.readOnly && !types[elem.type] );
|
310
|
-
};
|
311
|
-
})()
|
312
|
-
},
|
313
|
-
validity: {
|
314
|
-
writeable: false,
|
315
|
-
get: function(){
|
316
|
-
var jElm = $(this).getNativeElement();
|
317
|
-
var elem = jElm[0];
|
318
|
-
var validityState = $.data(elem, 'cachedValidity');
|
319
|
-
if(validityState){
|
320
|
-
return validityState;
|
321
|
-
}
|
322
|
-
validityState = $.extend({}, validityPrototype);
|
323
|
-
|
324
|
-
if( !$.prop(elem, 'willValidate') || elem.type == 'submit' ){
|
325
|
-
return validityState;
|
326
|
-
}
|
327
|
-
var val = jElm.val(),
|
328
|
-
cache = {nodeName: elem.nodeName.toLowerCase()}
|
329
|
-
;
|
330
|
-
|
331
|
-
validityState.customError = !!(webshims.data(elem, 'customvalidationMessage'));
|
332
|
-
if( validityState.customError ){
|
333
|
-
validityState.valid = false;
|
334
|
-
}
|
335
|
-
|
336
|
-
$.each(validityRules, function(rule, fn){
|
337
|
-
if (fn(jElm, val, cache)) {
|
338
|
-
validityState[rule] = true;
|
339
|
-
validityState.valid = false;
|
340
|
-
}
|
341
|
-
});
|
342
|
-
$(this).getShadowFocusElement().attr('aria-invalid', validityState.valid ? 'false' : 'true');
|
343
|
-
jElm = null;
|
344
|
-
elem = null;
|
345
|
-
return validityState;
|
346
|
-
}
|
347
|
-
}
|
348
|
-
}, 'prop');
|
349
|
-
|
350
|
-
webshims.defineNodeNamesBooleanProperty(['input', 'textarea', 'select'], 'required', {
|
351
|
-
set: function(value){
|
352
|
-
$(this).getShadowFocusElement().attr('aria-required', !!(value)+'');
|
353
|
-
},
|
354
|
-
initAttr: (!$.browser.msie || webshims.browserVersion > 7)//only if we have aria-support
|
355
|
-
});
|
356
|
-
|
357
|
-
webshims.reflectProperties(['input'], ['pattern']);
|
358
|
-
|
359
|
-
|
360
|
-
if( !('maxLength' in document.createElement('textarea')) ){
|
361
|
-
var constrainMaxLength = (function(){
|
362
|
-
var timer;
|
363
|
-
var curLength = 0;
|
364
|
-
var lastElement = $([]);
|
365
|
-
var max = 1e9;
|
366
|
-
var constrainLength = function(){
|
367
|
-
var nowValue = lastElement.prop('value');
|
368
|
-
var nowLen = nowValue.length;
|
369
|
-
if(nowLen > curLength && nowLen > max){
|
370
|
-
nowLen = Math.max(curLength, max);
|
371
|
-
lastElement.prop('value', nowValue.substr(0, nowLen ));
|
372
|
-
}
|
373
|
-
curLength = nowLen;
|
374
|
-
};
|
375
|
-
var remove = function(){
|
376
|
-
clearTimeout(timer);
|
377
|
-
lastElement.unbind('.maxlengthconstraint');
|
378
|
-
};
|
379
|
-
return function(element, maxLength){
|
380
|
-
remove();
|
381
|
-
if(maxLength > -1){
|
382
|
-
max = maxLength;
|
383
|
-
curLength = $.prop(element, 'value').length;
|
384
|
-
lastElement = $(element);
|
385
|
-
lastElement.on({
|
386
|
-
'keydown.maxlengthconstraint keypress.maxlengthconstraint paste.maxlengthconstraint cut.maxlengthconstraint': function(e){
|
387
|
-
setTimeout(constrainLength, 0);
|
388
|
-
},
|
389
|
-
'keyup.maxlengthconstraint': constrainLength,
|
390
|
-
'blur.maxlengthconstraint': remove
|
391
|
-
});
|
392
|
-
timer = setInterval(constrainLength, 200);
|
393
|
-
}
|
394
|
-
};
|
395
|
-
})();
|
396
|
-
|
397
|
-
constrainMaxLength.update = function(element, maxLength){
|
398
|
-
if($(element).is(':focus')){
|
399
|
-
if(!maxLength){
|
400
|
-
maxLength = $.prop(element, 'maxlength');
|
401
|
-
}
|
402
|
-
constrainMaxLength(element, maxLength);
|
403
|
-
}
|
404
|
-
};
|
405
|
-
|
406
|
-
$(document).on('focusin', function(e){
|
407
|
-
var maxLength;
|
408
|
-
if(e.target.nodeName == "TEXTAREA" && (maxLength = $.prop(e.target, 'maxlength')) > -1){
|
409
|
-
constrainMaxLength(e.target, maxLength);
|
410
|
-
}
|
411
|
-
});
|
412
|
-
|
413
|
-
webshims.defineNodeNameProperty('textarea', 'maxlength', {
|
414
|
-
attr: {
|
415
|
-
set: function(val){
|
416
|
-
this.setAttribute('maxlength', ''+val);
|
417
|
-
constrainMaxLength.update(this);
|
418
|
-
},
|
419
|
-
get: function(){
|
420
|
-
var ret = this.getAttribute('maxlength');
|
421
|
-
return ret == null ? undefined : ret;
|
422
|
-
}
|
423
|
-
},
|
424
|
-
prop: {
|
425
|
-
set: function(val){
|
426
|
-
if(isNumber(val)){
|
427
|
-
if(val < 0){
|
428
|
-
throw('INDEX_SIZE_ERR');
|
429
|
-
}
|
430
|
-
val = parseInt(val, 10);
|
431
|
-
this.setAttribute('maxlength', val);
|
432
|
-
constrainMaxLength.update(this, val);
|
433
|
-
return;
|
434
|
-
}
|
435
|
-
this.setAttribute('maxlength', '0');
|
436
|
-
constrainMaxLength.update(this, 0);
|
437
|
-
},
|
438
|
-
get: function(){
|
439
|
-
var val = this.getAttribute('maxlength');
|
440
|
-
return (isNumber(val) && val >= 0) ? parseInt(val, 10) : -1;
|
441
|
-
|
442
|
-
}
|
443
|
-
}
|
444
|
-
});
|
445
|
-
webshims.defineNodeNameProperty('textarea', 'maxLength', {
|
446
|
-
prop: {
|
447
|
-
set: function(val){
|
448
|
-
$.prop(this, 'maxlength', val);
|
449
|
-
},
|
450
|
-
get: function(){
|
451
|
-
return $.prop(this, 'maxlength');
|
452
|
-
}
|
453
|
-
}
|
454
|
-
});
|
455
|
-
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
var submitterTypes = {submit: 1, button: 1, image: 1};
|
460
|
-
var formSubmitterDescriptors = {};
|
461
|
-
[
|
462
|
-
{
|
463
|
-
name: "enctype",
|
464
|
-
limitedTo: {
|
465
|
-
"application/x-www-form-urlencoded": 1,
|
466
|
-
"multipart/form-data": 1,
|
467
|
-
"text/plain": 1
|
468
|
-
},
|
469
|
-
defaultProp: "application/x-www-form-urlencoded",
|
470
|
-
proptype: "enum"
|
471
|
-
},
|
472
|
-
{
|
473
|
-
name: "method",
|
474
|
-
limitedTo: {
|
475
|
-
"get": 1,
|
476
|
-
"post": 1
|
477
|
-
},
|
478
|
-
defaultProp: "get",
|
479
|
-
proptype: "enum"
|
480
|
-
},
|
481
|
-
{
|
482
|
-
name: "action",
|
483
|
-
proptype: "url"
|
484
|
-
},
|
485
|
-
{
|
486
|
-
name: "target"
|
487
|
-
},
|
488
|
-
{
|
489
|
-
name: "novalidate",
|
490
|
-
propName: "noValidate",
|
491
|
-
proptype: "boolean"
|
492
|
-
}
|
493
|
-
].forEach(function(desc){
|
494
|
-
var propName = 'form'+ (desc.propName || desc.name).replace(/^[a-z]/, function(f){
|
495
|
-
return f.toUpperCase();
|
496
|
-
});
|
497
|
-
var attrName = 'form'+ desc.name;
|
498
|
-
var formName = desc.name;
|
499
|
-
var eventName = 'click.webshimssubmittermutate'+formName;
|
500
|
-
|
501
|
-
var changeSubmitter = function(){
|
502
|
-
var elem = this;
|
503
|
-
if( !('form' in elem) || !submitterTypes[elem.type] ){return;}
|
504
|
-
var form = $.prop(elem, 'form');
|
505
|
-
if(!form){return;}
|
506
|
-
var attr = $.attr(elem, attrName);
|
507
|
-
if(attr != null && ( !desc.limitedTo || attr.toLowerCase() === $.prop(elem, propName))){
|
508
|
-
|
509
|
-
var oldAttr = $.attr(form, formName);
|
510
|
-
|
511
|
-
$.attr(form, formName, attr);
|
512
|
-
setTimeout(function(){
|
513
|
-
if(oldAttr != null){
|
514
|
-
$.attr(form, formName, oldAttr);
|
515
|
-
} else {
|
516
|
-
try {
|
517
|
-
$(form).removeAttr(formName);
|
518
|
-
} catch(er){
|
519
|
-
form.removeAttribute(formName);
|
520
|
-
}
|
521
|
-
}
|
522
|
-
}, 9);
|
523
|
-
}
|
524
|
-
};
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
switch(desc.proptype) {
|
529
|
-
case "url":
|
530
|
-
var urlForm = document.createElement('form');
|
531
|
-
formSubmitterDescriptors[propName] = {
|
532
|
-
prop: {
|
533
|
-
set: function(value){
|
534
|
-
$.attr(this, attrName, value);
|
535
|
-
},
|
536
|
-
get: function(){
|
537
|
-
var value = $.attr(this, attrName);
|
538
|
-
if(value == null){return '';}
|
539
|
-
urlForm.setAttribute('action', value);
|
540
|
-
return urlForm.action;
|
541
|
-
}
|
542
|
-
}
|
543
|
-
};
|
544
|
-
break;
|
545
|
-
case "boolean":
|
546
|
-
formSubmitterDescriptors[propName] = {
|
547
|
-
prop: {
|
548
|
-
set: function(val){
|
549
|
-
val = !!val;
|
550
|
-
if(val){
|
551
|
-
$.attr(this, 'formnovalidate', 'formnovalidate');
|
552
|
-
} else {
|
553
|
-
$(this).removeAttr('formnovalidate');
|
554
|
-
}
|
555
|
-
},
|
556
|
-
get: function(){
|
557
|
-
return $.attr(this, 'formnovalidate') != null;
|
558
|
-
}
|
559
|
-
}
|
560
|
-
};
|
561
|
-
break;
|
562
|
-
case "enum":
|
563
|
-
formSubmitterDescriptors[propName] = {
|
564
|
-
prop: {
|
565
|
-
set: function(value){
|
566
|
-
$.attr(this, attrName, value);
|
567
|
-
},
|
568
|
-
get: function(){
|
569
|
-
var value = $.attr(this, attrName);
|
570
|
-
return (!value || ( (value = value.toLowerCase()) && !desc.limitedTo[value] )) ? desc.defaultProp : value;
|
571
|
-
}
|
572
|
-
}
|
573
|
-
};
|
574
|
-
break;
|
575
|
-
default:
|
576
|
-
formSubmitterDescriptors[propName] = {
|
577
|
-
prop: {
|
578
|
-
set: function(value){
|
579
|
-
$.attr(this, attrName, value);
|
580
|
-
},
|
581
|
-
get: function(){
|
582
|
-
var value = $.attr(this, attrName);
|
583
|
-
return (value != null) ? value : "";
|
584
|
-
}
|
585
|
-
}
|
586
|
-
};
|
587
|
-
}
|
588
|
-
|
589
|
-
|
590
|
-
if(!formSubmitterDescriptors[attrName]){
|
591
|
-
formSubmitterDescriptors[attrName] = {};
|
592
|
-
}
|
593
|
-
formSubmitterDescriptors[attrName].attr = {
|
594
|
-
set: function(value){
|
595
|
-
formSubmitterDescriptors[attrName].attr._supset.call(this, value);
|
596
|
-
$(this).unbind(eventName).on(eventName, changeSubmitter);
|
597
|
-
},
|
598
|
-
get: function(){
|
599
|
-
return formSubmitterDescriptors[attrName].attr._supget.call(this);
|
600
|
-
}
|
601
|
-
};
|
602
|
-
formSubmitterDescriptors[attrName].initAttr = true;
|
603
|
-
formSubmitterDescriptors[attrName].removeAttr = {
|
604
|
-
value: function(){
|
605
|
-
$(this).unbind(eventName);
|
606
|
-
formSubmitterDescriptors[attrName].removeAttr._supvalue.call(this);
|
607
|
-
}
|
608
|
-
};
|
609
|
-
});
|
610
|
-
|
611
|
-
webshims.defineNodeNamesProperties(['input', 'button'], formSubmitterDescriptors);
|
612
|
-
|
613
|
-
|
614
|
-
if(!$.support.getSetAttribute && $('<form novalidate></form>').attr('novalidate') == null){
|
615
|
-
webshims.defineNodeNameProperty('form', 'novalidate', {
|
616
|
-
attr: {
|
617
|
-
set: function(val){
|
618
|
-
this.setAttribute('novalidate', ''+val);
|
619
|
-
},
|
620
|
-
get: function(){
|
621
|
-
var ret = this.getAttribute('novalidate');
|
622
|
-
return ret == null ? undefined : ret;
|
623
|
-
}
|
624
|
-
}
|
625
|
-
});
|
626
|
-
} else if(webshims.bugs.bustedValidity){
|
627
|
-
|
628
|
-
webshims.defineNodeNameProperty('form', 'novalidate', {
|
629
|
-
attr: {
|
630
|
-
set: function(val){
|
631
|
-
webshims.data(this, 'bustedNoValidate', ''+val);
|
632
|
-
},
|
633
|
-
get: function(){
|
634
|
-
var ret = webshims.data(this, 'bustedNoValidate');
|
635
|
-
return ret == null ? undefined : ret;
|
636
|
-
}
|
637
|
-
},
|
638
|
-
removeAttr: {
|
639
|
-
value: function(){
|
640
|
-
webshims.data(this, 'bustedNoValidate', null);
|
641
|
-
}
|
642
|
-
}
|
643
|
-
});
|
644
|
-
|
645
|
-
$.each(['rangeUnderflow', 'rangeOverflow', 'stepMismatch'], function(i, name){
|
646
|
-
validityRules[name] = function(elem){
|
647
|
-
return (elem[0].validity || {})[name] || false;
|
648
|
-
};
|
649
|
-
});
|
650
|
-
|
651
|
-
}
|
652
|
-
|
653
|
-
webshims.defineNodeNameProperty('form', 'noValidate', {
|
654
|
-
prop: {
|
655
|
-
set: function(val){
|
656
|
-
val = !!val;
|
657
|
-
if(val){
|
658
|
-
$.attr(this, 'novalidate', 'novalidate');
|
659
|
-
} else {
|
660
|
-
$(this).removeAttr('novalidate');
|
661
|
-
}
|
662
|
-
},
|
663
|
-
get: function(){
|
664
|
-
return $.attr(this, 'novalidate') != null;
|
665
|
-
}
|
666
|
-
}
|
667
|
-
});
|
668
|
-
|
669
|
-
if($.browser.webkit && Modernizr.inputtypes.date){
|
670
|
-
(function(){
|
671
|
-
|
672
|
-
var noInputTriggerEvts = {updateInput: 1, input: 1},
|
673
|
-
fixInputTypes = {
|
674
|
-
date: 1,
|
675
|
-
time: 1,
|
676
|
-
"datetime-local": 1
|
677
|
-
},
|
678
|
-
noFocusEvents = {
|
679
|
-
focusout: 1,
|
680
|
-
blur: 1
|
681
|
-
},
|
682
|
-
changeEvts = {
|
683
|
-
updateInput: 1,
|
684
|
-
change: 1
|
685
|
-
},
|
686
|
-
observe = function(input){
|
687
|
-
var timer,
|
688
|
-
focusedin = true,
|
689
|
-
lastInputVal = input.prop('value'),
|
690
|
-
lastChangeVal = lastInputVal,
|
691
|
-
trigger = function(e){
|
692
|
-
//input === null
|
693
|
-
if(!input){return;}
|
694
|
-
var newVal = input.prop('value');
|
695
|
-
|
696
|
-
if(newVal !== lastInputVal){
|
697
|
-
lastInputVal = newVal;
|
698
|
-
if(!e || !noInputTriggerEvts[e.type]){
|
699
|
-
input.trigger('input');
|
700
|
-
}
|
701
|
-
}
|
702
|
-
if(e && changeEvts[e.type]){
|
703
|
-
lastChangeVal = newVal;
|
704
|
-
}
|
705
|
-
if(!focusedin && newVal !== lastChangeVal){
|
706
|
-
input.trigger('change');
|
707
|
-
}
|
708
|
-
},
|
709
|
-
extraTimer,
|
710
|
-
extraTest = function(){
|
711
|
-
clearTimeout(extraTimer);
|
712
|
-
extraTimer = setTimeout(trigger, 9);
|
713
|
-
},
|
714
|
-
unbind = function(e){
|
715
|
-
clearInterval(timer);
|
716
|
-
setTimeout(function(){
|
717
|
-
if(e && noFocusEvents[e.type]){
|
718
|
-
focusedin = false;
|
719
|
-
}
|
720
|
-
if(input){
|
721
|
-
input.unbind('focusout blur', unbind).unbind('input change updateInput', trigger);
|
722
|
-
trigger();
|
723
|
-
}
|
724
|
-
input = null;
|
725
|
-
}, 1);
|
726
|
-
|
727
|
-
}
|
728
|
-
;
|
729
|
-
|
730
|
-
clearInterval(timer);
|
731
|
-
timer = setInterval(trigger, 160);
|
732
|
-
extraTest();
|
733
|
-
input
|
734
|
-
.off({
|
735
|
-
'focusout blur': unbind,
|
736
|
-
'input change updateInput': trigger
|
737
|
-
})
|
738
|
-
.on({
|
739
|
-
'focusout blur': unbind,
|
740
|
-
'input updateInput change': trigger
|
741
|
-
})
|
742
|
-
;
|
743
|
-
}
|
744
|
-
;
|
745
|
-
if($.event.customEvent){
|
746
|
-
$.event.customEvent.updateInput = true;
|
747
|
-
}
|
748
|
-
|
749
|
-
(function(){
|
750
|
-
|
751
|
-
var correctValue = function(elem){
|
752
|
-
var i = 1;
|
753
|
-
var len = 3;
|
754
|
-
var abort, val;
|
755
|
-
if(elem.type == 'date' && (isSubmit || !$(elem).is(':focus'))){
|
756
|
-
val = elem.value;
|
757
|
-
if(val && val.length < 10 && (val = val.split('-')) && val.length == len){
|
758
|
-
for(; i < len; i++){
|
759
|
-
if(val[i].length == 1){
|
760
|
-
val[i] = '0'+val[i];
|
761
|
-
} else if(val[i].length != 2){
|
762
|
-
abort = true;
|
763
|
-
break;
|
764
|
-
}
|
765
|
-
}
|
766
|
-
if(!abort){
|
767
|
-
val = val.join('-');
|
768
|
-
$.prop(elem, 'value', val);
|
769
|
-
return val;
|
770
|
-
}
|
771
|
-
}
|
772
|
-
}
|
773
|
-
};
|
774
|
-
var inputCheckValidityDesc, formCheckValidityDesc, inputValueDesc, inputValidityDesc;
|
775
|
-
|
776
|
-
inputCheckValidityDesc = webshims.defineNodeNameProperty('input', 'checkValidity', {
|
777
|
-
prop: {
|
778
|
-
value: function(){
|
779
|
-
correctValue(this);
|
780
|
-
return inputCheckValidityDesc.prop._supvalue.apply(this, arguments);
|
781
|
-
}
|
782
|
-
}
|
783
|
-
});
|
784
|
-
|
785
|
-
formCheckValidityDesc = webshims.defineNodeNameProperty('form', 'checkValidity', {
|
786
|
-
prop: {
|
787
|
-
value: function(){
|
788
|
-
$('input', this).each(function(){
|
789
|
-
correctValue(this);
|
790
|
-
});
|
791
|
-
return formCheckValidityDesc.prop._supvalue.apply(this, arguments);
|
792
|
-
}
|
793
|
-
}
|
794
|
-
});
|
795
|
-
|
796
|
-
inputValueDesc = webshims.defineNodeNameProperty('input', 'value', {
|
797
|
-
prop: {
|
798
|
-
set: function(){
|
799
|
-
return inputValueDesc.prop._supset.apply(this, arguments);
|
800
|
-
},
|
801
|
-
get: function(){
|
802
|
-
return correctValue(this) || inputValueDesc.prop._supget.apply(this, arguments);
|
803
|
-
}
|
804
|
-
}
|
805
|
-
});
|
806
|
-
|
807
|
-
inputValidityDesc = webshims.defineNodeNameProperty('input', 'validity', {
|
808
|
-
prop: {
|
809
|
-
writeable: false,
|
810
|
-
get: function(){
|
811
|
-
correctValue(this);
|
812
|
-
return inputValidityDesc.prop._supget.apply(this, arguments);
|
813
|
-
}
|
814
|
-
}
|
815
|
-
});
|
816
|
-
|
817
|
-
$(document).on('change', function(e){
|
818
|
-
correctValue(e.target);
|
819
|
-
});
|
820
|
-
|
821
|
-
})();
|
822
|
-
|
823
|
-
$(document)
|
824
|
-
.on('focusin', function(e){
|
825
|
-
if( e.target && fixInputTypes[e.target.type] && !e.target.readOnly && !e.target.disabled ){
|
826
|
-
observe($(e.target));
|
827
|
-
}
|
828
|
-
})
|
829
|
-
;
|
830
|
-
|
831
|
-
|
832
|
-
})();
|
833
|
-
}
|
834
|
-
|
835
|
-
webshims.addReady(function(context, contextElem){
|
836
|
-
//start constrain-validation
|
837
|
-
var focusElem;
|
838
|
-
$('form', context)
|
839
|
-
.add(contextElem.filter('form'))
|
840
|
-
.bind('invalid', $.noop)
|
841
|
-
;
|
842
|
-
|
843
|
-
try {
|
844
|
-
if(context == document && !('form' in (document.activeElement || {}))) {
|
845
|
-
focusElem = $('input[autofocus], select[autofocus], textarea[autofocus]', context).eq(0).getShadowFocusElement()[0];
|
846
|
-
if (focusElem && focusElem.offsetHeight && focusElem.offsetWidth) {
|
847
|
-
focusElem.focus();
|
848
|
-
}
|
849
|
-
}
|
850
|
-
}
|
851
|
-
catch (er) {}
|
852
|
-
|
853
|
-
});
|
854
|
-
|
855
|
-
if(!Modernizr.formattribute || !Modernizr.fieldsetdisabled){
|
856
|
-
(function(){
|
857
|
-
(function(prop, undefined){
|
858
|
-
$.prop = function(elem, name, value){
|
859
|
-
var ret;
|
860
|
-
if(elem && elem.nodeType == 1 && value === undefined && $.nodeName(elem, 'form') && elem.id){
|
861
|
-
ret = document.getElementsByName(name);
|
862
|
-
if(!ret || !ret.length){
|
863
|
-
ret = document.getElementById(name);
|
864
|
-
}
|
865
|
-
if(ret){
|
866
|
-
ret = $(ret).filter(function(){
|
867
|
-
return $.prop(this, 'form') == elem;
|
868
|
-
}).get();
|
869
|
-
if(ret.length){
|
870
|
-
return ret.length == 1 ? ret[0] : ret;
|
871
|
-
}
|
872
|
-
}
|
873
|
-
}
|
874
|
-
return prop.apply(this, arguments);
|
875
|
-
};
|
876
|
-
})($.prop, undefined);
|
877
|
-
var removeAddedElements = function(form){
|
878
|
-
var elements = $.data(form, 'webshimsAddedElements');
|
879
|
-
if(elements){
|
880
|
-
elements.remove();
|
881
|
-
$.removeData(form, 'webshimsAddedElements');
|
882
|
-
}
|
883
|
-
};
|
884
|
-
var rCRLF = /\r?\n/g,
|
885
|
-
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
886
|
-
rselectTextarea = /^(?:select|textarea)/i;
|
887
|
-
|
888
|
-
if(!Modernizr.formattribute){
|
889
|
-
webshims.defineNodeNamesProperty(['input', 'textarea', 'select', 'button', 'fieldset'], 'form', {
|
890
|
-
prop: {
|
891
|
-
get: function(){
|
892
|
-
var form = webshims.contentAttr(this, 'form');
|
893
|
-
if(form){
|
894
|
-
form = document.getElementById(form);
|
895
|
-
if(form && !$.nodeName(form, 'form')){
|
896
|
-
form = null;
|
897
|
-
}
|
898
|
-
}
|
899
|
-
return form || this.form;
|
900
|
-
},
|
901
|
-
writeable: false
|
902
|
-
}
|
903
|
-
});
|
904
|
-
|
905
|
-
|
906
|
-
webshims.defineNodeNamesProperty(['form'], 'elements', {
|
907
|
-
prop: {
|
908
|
-
get: function(){
|
909
|
-
var id = this.id;
|
910
|
-
var elements = $.makeArray(this.elements);
|
911
|
-
if(id){
|
912
|
-
elements = $(elements).add('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"], button[form="'+ id +'"], fieldset[form="'+ id +'"]').not('.webshims-visual-hide > *').get();
|
913
|
-
}
|
914
|
-
return elements;
|
915
|
-
},
|
916
|
-
writeable: false
|
917
|
-
}
|
918
|
-
});
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
$(function(){
|
923
|
-
var stopPropagation = function(e){
|
924
|
-
e.stopPropagation();
|
925
|
-
};
|
926
|
-
$(document).on('submit', function(e){
|
927
|
-
|
928
|
-
if(!e.isDefaultPrevented()){
|
929
|
-
var form = e.target;
|
930
|
-
var id = form.id;
|
931
|
-
var elements;
|
932
|
-
|
933
|
-
|
934
|
-
if(id){
|
935
|
-
removeAddedElements(form);
|
936
|
-
|
937
|
-
elements = $('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"]')
|
938
|
-
.filter(function(){
|
939
|
-
return !this.disabled && this.name && this.form != form;
|
940
|
-
})
|
941
|
-
.clone()
|
942
|
-
;
|
943
|
-
if(elements.length){
|
944
|
-
$.data(form, 'webshimsAddedElements', $('<div class="webshims-visual-hide" />').append(elements).appendTo(form));
|
945
|
-
setTimeout(function(){
|
946
|
-
removeAddedElements(form);
|
947
|
-
}, 9);
|
948
|
-
}
|
949
|
-
elements = null;
|
950
|
-
}
|
951
|
-
}
|
952
|
-
});
|
953
|
-
|
954
|
-
$(document).on('click', function(e){
|
955
|
-
if(!e.isDefaultPrevented() && $(e.target).is('input[type="submit"][form], button[form], input[type="button"][form], input[type="image"][form], input[type="reset"][form]')){
|
956
|
-
var trueForm = $.prop(e.target, 'form');
|
957
|
-
var formIn = e.target.form;
|
958
|
-
var clone;
|
959
|
-
if(trueForm && trueForm != formIn){
|
960
|
-
clone = $(e.target)
|
961
|
-
.clone()
|
962
|
-
.removeAttr('form')
|
963
|
-
.addClass('webshims-visual-hide')
|
964
|
-
.on('click', stopPropagation)
|
965
|
-
.appendTo(trueForm)
|
966
|
-
;
|
967
|
-
if(formIn){
|
968
|
-
e.preventDefault();
|
969
|
-
}
|
970
|
-
addSubmitBubbles(trueForm);
|
971
|
-
clone.trigger('click');
|
972
|
-
setTimeout(function(){
|
973
|
-
clone.remove();
|
974
|
-
clone = null;
|
975
|
-
}, 9);
|
976
|
-
}
|
977
|
-
}
|
978
|
-
});
|
979
|
-
});
|
980
|
-
}
|
981
|
-
|
982
|
-
if(!Modernizr.fieldsetdisabled){
|
983
|
-
webshims.defineNodeNamesProperty(['fieldset'], 'elements', {
|
984
|
-
prop: {
|
985
|
-
get: function(){
|
986
|
-
//add listed elements without keygen, object, output
|
987
|
-
return $('input, select, textarea, button, fieldset', this).get() || [];
|
988
|
-
},
|
989
|
-
writeable: false
|
990
|
-
}
|
991
|
-
});
|
992
|
-
}
|
993
|
-
|
994
|
-
$.fn.serializeArray = function() {
|
995
|
-
return this.map(function(){
|
996
|
-
var elements = $.prop(this, 'elements');
|
997
|
-
return elements ? $.makeArray( elements ) : this;
|
998
|
-
})
|
999
|
-
.filter(function(){
|
1000
|
-
return this.name && !this.disabled &&
|
1001
|
-
( this.checked || rselectTextarea.test( this.nodeName ) ||
|
1002
|
-
rinput.test( this.type ) );
|
1003
|
-
})
|
1004
|
-
.map(function( i, elem ){
|
1005
|
-
var val = $( this ).val();
|
1006
|
-
|
1007
|
-
return val == null ?
|
1008
|
-
null :
|
1009
|
-
$.isArray( val ) ?
|
1010
|
-
$.map( val, function( val, i ){
|
1011
|
-
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
1012
|
-
}) :
|
1013
|
-
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
1014
|
-
}).get();
|
1015
|
-
};
|
1016
|
-
|
1017
|
-
})();
|
1018
|
-
}
|
1019
|
-
|
1020
|
-
try {
|
1021
|
-
document.querySelector(':checked');
|
1022
|
-
} catch(er){
|
1023
|
-
(function(){
|
1024
|
-
var checkInputs = {
|
1025
|
-
radio: 1,
|
1026
|
-
checkbox: 1
|
1027
|
-
};
|
1028
|
-
var selectChange = function(){
|
1029
|
-
var options = this.options || [];
|
1030
|
-
var i, len, option;
|
1031
|
-
for(i = 0, len = options.length; i < len; i++){
|
1032
|
-
option = $(options[i]);
|
1033
|
-
option[$.prop(options[i], 'selected') ? 'addClass' : 'removeClass']('prop-checked');
|
1034
|
-
}
|
1035
|
-
};
|
1036
|
-
var checkChange = function(){
|
1037
|
-
var fn = $.prop(this, 'checked') ? 'addClass' : 'removeClass';
|
1038
|
-
var className = this.className || '';
|
1039
|
-
var parent;
|
1040
|
-
|
1041
|
-
//IE8- has problems to update styles, we help
|
1042
|
-
if( (className.indexOf('prop-checked') == -1) == (fn == 'addClass')){
|
1043
|
-
$(this)[fn]('prop-checked');
|
1044
|
-
if((parent = this.parentNode)){
|
1045
|
-
parent.className = parent.className;
|
1046
|
-
}
|
1047
|
-
}
|
1048
|
-
};
|
1049
|
-
|
1050
|
-
|
1051
|
-
webshims.onNodeNamesPropertyModify('select', 'value', selectChange);
|
1052
|
-
webshims.onNodeNamesPropertyModify('select', 'selectedIndex', selectChange);
|
1053
|
-
webshims.onNodeNamesPropertyModify('option', 'selected', function(){
|
1054
|
-
$(this).closest('select').each(selectChange);
|
1055
|
-
});
|
1056
|
-
webshims.onNodeNamesPropertyModify('input', 'checked', function(value, boolVal){
|
1057
|
-
var type = this.type;
|
1058
|
-
if(type == 'radio' && boolVal){
|
1059
|
-
webshims.modules["form-core"].getGroupElements(this).each(checkChange);
|
1060
|
-
} else if(checkInputs[type]) {
|
1061
|
-
$(this).each(checkChange);
|
1062
|
-
}
|
1063
|
-
});
|
1064
|
-
|
1065
|
-
$(document).on('change', function(e){
|
1066
|
-
|
1067
|
-
if(checkInputs[e.target.type]){
|
1068
|
-
if(e.target.type == 'radio'){
|
1069
|
-
webshims.modules["form-core"].getGroupElements(e.target).each(checkChange);
|
1070
|
-
} else {
|
1071
|
-
$(e.target)[$.prop(e.target, 'checked') ? 'addClass' : 'removeClass']('prop-checked');
|
1072
|
-
}
|
1073
|
-
} else if(e.target.nodeName.toLowerCase() == 'select'){
|
1074
|
-
$(e.target).each(selectChange);
|
1075
|
-
}
|
1076
|
-
});
|
1077
|
-
|
1078
|
-
webshims.addReady(function(context, contextElem){
|
1079
|
-
$('option, input', context)
|
1080
|
-
.add(contextElem.filter('option, input'))
|
1081
|
-
.each(function(){
|
1082
|
-
var prop;
|
1083
|
-
if(checkInputs[this.type]){
|
1084
|
-
prop = 'checked';
|
1085
|
-
} else if(this.nodeName.toLowerCase() == 'option'){
|
1086
|
-
prop = 'selected';
|
1087
|
-
}
|
1088
|
-
if(prop){
|
1089
|
-
$(this)[$.prop(this, prop) ? 'addClass' : 'removeClass']('prop-checked');
|
1090
|
-
}
|
1091
|
-
|
1092
|
-
})
|
1093
|
-
;
|
1094
|
-
});
|
1095
|
-
})();
|
1096
|
-
}
|
1097
|
-
|
1098
|
-
(function(){
|
1099
|
-
Modernizr.textareaPlaceholder = !!('placeholder' in $('<textarea />')[0]);
|
1100
|
-
var bustedTextarea = $.browser.webkit && Modernizr.textareaPlaceholder && webshims.browserVersion < 535;
|
1101
|
-
if(Modernizr.input.placeholder && Modernizr.textareaPlaceholder && !bustedTextarea){return;}
|
1102
|
-
|
1103
|
-
var isOver = (webshims.cfg.forms.placeholderType == 'over');
|
1104
|
-
var isResponsive = (webshims.cfg.forms.responsivePlaceholder);
|
1105
|
-
var polyfillElements = ['textarea'];
|
1106
|
-
if(!Modernizr.input.placeholder){
|
1107
|
-
polyfillElements.push('input');
|
1108
|
-
}
|
1109
|
-
|
1110
|
-
var setSelection = function(elem){
|
1111
|
-
try {
|
1112
|
-
if(elem.setSelectionRange){
|
1113
|
-
elem.setSelectionRange(0, 0);
|
1114
|
-
return true;
|
1115
|
-
} else if(elem.createTextRange){
|
1116
|
-
var range = elem.createTextRange();
|
1117
|
-
range.collapse(true);
|
1118
|
-
range.moveEnd('character', 0);
|
1119
|
-
range.moveStart('character', 0);
|
1120
|
-
range.select();
|
1121
|
-
return true;
|
1122
|
-
}
|
1123
|
-
} catch(er){}
|
1124
|
-
};
|
1125
|
-
|
1126
|
-
var hidePlaceholder = function(elem, data, value, _onFocus){
|
1127
|
-
if(value === false){
|
1128
|
-
value = $.prop(elem, 'value');
|
1129
|
-
}
|
1130
|
-
if(!isOver && elem.type != 'password'){
|
1131
|
-
if(!value && _onFocus && setSelection(elem)){
|
1132
|
-
var selectTimer = setTimeout(function(){
|
1133
|
-
setSelection(elem);
|
1134
|
-
}, 9);
|
1135
|
-
$(elem)
|
1136
|
-
.off('.placeholderremove')
|
1137
|
-
.on({
|
1138
|
-
'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
|
1139
|
-
if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
|
1140
|
-
elem.value = $.prop(elem, 'value');
|
1141
|
-
data.box.removeClass('placeholder-visible');
|
1142
|
-
clearTimeout(selectTimer);
|
1143
|
-
$(elem).unbind('.placeholderremove');
|
1144
|
-
},
|
1145
|
-
'mousedown.placeholderremove drag.placeholderremove select.placeholderremove': function(e){
|
1146
|
-
setSelection(elem);
|
1147
|
-
clearTimeout(selectTimer);
|
1148
|
-
selectTimer = setTimeout(function(){
|
1149
|
-
setSelection(elem);
|
1150
|
-
}, 9);
|
1151
|
-
},
|
1152
|
-
'blur.placeholderremove': function(){
|
1153
|
-
clearTimeout(selectTimer);
|
1154
|
-
$(elem).unbind('.placeholderremove');
|
1155
|
-
}
|
1156
|
-
})
|
1157
|
-
;
|
1158
|
-
return;
|
1159
|
-
}
|
1160
|
-
elem.value = value;
|
1161
|
-
} else if(!value && _onFocus){
|
1162
|
-
$(elem)
|
1163
|
-
.off('.placeholderremove')
|
1164
|
-
.on({
|
1165
|
-
'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
|
1166
|
-
if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
|
1167
|
-
data.box.removeClass('placeholder-visible');
|
1168
|
-
$(elem).unbind('.placeholderremove');
|
1169
|
-
},
|
1170
|
-
'blur.placeholderremove': function(){
|
1171
|
-
$(elem).unbind('.placeholderremove');
|
1172
|
-
}
|
1173
|
-
})
|
1174
|
-
;
|
1175
|
-
return;
|
1176
|
-
}
|
1177
|
-
data.box.removeClass('placeholder-visible');
|
1178
|
-
},
|
1179
|
-
showPlaceholder = function(elem, data, placeholderTxt){
|
1180
|
-
if(placeholderTxt === false){
|
1181
|
-
placeholderTxt = $.prop(elem, 'placeholder');
|
1182
|
-
}
|
1183
|
-
|
1184
|
-
if(!isOver && elem.type != 'password'){
|
1185
|
-
elem.value = placeholderTxt;
|
1186
|
-
}
|
1187
|
-
data.box.addClass('placeholder-visible');
|
1188
|
-
},
|
1189
|
-
changePlaceholderVisibility = function(elem, value, placeholderTxt, data, type){
|
1190
|
-
if(!data){
|
1191
|
-
data = $.data(elem, 'placeHolder');
|
1192
|
-
if(!data){return;}
|
1193
|
-
}
|
1194
|
-
$(elem).unbind('.placeholderremove');
|
1195
|
-
if(type == 'focus' || (!type && $(elem).is(':focus'))){
|
1196
|
-
if(elem.type == 'password' || isOver || $(elem).hasClass('placeholder-visible')){
|
1197
|
-
hidePlaceholder(elem, data, '', true);
|
1198
|
-
}
|
1199
|
-
return;
|
1200
|
-
}
|
1201
|
-
if(value === false){
|
1202
|
-
value = $.prop(elem, 'value');
|
1203
|
-
}
|
1204
|
-
if(value){
|
1205
|
-
hidePlaceholder(elem, data, value);
|
1206
|
-
return;
|
1207
|
-
}
|
1208
|
-
if(placeholderTxt === false){
|
1209
|
-
placeholderTxt = $.attr(elem, 'placeholder') || '';
|
1210
|
-
}
|
1211
|
-
if(placeholderTxt && !value){
|
1212
|
-
showPlaceholder(elem, data, placeholderTxt);
|
1213
|
-
} else {
|
1214
|
-
hidePlaceholder(elem, data, value);
|
1215
|
-
}
|
1216
|
-
},
|
1217
|
-
createPlaceholder = function(elem){
|
1218
|
-
elem = $(elem);
|
1219
|
-
var id = elem.prop('id'),
|
1220
|
-
hasLabel = !!(elem.prop('title') || elem.attr('aria-labelledby'))
|
1221
|
-
;
|
1222
|
-
if(!hasLabel && id){
|
1223
|
-
hasLabel = !!( $('label[for="'+ id +'"]', elem[0].form)[0] );
|
1224
|
-
}
|
1225
|
-
if(!hasLabel){
|
1226
|
-
if(!id){
|
1227
|
-
id = $.webshims.getID(elem);
|
1228
|
-
}
|
1229
|
-
hasLabel = !!($('label #'+ id)[0]);
|
1230
|
-
}
|
1231
|
-
return $( hasLabel ? '<span class="placeholder-text"></span>' : '<label for="'+ id +'" class="placeholder-text"></label>');
|
1232
|
-
},
|
1233
|
-
pHolder = (function(){
|
1234
|
-
var delReg = /\n|\r|\f|\t/g,
|
1235
|
-
allowedPlaceholder = {
|
1236
|
-
text: 1,
|
1237
|
-
search: 1,
|
1238
|
-
url: 1,
|
1239
|
-
email: 1,
|
1240
|
-
password: 1,
|
1241
|
-
tel: 1,
|
1242
|
-
number: 1
|
1243
|
-
}
|
1244
|
-
;
|
1245
|
-
|
1246
|
-
return {
|
1247
|
-
create: function(elem){
|
1248
|
-
var data = $.data(elem, 'placeHolder');
|
1249
|
-
var form;
|
1250
|
-
var responsiveElem;
|
1251
|
-
if(data){return data;}
|
1252
|
-
data = $.data(elem, 'placeHolder', {});
|
1253
|
-
|
1254
|
-
$(elem).on('focus.placeholder blur.placeholder', function(e){
|
1255
|
-
changePlaceholderVisibility(this, false, false, data, e.type );
|
1256
|
-
data.box[e.type == 'focus' ? 'addClass' : 'removeClass']('placeholder-focused');
|
1257
|
-
});
|
1258
|
-
|
1259
|
-
if((form = $.prop(elem, 'form'))){
|
1260
|
-
$(form).on('reset.placeholder', function(e){
|
1261
|
-
setTimeout(function(){
|
1262
|
-
changePlaceholderVisibility(elem, false, false, data, e.type );
|
1263
|
-
}, 0);
|
1264
|
-
});
|
1265
|
-
}
|
1266
|
-
|
1267
|
-
if(elem.type == 'password' || isOver){
|
1268
|
-
data.text = createPlaceholder(elem);
|
1269
|
-
if(isResponsive || $(elem).is('.responsive-width') || (elem.currentStyle || {width: ''}).width.indexOf('%') != -1){
|
1270
|
-
responsiveElem = true;
|
1271
|
-
data.box = data.text;
|
1272
|
-
} else {
|
1273
|
-
data.box = $(elem)
|
1274
|
-
.wrap('<span class="placeholder-box placeholder-box-'+ (elem.nodeName || '').toLowerCase() +' placeholder-box-'+$.css(elem, 'float')+'" />')
|
1275
|
-
.parent()
|
1276
|
-
;
|
1277
|
-
}
|
1278
|
-
data.text
|
1279
|
-
.insertAfter(elem)
|
1280
|
-
.on('mousedown.placeholder', function(){
|
1281
|
-
changePlaceholderVisibility(this, false, false, data, 'focus');
|
1282
|
-
try {
|
1283
|
-
setTimeout(function(){
|
1284
|
-
elem.focus();
|
1285
|
-
}, 0);
|
1286
|
-
} catch(e){}
|
1287
|
-
return false;
|
1288
|
-
})
|
1289
|
-
;
|
1290
|
-
|
1291
|
-
|
1292
|
-
$.each(['lineHeight', 'fontSize', 'fontFamily', 'fontWeight'], function(i, style){
|
1293
|
-
var prop = $.css(elem, style);
|
1294
|
-
if(data.text.css(style) != prop){
|
1295
|
-
data.text.css(style, prop);
|
1296
|
-
}
|
1297
|
-
});
|
1298
|
-
$.each(['Left', 'Top'], function(i, side){
|
1299
|
-
var size = (parseInt($.css(elem, 'padding'+ side), 10) || 0) + Math.max((parseInt($.css(elem, 'margin'+ side), 10) || 0), 0) + (parseInt($.css(elem, 'border'+ side +'Width'), 10) || 0);
|
1300
|
-
data.text.css('padding'+ side, size);
|
1301
|
-
});
|
1302
|
-
|
1303
|
-
$(elem)
|
1304
|
-
.on('updateshadowdom', function(){
|
1305
|
-
var height, width;
|
1306
|
-
if((width = elem.offsetWidth) || (height = elem.offsetHeight)){
|
1307
|
-
data.text
|
1308
|
-
.css({
|
1309
|
-
width: width,
|
1310
|
-
height: height
|
1311
|
-
})
|
1312
|
-
.css($(elem).position())
|
1313
|
-
;
|
1314
|
-
}
|
1315
|
-
})
|
1316
|
-
.triggerHandler('updateshadowdom')
|
1317
|
-
;
|
1318
|
-
|
1319
|
-
} else {
|
1320
|
-
var reset = function(e){
|
1321
|
-
if($(elem).hasClass('placeholder-visible')){
|
1322
|
-
hidePlaceholder(elem, data, '');
|
1323
|
-
if(e && e.type == 'submit'){
|
1324
|
-
setTimeout(function(){
|
1325
|
-
if(e.isDefaultPrevented()){
|
1326
|
-
changePlaceholderVisibility(elem, false, false, data );
|
1327
|
-
}
|
1328
|
-
}, 9);
|
1329
|
-
}
|
1330
|
-
}
|
1331
|
-
};
|
1332
|
-
|
1333
|
-
$(window).on('beforeunload', reset);
|
1334
|
-
data.box = $(elem);
|
1335
|
-
if(form){
|
1336
|
-
$(form).submit(reset);
|
1337
|
-
}
|
1338
|
-
}
|
1339
|
-
|
1340
|
-
return data;
|
1341
|
-
},
|
1342
|
-
update: function(elem, val){
|
1343
|
-
var type = ($.attr(elem, 'type') || $.prop(elem, 'type') || '').toLowerCase();
|
1344
|
-
if(!allowedPlaceholder[type] && !$.nodeName(elem, 'textarea')){
|
1345
|
-
webshims.error('placeholder not allowed on input[type="'+type+'"]');
|
1346
|
-
if(type == 'date'){
|
1347
|
-
webshims.error('but you can use data-placeholder for input[type="date"]');
|
1348
|
-
}
|
1349
|
-
return;
|
1350
|
-
}
|
1351
|
-
|
1352
|
-
|
1353
|
-
var data = pHolder.create(elem);
|
1354
|
-
if(data.text){
|
1355
|
-
data.text.text(val);
|
1356
|
-
}
|
1357
|
-
|
1358
|
-
changePlaceholderVisibility(elem, false, val, data);
|
1359
|
-
}
|
1360
|
-
};
|
1361
|
-
})()
|
1362
|
-
;
|
1363
|
-
|
1364
|
-
$.webshims.publicMethods = {
|
1365
|
-
pHolder: pHolder
|
1366
|
-
};
|
1367
|
-
polyfillElements.forEach(function(nodeName){
|
1368
|
-
var desc = webshims.defineNodeNameProperty(nodeName, 'placeholder', {
|
1369
|
-
attr: {
|
1370
|
-
set: function(val){
|
1371
|
-
var elem = this;
|
1372
|
-
if(bustedTextarea){
|
1373
|
-
webshims.data(elem, 'textareaPlaceholder', val);
|
1374
|
-
elem.placeholder = '';
|
1375
|
-
} else {
|
1376
|
-
webshims.contentAttr(elem, 'placeholder', val);
|
1377
|
-
}
|
1378
|
-
pHolder.update(elem, val);
|
1379
|
-
},
|
1380
|
-
get: function(){
|
1381
|
-
var ret = (bustedTextarea) ? webshims.data(this, 'textareaPlaceholder') : '';
|
1382
|
-
return ret || webshims.contentAttr(this, 'placeholder');
|
1383
|
-
}
|
1384
|
-
},
|
1385
|
-
reflect: true,
|
1386
|
-
initAttr: true
|
1387
|
-
});
|
1388
|
-
});
|
1389
|
-
|
1390
|
-
|
1391
|
-
polyfillElements.forEach(function(name){
|
1392
|
-
var placeholderValueDesc = {};
|
1393
|
-
var desc;
|
1394
|
-
['attr', 'prop'].forEach(function(propType){
|
1395
|
-
placeholderValueDesc[propType] = {
|
1396
|
-
set: function(val){
|
1397
|
-
var elem = this;
|
1398
|
-
var placeholder;
|
1399
|
-
if(bustedTextarea){
|
1400
|
-
placeholder = webshims.data(elem, 'textareaPlaceholder');
|
1401
|
-
}
|
1402
|
-
if(!placeholder){
|
1403
|
-
placeholder = webshims.contentAttr(elem, 'placeholder');
|
1404
|
-
}
|
1405
|
-
$.removeData(elem, 'cachedValidity');
|
1406
|
-
var ret = desc[propType]._supset.call(elem, val);
|
1407
|
-
if(placeholder && 'value' in elem){
|
1408
|
-
changePlaceholderVisibility(elem, val, placeholder);
|
1409
|
-
}
|
1410
|
-
return ret;
|
1411
|
-
},
|
1412
|
-
get: function(){
|
1413
|
-
var elem = this;
|
1414
|
-
return $(elem).hasClass('placeholder-visible') ? '' : desc[propType]._supget.call(elem);
|
1415
|
-
}
|
1416
|
-
};
|
1417
|
-
});
|
1418
|
-
desc = webshims.defineNodeNameProperty(name, 'value', placeholderValueDesc);
|
1419
|
-
});
|
1420
|
-
|
1421
|
-
})();
|
1422
|
-
|
1423
|
-
(function(){
|
1424
|
-
var doc = document;
|
1425
|
-
if( 'value' in document.createElement('output') ){return;}
|
1426
|
-
|
1427
|
-
webshims.defineNodeNameProperty('output', 'value', {
|
1428
|
-
prop: {
|
1429
|
-
set: function(value){
|
1430
|
-
var setVal = $.data(this, 'outputShim');
|
1431
|
-
if(!setVal){
|
1432
|
-
setVal = outputCreate(this);
|
1433
|
-
}
|
1434
|
-
setVal(value);
|
1435
|
-
},
|
1436
|
-
get: function(){
|
1437
|
-
return webshims.contentAttr(this, 'value') || $(this).text() || '';
|
1438
|
-
}
|
1439
|
-
}
|
1440
|
-
});
|
1441
|
-
|
1442
|
-
|
1443
|
-
webshims.onNodeNamesPropertyModify('input', 'value', function(value, boolVal, type){
|
1444
|
-
if(type == 'removeAttr'){return;}
|
1445
|
-
var setVal = $.data(this, 'outputShim');
|
1446
|
-
if(setVal){
|
1447
|
-
setVal(value);
|
1448
|
-
}
|
1449
|
-
});
|
1450
|
-
|
1451
|
-
var outputCreate = function(elem){
|
1452
|
-
if(elem.getAttribute('aria-live')){return;}
|
1453
|
-
elem = $(elem);
|
1454
|
-
var value = (elem.text() || '').trim();
|
1455
|
-
var id = elem.attr('id');
|
1456
|
-
var htmlFor = elem.attr('for');
|
1457
|
-
var shim = $('<input class="output-shim" type="text" disabled name="'+ (elem.attr('name') || '')+'" value="'+value+'" style="display: none !important;" />').insertAfter(elem);
|
1458
|
-
var form = shim[0].form || doc;
|
1459
|
-
var setValue = function(val){
|
1460
|
-
shim[0].value = val;
|
1461
|
-
val = shim[0].value;
|
1462
|
-
elem.text(val);
|
1463
|
-
webshims.contentAttr(elem[0], 'value', val);
|
1464
|
-
};
|
1465
|
-
|
1466
|
-
elem[0].defaultValue = value;
|
1467
|
-
webshims.contentAttr(elem[0], 'value', value);
|
1468
|
-
|
1469
|
-
elem.attr({'aria-live': 'polite'});
|
1470
|
-
if(id){
|
1471
|
-
shim.attr('id', id);
|
1472
|
-
elem.attr('aria-labelledby', webshims.getID($('label[for="'+id+'"]', form)));
|
1473
|
-
}
|
1474
|
-
if(htmlFor){
|
1475
|
-
id = webshims.getID(elem);
|
1476
|
-
htmlFor.split(' ').forEach(function(control){
|
1477
|
-
control = document.getElementById(control);
|
1478
|
-
if(control){
|
1479
|
-
control.setAttribute('aria-controls', id);
|
1480
|
-
}
|
1481
|
-
});
|
1482
|
-
}
|
1483
|
-
elem.data('outputShim', setValue );
|
1484
|
-
shim.data('outputShim', setValue );
|
1485
|
-
return setValue;
|
1486
|
-
};
|
1487
|
-
|
1488
|
-
webshims.addReady(function(context, contextElem){
|
1489
|
-
$('output', context).add(contextElem.filter('output')).each(function(){
|
1490
|
-
outputCreate(this);
|
1491
|
-
});
|
1492
|
-
});
|
1493
|
-
|
1494
|
-
/*
|
1495
|
-
* Implements input event in all browsers
|
1496
|
-
*/
|
1497
|
-
(function(){
|
1498
|
-
var noInputTriggerEvts = {updateInput: 1, input: 1},
|
1499
|
-
noInputTypes = {
|
1500
|
-
radio: 1,
|
1501
|
-
checkbox: 1,
|
1502
|
-
submit: 1,
|
1503
|
-
button: 1,
|
1504
|
-
image: 1,
|
1505
|
-
reset: 1,
|
1506
|
-
file: 1
|
1507
|
-
|
1508
|
-
//pro forma
|
1509
|
-
,color: 1
|
1510
|
-
//,range: 1
|
1511
|
-
},
|
1512
|
-
observe = function(input){
|
1513
|
-
var timer,
|
1514
|
-
lastVal = input.prop('value'),
|
1515
|
-
trigger = function(e){
|
1516
|
-
//input === null
|
1517
|
-
if(!input){return;}
|
1518
|
-
var newVal = input.prop('value');
|
1519
|
-
|
1520
|
-
if(newVal !== lastVal){
|
1521
|
-
lastVal = newVal;
|
1522
|
-
if(!e || !noInputTriggerEvts[e.type]){
|
1523
|
-
webshims.triggerInlineForm && webshims.triggerInlineForm(input[0], 'input');
|
1524
|
-
}
|
1525
|
-
}
|
1526
|
-
},
|
1527
|
-
extraTimer,
|
1528
|
-
extraTest = function(){
|
1529
|
-
clearTimeout(extraTimer);
|
1530
|
-
extraTimer = setTimeout(trigger, 9);
|
1531
|
-
},
|
1532
|
-
unbind = function(){
|
1533
|
-
input.unbind('focusout', unbind).unbind('keyup keypress keydown paste cut', extraTest).unbind('input change updateInput', trigger);
|
1534
|
-
clearInterval(timer);
|
1535
|
-
setTimeout(function(){
|
1536
|
-
trigger();
|
1537
|
-
input = null;
|
1538
|
-
}, 1);
|
1539
|
-
|
1540
|
-
}
|
1541
|
-
;
|
1542
|
-
|
1543
|
-
clearInterval(timer);
|
1544
|
-
timer = setInterval(trigger, 99);
|
1545
|
-
extraTest();
|
1546
|
-
input.on({
|
1547
|
-
'keyup keypress keydown paste cut': extraTest,
|
1548
|
-
focusout: unbind,
|
1549
|
-
'input updateInput change': trigger
|
1550
|
-
});
|
1551
|
-
}
|
1552
|
-
;
|
1553
|
-
if($.event.customEvent){
|
1554
|
-
$.event.customEvent.updateInput = true;
|
1555
|
-
}
|
1556
|
-
|
1557
|
-
$(doc)
|
1558
|
-
.on('focusin', function(e){
|
1559
|
-
if( e.target && e.target.type && !e.target.readOnly && !e.target.disabled && (e.target.nodeName || '').toLowerCase() == 'input' && !noInputTypes[e.target.type] ){
|
1560
|
-
observe($(e.target));
|
1561
|
-
}
|
1562
|
-
})
|
1563
|
-
;
|
1564
|
-
})();
|
1565
|
-
})();
|
1566
|
-
|
1567
|
-
}); //webshims.ready end
|
1568
|
-
}//end formvalidation
|
1569
|
-
|
1570
|
-
jQuery.webshims.register('form-message', function($, webshims, window, document, undefined, options){
|
1571
|
-
"use strict";
|
1572
|
-
var validityMessages = webshims.validityMessages;
|
1573
|
-
|
1574
|
-
var implementProperties = (options.overrideMessages || options.customMessages) ? ['customValidationMessage'] : [];
|
1575
|
-
|
1576
|
-
validityMessages['en'] = $.extend(true, {
|
1577
|
-
typeMismatch: {
|
1578
|
-
email: 'Please enter an email address.',
|
1579
|
-
url: 'Please enter a URL.',
|
1580
|
-
number: 'Please enter a number.',
|
1581
|
-
date: 'Please enter a date.',
|
1582
|
-
time: 'Please enter a time.',
|
1583
|
-
range: 'Invalid input.',
|
1584
|
-
"datetime-local": 'Please enter a datetime.'
|
1585
|
-
},
|
1586
|
-
rangeUnderflow: {
|
1587
|
-
defaultMessage: 'Value must be greater than or equal to {%min}.'
|
1588
|
-
},
|
1589
|
-
rangeOverflow: {
|
1590
|
-
defaultMessage: 'Value must be less than or equal to {%max}.'
|
1591
|
-
},
|
1592
|
-
stepMismatch: 'Invalid input.',
|
1593
|
-
tooLong: 'Please enter at most {%maxlength} character(s). You entered {%valueLen}.',
|
1594
|
-
|
1595
|
-
patternMismatch: 'Invalid input. {%title}',
|
1596
|
-
valueMissing: {
|
1597
|
-
defaultMessage: 'Please fill out this field.',
|
1598
|
-
checkbox: 'Please check this box if you want to proceed.'
|
1599
|
-
}
|
1600
|
-
}, (validityMessages['en'] || validityMessages['en-US'] || {}));
|
1601
|
-
|
1602
|
-
|
1603
|
-
['select', 'radio'].forEach(function(type){
|
1604
|
-
validityMessages['en'].valueMissing
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
},
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
defaultMessage: '
|
1638
|
-
|
1639
|
-
}
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
}
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1
|
+
if(!Modernizr.formvalidation || jQuery.webshims.bugs.bustedValidity){
|
2
|
+
jQuery.webshims.register('form-shim-extend', function($, webshims, window, document){
|
3
|
+
"use strict";
|
4
|
+
webshims.inputTypes = webshims.inputTypes || {};
|
5
|
+
//some helper-functions
|
6
|
+
var cfg = webshims.cfg.forms;
|
7
|
+
var isSubmit;
|
8
|
+
|
9
|
+
var isNumber = function(string){
|
10
|
+
return (typeof string == 'number' || (string && string == string * 1));
|
11
|
+
},
|
12
|
+
typeModels = webshims.inputTypes,
|
13
|
+
checkTypes = {
|
14
|
+
radio: 1,
|
15
|
+
checkbox: 1
|
16
|
+
},
|
17
|
+
getType = function(elem){
|
18
|
+
return (elem.getAttribute('type') || elem.type || '').toLowerCase();
|
19
|
+
}
|
20
|
+
;
|
21
|
+
|
22
|
+
//API to add new input types
|
23
|
+
webshims.addInputType = function(type, obj){
|
24
|
+
typeModels[type] = obj;
|
25
|
+
};
|
26
|
+
|
27
|
+
//contsrain-validation-api
|
28
|
+
var validityPrototype = {
|
29
|
+
customError: false,
|
30
|
+
|
31
|
+
typeMismatch: false,
|
32
|
+
rangeUnderflow: false,
|
33
|
+
rangeOverflow: false,
|
34
|
+
stepMismatch: false,
|
35
|
+
tooLong: false,
|
36
|
+
patternMismatch: false,
|
37
|
+
valueMissing: false,
|
38
|
+
|
39
|
+
valid: true
|
40
|
+
};
|
41
|
+
|
42
|
+
var isPlaceholderOptionSelected = function(select){
|
43
|
+
if(select.type == 'select-one' && select.size < 2){
|
44
|
+
var option = $('> option:first-child', select);
|
45
|
+
return !!option.prop('selected');
|
46
|
+
}
|
47
|
+
return false;
|
48
|
+
};
|
49
|
+
|
50
|
+
var validityRules = {
|
51
|
+
valueMissing: function(input, val, cache){
|
52
|
+
if(!input.prop('required')){return false;}
|
53
|
+
var ret = false;
|
54
|
+
if(!('type' in cache)){
|
55
|
+
cache.type = getType(input[0]);
|
56
|
+
}
|
57
|
+
if(cache.nodeName == 'select'){
|
58
|
+
ret = (!val && (input[0].selectedIndex < 0 || isPlaceholderOptionSelected(input[0]) ));
|
59
|
+
} else if(checkTypes[cache.type]){
|
60
|
+
ret = (cache.type == 'checkbox') ? !input.is(':checked') : !webshims.modules["form-core"].getGroupElements(input).filter(':checked')[0];
|
61
|
+
} else {
|
62
|
+
ret = !(val);
|
63
|
+
}
|
64
|
+
return ret;
|
65
|
+
},
|
66
|
+
tooLong: function(){
|
67
|
+
return false;
|
68
|
+
},
|
69
|
+
typeMismatch: function (input, val, cache){
|
70
|
+
if(val === '' || cache.nodeName == 'select'){return false;}
|
71
|
+
var ret = false;
|
72
|
+
if(!('type' in cache)){
|
73
|
+
cache.type = getType(input[0]);
|
74
|
+
}
|
75
|
+
|
76
|
+
if(typeModels[cache.type] && typeModels[cache.type].mismatch){
|
77
|
+
ret = typeModels[cache.type].mismatch(val, input);
|
78
|
+
} else if('validity' in input[0]){
|
79
|
+
ret = input[0].validity.typeMismatch;
|
80
|
+
}
|
81
|
+
return ret;
|
82
|
+
},
|
83
|
+
patternMismatch: function(input, val, cache) {
|
84
|
+
if(val === '' || cache.nodeName == 'select'){return false;}
|
85
|
+
var pattern = input.attr('pattern');
|
86
|
+
if(!pattern){return false;}
|
87
|
+
try {
|
88
|
+
pattern = new RegExp('^(?:' + pattern + ')$');
|
89
|
+
} catch(er){
|
90
|
+
webshims.error('invalid pattern value: "'+ pattern +'" | '+ er);
|
91
|
+
pattern = false;
|
92
|
+
}
|
93
|
+
if(!pattern){return false;}
|
94
|
+
return !(pattern.test(val));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
;
|
98
|
+
|
99
|
+
webshims.addValidityRule = function(type, fn){
|
100
|
+
validityRules[type] = fn;
|
101
|
+
};
|
102
|
+
|
103
|
+
$.event.special.invalid = {
|
104
|
+
add: function(){
|
105
|
+
$.event.special.invalid.setup.call(this.form || this);
|
106
|
+
},
|
107
|
+
setup: function(){
|
108
|
+
var form = this.form || this;
|
109
|
+
if( $.data(form, 'invalidEventShim') ){
|
110
|
+
form = null;
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
$(form)
|
114
|
+
.data('invalidEventShim', true)
|
115
|
+
.on('submit', $.event.special.invalid.handler)
|
116
|
+
;
|
117
|
+
webshims.moveToFirstEvent(form, 'submit');
|
118
|
+
if(webshims.bugs.bustedValidity && $.nodeName(form, 'form')){
|
119
|
+
(function(){
|
120
|
+
var noValidate = form.getAttribute('novalidate');
|
121
|
+
form.setAttribute('novalidate', 'novalidate');
|
122
|
+
webshims.data(form, 'bustedNoValidate', (noValidate == null) ? null : noValidate);
|
123
|
+
})();
|
124
|
+
}
|
125
|
+
form = null;
|
126
|
+
},
|
127
|
+
teardown: $.noop,
|
128
|
+
handler: function(e, d){
|
129
|
+
|
130
|
+
if( e.type != 'submit' || e.testedValidity || !e.originalEvent || !$.nodeName(e.target, 'form') || $.prop(e.target, 'noValidate') ){return;}
|
131
|
+
|
132
|
+
isSubmit = true;
|
133
|
+
e.testedValidity = true;
|
134
|
+
var notValid = !($(e.target).checkValidity());
|
135
|
+
if(notValid){
|
136
|
+
e.stopImmediatePropagation();
|
137
|
+
isSubmit = false;
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
isSubmit = false;
|
141
|
+
}
|
142
|
+
};
|
143
|
+
|
144
|
+
var addSubmitBubbles = function(form){
|
145
|
+
if (!$.support.submitBubbles && form && typeof form == 'object' && !form._submit_attached ) {
|
146
|
+
|
147
|
+
$.event.add( form, 'submit._submit', function( event ) {
|
148
|
+
event._submit_bubble = true;
|
149
|
+
});
|
150
|
+
|
151
|
+
form._submit_attached = true;
|
152
|
+
}
|
153
|
+
};
|
154
|
+
if(!$.support.submitBubbles && $.event.special.submit){
|
155
|
+
$.event.special.submit.setup = function() {
|
156
|
+
// Only need this for delegated form submit events
|
157
|
+
if ( $.nodeName( this, "form" ) ) {
|
158
|
+
return false;
|
159
|
+
}
|
160
|
+
|
161
|
+
// Lazy-add a submit handler when a descendant form may potentially be submitted
|
162
|
+
$.event.add( this, "click._submit keypress._submit", function( e ) {
|
163
|
+
// Node name check avoids a VML-related crash in IE (#9807)
|
164
|
+
var elem = e.target,
|
165
|
+
form = $.nodeName( elem, 'input' ) || $.nodeName( elem, 'button' ) ? $.prop(elem, 'form') : undefined;
|
166
|
+
addSubmitBubbles(form);
|
167
|
+
|
168
|
+
});
|
169
|
+
// return undefined since we don't need an event listener
|
170
|
+
};
|
171
|
+
}
|
172
|
+
|
173
|
+
$.event.special.submit = $.event.special.submit || {setup: function(){return false;}};
|
174
|
+
var submitSetup = $.event.special.submit.setup;
|
175
|
+
$.extend($.event.special.submit, {
|
176
|
+
setup: function(){
|
177
|
+
if($.nodeName(this, 'form')){
|
178
|
+
$(this).on('invalid', $.noop);
|
179
|
+
} else {
|
180
|
+
$('form', this).on('invalid', $.noop);
|
181
|
+
}
|
182
|
+
return submitSetup.apply(this, arguments);
|
183
|
+
}
|
184
|
+
});
|
185
|
+
|
186
|
+
$(window).on('invalid', $.noop);
|
187
|
+
|
188
|
+
|
189
|
+
webshims.addInputType('email', {
|
190
|
+
mismatch: (function(){
|
191
|
+
//taken from http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
|
192
|
+
var test = cfg.emailReg || /^[a-zA-Z0-9.!#$%&'*+-\/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
193
|
+
return function(val){
|
194
|
+
return !test.test(val);
|
195
|
+
};
|
196
|
+
})()
|
197
|
+
});
|
198
|
+
|
199
|
+
webshims.addInputType('url', {
|
200
|
+
mismatch: (function(){
|
201
|
+
//taken from scott gonzales
|
202
|
+
var test = cfg.urlReg || /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
|
203
|
+
return function(val){
|
204
|
+
return !test.test(val);
|
205
|
+
};
|
206
|
+
})()
|
207
|
+
});
|
208
|
+
|
209
|
+
webshims.defineNodeNameProperty('input', 'type', {
|
210
|
+
prop: {
|
211
|
+
get: function(){
|
212
|
+
var elem = this;
|
213
|
+
var type = (elem.getAttribute('type') || '').toLowerCase();
|
214
|
+
return (webshims.inputTypes[type]) ? type : elem.type;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
});
|
218
|
+
|
219
|
+
// IDLs for constrain validation API
|
220
|
+
//ToDo: add object to this list
|
221
|
+
webshims.defineNodeNamesProperties(['button', 'fieldset', 'output'], {
|
222
|
+
checkValidity: {
|
223
|
+
value: function(){return true;}
|
224
|
+
},
|
225
|
+
willValidate: {
|
226
|
+
value: false
|
227
|
+
},
|
228
|
+
setCustomValidity: {
|
229
|
+
value: $.noop
|
230
|
+
},
|
231
|
+
validity: {
|
232
|
+
writeable: false,
|
233
|
+
get: function(){
|
234
|
+
return $.extend({}, validityPrototype);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}, 'prop');
|
238
|
+
|
239
|
+
var baseCheckValidity = function(elem){
|
240
|
+
var e,
|
241
|
+
v = $.prop(elem, 'validity')
|
242
|
+
;
|
243
|
+
if(v){
|
244
|
+
$.data(elem, 'cachedValidity', v);
|
245
|
+
} else {
|
246
|
+
return true;
|
247
|
+
}
|
248
|
+
if( !v.valid ){
|
249
|
+
e = $.Event('invalid');
|
250
|
+
var jElm = $(elem).trigger(e);
|
251
|
+
if(isSubmit && !baseCheckValidity.unhandledInvalids && !e.isDefaultPrevented()){
|
252
|
+
webshims.validityAlert.showFor(jElm);
|
253
|
+
baseCheckValidity.unhandledInvalids = true;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
$.removeData(elem, 'cachedValidity');
|
257
|
+
return v.valid;
|
258
|
+
};
|
259
|
+
var rsubmittable = /^(?:select|textarea|input)/i;
|
260
|
+
webshims.defineNodeNameProperty('form', 'checkValidity', {
|
261
|
+
prop: {
|
262
|
+
value: function(){
|
263
|
+
|
264
|
+
var ret = true,
|
265
|
+
elems = $($.prop(this, 'elements')).filter(function(){
|
266
|
+
if(!rsubmittable.test(this.nodeName)){return false;}
|
267
|
+
var shadowData = webshims.data(this, 'shadowData');
|
268
|
+
return !shadowData || !shadowData.nativeElement || shadowData.nativeElement === this;
|
269
|
+
})
|
270
|
+
;
|
271
|
+
|
272
|
+
baseCheckValidity.unhandledInvalids = false;
|
273
|
+
for(var i = 0, len = elems.length; i < len; i++){
|
274
|
+
if( !baseCheckValidity(elems[i]) ){
|
275
|
+
ret = false;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
return ret;
|
279
|
+
}
|
280
|
+
}
|
281
|
+
});
|
282
|
+
|
283
|
+
webshims.defineNodeNamesProperties(['input', 'textarea', 'select'], {
|
284
|
+
checkValidity: {
|
285
|
+
value: function(){
|
286
|
+
baseCheckValidity.unhandledInvalids = false;
|
287
|
+
return baseCheckValidity($(this).getNativeElement()[0]);
|
288
|
+
}
|
289
|
+
},
|
290
|
+
setCustomValidity: {
|
291
|
+
value: function(error){
|
292
|
+
$.removeData(this, 'cachedValidity');
|
293
|
+
webshims.data(this, 'customvalidationMessage', ''+error);
|
294
|
+
}
|
295
|
+
},
|
296
|
+
willValidate: {
|
297
|
+
writeable: false,
|
298
|
+
get: (function(){
|
299
|
+
var types = {
|
300
|
+
button: 1,
|
301
|
+
reset: 1,
|
302
|
+
hidden: 1,
|
303
|
+
image: 1
|
304
|
+
}
|
305
|
+
;
|
306
|
+
return function(){
|
307
|
+
var elem = $(this).getNativeElement()[0];
|
308
|
+
//elem.name && <- we don't use to make it easier for developers
|
309
|
+
return !!(!elem.disabled && !elem.readOnly && !types[elem.type] );
|
310
|
+
};
|
311
|
+
})()
|
312
|
+
},
|
313
|
+
validity: {
|
314
|
+
writeable: false,
|
315
|
+
get: function(){
|
316
|
+
var jElm = $(this).getNativeElement();
|
317
|
+
var elem = jElm[0];
|
318
|
+
var validityState = $.data(elem, 'cachedValidity');
|
319
|
+
if(validityState){
|
320
|
+
return validityState;
|
321
|
+
}
|
322
|
+
validityState = $.extend({}, validityPrototype);
|
323
|
+
|
324
|
+
if( !$.prop(elem, 'willValidate') || elem.type == 'submit' ){
|
325
|
+
return validityState;
|
326
|
+
}
|
327
|
+
var val = jElm.val(),
|
328
|
+
cache = {nodeName: elem.nodeName.toLowerCase()}
|
329
|
+
;
|
330
|
+
|
331
|
+
validityState.customError = !!(webshims.data(elem, 'customvalidationMessage'));
|
332
|
+
if( validityState.customError ){
|
333
|
+
validityState.valid = false;
|
334
|
+
}
|
335
|
+
|
336
|
+
$.each(validityRules, function(rule, fn){
|
337
|
+
if (fn(jElm, val, cache)) {
|
338
|
+
validityState[rule] = true;
|
339
|
+
validityState.valid = false;
|
340
|
+
}
|
341
|
+
});
|
342
|
+
$(this).getShadowFocusElement().attr('aria-invalid', validityState.valid ? 'false' : 'true');
|
343
|
+
jElm = null;
|
344
|
+
elem = null;
|
345
|
+
return validityState;
|
346
|
+
}
|
347
|
+
}
|
348
|
+
}, 'prop');
|
349
|
+
|
350
|
+
webshims.defineNodeNamesBooleanProperty(['input', 'textarea', 'select'], 'required', {
|
351
|
+
set: function(value){
|
352
|
+
$(this).getShadowFocusElement().attr('aria-required', !!(value)+'');
|
353
|
+
},
|
354
|
+
initAttr: (!$.browser.msie || webshims.browserVersion > 7)//only if we have aria-support
|
355
|
+
});
|
356
|
+
|
357
|
+
webshims.reflectProperties(['input'], ['pattern']);
|
358
|
+
|
359
|
+
|
360
|
+
if( !('maxLength' in document.createElement('textarea')) ){
|
361
|
+
var constrainMaxLength = (function(){
|
362
|
+
var timer;
|
363
|
+
var curLength = 0;
|
364
|
+
var lastElement = $([]);
|
365
|
+
var max = 1e9;
|
366
|
+
var constrainLength = function(){
|
367
|
+
var nowValue = lastElement.prop('value');
|
368
|
+
var nowLen = nowValue.length;
|
369
|
+
if(nowLen > curLength && nowLen > max){
|
370
|
+
nowLen = Math.max(curLength, max);
|
371
|
+
lastElement.prop('value', nowValue.substr(0, nowLen ));
|
372
|
+
}
|
373
|
+
curLength = nowLen;
|
374
|
+
};
|
375
|
+
var remove = function(){
|
376
|
+
clearTimeout(timer);
|
377
|
+
lastElement.unbind('.maxlengthconstraint');
|
378
|
+
};
|
379
|
+
return function(element, maxLength){
|
380
|
+
remove();
|
381
|
+
if(maxLength > -1){
|
382
|
+
max = maxLength;
|
383
|
+
curLength = $.prop(element, 'value').length;
|
384
|
+
lastElement = $(element);
|
385
|
+
lastElement.on({
|
386
|
+
'keydown.maxlengthconstraint keypress.maxlengthconstraint paste.maxlengthconstraint cut.maxlengthconstraint': function(e){
|
387
|
+
setTimeout(constrainLength, 0);
|
388
|
+
},
|
389
|
+
'keyup.maxlengthconstraint': constrainLength,
|
390
|
+
'blur.maxlengthconstraint': remove
|
391
|
+
});
|
392
|
+
timer = setInterval(constrainLength, 200);
|
393
|
+
}
|
394
|
+
};
|
395
|
+
})();
|
396
|
+
|
397
|
+
constrainMaxLength.update = function(element, maxLength){
|
398
|
+
if($(element).is(':focus')){
|
399
|
+
if(!maxLength){
|
400
|
+
maxLength = $.prop(element, 'maxlength');
|
401
|
+
}
|
402
|
+
constrainMaxLength(element, maxLength);
|
403
|
+
}
|
404
|
+
};
|
405
|
+
|
406
|
+
$(document).on('focusin', function(e){
|
407
|
+
var maxLength;
|
408
|
+
if(e.target.nodeName == "TEXTAREA" && (maxLength = $.prop(e.target, 'maxlength')) > -1){
|
409
|
+
constrainMaxLength(e.target, maxLength);
|
410
|
+
}
|
411
|
+
});
|
412
|
+
|
413
|
+
webshims.defineNodeNameProperty('textarea', 'maxlength', {
|
414
|
+
attr: {
|
415
|
+
set: function(val){
|
416
|
+
this.setAttribute('maxlength', ''+val);
|
417
|
+
constrainMaxLength.update(this);
|
418
|
+
},
|
419
|
+
get: function(){
|
420
|
+
var ret = this.getAttribute('maxlength');
|
421
|
+
return ret == null ? undefined : ret;
|
422
|
+
}
|
423
|
+
},
|
424
|
+
prop: {
|
425
|
+
set: function(val){
|
426
|
+
if(isNumber(val)){
|
427
|
+
if(val < 0){
|
428
|
+
throw('INDEX_SIZE_ERR');
|
429
|
+
}
|
430
|
+
val = parseInt(val, 10);
|
431
|
+
this.setAttribute('maxlength', val);
|
432
|
+
constrainMaxLength.update(this, val);
|
433
|
+
return;
|
434
|
+
}
|
435
|
+
this.setAttribute('maxlength', '0');
|
436
|
+
constrainMaxLength.update(this, 0);
|
437
|
+
},
|
438
|
+
get: function(){
|
439
|
+
var val = this.getAttribute('maxlength');
|
440
|
+
return (isNumber(val) && val >= 0) ? parseInt(val, 10) : -1;
|
441
|
+
|
442
|
+
}
|
443
|
+
}
|
444
|
+
});
|
445
|
+
webshims.defineNodeNameProperty('textarea', 'maxLength', {
|
446
|
+
prop: {
|
447
|
+
set: function(val){
|
448
|
+
$.prop(this, 'maxlength', val);
|
449
|
+
},
|
450
|
+
get: function(){
|
451
|
+
return $.prop(this, 'maxlength');
|
452
|
+
}
|
453
|
+
}
|
454
|
+
});
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
var submitterTypes = {submit: 1, button: 1, image: 1};
|
460
|
+
var formSubmitterDescriptors = {};
|
461
|
+
[
|
462
|
+
{
|
463
|
+
name: "enctype",
|
464
|
+
limitedTo: {
|
465
|
+
"application/x-www-form-urlencoded": 1,
|
466
|
+
"multipart/form-data": 1,
|
467
|
+
"text/plain": 1
|
468
|
+
},
|
469
|
+
defaultProp: "application/x-www-form-urlencoded",
|
470
|
+
proptype: "enum"
|
471
|
+
},
|
472
|
+
{
|
473
|
+
name: "method",
|
474
|
+
limitedTo: {
|
475
|
+
"get": 1,
|
476
|
+
"post": 1
|
477
|
+
},
|
478
|
+
defaultProp: "get",
|
479
|
+
proptype: "enum"
|
480
|
+
},
|
481
|
+
{
|
482
|
+
name: "action",
|
483
|
+
proptype: "url"
|
484
|
+
},
|
485
|
+
{
|
486
|
+
name: "target"
|
487
|
+
},
|
488
|
+
{
|
489
|
+
name: "novalidate",
|
490
|
+
propName: "noValidate",
|
491
|
+
proptype: "boolean"
|
492
|
+
}
|
493
|
+
].forEach(function(desc){
|
494
|
+
var propName = 'form'+ (desc.propName || desc.name).replace(/^[a-z]/, function(f){
|
495
|
+
return f.toUpperCase();
|
496
|
+
});
|
497
|
+
var attrName = 'form'+ desc.name;
|
498
|
+
var formName = desc.name;
|
499
|
+
var eventName = 'click.webshimssubmittermutate'+formName;
|
500
|
+
|
501
|
+
var changeSubmitter = function(){
|
502
|
+
var elem = this;
|
503
|
+
if( !('form' in elem) || !submitterTypes[elem.type] ){return;}
|
504
|
+
var form = $.prop(elem, 'form');
|
505
|
+
if(!form){return;}
|
506
|
+
var attr = $.attr(elem, attrName);
|
507
|
+
if(attr != null && ( !desc.limitedTo || attr.toLowerCase() === $.prop(elem, propName))){
|
508
|
+
|
509
|
+
var oldAttr = $.attr(form, formName);
|
510
|
+
|
511
|
+
$.attr(form, formName, attr);
|
512
|
+
setTimeout(function(){
|
513
|
+
if(oldAttr != null){
|
514
|
+
$.attr(form, formName, oldAttr);
|
515
|
+
} else {
|
516
|
+
try {
|
517
|
+
$(form).removeAttr(formName);
|
518
|
+
} catch(er){
|
519
|
+
form.removeAttribute(formName);
|
520
|
+
}
|
521
|
+
}
|
522
|
+
}, 9);
|
523
|
+
}
|
524
|
+
};
|
525
|
+
|
526
|
+
|
527
|
+
|
528
|
+
switch(desc.proptype) {
|
529
|
+
case "url":
|
530
|
+
var urlForm = document.createElement('form');
|
531
|
+
formSubmitterDescriptors[propName] = {
|
532
|
+
prop: {
|
533
|
+
set: function(value){
|
534
|
+
$.attr(this, attrName, value);
|
535
|
+
},
|
536
|
+
get: function(){
|
537
|
+
var value = $.attr(this, attrName);
|
538
|
+
if(value == null){return '';}
|
539
|
+
urlForm.setAttribute('action', value);
|
540
|
+
return urlForm.action;
|
541
|
+
}
|
542
|
+
}
|
543
|
+
};
|
544
|
+
break;
|
545
|
+
case "boolean":
|
546
|
+
formSubmitterDescriptors[propName] = {
|
547
|
+
prop: {
|
548
|
+
set: function(val){
|
549
|
+
val = !!val;
|
550
|
+
if(val){
|
551
|
+
$.attr(this, 'formnovalidate', 'formnovalidate');
|
552
|
+
} else {
|
553
|
+
$(this).removeAttr('formnovalidate');
|
554
|
+
}
|
555
|
+
},
|
556
|
+
get: function(){
|
557
|
+
return $.attr(this, 'formnovalidate') != null;
|
558
|
+
}
|
559
|
+
}
|
560
|
+
};
|
561
|
+
break;
|
562
|
+
case "enum":
|
563
|
+
formSubmitterDescriptors[propName] = {
|
564
|
+
prop: {
|
565
|
+
set: function(value){
|
566
|
+
$.attr(this, attrName, value);
|
567
|
+
},
|
568
|
+
get: function(){
|
569
|
+
var value = $.attr(this, attrName);
|
570
|
+
return (!value || ( (value = value.toLowerCase()) && !desc.limitedTo[value] )) ? desc.defaultProp : value;
|
571
|
+
}
|
572
|
+
}
|
573
|
+
};
|
574
|
+
break;
|
575
|
+
default:
|
576
|
+
formSubmitterDescriptors[propName] = {
|
577
|
+
prop: {
|
578
|
+
set: function(value){
|
579
|
+
$.attr(this, attrName, value);
|
580
|
+
},
|
581
|
+
get: function(){
|
582
|
+
var value = $.attr(this, attrName);
|
583
|
+
return (value != null) ? value : "";
|
584
|
+
}
|
585
|
+
}
|
586
|
+
};
|
587
|
+
}
|
588
|
+
|
589
|
+
|
590
|
+
if(!formSubmitterDescriptors[attrName]){
|
591
|
+
formSubmitterDescriptors[attrName] = {};
|
592
|
+
}
|
593
|
+
formSubmitterDescriptors[attrName].attr = {
|
594
|
+
set: function(value){
|
595
|
+
formSubmitterDescriptors[attrName].attr._supset.call(this, value);
|
596
|
+
$(this).unbind(eventName).on(eventName, changeSubmitter);
|
597
|
+
},
|
598
|
+
get: function(){
|
599
|
+
return formSubmitterDescriptors[attrName].attr._supget.call(this);
|
600
|
+
}
|
601
|
+
};
|
602
|
+
formSubmitterDescriptors[attrName].initAttr = true;
|
603
|
+
formSubmitterDescriptors[attrName].removeAttr = {
|
604
|
+
value: function(){
|
605
|
+
$(this).unbind(eventName);
|
606
|
+
formSubmitterDescriptors[attrName].removeAttr._supvalue.call(this);
|
607
|
+
}
|
608
|
+
};
|
609
|
+
});
|
610
|
+
|
611
|
+
webshims.defineNodeNamesProperties(['input', 'button'], formSubmitterDescriptors);
|
612
|
+
|
613
|
+
|
614
|
+
if(!$.support.getSetAttribute && $('<form novalidate></form>').attr('novalidate') == null){
|
615
|
+
webshims.defineNodeNameProperty('form', 'novalidate', {
|
616
|
+
attr: {
|
617
|
+
set: function(val){
|
618
|
+
this.setAttribute('novalidate', ''+val);
|
619
|
+
},
|
620
|
+
get: function(){
|
621
|
+
var ret = this.getAttribute('novalidate');
|
622
|
+
return ret == null ? undefined : ret;
|
623
|
+
}
|
624
|
+
}
|
625
|
+
});
|
626
|
+
} else if(webshims.bugs.bustedValidity){
|
627
|
+
|
628
|
+
webshims.defineNodeNameProperty('form', 'novalidate', {
|
629
|
+
attr: {
|
630
|
+
set: function(val){
|
631
|
+
webshims.data(this, 'bustedNoValidate', ''+val);
|
632
|
+
},
|
633
|
+
get: function(){
|
634
|
+
var ret = webshims.data(this, 'bustedNoValidate');
|
635
|
+
return ret == null ? undefined : ret;
|
636
|
+
}
|
637
|
+
},
|
638
|
+
removeAttr: {
|
639
|
+
value: function(){
|
640
|
+
webshims.data(this, 'bustedNoValidate', null);
|
641
|
+
}
|
642
|
+
}
|
643
|
+
});
|
644
|
+
|
645
|
+
$.each(['rangeUnderflow', 'rangeOverflow', 'stepMismatch'], function(i, name){
|
646
|
+
validityRules[name] = function(elem){
|
647
|
+
return (elem[0].validity || {})[name] || false;
|
648
|
+
};
|
649
|
+
});
|
650
|
+
|
651
|
+
}
|
652
|
+
|
653
|
+
webshims.defineNodeNameProperty('form', 'noValidate', {
|
654
|
+
prop: {
|
655
|
+
set: function(val){
|
656
|
+
val = !!val;
|
657
|
+
if(val){
|
658
|
+
$.attr(this, 'novalidate', 'novalidate');
|
659
|
+
} else {
|
660
|
+
$(this).removeAttr('novalidate');
|
661
|
+
}
|
662
|
+
},
|
663
|
+
get: function(){
|
664
|
+
return $.attr(this, 'novalidate') != null;
|
665
|
+
}
|
666
|
+
}
|
667
|
+
});
|
668
|
+
|
669
|
+
if($.browser.webkit && Modernizr.inputtypes.date){
|
670
|
+
(function(){
|
671
|
+
|
672
|
+
var noInputTriggerEvts = {updateInput: 1, input: 1},
|
673
|
+
fixInputTypes = {
|
674
|
+
date: 1,
|
675
|
+
time: 1,
|
676
|
+
"datetime-local": 1
|
677
|
+
},
|
678
|
+
noFocusEvents = {
|
679
|
+
focusout: 1,
|
680
|
+
blur: 1
|
681
|
+
},
|
682
|
+
changeEvts = {
|
683
|
+
updateInput: 1,
|
684
|
+
change: 1
|
685
|
+
},
|
686
|
+
observe = function(input){
|
687
|
+
var timer,
|
688
|
+
focusedin = true,
|
689
|
+
lastInputVal = input.prop('value'),
|
690
|
+
lastChangeVal = lastInputVal,
|
691
|
+
trigger = function(e){
|
692
|
+
//input === null
|
693
|
+
if(!input){return;}
|
694
|
+
var newVal = input.prop('value');
|
695
|
+
|
696
|
+
if(newVal !== lastInputVal){
|
697
|
+
lastInputVal = newVal;
|
698
|
+
if(!e || !noInputTriggerEvts[e.type]){
|
699
|
+
input.trigger('input');
|
700
|
+
}
|
701
|
+
}
|
702
|
+
if(e && changeEvts[e.type]){
|
703
|
+
lastChangeVal = newVal;
|
704
|
+
}
|
705
|
+
if(!focusedin && newVal !== lastChangeVal){
|
706
|
+
input.trigger('change');
|
707
|
+
}
|
708
|
+
},
|
709
|
+
extraTimer,
|
710
|
+
extraTest = function(){
|
711
|
+
clearTimeout(extraTimer);
|
712
|
+
extraTimer = setTimeout(trigger, 9);
|
713
|
+
},
|
714
|
+
unbind = function(e){
|
715
|
+
clearInterval(timer);
|
716
|
+
setTimeout(function(){
|
717
|
+
if(e && noFocusEvents[e.type]){
|
718
|
+
focusedin = false;
|
719
|
+
}
|
720
|
+
if(input){
|
721
|
+
input.unbind('focusout blur', unbind).unbind('input change updateInput', trigger);
|
722
|
+
trigger();
|
723
|
+
}
|
724
|
+
input = null;
|
725
|
+
}, 1);
|
726
|
+
|
727
|
+
}
|
728
|
+
;
|
729
|
+
|
730
|
+
clearInterval(timer);
|
731
|
+
timer = setInterval(trigger, 160);
|
732
|
+
extraTest();
|
733
|
+
input
|
734
|
+
.off({
|
735
|
+
'focusout blur': unbind,
|
736
|
+
'input change updateInput': trigger
|
737
|
+
})
|
738
|
+
.on({
|
739
|
+
'focusout blur': unbind,
|
740
|
+
'input updateInput change': trigger
|
741
|
+
})
|
742
|
+
;
|
743
|
+
}
|
744
|
+
;
|
745
|
+
if($.event.customEvent){
|
746
|
+
$.event.customEvent.updateInput = true;
|
747
|
+
}
|
748
|
+
|
749
|
+
(function(){
|
750
|
+
|
751
|
+
var correctValue = function(elem){
|
752
|
+
var i = 1;
|
753
|
+
var len = 3;
|
754
|
+
var abort, val;
|
755
|
+
if(elem.type == 'date' && (isSubmit || !$(elem).is(':focus'))){
|
756
|
+
val = elem.value;
|
757
|
+
if(val && val.length < 10 && (val = val.split('-')) && val.length == len){
|
758
|
+
for(; i < len; i++){
|
759
|
+
if(val[i].length == 1){
|
760
|
+
val[i] = '0'+val[i];
|
761
|
+
} else if(val[i].length != 2){
|
762
|
+
abort = true;
|
763
|
+
break;
|
764
|
+
}
|
765
|
+
}
|
766
|
+
if(!abort){
|
767
|
+
val = val.join('-');
|
768
|
+
$.prop(elem, 'value', val);
|
769
|
+
return val;
|
770
|
+
}
|
771
|
+
}
|
772
|
+
}
|
773
|
+
};
|
774
|
+
var inputCheckValidityDesc, formCheckValidityDesc, inputValueDesc, inputValidityDesc;
|
775
|
+
|
776
|
+
inputCheckValidityDesc = webshims.defineNodeNameProperty('input', 'checkValidity', {
|
777
|
+
prop: {
|
778
|
+
value: function(){
|
779
|
+
correctValue(this);
|
780
|
+
return inputCheckValidityDesc.prop._supvalue.apply(this, arguments);
|
781
|
+
}
|
782
|
+
}
|
783
|
+
});
|
784
|
+
|
785
|
+
formCheckValidityDesc = webshims.defineNodeNameProperty('form', 'checkValidity', {
|
786
|
+
prop: {
|
787
|
+
value: function(){
|
788
|
+
$('input', this).each(function(){
|
789
|
+
correctValue(this);
|
790
|
+
});
|
791
|
+
return formCheckValidityDesc.prop._supvalue.apply(this, arguments);
|
792
|
+
}
|
793
|
+
}
|
794
|
+
});
|
795
|
+
|
796
|
+
inputValueDesc = webshims.defineNodeNameProperty('input', 'value', {
|
797
|
+
prop: {
|
798
|
+
set: function(){
|
799
|
+
return inputValueDesc.prop._supset.apply(this, arguments);
|
800
|
+
},
|
801
|
+
get: function(){
|
802
|
+
return correctValue(this) || inputValueDesc.prop._supget.apply(this, arguments);
|
803
|
+
}
|
804
|
+
}
|
805
|
+
});
|
806
|
+
|
807
|
+
inputValidityDesc = webshims.defineNodeNameProperty('input', 'validity', {
|
808
|
+
prop: {
|
809
|
+
writeable: false,
|
810
|
+
get: function(){
|
811
|
+
correctValue(this);
|
812
|
+
return inputValidityDesc.prop._supget.apply(this, arguments);
|
813
|
+
}
|
814
|
+
}
|
815
|
+
});
|
816
|
+
|
817
|
+
$(document).on('change', function(e){
|
818
|
+
correctValue(e.target);
|
819
|
+
});
|
820
|
+
|
821
|
+
})();
|
822
|
+
|
823
|
+
$(document)
|
824
|
+
.on('focusin', function(e){
|
825
|
+
if( e.target && fixInputTypes[e.target.type] && !e.target.readOnly && !e.target.disabled ){
|
826
|
+
observe($(e.target));
|
827
|
+
}
|
828
|
+
})
|
829
|
+
;
|
830
|
+
|
831
|
+
|
832
|
+
})();
|
833
|
+
}
|
834
|
+
|
835
|
+
webshims.addReady(function(context, contextElem){
|
836
|
+
//start constrain-validation
|
837
|
+
var focusElem;
|
838
|
+
$('form', context)
|
839
|
+
.add(contextElem.filter('form'))
|
840
|
+
.bind('invalid', $.noop)
|
841
|
+
;
|
842
|
+
|
843
|
+
try {
|
844
|
+
if(context == document && !('form' in (document.activeElement || {}))) {
|
845
|
+
focusElem = $('input[autofocus], select[autofocus], textarea[autofocus]', context).eq(0).getShadowFocusElement()[0];
|
846
|
+
if (focusElem && focusElem.offsetHeight && focusElem.offsetWidth) {
|
847
|
+
focusElem.focus();
|
848
|
+
}
|
849
|
+
}
|
850
|
+
}
|
851
|
+
catch (er) {}
|
852
|
+
|
853
|
+
});
|
854
|
+
|
855
|
+
if(!Modernizr.formattribute || !Modernizr.fieldsetdisabled){
|
856
|
+
(function(){
|
857
|
+
(function(prop, undefined){
|
858
|
+
$.prop = function(elem, name, value){
|
859
|
+
var ret;
|
860
|
+
if(elem && elem.nodeType == 1 && value === undefined && $.nodeName(elem, 'form') && elem.id){
|
861
|
+
ret = document.getElementsByName(name);
|
862
|
+
if(!ret || !ret.length){
|
863
|
+
ret = document.getElementById(name);
|
864
|
+
}
|
865
|
+
if(ret){
|
866
|
+
ret = $(ret).filter(function(){
|
867
|
+
return $.prop(this, 'form') == elem;
|
868
|
+
}).get();
|
869
|
+
if(ret.length){
|
870
|
+
return ret.length == 1 ? ret[0] : ret;
|
871
|
+
}
|
872
|
+
}
|
873
|
+
}
|
874
|
+
return prop.apply(this, arguments);
|
875
|
+
};
|
876
|
+
})($.prop, undefined);
|
877
|
+
var removeAddedElements = function(form){
|
878
|
+
var elements = $.data(form, 'webshimsAddedElements');
|
879
|
+
if(elements){
|
880
|
+
elements.remove();
|
881
|
+
$.removeData(form, 'webshimsAddedElements');
|
882
|
+
}
|
883
|
+
};
|
884
|
+
var rCRLF = /\r?\n/g,
|
885
|
+
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
886
|
+
rselectTextarea = /^(?:select|textarea)/i;
|
887
|
+
|
888
|
+
if(!Modernizr.formattribute){
|
889
|
+
webshims.defineNodeNamesProperty(['input', 'textarea', 'select', 'button', 'fieldset'], 'form', {
|
890
|
+
prop: {
|
891
|
+
get: function(){
|
892
|
+
var form = webshims.contentAttr(this, 'form');
|
893
|
+
if(form){
|
894
|
+
form = document.getElementById(form);
|
895
|
+
if(form && !$.nodeName(form, 'form')){
|
896
|
+
form = null;
|
897
|
+
}
|
898
|
+
}
|
899
|
+
return form || this.form;
|
900
|
+
},
|
901
|
+
writeable: false
|
902
|
+
}
|
903
|
+
});
|
904
|
+
|
905
|
+
|
906
|
+
webshims.defineNodeNamesProperty(['form'], 'elements', {
|
907
|
+
prop: {
|
908
|
+
get: function(){
|
909
|
+
var id = this.id;
|
910
|
+
var elements = $.makeArray(this.elements);
|
911
|
+
if(id){
|
912
|
+
elements = $(elements).add('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"], button[form="'+ id +'"], fieldset[form="'+ id +'"]').not('.webshims-visual-hide > *').get();
|
913
|
+
}
|
914
|
+
return elements;
|
915
|
+
},
|
916
|
+
writeable: false
|
917
|
+
}
|
918
|
+
});
|
919
|
+
|
920
|
+
|
921
|
+
|
922
|
+
$(function(){
|
923
|
+
var stopPropagation = function(e){
|
924
|
+
e.stopPropagation();
|
925
|
+
};
|
926
|
+
$(document).on('submit', function(e){
|
927
|
+
|
928
|
+
if(!e.isDefaultPrevented()){
|
929
|
+
var form = e.target;
|
930
|
+
var id = form.id;
|
931
|
+
var elements;
|
932
|
+
|
933
|
+
|
934
|
+
if(id){
|
935
|
+
removeAddedElements(form);
|
936
|
+
|
937
|
+
elements = $('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"]')
|
938
|
+
.filter(function(){
|
939
|
+
return !this.disabled && this.name && this.form != form;
|
940
|
+
})
|
941
|
+
.clone()
|
942
|
+
;
|
943
|
+
if(elements.length){
|
944
|
+
$.data(form, 'webshimsAddedElements', $('<div class="webshims-visual-hide" />').append(elements).appendTo(form));
|
945
|
+
setTimeout(function(){
|
946
|
+
removeAddedElements(form);
|
947
|
+
}, 9);
|
948
|
+
}
|
949
|
+
elements = null;
|
950
|
+
}
|
951
|
+
}
|
952
|
+
});
|
953
|
+
|
954
|
+
$(document).on('click', function(e){
|
955
|
+
if(!e.isDefaultPrevented() && $(e.target).is('input[type="submit"][form], button[form], input[type="button"][form], input[type="image"][form], input[type="reset"][form]')){
|
956
|
+
var trueForm = $.prop(e.target, 'form');
|
957
|
+
var formIn = e.target.form;
|
958
|
+
var clone;
|
959
|
+
if(trueForm && trueForm != formIn){
|
960
|
+
clone = $(e.target)
|
961
|
+
.clone()
|
962
|
+
.removeAttr('form')
|
963
|
+
.addClass('webshims-visual-hide')
|
964
|
+
.on('click', stopPropagation)
|
965
|
+
.appendTo(trueForm)
|
966
|
+
;
|
967
|
+
if(formIn){
|
968
|
+
e.preventDefault();
|
969
|
+
}
|
970
|
+
addSubmitBubbles(trueForm);
|
971
|
+
clone.trigger('click');
|
972
|
+
setTimeout(function(){
|
973
|
+
clone.remove();
|
974
|
+
clone = null;
|
975
|
+
}, 9);
|
976
|
+
}
|
977
|
+
}
|
978
|
+
});
|
979
|
+
});
|
980
|
+
}
|
981
|
+
|
982
|
+
if(!Modernizr.fieldsetdisabled){
|
983
|
+
webshims.defineNodeNamesProperty(['fieldset'], 'elements', {
|
984
|
+
prop: {
|
985
|
+
get: function(){
|
986
|
+
//add listed elements without keygen, object, output
|
987
|
+
return $('input, select, textarea, button, fieldset', this).get() || [];
|
988
|
+
},
|
989
|
+
writeable: false
|
990
|
+
}
|
991
|
+
});
|
992
|
+
}
|
993
|
+
|
994
|
+
$.fn.serializeArray = function() {
|
995
|
+
return this.map(function(){
|
996
|
+
var elements = $.prop(this, 'elements');
|
997
|
+
return elements ? $.makeArray( elements ) : this;
|
998
|
+
})
|
999
|
+
.filter(function(){
|
1000
|
+
return this.name && !this.disabled &&
|
1001
|
+
( this.checked || rselectTextarea.test( this.nodeName ) ||
|
1002
|
+
rinput.test( this.type ) );
|
1003
|
+
})
|
1004
|
+
.map(function( i, elem ){
|
1005
|
+
var val = $( this ).val();
|
1006
|
+
|
1007
|
+
return val == null ?
|
1008
|
+
null :
|
1009
|
+
$.isArray( val ) ?
|
1010
|
+
$.map( val, function( val, i ){
|
1011
|
+
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
1012
|
+
}) :
|
1013
|
+
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
1014
|
+
}).get();
|
1015
|
+
};
|
1016
|
+
|
1017
|
+
})();
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
try {
|
1021
|
+
document.querySelector(':checked');
|
1022
|
+
} catch(er){
|
1023
|
+
(function(){
|
1024
|
+
var checkInputs = {
|
1025
|
+
radio: 1,
|
1026
|
+
checkbox: 1
|
1027
|
+
};
|
1028
|
+
var selectChange = function(){
|
1029
|
+
var options = this.options || [];
|
1030
|
+
var i, len, option;
|
1031
|
+
for(i = 0, len = options.length; i < len; i++){
|
1032
|
+
option = $(options[i]);
|
1033
|
+
option[$.prop(options[i], 'selected') ? 'addClass' : 'removeClass']('prop-checked');
|
1034
|
+
}
|
1035
|
+
};
|
1036
|
+
var checkChange = function(){
|
1037
|
+
var fn = $.prop(this, 'checked') ? 'addClass' : 'removeClass';
|
1038
|
+
var className = this.className || '';
|
1039
|
+
var parent;
|
1040
|
+
|
1041
|
+
//IE8- has problems to update styles, we help
|
1042
|
+
if( (className.indexOf('prop-checked') == -1) == (fn == 'addClass')){
|
1043
|
+
$(this)[fn]('prop-checked');
|
1044
|
+
if((parent = this.parentNode)){
|
1045
|
+
parent.className = parent.className;
|
1046
|
+
}
|
1047
|
+
}
|
1048
|
+
};
|
1049
|
+
|
1050
|
+
|
1051
|
+
webshims.onNodeNamesPropertyModify('select', 'value', selectChange);
|
1052
|
+
webshims.onNodeNamesPropertyModify('select', 'selectedIndex', selectChange);
|
1053
|
+
webshims.onNodeNamesPropertyModify('option', 'selected', function(){
|
1054
|
+
$(this).closest('select').each(selectChange);
|
1055
|
+
});
|
1056
|
+
webshims.onNodeNamesPropertyModify('input', 'checked', function(value, boolVal){
|
1057
|
+
var type = this.type;
|
1058
|
+
if(type == 'radio' && boolVal){
|
1059
|
+
webshims.modules["form-core"].getGroupElements(this).each(checkChange);
|
1060
|
+
} else if(checkInputs[type]) {
|
1061
|
+
$(this).each(checkChange);
|
1062
|
+
}
|
1063
|
+
});
|
1064
|
+
|
1065
|
+
$(document).on('change', function(e){
|
1066
|
+
|
1067
|
+
if(checkInputs[e.target.type]){
|
1068
|
+
if(e.target.type == 'radio'){
|
1069
|
+
webshims.modules["form-core"].getGroupElements(e.target).each(checkChange);
|
1070
|
+
} else {
|
1071
|
+
$(e.target)[$.prop(e.target, 'checked') ? 'addClass' : 'removeClass']('prop-checked');
|
1072
|
+
}
|
1073
|
+
} else if(e.target.nodeName.toLowerCase() == 'select'){
|
1074
|
+
$(e.target).each(selectChange);
|
1075
|
+
}
|
1076
|
+
});
|
1077
|
+
|
1078
|
+
webshims.addReady(function(context, contextElem){
|
1079
|
+
$('option, input', context)
|
1080
|
+
.add(contextElem.filter('option, input'))
|
1081
|
+
.each(function(){
|
1082
|
+
var prop;
|
1083
|
+
if(checkInputs[this.type]){
|
1084
|
+
prop = 'checked';
|
1085
|
+
} else if(this.nodeName.toLowerCase() == 'option'){
|
1086
|
+
prop = 'selected';
|
1087
|
+
}
|
1088
|
+
if(prop){
|
1089
|
+
$(this)[$.prop(this, prop) ? 'addClass' : 'removeClass']('prop-checked');
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
})
|
1093
|
+
;
|
1094
|
+
});
|
1095
|
+
})();
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
(function(){
|
1099
|
+
Modernizr.textareaPlaceholder = !!('placeholder' in $('<textarea />')[0]);
|
1100
|
+
var bustedTextarea = $.browser.webkit && Modernizr.textareaPlaceholder && webshims.browserVersion < 535;
|
1101
|
+
if(Modernizr.input.placeholder && Modernizr.textareaPlaceholder && !bustedTextarea){return;}
|
1102
|
+
|
1103
|
+
var isOver = (webshims.cfg.forms.placeholderType == 'over');
|
1104
|
+
var isResponsive = (webshims.cfg.forms.responsivePlaceholder);
|
1105
|
+
var polyfillElements = ['textarea'];
|
1106
|
+
if(!Modernizr.input.placeholder){
|
1107
|
+
polyfillElements.push('input');
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
var setSelection = function(elem){
|
1111
|
+
try {
|
1112
|
+
if(elem.setSelectionRange){
|
1113
|
+
elem.setSelectionRange(0, 0);
|
1114
|
+
return true;
|
1115
|
+
} else if(elem.createTextRange){
|
1116
|
+
var range = elem.createTextRange();
|
1117
|
+
range.collapse(true);
|
1118
|
+
range.moveEnd('character', 0);
|
1119
|
+
range.moveStart('character', 0);
|
1120
|
+
range.select();
|
1121
|
+
return true;
|
1122
|
+
}
|
1123
|
+
} catch(er){}
|
1124
|
+
};
|
1125
|
+
|
1126
|
+
var hidePlaceholder = function(elem, data, value, _onFocus){
|
1127
|
+
if(value === false){
|
1128
|
+
value = $.prop(elem, 'value');
|
1129
|
+
}
|
1130
|
+
if(!isOver && elem.type != 'password'){
|
1131
|
+
if(!value && _onFocus && setSelection(elem)){
|
1132
|
+
var selectTimer = setTimeout(function(){
|
1133
|
+
setSelection(elem);
|
1134
|
+
}, 9);
|
1135
|
+
$(elem)
|
1136
|
+
.off('.placeholderremove')
|
1137
|
+
.on({
|
1138
|
+
'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
|
1139
|
+
if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
|
1140
|
+
elem.value = $.prop(elem, 'value');
|
1141
|
+
data.box.removeClass('placeholder-visible');
|
1142
|
+
clearTimeout(selectTimer);
|
1143
|
+
$(elem).unbind('.placeholderremove');
|
1144
|
+
},
|
1145
|
+
'mousedown.placeholderremove drag.placeholderremove select.placeholderremove': function(e){
|
1146
|
+
setSelection(elem);
|
1147
|
+
clearTimeout(selectTimer);
|
1148
|
+
selectTimer = setTimeout(function(){
|
1149
|
+
setSelection(elem);
|
1150
|
+
}, 9);
|
1151
|
+
},
|
1152
|
+
'blur.placeholderremove': function(){
|
1153
|
+
clearTimeout(selectTimer);
|
1154
|
+
$(elem).unbind('.placeholderremove');
|
1155
|
+
}
|
1156
|
+
})
|
1157
|
+
;
|
1158
|
+
return;
|
1159
|
+
}
|
1160
|
+
elem.value = value;
|
1161
|
+
} else if(!value && _onFocus){
|
1162
|
+
$(elem)
|
1163
|
+
.off('.placeholderremove')
|
1164
|
+
.on({
|
1165
|
+
'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
|
1166
|
+
if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
|
1167
|
+
data.box.removeClass('placeholder-visible');
|
1168
|
+
$(elem).unbind('.placeholderremove');
|
1169
|
+
},
|
1170
|
+
'blur.placeholderremove': function(){
|
1171
|
+
$(elem).unbind('.placeholderremove');
|
1172
|
+
}
|
1173
|
+
})
|
1174
|
+
;
|
1175
|
+
return;
|
1176
|
+
}
|
1177
|
+
data.box.removeClass('placeholder-visible');
|
1178
|
+
},
|
1179
|
+
showPlaceholder = function(elem, data, placeholderTxt){
|
1180
|
+
if(placeholderTxt === false){
|
1181
|
+
placeholderTxt = $.prop(elem, 'placeholder');
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
if(!isOver && elem.type != 'password'){
|
1185
|
+
elem.value = placeholderTxt;
|
1186
|
+
}
|
1187
|
+
data.box.addClass('placeholder-visible');
|
1188
|
+
},
|
1189
|
+
changePlaceholderVisibility = function(elem, value, placeholderTxt, data, type){
|
1190
|
+
if(!data){
|
1191
|
+
data = $.data(elem, 'placeHolder');
|
1192
|
+
if(!data){return;}
|
1193
|
+
}
|
1194
|
+
$(elem).unbind('.placeholderremove');
|
1195
|
+
if(type == 'focus' || (!type && $(elem).is(':focus'))){
|
1196
|
+
if(elem.type == 'password' || isOver || $(elem).hasClass('placeholder-visible')){
|
1197
|
+
hidePlaceholder(elem, data, '', true);
|
1198
|
+
}
|
1199
|
+
return;
|
1200
|
+
}
|
1201
|
+
if(value === false){
|
1202
|
+
value = $.prop(elem, 'value');
|
1203
|
+
}
|
1204
|
+
if(value){
|
1205
|
+
hidePlaceholder(elem, data, value);
|
1206
|
+
return;
|
1207
|
+
}
|
1208
|
+
if(placeholderTxt === false){
|
1209
|
+
placeholderTxt = $.attr(elem, 'placeholder') || '';
|
1210
|
+
}
|
1211
|
+
if(placeholderTxt && !value){
|
1212
|
+
showPlaceholder(elem, data, placeholderTxt);
|
1213
|
+
} else {
|
1214
|
+
hidePlaceholder(elem, data, value);
|
1215
|
+
}
|
1216
|
+
},
|
1217
|
+
createPlaceholder = function(elem){
|
1218
|
+
elem = $(elem);
|
1219
|
+
var id = elem.prop('id'),
|
1220
|
+
hasLabel = !!(elem.prop('title') || elem.attr('aria-labelledby'))
|
1221
|
+
;
|
1222
|
+
if(!hasLabel && id){
|
1223
|
+
hasLabel = !!( $('label[for="'+ id +'"]', elem[0].form)[0] );
|
1224
|
+
}
|
1225
|
+
if(!hasLabel){
|
1226
|
+
if(!id){
|
1227
|
+
id = $.webshims.getID(elem);
|
1228
|
+
}
|
1229
|
+
hasLabel = !!($('label #'+ id)[0]);
|
1230
|
+
}
|
1231
|
+
return $( hasLabel ? '<span class="placeholder-text"></span>' : '<label for="'+ id +'" class="placeholder-text"></label>');
|
1232
|
+
},
|
1233
|
+
pHolder = (function(){
|
1234
|
+
var delReg = /\n|\r|\f|\t/g,
|
1235
|
+
allowedPlaceholder = {
|
1236
|
+
text: 1,
|
1237
|
+
search: 1,
|
1238
|
+
url: 1,
|
1239
|
+
email: 1,
|
1240
|
+
password: 1,
|
1241
|
+
tel: 1,
|
1242
|
+
number: 1
|
1243
|
+
}
|
1244
|
+
;
|
1245
|
+
|
1246
|
+
return {
|
1247
|
+
create: function(elem){
|
1248
|
+
var data = $.data(elem, 'placeHolder');
|
1249
|
+
var form;
|
1250
|
+
var responsiveElem;
|
1251
|
+
if(data){return data;}
|
1252
|
+
data = $.data(elem, 'placeHolder', {});
|
1253
|
+
|
1254
|
+
$(elem).on('focus.placeholder blur.placeholder', function(e){
|
1255
|
+
changePlaceholderVisibility(this, false, false, data, e.type );
|
1256
|
+
data.box[e.type == 'focus' ? 'addClass' : 'removeClass']('placeholder-focused');
|
1257
|
+
});
|
1258
|
+
|
1259
|
+
if((form = $.prop(elem, 'form'))){
|
1260
|
+
$(form).on('reset.placeholder', function(e){
|
1261
|
+
setTimeout(function(){
|
1262
|
+
changePlaceholderVisibility(elem, false, false, data, e.type );
|
1263
|
+
}, 0);
|
1264
|
+
});
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
if(elem.type == 'password' || isOver){
|
1268
|
+
data.text = createPlaceholder(elem);
|
1269
|
+
if(isResponsive || $(elem).is('.responsive-width') || (elem.currentStyle || {width: ''}).width.indexOf('%') != -1){
|
1270
|
+
responsiveElem = true;
|
1271
|
+
data.box = data.text;
|
1272
|
+
} else {
|
1273
|
+
data.box = $(elem)
|
1274
|
+
.wrap('<span class="placeholder-box placeholder-box-'+ (elem.nodeName || '').toLowerCase() +' placeholder-box-'+$.css(elem, 'float')+'" />')
|
1275
|
+
.parent()
|
1276
|
+
;
|
1277
|
+
}
|
1278
|
+
data.text
|
1279
|
+
.insertAfter(elem)
|
1280
|
+
.on('mousedown.placeholder', function(){
|
1281
|
+
changePlaceholderVisibility(this, false, false, data, 'focus');
|
1282
|
+
try {
|
1283
|
+
setTimeout(function(){
|
1284
|
+
elem.focus();
|
1285
|
+
}, 0);
|
1286
|
+
} catch(e){}
|
1287
|
+
return false;
|
1288
|
+
})
|
1289
|
+
;
|
1290
|
+
|
1291
|
+
|
1292
|
+
$.each(['lineHeight', 'fontSize', 'fontFamily', 'fontWeight'], function(i, style){
|
1293
|
+
var prop = $.css(elem, style);
|
1294
|
+
if(data.text.css(style) != prop){
|
1295
|
+
data.text.css(style, prop);
|
1296
|
+
}
|
1297
|
+
});
|
1298
|
+
$.each(['Left', 'Top'], function(i, side){
|
1299
|
+
var size = (parseInt($.css(elem, 'padding'+ side), 10) || 0) + Math.max((parseInt($.css(elem, 'margin'+ side), 10) || 0), 0) + (parseInt($.css(elem, 'border'+ side +'Width'), 10) || 0);
|
1300
|
+
data.text.css('padding'+ side, size);
|
1301
|
+
});
|
1302
|
+
|
1303
|
+
$(elem)
|
1304
|
+
.on('updateshadowdom', function(){
|
1305
|
+
var height, width;
|
1306
|
+
if((width = elem.offsetWidth) || (height = elem.offsetHeight)){
|
1307
|
+
data.text
|
1308
|
+
.css({
|
1309
|
+
width: width,
|
1310
|
+
height: height
|
1311
|
+
})
|
1312
|
+
.css($(elem).position())
|
1313
|
+
;
|
1314
|
+
}
|
1315
|
+
})
|
1316
|
+
.triggerHandler('updateshadowdom')
|
1317
|
+
;
|
1318
|
+
|
1319
|
+
} else {
|
1320
|
+
var reset = function(e){
|
1321
|
+
if($(elem).hasClass('placeholder-visible')){
|
1322
|
+
hidePlaceholder(elem, data, '');
|
1323
|
+
if(e && e.type == 'submit'){
|
1324
|
+
setTimeout(function(){
|
1325
|
+
if(e.isDefaultPrevented()){
|
1326
|
+
changePlaceholderVisibility(elem, false, false, data );
|
1327
|
+
}
|
1328
|
+
}, 9);
|
1329
|
+
}
|
1330
|
+
}
|
1331
|
+
};
|
1332
|
+
|
1333
|
+
$(window).on('beforeunload', reset);
|
1334
|
+
data.box = $(elem);
|
1335
|
+
if(form){
|
1336
|
+
$(form).submit(reset);
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
|
1340
|
+
return data;
|
1341
|
+
},
|
1342
|
+
update: function(elem, val){
|
1343
|
+
var type = ($.attr(elem, 'type') || $.prop(elem, 'type') || '').toLowerCase();
|
1344
|
+
if(!allowedPlaceholder[type] && !$.nodeName(elem, 'textarea')){
|
1345
|
+
webshims.error('placeholder not allowed on input[type="'+type+'"]');
|
1346
|
+
if(type == 'date'){
|
1347
|
+
webshims.error('but you can use data-placeholder for input[type="date"]');
|
1348
|
+
}
|
1349
|
+
return;
|
1350
|
+
}
|
1351
|
+
|
1352
|
+
|
1353
|
+
var data = pHolder.create(elem);
|
1354
|
+
if(data.text){
|
1355
|
+
data.text.text(val);
|
1356
|
+
}
|
1357
|
+
|
1358
|
+
changePlaceholderVisibility(elem, false, val, data);
|
1359
|
+
}
|
1360
|
+
};
|
1361
|
+
})()
|
1362
|
+
;
|
1363
|
+
|
1364
|
+
$.webshims.publicMethods = {
|
1365
|
+
pHolder: pHolder
|
1366
|
+
};
|
1367
|
+
polyfillElements.forEach(function(nodeName){
|
1368
|
+
var desc = webshims.defineNodeNameProperty(nodeName, 'placeholder', {
|
1369
|
+
attr: {
|
1370
|
+
set: function(val){
|
1371
|
+
var elem = this;
|
1372
|
+
if(bustedTextarea){
|
1373
|
+
webshims.data(elem, 'textareaPlaceholder', val);
|
1374
|
+
elem.placeholder = '';
|
1375
|
+
} else {
|
1376
|
+
webshims.contentAttr(elem, 'placeholder', val);
|
1377
|
+
}
|
1378
|
+
pHolder.update(elem, val);
|
1379
|
+
},
|
1380
|
+
get: function(){
|
1381
|
+
var ret = (bustedTextarea) ? webshims.data(this, 'textareaPlaceholder') : '';
|
1382
|
+
return ret || webshims.contentAttr(this, 'placeholder');
|
1383
|
+
}
|
1384
|
+
},
|
1385
|
+
reflect: true,
|
1386
|
+
initAttr: true
|
1387
|
+
});
|
1388
|
+
});
|
1389
|
+
|
1390
|
+
|
1391
|
+
polyfillElements.forEach(function(name){
|
1392
|
+
var placeholderValueDesc = {};
|
1393
|
+
var desc;
|
1394
|
+
['attr', 'prop'].forEach(function(propType){
|
1395
|
+
placeholderValueDesc[propType] = {
|
1396
|
+
set: function(val){
|
1397
|
+
var elem = this;
|
1398
|
+
var placeholder;
|
1399
|
+
if(bustedTextarea){
|
1400
|
+
placeholder = webshims.data(elem, 'textareaPlaceholder');
|
1401
|
+
}
|
1402
|
+
if(!placeholder){
|
1403
|
+
placeholder = webshims.contentAttr(elem, 'placeholder');
|
1404
|
+
}
|
1405
|
+
$.removeData(elem, 'cachedValidity');
|
1406
|
+
var ret = desc[propType]._supset.call(elem, val);
|
1407
|
+
if(placeholder && 'value' in elem){
|
1408
|
+
changePlaceholderVisibility(elem, val, placeholder);
|
1409
|
+
}
|
1410
|
+
return ret;
|
1411
|
+
},
|
1412
|
+
get: function(){
|
1413
|
+
var elem = this;
|
1414
|
+
return $(elem).hasClass('placeholder-visible') ? '' : desc[propType]._supget.call(elem);
|
1415
|
+
}
|
1416
|
+
};
|
1417
|
+
});
|
1418
|
+
desc = webshims.defineNodeNameProperty(name, 'value', placeholderValueDesc);
|
1419
|
+
});
|
1420
|
+
|
1421
|
+
})();
|
1422
|
+
|
1423
|
+
(function(){
|
1424
|
+
var doc = document;
|
1425
|
+
if( 'value' in document.createElement('output') ){return;}
|
1426
|
+
|
1427
|
+
webshims.defineNodeNameProperty('output', 'value', {
|
1428
|
+
prop: {
|
1429
|
+
set: function(value){
|
1430
|
+
var setVal = $.data(this, 'outputShim');
|
1431
|
+
if(!setVal){
|
1432
|
+
setVal = outputCreate(this);
|
1433
|
+
}
|
1434
|
+
setVal(value);
|
1435
|
+
},
|
1436
|
+
get: function(){
|
1437
|
+
return webshims.contentAttr(this, 'value') || $(this).text() || '';
|
1438
|
+
}
|
1439
|
+
}
|
1440
|
+
});
|
1441
|
+
|
1442
|
+
|
1443
|
+
webshims.onNodeNamesPropertyModify('input', 'value', function(value, boolVal, type){
|
1444
|
+
if(type == 'removeAttr'){return;}
|
1445
|
+
var setVal = $.data(this, 'outputShim');
|
1446
|
+
if(setVal){
|
1447
|
+
setVal(value);
|
1448
|
+
}
|
1449
|
+
});
|
1450
|
+
|
1451
|
+
var outputCreate = function(elem){
|
1452
|
+
if(elem.getAttribute('aria-live')){return;}
|
1453
|
+
elem = $(elem);
|
1454
|
+
var value = (elem.text() || '').trim();
|
1455
|
+
var id = elem.attr('id');
|
1456
|
+
var htmlFor = elem.attr('for');
|
1457
|
+
var shim = $('<input class="output-shim" type="text" disabled name="'+ (elem.attr('name') || '')+'" value="'+value+'" style="display: none !important;" />').insertAfter(elem);
|
1458
|
+
var form = shim[0].form || doc;
|
1459
|
+
var setValue = function(val){
|
1460
|
+
shim[0].value = val;
|
1461
|
+
val = shim[0].value;
|
1462
|
+
elem.text(val);
|
1463
|
+
webshims.contentAttr(elem[0], 'value', val);
|
1464
|
+
};
|
1465
|
+
|
1466
|
+
elem[0].defaultValue = value;
|
1467
|
+
webshims.contentAttr(elem[0], 'value', value);
|
1468
|
+
|
1469
|
+
elem.attr({'aria-live': 'polite'});
|
1470
|
+
if(id){
|
1471
|
+
shim.attr('id', id);
|
1472
|
+
elem.attr('aria-labelledby', webshims.getID($('label[for="'+id+'"]', form)));
|
1473
|
+
}
|
1474
|
+
if(htmlFor){
|
1475
|
+
id = webshims.getID(elem);
|
1476
|
+
htmlFor.split(' ').forEach(function(control){
|
1477
|
+
control = document.getElementById(control);
|
1478
|
+
if(control){
|
1479
|
+
control.setAttribute('aria-controls', id);
|
1480
|
+
}
|
1481
|
+
});
|
1482
|
+
}
|
1483
|
+
elem.data('outputShim', setValue );
|
1484
|
+
shim.data('outputShim', setValue );
|
1485
|
+
return setValue;
|
1486
|
+
};
|
1487
|
+
|
1488
|
+
webshims.addReady(function(context, contextElem){
|
1489
|
+
$('output', context).add(contextElem.filter('output')).each(function(){
|
1490
|
+
outputCreate(this);
|
1491
|
+
});
|
1492
|
+
});
|
1493
|
+
|
1494
|
+
/*
|
1495
|
+
* Implements input event in all browsers
|
1496
|
+
*/
|
1497
|
+
(function(){
|
1498
|
+
var noInputTriggerEvts = {updateInput: 1, input: 1},
|
1499
|
+
noInputTypes = {
|
1500
|
+
radio: 1,
|
1501
|
+
checkbox: 1,
|
1502
|
+
submit: 1,
|
1503
|
+
button: 1,
|
1504
|
+
image: 1,
|
1505
|
+
reset: 1,
|
1506
|
+
file: 1
|
1507
|
+
|
1508
|
+
//pro forma
|
1509
|
+
,color: 1
|
1510
|
+
//,range: 1
|
1511
|
+
},
|
1512
|
+
observe = function(input){
|
1513
|
+
var timer,
|
1514
|
+
lastVal = input.prop('value'),
|
1515
|
+
trigger = function(e){
|
1516
|
+
//input === null
|
1517
|
+
if(!input){return;}
|
1518
|
+
var newVal = input.prop('value');
|
1519
|
+
|
1520
|
+
if(newVal !== lastVal){
|
1521
|
+
lastVal = newVal;
|
1522
|
+
if(!e || !noInputTriggerEvts[e.type]){
|
1523
|
+
webshims.triggerInlineForm && webshims.triggerInlineForm(input[0], 'input');
|
1524
|
+
}
|
1525
|
+
}
|
1526
|
+
},
|
1527
|
+
extraTimer,
|
1528
|
+
extraTest = function(){
|
1529
|
+
clearTimeout(extraTimer);
|
1530
|
+
extraTimer = setTimeout(trigger, 9);
|
1531
|
+
},
|
1532
|
+
unbind = function(){
|
1533
|
+
input.unbind('focusout', unbind).unbind('keyup keypress keydown paste cut', extraTest).unbind('input change updateInput', trigger);
|
1534
|
+
clearInterval(timer);
|
1535
|
+
setTimeout(function(){
|
1536
|
+
trigger();
|
1537
|
+
input = null;
|
1538
|
+
}, 1);
|
1539
|
+
|
1540
|
+
}
|
1541
|
+
;
|
1542
|
+
|
1543
|
+
clearInterval(timer);
|
1544
|
+
timer = setInterval(trigger, 99);
|
1545
|
+
extraTest();
|
1546
|
+
input.on({
|
1547
|
+
'keyup keypress keydown paste cut': extraTest,
|
1548
|
+
focusout: unbind,
|
1549
|
+
'input updateInput change': trigger
|
1550
|
+
});
|
1551
|
+
}
|
1552
|
+
;
|
1553
|
+
if($.event.customEvent){
|
1554
|
+
$.event.customEvent.updateInput = true;
|
1555
|
+
}
|
1556
|
+
|
1557
|
+
$(doc)
|
1558
|
+
.on('focusin', function(e){
|
1559
|
+
if( e.target && e.target.type && !e.target.readOnly && !e.target.disabled && (e.target.nodeName || '').toLowerCase() == 'input' && !noInputTypes[e.target.type] ){
|
1560
|
+
observe($(e.target));
|
1561
|
+
}
|
1562
|
+
})
|
1563
|
+
;
|
1564
|
+
})();
|
1565
|
+
})();
|
1566
|
+
|
1567
|
+
}); //webshims.ready end
|
1568
|
+
}//end formvalidation
|
1569
|
+
|
1570
|
+
jQuery.webshims.register('form-message', function($, webshims, window, document, undefined, options){
|
1571
|
+
"use strict";
|
1572
|
+
var validityMessages = webshims.validityMessages;
|
1573
|
+
|
1574
|
+
var implementProperties = (options.overrideMessages || options.customMessages) ? ['customValidationMessage'] : [];
|
1575
|
+
|
1576
|
+
validityMessages['en'] = $.extend(true, {
|
1577
|
+
typeMismatch: {
|
1578
|
+
email: 'Please enter an email address.',
|
1579
|
+
url: 'Please enter a URL.',
|
1580
|
+
number: 'Please enter a number.',
|
1581
|
+
date: 'Please enter a date.',
|
1582
|
+
time: 'Please enter a time.',
|
1583
|
+
range: 'Invalid input.',
|
1584
|
+
"datetime-local": 'Please enter a datetime.'
|
1585
|
+
},
|
1586
|
+
rangeUnderflow: {
|
1587
|
+
defaultMessage: 'Value must be greater than or equal to {%min}.'
|
1588
|
+
},
|
1589
|
+
rangeOverflow: {
|
1590
|
+
defaultMessage: 'Value must be less than or equal to {%max}.'
|
1591
|
+
},
|
1592
|
+
stepMismatch: 'Invalid input.',
|
1593
|
+
tooLong: 'Please enter at most {%maxlength} character(s). You entered {%valueLen}.',
|
1594
|
+
|
1595
|
+
patternMismatch: 'Invalid input. {%title}',
|
1596
|
+
valueMissing: {
|
1597
|
+
defaultMessage: 'Please fill out this field.',
|
1598
|
+
checkbox: 'Please check this box if you want to proceed.'
|
1599
|
+
}
|
1600
|
+
}, (validityMessages['en'] || validityMessages['en-US'] || {}));
|
1601
|
+
|
1602
|
+
|
1603
|
+
['select', 'radio'].forEach(function(type){
|
1604
|
+
if(typeof validityMessages['en'].valueMissing == 'object'){
|
1605
|
+
validityMessages['en'].valueMissing[type] = 'Please select an option.';
|
1606
|
+
}
|
1607
|
+
});
|
1608
|
+
|
1609
|
+
['date', 'time', 'datetime-local'].forEach(function(type){
|
1610
|
+
if(typeof validityMessages['en'].rangeUnderflow == 'object'){
|
1611
|
+
validityMessages.en.rangeUnderflow[type] = 'Value must be at or after {%min}.';
|
1612
|
+
}
|
1613
|
+
});
|
1614
|
+
['date', 'time', 'datetime-local'].forEach(function(type){
|
1615
|
+
if(typeof validityMessages['en'].rangeOverflow == 'object'){
|
1616
|
+
validityMessages.en.rangeOverflow[type] = 'Value must be at or before {%max}.';
|
1617
|
+
}
|
1618
|
+
});
|
1619
|
+
|
1620
|
+
validityMessages['en-US'] = validityMessages['en-US'] || validityMessages['en'];
|
1621
|
+
validityMessages[''] = validityMessages[''] || validityMessages['en-US'];
|
1622
|
+
|
1623
|
+
validityMessages['de'] = $.extend(true, {
|
1624
|
+
typeMismatch: {
|
1625
|
+
email: '{%value} ist keine zulässige E-Mail-Adresse',
|
1626
|
+
url: '{%value} ist keine zulässige Webadresse',
|
1627
|
+
number: '{%value} ist keine Nummer!',
|
1628
|
+
date: '{%value} ist kein Datum',
|
1629
|
+
time: '{%value} ist keine Uhrzeit',
|
1630
|
+
range: '{%value} ist keine Nummer!',
|
1631
|
+
"datetime-local": '{%value} ist kein Datum-Uhrzeit Format.'
|
1632
|
+
},
|
1633
|
+
rangeUnderflow: {
|
1634
|
+
defaultMessage: '{%value} ist zu niedrig. {%min} ist der unterste Wert, den Sie benutzen können.'
|
1635
|
+
},
|
1636
|
+
rangeOverflow: {
|
1637
|
+
defaultMessage: '{%value} ist zu hoch. {%max} ist der oberste Wert, den Sie benutzen können.'
|
1638
|
+
},
|
1639
|
+
stepMismatch: 'Der Wert {%value} ist in diesem Feld nicht zulässig. Hier sind nur bestimmte Werte zulässig. {%title}',
|
1640
|
+
tooLong: 'Der eingegebene Text ist zu lang! Sie haben {%valueLen} Zeichen eingegeben, dabei sind {%maxlength} das Maximum.',
|
1641
|
+
patternMismatch: '{%value} hat für dieses Eingabefeld ein falsches Format! {%title}',
|
1642
|
+
valueMissing: {
|
1643
|
+
defaultMessage: 'Bitte geben Sie einen Wert ein',
|
1644
|
+
checkbox: 'Bitte aktivieren Sie das Kästchen'
|
1645
|
+
}
|
1646
|
+
}, (validityMessages['de'] || {}));
|
1647
|
+
|
1648
|
+
['select', 'radio'].forEach(function(type){
|
1649
|
+
if(typeof validityMessages['de'].valueMissing == 'object'){
|
1650
|
+
validityMessages['de'].valueMissing[type] = 'Bitte wählen Sie eine Option aus';
|
1651
|
+
}
|
1652
|
+
});
|
1653
|
+
|
1654
|
+
['date', 'time', 'datetime-local'].forEach(function(type){
|
1655
|
+
if(typeof validityMessages['de'].rangeUnderflow == 'object'){
|
1656
|
+
validityMessages.de.rangeUnderflow[type] = '{%value} ist zu früh. {%min} ist die früheste Zeit, die Sie benutzen können.';
|
1657
|
+
}
|
1658
|
+
});
|
1659
|
+
['date', 'time', 'datetime-local'].forEach(function(type){
|
1660
|
+
if(typeof validityMessages['de'].rangeOverflow == 'object'){
|
1661
|
+
validityMessages.de.rangeOverflow[type] = '{%value} ist zu spät. {%max} ist die späteste Zeit, die Sie benutzen können.';
|
1662
|
+
}
|
1663
|
+
});
|
1664
|
+
|
1665
|
+
var currentValidationMessage = validityMessages[''];
|
1666
|
+
|
1667
|
+
|
1668
|
+
webshims.createValidationMessage = function(elem, name){
|
1669
|
+
var message = currentValidationMessage[name];
|
1670
|
+
if(message && typeof message !== 'string'){
|
1671
|
+
message = message[ $.prop(elem, 'type') ] || message[ (elem.nodeName || '').toLowerCase() ] || message[ 'defaultMessage' ];
|
1672
|
+
}
|
1673
|
+
if(message){
|
1674
|
+
['value', 'min', 'max', 'title', 'maxlength', 'label'].forEach(function(attr){
|
1675
|
+
if(message.indexOf('{%'+attr) === -1){return;}
|
1676
|
+
var val = ((attr == 'label') ? $.trim($('label[for="'+ elem.id +'"]', elem.form).text()).replace(/\*$|:$/, '') : $.attr(elem, attr)) || '';
|
1677
|
+
if(name == 'patternMismatch' && attr == 'title' && !val){
|
1678
|
+
webshims.error('no title for patternMismatch provided. Always add a title attribute.');
|
1679
|
+
}
|
1680
|
+
message = message.replace('{%'+ attr +'}', val);
|
1681
|
+
if('value' == attr){
|
1682
|
+
message = message.replace('{%valueLen}', val.length);
|
1683
|
+
}
|
1684
|
+
});
|
1685
|
+
}
|
1686
|
+
return message || '';
|
1687
|
+
};
|
1688
|
+
|
1689
|
+
|
1690
|
+
if(webshims.bugs.validationMessage || !Modernizr.formvalidation || webshims.bugs.bustedValidity){
|
1691
|
+
implementProperties.push('validationMessage');
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
webshims.activeLang({
|
1695
|
+
langObj: validityMessages,
|
1696
|
+
module: 'form-core',
|
1697
|
+
callback: function(langObj){
|
1698
|
+
currentValidationMessage = langObj;
|
1699
|
+
}
|
1700
|
+
});
|
1701
|
+
|
1702
|
+
implementProperties.forEach(function(messageProp){
|
1703
|
+
webshims.defineNodeNamesProperty(['fieldset', 'output', 'button'], messageProp, {
|
1704
|
+
prop: {
|
1705
|
+
value: '',
|
1706
|
+
writeable: false
|
1707
|
+
}
|
1708
|
+
});
|
1709
|
+
['input', 'select', 'textarea'].forEach(function(nodeName){
|
1710
|
+
var desc = webshims.defineNodeNameProperty(nodeName, messageProp, {
|
1711
|
+
prop: {
|
1712
|
+
get: function(){
|
1713
|
+
var elem = this;
|
1714
|
+
var message = '';
|
1715
|
+
if(!$.prop(elem, 'willValidate')){
|
1716
|
+
return message;
|
1717
|
+
}
|
1718
|
+
|
1719
|
+
var validity = $.prop(elem, 'validity') || {valid: 1};
|
1720
|
+
|
1721
|
+
if(validity.valid){return message;}
|
1722
|
+
message = webshims.getContentValidationMessage(elem, validity);
|
1723
|
+
|
1724
|
+
if(message){return message;}
|
1725
|
+
|
1726
|
+
if(validity.customError && elem.nodeName){
|
1727
|
+
message = (Modernizr.formvalidation && !webshims.bugs.bustedValidity && desc.prop._supget) ? desc.prop._supget.call(elem) : webshims.data(elem, 'customvalidationMessage');
|
1728
|
+
if(message){return message;}
|
1729
|
+
}
|
1730
|
+
$.each(validity, function(name, prop){
|
1731
|
+
if(name == 'valid' || !prop){return;}
|
1732
|
+
|
1733
|
+
message = webshims.createValidationMessage(elem, name);
|
1734
|
+
if(message){
|
1735
|
+
return false;
|
1736
|
+
}
|
1737
|
+
});
|
1738
|
+
return message || '';
|
1739
|
+
},
|
1740
|
+
writeable: false
|
1741
|
+
}
|
1742
|
+
});
|
1743
|
+
});
|
1744
|
+
|
1745
|
+
});
|
1734
1746
|
});
|