7
7
*/
8
8
class Selector {
9
9
10
- const
11
- NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
12
- (\.[\w]+) # classes
13
- |
14
- \[(\w+) # attributes
15
- |
16
- (\:( # pseudo classes
17
- link|visited|active
18
- |hover|focus
19
- |lang
20
- |target
21
- |enabled|disabled|checked|indeterminate
22
- |root
23
- |nth-child|nth-last-child|nth-of-type|nth-last-of-type
24
- |first-child|last-child|first-of-type|last-of-type
25
- |only-child|only-of-type
26
- |empty|contains
27
- ))
28
- /ix ' ,
29
- ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
30
- ((^|[\s\+\>\~]+)[\w]+ # elements
31
- |
32
- \:{1,2}( # pseudo-elements
33
- after|before
34
- |first-letter|first-line
35
- |selection
36
- )
37
- )/ix ' ;
10
+ //Regexes for specificity calculations
11
+ const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
12
+ (\.[\w]+) # classes
13
+ |
14
+ \[(\w+) # attributes
15
+ |
16
+ (\:( # pseudo classes
17
+ link|visited|active
18
+ |hover|focus
19
+ |lang
20
+ |target
21
+ |enabled|disabled|checked|indeterminate
22
+ |root
23
+ |nth-child|nth-last-child|nth-of-type|nth-last-of-type
24
+ |first-child|last-child|first-of-type|last-of-type
25
+ |only-child|only-of-type
26
+ |empty|contains
27
+ ))
28
+ /ix ' ;
29
+
30
+ const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
31
+ ((^|[\s\+\>\~]+)[\w]+ # elements
32
+ |
33
+ \:{1,2}( # pseudo-elements
34
+ after|before|first-letter|first-line|selection
35
+ ))
36
+ /ix ' ;
38
37
39
38
private $ sSelector ;
40
39
private $ iSpecificity ;
@@ -63,7 +62,7 @@ public function getSpecificity() {
63
62
if ($ this ->iSpecificity === null ) {
64
63
$ a = 0 ;
65
64
/// @todo should exclude \# as well as "#"
66
- $ aMatches ;
65
+ $ aMatches = null ;
67
66
$ b = substr_count ($ this ->sSelector , '# ' );
68
67
$ c = preg_match_all (self ::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX , $ this ->sSelector , $ aMatches );
69
68
$ d = preg_match_all (self ::ELEMENTS_AND_PSEUDO_ELEMENTS_RX , $ this ->sSelector , $ aMatches );
@@ -72,4 +71,4 @@ public function getSpecificity() {
72
71
return $ this ->iSpecificity ;
73
72
}
74
73
75
- }
74
+ }
0 commit comments