1- /**
2- * Not type checking this file because flow doesn't like attaching
3- * properties to Elements.
4- */
5-
6- export const inBrowser = typeof window !== 'undefined' ;
7- export const UA = inBrowser && window . navigator . userAgent . toLowerCase ( ) ;
8- export const isIE9 = UA && UA . indexOf ( 'msie 9.0' ) > 0 ;
9- function makeMap ( str , expectsLowerCase ) {
10- const map = Object . create ( null ) ;
11- const list = str . split ( ',' ) ;
12- for ( let i = 0 ; i < list . length ; i ++ ) {
13- map [ list [ i ] ] = true ;
14- }
15- return expectsLowerCase ? val => map [ val . toLowerCase ( ) ] : val => map [ val ] ;
16- }
17- const isTextInputType = makeMap ( 'text,number,password,search,email,tel,url' ) ;
18-
191function onCompositionStart ( e ) {
202 e . target . composing = true ;
213}
@@ -33,40 +15,21 @@ function trigger(el, type) {
3315 el . dispatchEvent ( e ) ;
3416}
3517
36- /* istanbul ignore if */
37- if ( isIE9 ) {
38- // http://www.matts411.com/post/internet-explorer-9-oninput/
39- document . addEventListener ( 'selectionchange' , ( ) => {
40- const el = document . activeElement ;
41- if ( el && el . vmodel ) {
42- trigger ( el , 'input' ) ;
43- }
44- } ) ;
18+ export function addEventListener ( el , event , handler , options ) {
19+ el . addEventListener ( event , handler , options ) ;
4520}
46-
47- export const antInput = {
48- mounted ( el , binding , vnode ) {
49- if ( vnode . type === 'textarea' || isTextInputType ( el . type ) ) {
50- if ( ! binding . modifiers || ! binding . modifiers . lazy ) {
51- el . addEventListener ( 'compositionstart' , onCompositionStart ) ;
52- el . addEventListener ( 'compositionend' , onCompositionEnd ) ;
53- // Safari < 10.2 & UIWebView doesn't fire compositionend when
54- // switching focus before confirming composition choice
55- // this also fixes the issue where some browsers e.g. iOS Chrome
56- // fires "change" instead of "input" on autocomplete.
57- el . addEventListener ( 'change' , onCompositionEnd ) ;
58- /* istanbul ignore if */
59- if ( isIE9 ) {
60- el . vmodel = true ;
61- }
62- }
21+ const antInput = {
22+ created ( el , binding ) {
23+ if ( ! binding . modifiers || ! binding . modifiers . lazy ) {
24+ addEventListener ( el , 'compositionstart' , onCompositionStart ) ;
25+ addEventListener ( el , 'compositionend' , onCompositionEnd ) ;
26+ // Safari < 10.2 & UIWebView doesn't fire compositionend when
27+ // switching focus before confirming composition choice
28+ // this also fixes the issue where some browsers e.g. iOS Chrome
29+ // fires "change" instead of "input" on autocomplete.
30+ addEventListener ( el , 'change' , onCompositionEnd ) ;
6331 }
6432 } ,
6533} ;
6634
67- export default {
68- install : app => {
69- antInput ( app ) ;
70- app . directive ( 'ant-input' , antInput ) ;
71- } ,
72- } ;
35+ export default antInput ;
0 commit comments