nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery / src / attributes / val.js
1 define( [
2         "../core",
3         "./support",
4         "../core/init"
5 ], function( jQuery, support ) {
6
7 var rreturn = /\r/g,
8         rspaces = /[\x20\t\r\n\f]+/g;
9
10 jQuery.fn.extend( {
11         val: function( value ) {
12                 var hooks, ret, isFunction,
13                         elem = this[ 0 ];
14
15                 if ( !arguments.length ) {
16                         if ( elem ) {
17                                 hooks = jQuery.valHooks[ elem.type ] ||
18                                         jQuery.valHooks[ elem.nodeName.toLowerCase() ];
19
20                                 if ( hooks &&
21                                         "get" in hooks &&
22                                         ( ret = hooks.get( elem, "value" ) ) !== undefined
23                                 ) {
24                                         return ret;
25                                 }
26
27                                 ret = elem.value;
28
29                                 return typeof ret === "string" ?
30
31                                         // Handle most common string cases
32                                         ret.replace( rreturn, "" ) :
33
34                                         // Handle cases where value is null/undef or number
35                                         ret == null ? "" : ret;
36                         }
37
38                         return;
39                 }
40
41                 isFunction = jQuery.isFunction( value );
42
43                 return this.each( function( i ) {
44                         var val;
45
46                         if ( this.nodeType !== 1 ) {
47                                 return;
48                         }
49
50                         if ( isFunction ) {
51                                 val = value.call( this, i, jQuery( this ).val() );
52                         } else {
53                                 val = value;
54                         }
55
56                         // Treat null/undefined as ""; convert numbers to string
57                         if ( val == null ) {
58                                 val = "";
59
60                         } else if ( typeof val === "number" ) {
61                                 val += "";
62
63                         } else if ( jQuery.isArray( val ) ) {
64                                 val = jQuery.map( val, function( value ) {
65                                         return value == null ? "" : value + "";
66                                 } );
67                         }
68
69                         hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
70
71                         // If set returns undefined, fall back to normal setting
72                         if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
73                                 this.value = val;
74                         }
75                 } );
76         }
77 } );
78
79 jQuery.extend( {
80         valHooks: {
81                 option: {
82                         get: function( elem ) {
83
84                                 var val = jQuery.find.attr( elem, "value" );
85                                 return val != null ?
86                                         val :
87
88                                         // Support: IE10-11+
89                                         // option.text throws exceptions (#14686, #14858)
90                                         // Strip and collapse whitespace
91                                         // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
92                                         jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " );
93                         }
94                 },
95                 select: {
96                         get: function( elem ) {
97                                 var value, option,
98                                         options = elem.options,
99                                         index = elem.selectedIndex,
100                                         one = elem.type === "select-one" || index < 0,
101                                         values = one ? null : [],
102                                         max = one ? index + 1 : options.length,
103                                         i = index < 0 ?
104                                                 max :
105                                                 one ? index : 0;
106
107                                 // Loop through all the selected options
108                                 for ( ; i < max; i++ ) {
109                                         option = options[ i ];
110
111                                         // IE8-9 doesn't update selected after form reset (#2551)
112                                         if ( ( option.selected || i === index ) &&
113
114                                                         // Don't return options that are disabled or in a disabled optgroup
115                                                         ( support.optDisabled ?
116                                                                 !option.disabled : option.getAttribute( "disabled" ) === null ) &&
117                                                         ( !option.parentNode.disabled ||
118                                                                 !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
119
120                                                 // Get the specific value for the option
121                                                 value = jQuery( option ).val();
122
123                                                 // We don't need an array for one selects
124                                                 if ( one ) {
125                                                         return value;
126                                                 }
127
128                                                 // Multi-Selects return an array
129                                                 values.push( value );
130                                         }
131                                 }
132
133                                 return values;
134                         },
135
136                         set: function( elem, value ) {
137                                 var optionSet, option,
138                                         options = elem.options,
139                                         values = jQuery.makeArray( value ),
140                                         i = options.length;
141
142                                 while ( i-- ) {
143                                         option = options[ i ];
144                                         if ( option.selected =
145                                                 jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
146                                         ) {
147                                                 optionSet = true;
148                                         }
149                                 }
150
151                                 // Force browsers to behave consistently when non-matching value is set
152                                 if ( !optionSet ) {
153                                         elem.selectedIndex = -1;
154                                 }
155                                 return values;
156                         }
157                 }
158         }
159 } );
160
161 // Radios and checkboxes getter/setter
162 jQuery.each( [ "radio", "checkbox" ], function() {
163         jQuery.valHooks[ this ] = {
164                 set: function( elem, value ) {
165                         if ( jQuery.isArray( value ) ) {
166                                 return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
167                         }
168                 }
169         };
170         if ( !support.checkOn ) {
171                 jQuery.valHooks[ this ].get = function( elem ) {
172                         return elem.getAttribute( "value" ) === null ? "on" : elem.value;
173                 };
174         }
175 } );
176
177 } );