@@ -18,7 +18,7 @@ function Specificity(a, b, c, d){
18
18
19
19
Specificity . prototype = {
20
20
constructor : Specificity ,
21
-
21
+
22
22
/**
23
23
* Compare this specificity to another.
24
24
* @param {Specificity } other The other specificity to compare to.
@@ -28,18 +28,18 @@ Specificity.prototype = {
28
28
compare : function ( other ) {
29
29
var comps = [ "a" , "b" , "c" , "d" ] ,
30
30
i , len ;
31
-
31
+
32
32
for ( i = 0 , len = comps . length ; i < len ; i ++ ) {
33
33
if ( this [ comps [ i ] ] < other [ comps [ i ] ] ) {
34
34
return - 1 ;
35
35
} else if ( this [ comps [ i ] ] > other [ comps [ i ] ] ) {
36
36
return 1 ;
37
37
}
38
38
}
39
-
39
+
40
40
return 0 ;
41
41
} ,
42
-
42
+
43
43
/**
44
44
* Creates a numeric value for the specificity.
45
45
* @return {int } The numeric value for the specificity.
@@ -48,7 +48,7 @@ Specificity.prototype = {
48
48
valueOf : function ( ) {
49
49
return ( this . a * 1000 ) + ( this . b * 100 ) + ( this . c * 10 ) + this . d ;
50
50
} ,
51
-
51
+
52
52
/**
53
53
* Returns a string representation for specificity.
54
54
* @return {String } The string representation of specificity.
@@ -72,52 +72,52 @@ Specificity.calculate = function(selector){
72
72
var i , len ,
73
73
part ,
74
74
b = 0 , c = 0 , d = 0 ;
75
-
75
+
76
76
function updateValues ( part ) {
77
-
77
+
78
78
var i , j , len , num ,
79
79
elementName = part . elementName ? part . elementName . text : "" ,
80
80
modifier ;
81
-
81
+
82
82
if ( elementName && elementName . charAt ( elementName . length - 1 ) != "*" ) {
83
83
d ++ ;
84
- }
85
-
84
+ }
85
+
86
86
for ( i = 0 , len = part . modifiers . length ; i < len ; i ++ ) {
87
87
modifier = part . modifiers [ i ] ;
88
88
switch ( modifier . type ) {
89
89
case "class" :
90
90
case "attribute" :
91
91
c ++ ;
92
92
break ;
93
-
93
+
94
94
case "id" :
95
95
b ++ ;
96
96
break ;
97
-
97
+
98
98
case "pseudo" :
99
99
if ( Pseudos . isElement ( modifier . text ) ) {
100
100
d ++ ;
101
101
} else {
102
102
c ++ ;
103
- }
103
+ }
104
104
break ;
105
-
105
+
106
106
case "not" :
107
107
for ( j = 0 , num = modifier . args . length ; j < num ; j ++ ) {
108
108
updateValues ( modifier . args [ j ] ) ;
109
109
}
110
- }
110
+ }
111
111
}
112
112
}
113
-
113
+
114
114
for ( i = 0 , len = selector . parts . length ; i < len ; i ++ ) {
115
115
part = selector . parts [ i ] ;
116
-
116
+
117
117
if ( part instanceof SelectorPart ) {
118
- updateValues ( part ) ;
118
+ updateValues ( part ) ;
119
119
}
120
120
}
121
-
121
+
122
122
return new Specificity ( 0 , b , c , d ) ;
123
123
} ;
0 commit comments