1
|
define( [
|
2
|
"../core",
|
3
|
"../core/access",
|
4
|
"./support",
|
5
|
"../selector"
|
6
|
], function( jQuery, access, support ) {
|
7
|
|
8
|
"use strict";
|
9
|
|
10
|
var rfocusable = /^(?:input|select|textarea|button)$/i,
|
11
|
rclickable = /^(?:a|area)$/i;
|
12
|
|
13
|
jQuery.fn.extend( {
|
14
|
prop: function( name, value ) {
|
15
|
return access( this, jQuery.prop, name, value, arguments.length > 1 );
|
16
|
},
|
17
|
|
18
|
removeProp: function( name ) {
|
19
|
return this.each( function() {
|
20
|
delete this[ jQuery.propFix[ name ] || name ];
|
21
|
} );
|
22
|
}
|
23
|
} );
|
24
|
|
25
|
jQuery.extend( {
|
26
|
prop: function( elem, name, value ) {
|
27
|
var ret, hooks,
|
28
|
nType = elem.nodeType;
|
29
|
|
30
|
// Don't get/set properties on text, comment and attribute nodes
|
31
|
if ( nType === 3 || nType === 8 || nType === 2 ) {
|
32
|
return;
|
33
|
}
|
34
|
|
35
|
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
|
36
|
|
37
|
// Fix name and attach hooks
|
38
|
name = jQuery.propFix[ name ] || name;
|
39
|
hooks = jQuery.propHooks[ name ];
|
40
|
}
|
41
|
|
42
|
if ( value !== undefined ) {
|
43
|
if ( hooks && "set" in hooks &&
|
44
|
( ret = hooks.set( elem, value, name ) ) !== undefined ) {
|
45
|
return ret;
|
46
|
}
|
47
|
|
48
|
return ( elem[ name ] = value );
|
49
|
}
|
50
|
|
51
|
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
|
52
|
return ret;
|
53
|
}
|
54
|
|
55
|
return elem[ name ];
|
56
|
},
|
57
|
|
58
|
propHooks: {
|
59
|
tabIndex: {
|
60
|
get: function( elem ) {
|
61
|
|
62
|
// Support: IE <=9 - 11 only
|
63
|
// elem.tabIndex doesn't always return the
|
64
|
// correct value when it hasn't been explicitly set
|
65
|
// https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
66
|
// Use proper attribute retrieval(#12072)
|
67
|
var tabindex = jQuery.find.attr( elem, "tabindex" );
|
68
|
|
69
|
if ( tabindex ) {
|
70
|
return parseInt( tabindex, 10 );
|
71
|
}
|
72
|
|
73
|
if (
|
74
|
rfocusable.test( elem.nodeName ) ||
|
75
|
rclickable.test( elem.nodeName ) &&
|
76
|
elem.href
|
77
|
) {
|
78
|
return 0;
|
79
|
}
|
80
|
|
81
|
return -1;
|
82
|
}
|
83
|
}
|
84
|
},
|
85
|
|
86
|
propFix: {
|
87
|
"for": "htmlFor",
|
88
|
"class": "className"
|
89
|
}
|
90
|
} );
|
91
|
|
92
|
// Support: IE <=11 only
|
93
|
// Accessing the selectedIndex property
|
94
|
// forces the browser to respect setting selected
|
95
|
// on the option
|
96
|
// The getter ensures a default option is selected
|
97
|
// when in an optgroup
|
98
|
// eslint rule "no-unused-expressions" is disabled for this code
|
99
|
// since it considers such accessions noop
|
100
|
if ( !support.optSelected ) {
|
101
|
jQuery.propHooks.selected = {
|
102
|
get: function( elem ) {
|
103
|
|
104
|
/* eslint no-unused-expressions: "off" */
|
105
|
|
106
|
var parent = elem.parentNode;
|
107
|
if ( parent && parent.parentNode ) {
|
108
|
parent.parentNode.selectedIndex;
|
109
|
}
|
110
|
return null;
|
111
|
},
|
112
|
set: function( elem ) {
|
113
|
|
114
|
/* eslint no-unused-expressions: "off" */
|
115
|
|
116
|
var parent = elem.parentNode;
|
117
|
if ( parent ) {
|
118
|
parent.selectedIndex;
|
119
|
|
120
|
if ( parent.parentNode ) {
|
121
|
parent.parentNode.selectedIndex;
|
122
|
}
|
123
|
}
|
124
|
}
|
125
|
};
|
126
|
}
|
127
|
|
128
|
jQuery.each( [
|
129
|
"tabIndex",
|
130
|
"readOnly",
|
131
|
"maxLength",
|
132
|
"cellSpacing",
|
133
|
"cellPadding",
|
134
|
"rowSpan",
|
135
|
"colSpan",
|
136
|
"useMap",
|
137
|
"frameBorder",
|
138
|
"contentEditable"
|
139
|
], function() {
|
140
|
jQuery.propFix[ this.toLowerCase() ] = this;
|
141
|
} );
|
142
|
|
143
|
} );
|