-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathoninput.js
More file actions
59 lines (55 loc) · 1.92 KB
/
oninput.js
File metadata and controls
59 lines (55 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*!
{
"name": "onInput Event",
"property": "oninput",
"notes": [{
"name": "MDN Docs",
"href": "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.oninput"
}, {
"name": "WHATWG Spec",
"href": "https://html.spec.whatwg.org/multipage/input.html#common-input-element-attributes"
}, {
"name": "Related Github Issue",
"href": "https://github.com/Modernizr/Modernizr/issues/210"
}],
"authors": ["Patrick Kettner"],
"tags": ["event"]
}
!*/
/* DOC
`oninput` tests if the browser is able to detect the input event
*/
define(['Modernizr', 'docElement', 'createElement', 'testStyles', 'hasEvent'], function(Modernizr, docElement, createElement, testStyles, hasEvent) {
Modernizr.addTest('oninput', function() {
var input = createElement('input');
var supportsOnInput;
input.setAttribute('oninput', 'return');
input.style.cssText = 'position:fixed;top:0;';
if (hasEvent('oninput', docElement) || typeof input.oninput === 'function') {
return true;
}
// IE doesn't support onInput, so we wrap up the non IE APIs
// (createEvent, addEventListener) in a try catch, rather than test for
// their trident equivalent.
try {
// Older Firefox didn't map oninput attribute to oninput property
var testEvent = document.createEvent('KeyboardEvent');
supportsOnInput = false;
var handler = function(e) {
supportsOnInput = true;
e.preventDefault();
e.stopPropagation();
};
testEvent.initKeyEvent('keypress', true, true, window, false, false, false, false, 0, 'e'.charCodeAt(0));
docElement.appendChild(input);
input.addEventListener('input', handler, false);
input.focus();
input.dispatchEvent(testEvent);
input.removeEventListener('input', handler, false);
docElement.removeChild(input);
} catch (e) {
supportsOnInput = false;
}
return supportsOnInput;
});
});