Mercurial > nebulaweb3
comparison default/node_modules/shoestring/src/dom/css/getStyle.js @ 0:1d038bc9b3d2 default tip
Up:default
author | Liny <dev@neowd.com> |
---|---|
date | Sat, 31 May 2025 09:21:51 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1d038bc9b3d2 |
---|---|
1 //>>excludeStart("exclude", pragmas.exclude); | |
2 define([ | |
3 "shoestring", | |
4 "dom/css/exceptions", | |
5 ], function(){ | |
6 //>>excludeEnd("exclude"); | |
7 | |
8 (function() { | |
9 var cssExceptions = shoestring.cssExceptions; | |
10 | |
11 // marginRight instead of margin-right | |
12 function convertPropertyName( str ) { | |
13 return str.replace( /\-([A-Za-z])/g, function ( match, character ) { | |
14 return character.toUpperCase(); | |
15 }); | |
16 } | |
17 | |
18 function _getStyle( element, property ) { | |
19 return win.getComputedStyle( element, null ).getPropertyValue( property ); | |
20 } | |
21 | |
22 var vendorPrefixes = [ '', '-webkit-', '-ms-', '-moz-', '-o-', '-khtml-' ]; | |
23 | |
24 /** | |
25 * Private function for getting the computed style of an element. | |
26 * | |
27 * **NOTE** Please use the [css](../css.js.html) method instead. | |
28 * | |
29 * @method _getStyle | |
30 * @param {HTMLElement} element The element we want the style property for. | |
31 * @param {string} property The css property we want the style for. | |
32 */ | |
33 shoestring._getStyle = function( element, property ) { | |
34 var convert, value, j, k; | |
35 | |
36 if( cssExceptions[ property ] ) { | |
37 for( j = 0, k = cssExceptions[ property ].length; j < k; j++ ) { | |
38 value = _getStyle( element, cssExceptions[ property ][ j ] ); | |
39 | |
40 if( value ) { | |
41 return value; | |
42 } | |
43 } | |
44 } | |
45 | |
46 for( j = 0, k = vendorPrefixes.length; j < k; j++ ) { | |
47 convert = convertPropertyName( vendorPrefixes[ j ] + property ); | |
48 | |
49 // VendorprefixKeyName || key-name | |
50 value = _getStyle( element, convert ); | |
51 | |
52 if( convert !== property ) { | |
53 value = value || _getStyle( element, property ); | |
54 } | |
55 | |
56 if( vendorPrefixes[ j ] ) { | |
57 // -vendorprefix-key-name | |
58 value = value || _getStyle( element, vendorPrefixes[ j ] + property ); | |
59 } | |
60 | |
61 if( value ) { | |
62 return value; | |
63 } | |
64 } | |
65 | |
66 return undefined; | |
67 }; | |
68 })(); | |
69 | |
70 //>>excludeStart("exclude", pragmas.exclude); | |
71 }); | |
72 //>>excludeEnd("exclude"); |