1 | define([
|
2 | "./core",
|
3 | "./var/pnum",
|
4 | "./core/access",
|
5 | "./css/var/rmargin",
|
6 | "./css/var/rnumnonpx",
|
7 | "./css/var/cssExpand",
|
8 | "./css/var/isHidden",
|
9 | "./css/var/getStyles",
|
10 | "./css/curCSS",
|
11 | "./css/defaultDisplay",
|
12 | "./css/addGetHookIf",
|
13 | "./css/support",
|
14 | "./data/var/data_priv",
|
15 |
|
16 | "./core/init",
|
17 | "./css/swap",
|
18 | "./core/ready",
|
19 | "./selector"
|
20 | ], function( jQuery, pnum, access, rmargin, rnumnonpx, cssExpand, isHidden,
|
21 | getStyles, curCSS, defaultDisplay, addGetHookIf, support, data_priv ) {
|
22 |
|
23 | var
|
24 |
|
25 |
|
26 | rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
27 | rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
|
28 | rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
|
29 |
|
30 | cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
31 | cssNormalTransform = {
|
32 | letterSpacing: "0",
|
33 | fontWeight: "400"
|
34 | },
|
35 |
|
36 | cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
|
37 |
|
38 |
|
39 | function vendorPropName( style, name ) {
|
40 |
|
41 |
|
42 | if ( name in style ) {
|
43 | return name;
|
44 | }
|
45 |
|
46 |
|
47 | var capName = name[0].toUpperCase() + name.slice(1),
|
48 | origName = name,
|
49 | i = cssPrefixes.length;
|
50 |
|
51 | while ( i-- ) {
|
52 | name = cssPrefixes[ i ] + capName;
|
53 | if ( name in style ) {
|
54 | return name;
|
55 | }
|
56 | }
|
57 |
|
58 | return origName;
|
59 | }
|
60 |
|
61 | function setPositiveNumber( elem, value, subtract ) {
|
62 | var matches = rnumsplit.exec( value );
|
63 | return matches ?
|
64 |
|
65 | Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
|
66 | value;
|
67 | }
|
68 |
|
69 | function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
|
70 | var i = extra === ( isBorderBox ? "border" : "content" ) ?
|
71 |
|
72 | 4 :
|
73 |
|
74 | name === "width" ? 1 : 0,
|
75 |
|
76 | val = 0;
|
77 |
|
78 | for ( ; i < 4; i += 2 ) {
|
79 |
|
80 | if ( extra === "margin" ) {
|
81 | val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
|
82 | }
|
83 |
|
84 | if ( isBorderBox ) {
|
85 |
|
86 | if ( extra === "content" ) {
|
87 | val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
88 | }
|
89 |
|
90 |
|
91 | if ( extra !== "margin" ) {
|
92 | val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
93 | }
|
94 | } else {
|
95 |
|
96 | val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
97 |
|
98 |
|
99 | if ( extra !== "padding" ) {
|
100 | val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
101 | }
|
102 | }
|
103 | }
|
104 |
|
105 | return val;
|
106 | }
|
107 |
|
108 | function getWidthOrHeight( elem, name, extra ) {
|
109 |
|
110 |
|
111 | var valueIsBorderBox = true,
|
112 | val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
|
113 | styles = getStyles( elem ),
|
114 | isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | if ( val <= 0 || val == null ) {
|
120 |
|
121 | val = curCSS( elem, name, styles );
|
122 | if ( val < 0 || val == null ) {
|
123 | val = elem.style[ name ];
|
124 | }
|
125 |
|
126 |
|
127 | if ( rnumnonpx.test(val) ) {
|
128 | return val;
|
129 | }
|
130 |
|
131 |
|
132 |
|
133 | valueIsBorderBox = isBorderBox &&
|
134 | ( support.boxSizingReliable() || val === elem.style[ name ] );
|
135 |
|
136 |
|
137 | val = parseFloat( val ) || 0;
|
138 | }
|
139 |
|
140 |
|
141 | return ( val +
|
142 | augmentWidthOrHeight(
|
143 | elem,
|
144 | name,
|
145 | extra || ( isBorderBox ? "border" : "content" ),
|
146 | valueIsBorderBox,
|
147 | styles
|
148 | )
|
149 | ) + "px";
|
150 | }
|
151 |
|
152 | function showHide( elements, show ) {
|
153 | var display, elem, hidden,
|
154 | values = [],
|
155 | index = 0,
|
156 | length = elements.length;
|
157 |
|
158 | for ( ; index < length; index++ ) {
|
159 | elem = elements[ index ];
|
160 | if ( !elem.style ) {
|
161 | continue;
|
162 | }
|
163 |
|
164 | values[ index ] = data_priv.get( elem, "olddisplay" );
|
165 | display = elem.style.display;
|
166 | if ( show ) {
|
167 |
|
168 |
|
169 | if ( !values[ index ] && display === "none" ) {
|
170 | elem.style.display = "";
|
171 | }
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | if ( elem.style.display === "" && isHidden( elem ) ) {
|
177 | values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
|
178 | }
|
179 | } else {
|
180 | hidden = isHidden( elem );
|
181 |
|
182 | if ( display !== "none" || !hidden ) {
|
183 | data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
|
184 | }
|
185 | }
|
186 | }
|
187 |
|
188 |
|
189 |
|
190 | for ( index = 0; index < length; index++ ) {
|
191 | elem = elements[ index ];
|
192 | if ( !elem.style ) {
|
193 | continue;
|
194 | }
|
195 | if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
|
196 | elem.style.display = show ? values[ index ] || "" : "none";
|
197 | }
|
198 | }
|
199 |
|
200 | return elements;
|
201 | }
|
202 |
|
203 | jQuery.extend({
|
204 |
|
205 |
|
206 | cssHooks: {
|
207 | opacity: {
|
208 | get: function( elem, computed ) {
|
209 | if ( computed ) {
|
210 |
|
211 | var ret = curCSS( elem, "opacity" );
|
212 | return ret === "" ? "1" : ret;
|
213 | }
|
214 | }
|
215 | }
|
216 | },
|
217 |
|
218 |
|
219 | cssNumber: {
|
220 | "columnCount": true,
|
221 | "fillOpacity": true,
|
222 | "flexGrow": true,
|
223 | "flexShrink": true,
|
224 | "fontWeight": true,
|
225 | "lineHeight": true,
|
226 | "opacity": true,
|
227 | "order": true,
|
228 | "orphans": true,
|
229 | "widows": true,
|
230 | "zIndex": true,
|
231 | "zoom": true
|
232 | },
|
233 |
|
234 |
|
235 |
|
236 | cssProps: {
|
237 |
|
238 | "float": "cssFloat"
|
239 | },
|
240 |
|
241 |
|
242 | style: function( elem, name, value, extra ) {
|
243 |
|
244 | if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
|
245 | return;
|
246 | }
|
247 |
|
248 |
|
249 | var ret, type, hooks,
|
250 | origName = jQuery.camelCase( name ),
|
251 | style = elem.style;
|
252 |
|
253 | name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
|
254 |
|
255 |
|
256 |
|
257 | hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
258 |
|
259 |
|
260 | if ( value !== undefined ) {
|
261 | type = typeof value;
|
262 |
|
263 |
|
264 | if ( type === "string" && (ret = rrelNum.exec( value )) ) {
|
265 | value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
|
266 |
|
267 | type = "number";
|
268 | }
|
269 |
|
270 |
|
271 | if ( value == null || value !== value ) {
|
272 | return;
|
273 | }
|
274 |
|
275 |
|
276 | if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
|
277 | value += "px";
|
278 | }
|
279 |
|
280 |
|
281 |
|
282 | if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
|
283 | style[ name ] = "inherit";
|
284 | }
|
285 |
|
286 |
|
287 | if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
|
288 | style[ name ] = value;
|
289 | }
|
290 |
|
291 | } else {
|
292 |
|
293 | if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
|
294 | return ret;
|
295 | }
|
296 |
|
297 |
|
298 | return style[ name ];
|
299 | }
|
300 | },
|
301 |
|
302 | css: function( elem, name, extra, styles ) {
|
303 | var val, num, hooks,
|
304 | origName = jQuery.camelCase( name );
|
305 |
|
306 |
|
307 | name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
|
308 |
|
309 |
|
310 |
|
311 | hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
312 |
|
313 |
|
314 | if ( hooks && "get" in hooks ) {
|
315 | val = hooks.get( elem, true, extra );
|
316 | }
|
317 |
|
318 |
|
319 | if ( val === undefined ) {
|
320 | val = curCSS( elem, name, styles );
|
321 | }
|
322 |
|
323 |
|
324 | if ( val === "normal" && name in cssNormalTransform ) {
|
325 | val = cssNormalTransform[ name ];
|
326 | }
|
327 |
|
328 |
|
329 | if ( extra === "" || extra ) {
|
330 | num = parseFloat( val );
|
331 | return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
|
332 | }
|
333 | return val;
|
334 | }
|
335 | });
|
336 |
|
337 | jQuery.each([ "height", "width" ], function( i, name ) {
|
338 | jQuery.cssHooks[ name ] = {
|
339 | get: function( elem, computed, extra ) {
|
340 | if ( computed ) {
|
341 |
|
342 |
|
343 | return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
|
344 | jQuery.swap( elem, cssShow, function() {
|
345 | return getWidthOrHeight( elem, name, extra );
|
346 | }) :
|
347 | getWidthOrHeight( elem, name, extra );
|
348 | }
|
349 | },
|
350 |
|
351 | set: function( elem, value, extra ) {
|
352 | var styles = extra && getStyles( elem );
|
353 | return setPositiveNumber( elem, value, extra ?
|
354 | augmentWidthOrHeight(
|
355 | elem,
|
356 | name,
|
357 | extra,
|
358 | jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
|
359 | styles
|
360 | ) : 0
|
361 | );
|
362 | }
|
363 | };
|
364 | });
|
365 |
|
366 |
|
367 | jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
|
368 | function( elem, computed ) {
|
369 | if ( computed ) {
|
370 |
|
371 |
|
372 | return jQuery.swap( elem, { "display": "inline-block" },
|
373 | curCSS, [ elem, "marginRight" ] );
|
374 | }
|
375 | }
|
376 | );
|
377 |
|
378 |
|
379 | jQuery.each({
|
380 | margin: "",
|
381 | padding: "",
|
382 | border: "Width"
|
383 | }, function( prefix, suffix ) {
|
384 | jQuery.cssHooks[ prefix + suffix ] = {
|
385 | expand: function( value ) {
|
386 | var i = 0,
|
387 | expanded = {},
|
388 |
|
389 |
|
390 | parts = typeof value === "string" ? value.split(" ") : [ value ];
|
391 |
|
392 | for ( ; i < 4; i++ ) {
|
393 | expanded[ prefix + cssExpand[ i ] + suffix ] =
|
394 | parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
|
395 | }
|
396 |
|
397 | return expanded;
|
398 | }
|
399 | };
|
400 |
|
401 | if ( !rmargin.test( prefix ) ) {
|
402 | jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
|
403 | }
|
404 | });
|
405 |
|
406 | jQuery.fn.extend({
|
407 | css: function( name, value ) {
|
408 | return access( this, function( elem, name, value ) {
|
409 | var styles, len,
|
410 | map = {},
|
411 | i = 0;
|
412 |
|
413 | if ( jQuery.isArray( name ) ) {
|
414 | styles = getStyles( elem );
|
415 | len = name.length;
|
416 |
|
417 | for ( ; i < len; i++ ) {
|
418 | map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
|
419 | }
|
420 |
|
421 | return map;
|
422 | }
|
423 |
|
424 | return value !== undefined ?
|
425 | jQuery.style( elem, name, value ) :
|
426 | jQuery.css( elem, name );
|
427 | }, name, value, arguments.length > 1 );
|
428 | },
|
429 | show: function() {
|
430 | return showHide( this, true );
|
431 | },
|
432 | hide: function() {
|
433 | return showHide( this );
|
434 | },
|
435 | toggle: function( state ) {
|
436 | if ( typeof state === "boolean" ) {
|
437 | return state ? this.show() : this.hide();
|
438 | }
|
439 |
|
440 | return this.each(function() {
|
441 | if ( isHidden( this ) ) {
|
442 | jQuery( this ).show();
|
443 | } else {
|
444 | jQuery( this ).hide();
|
445 | }
|
446 | });
|
447 | }
|
448 | });
|
449 |
|
450 | return jQuery;
|
451 | });
|