scratch – Blame information for rev 125

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