Blame view

app/bower_components/jquery/src/attributes/attr.js 3.17 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"../core",
f986e111b   TRUONG   add libs
3
4
  	"../core/access",
  	"./support",
87c93a029   Dang YoungWorld   add modal
5
  	"../var/rnothtmlwhite",
f986e111b   TRUONG   add libs
6
  	"../selector"
87c93a029   Dang YoungWorld   add modal
7
  ], function( jQuery, access, support, rnothtmlwhite ) {
f986e111b   TRUONG   add libs
8

87c93a029   Dang YoungWorld   add modal
9
  "use strict";
f986e111b   TRUONG   add libs
10

87c93a029   Dang YoungWorld   add modal
11
12
13
14
  var boolHook,
  	attrHandle = jQuery.expr.attrHandle;
  
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
15
16
17
18
19
  	attr: function( name, value ) {
  		return access( this, jQuery.attr, name, value, arguments.length > 1 );
  	},
  
  	removeAttr: function( name ) {
87c93a029   Dang YoungWorld   add modal
20
  		return this.each( function() {
f986e111b   TRUONG   add libs
21
  			jQuery.removeAttr( this, name );
87c93a029   Dang YoungWorld   add modal
22
  		} );
f986e111b   TRUONG   add libs
23
  	}
87c93a029   Dang YoungWorld   add modal
24
  } );
f986e111b   TRUONG   add libs
25

87c93a029   Dang YoungWorld   add modal
26
  jQuery.extend( {
f986e111b   TRUONG   add libs
27
  	attr: function( elem, name, value ) {
87c93a029   Dang YoungWorld   add modal
28
  		var ret, hooks,
f986e111b   TRUONG   add libs
29
  			nType = elem.nodeType;
87c93a029   Dang YoungWorld   add modal
30
31
  		// Don't get/set attributes on text, comment and attribute nodes
  		if ( nType === 3 || nType === 8 || nType === 2 ) {
f986e111b   TRUONG   add libs
32
33
34
35
  			return;
  		}
  
  		// Fallback to prop when attributes are not supported
87c93a029   Dang YoungWorld   add modal
36
  		if ( typeof elem.getAttribute === "undefined" ) {
f986e111b   TRUONG   add libs
37
38
  			return jQuery.prop( elem, name, value );
  		}
87c93a029   Dang YoungWorld   add modal
39
  		// Attribute hooks are determined by the lowercase version
f986e111b   TRUONG   add libs
40
41
  		// Grab necessary hook if one is defined
  		if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
87c93a029   Dang YoungWorld   add modal
42
43
  			hooks = jQuery.attrHooks[ name.toLowerCase() ] ||
  				( jQuery.expr.match.bool.test( name ) ? boolHook : undefined );
f986e111b   TRUONG   add libs
44
45
46
  		}
  
  		if ( value !== undefined ) {
f986e111b   TRUONG   add libs
47
48
  			if ( value === null ) {
  				jQuery.removeAttr( elem, name );
87c93a029   Dang YoungWorld   add modal
49
50
  				return;
  			}
f986e111b   TRUONG   add libs
51

87c93a029   Dang YoungWorld   add modal
52
53
  			if ( hooks && "set" in hooks &&
  				( ret = hooks.set( elem, value, name ) ) !== undefined ) {
f986e111b   TRUONG   add libs
54
  				return ret;
f986e111b   TRUONG   add libs
55
  			}
87c93a029   Dang YoungWorld   add modal
56
57
  			elem.setAttribute( name, value + "" );
  			return value;
f986e111b   TRUONG   add libs
58
  		}
f986e111b   TRUONG   add libs
59

87c93a029   Dang YoungWorld   add modal
60
61
62
  		if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
  			return ret;
  		}
f986e111b   TRUONG   add libs
63

87c93a029   Dang YoungWorld   add modal
64
  		ret = jQuery.find.attr( elem, name );
f986e111b   TRUONG   add libs
65

87c93a029   Dang YoungWorld   add modal
66
67
  		// Non-existent attributes return null, we normalize to undefined
  		return ret == null ? undefined : ret;
f986e111b   TRUONG   add libs
68
69
70
71
72
  	},
  
  	attrHooks: {
  		type: {
  			set: function( elem, value ) {
87c93a029   Dang YoungWorld   add modal
73
74
  				if ( !support.radioValue && value === "radio" &&
  					jQuery.nodeName( elem, "input" ) ) {
f986e111b   TRUONG   add libs
75
76
77
78
79
80
81
82
83
  					var val = elem.value;
  					elem.setAttribute( "type", value );
  					if ( val ) {
  						elem.value = val;
  					}
  					return value;
  				}
  			}
  		}
87c93a029   Dang YoungWorld   add modal
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  	},
  
  	removeAttr: function( elem, value ) {
  		var name,
  			i = 0,
  
  			// Attribute names can contain non-HTML whitespace characters
  			// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
  			attrNames = value && value.match( rnothtmlwhite );
  
  		if ( attrNames && elem.nodeType === 1 ) {
  			while ( ( name = attrNames[ i++ ] ) ) {
  				elem.removeAttribute( name );
  			}
  		}
f986e111b   TRUONG   add libs
99
  	}
87c93a029   Dang YoungWorld   add modal
100
  } );
f986e111b   TRUONG   add libs
101

87c93a029   Dang YoungWorld   add modal
102
  // Hooks for boolean attributes
f986e111b   TRUONG   add libs
103
104
105
  boolHook = {
  	set: function( elem, value, name ) {
  		if ( value === false ) {
87c93a029   Dang YoungWorld   add modal
106

f986e111b   TRUONG   add libs
107
108
  			// Remove boolean attributes when set to false
  			jQuery.removeAttr( elem, name );
f986e111b   TRUONG   add libs
109
  		} else {
87c93a029   Dang YoungWorld   add modal
110
  			elem.setAttribute( name, name );
f986e111b   TRUONG   add libs
111
  		}
f986e111b   TRUONG   add libs
112
113
114
  		return name;
  	}
  };
f986e111b   TRUONG   add libs
115
  jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
f986e111b   TRUONG   add libs
116
  	var getter = attrHandle[ name ] || jQuery.find.attr;
87c93a029   Dang YoungWorld   add modal
117
118
119
  	attrHandle[ name ] = function( elem, name, isXML ) {
  		var ret, handle,
  			lowercaseName = name.toLowerCase();
f986e111b   TRUONG   add libs
120

87c93a029   Dang YoungWorld   add modal
121
  		if ( !isXML ) {
f986e111b   TRUONG   add libs
122

87c93a029   Dang YoungWorld   add modal
123
124
125
126
127
128
129
  			// Avoid an infinite loop by temporarily removing this function from the getter
  			handle = attrHandle[ lowercaseName ];
  			attrHandle[ lowercaseName ] = ret;
  			ret = getter( elem, name, isXML ) != null ?
  				lowercaseName :
  				null;
  			attrHandle[ lowercaseName ] = handle;
f986e111b   TRUONG   add libs
130
  		}
87c93a029   Dang YoungWorld   add modal
131
  		return ret;
f986e111b   TRUONG   add libs
132
  	};
87c93a029   Dang YoungWorld   add modal
133
  } );
f986e111b   TRUONG   add libs
134

87c93a029   Dang YoungWorld   add modal
135
  } );