@@ -19,8 +19,8 @@ tree.Media.prototype = {
19
19
} ,
20
20
eval : function ( env ) {
21
21
if ( ! env . mediaBlocks ) {
22
- env . mediaBlocks = [ ] ;
23
- env . mediaPath = [ ] ;
22
+ env . mediaBlocks = [ ] ;
23
+ env . mediaPath = [ ] ;
24
24
}
25
25
26
26
env . mediaBlocks . push ( this ) ;
@@ -34,78 +34,78 @@ tree.Media.prototype = {
34
34
env . mediaPath . pop ( ) ;
35
35
36
36
if ( env . mediaPath . length === 0 ) {
37
- return this . evalTop ( env ) ;
37
+ return this . evalTop ( env ) ;
38
38
} else {
39
- return this . evalNested ( env ) ;
39
+ return this . evalNested ( env ) ;
40
40
}
41
41
} ,
42
42
variable : function ( name ) { return tree . Ruleset . prototype . variable . call ( this . ruleset , name ) } ,
43
43
find : function ( ) { return tree . Ruleset . prototype . find . apply ( this . ruleset , arguments ) } ,
44
44
rulesets : function ( ) { return tree . Ruleset . prototype . rulesets . apply ( this . ruleset ) } ,
45
45
46
46
evalTop : function ( env ) {
47
- var result = this ;
48
-
49
- // Render all dependent Media blocks.
50
- if ( env . mediaBlocks . length > 1 ) {
51
- var el = new ( tree . Element ) ( '&' , null , 0 ) ;
52
- var selectors = [ new ( tree . Selector ) ( [ el ] ) ] ;
53
- result = new ( tree . Ruleset ) ( selectors , env . mediaBlocks ) ;
54
- result . multiMedia = true ;
55
- }
47
+ var result = this ;
48
+
49
+ // Render all dependent Media blocks.
50
+ if ( env . mediaBlocks . length > 1 ) {
51
+ var el = new ( tree . Element ) ( '&' , null , 0 ) ;
52
+ var selectors = [ new ( tree . Selector ) ( [ el ] ) ] ;
53
+ result = new ( tree . Ruleset ) ( selectors , env . mediaBlocks ) ;
54
+ result . multiMedia = true ;
55
+ }
56
56
57
- delete env . mediaBlocks ;
58
- delete env . mediaPath ;
57
+ delete env . mediaBlocks ;
58
+ delete env . mediaPath ;
59
59
60
- return result ;
60
+ return result ;
61
61
} ,
62
62
evalNested : function ( env ) {
63
- var i , value ,
64
- path = env . mediaPath . concat ( [ this ] ) ;
65
-
66
- // Extract the media-query conditions separated with `,` (OR).
67
- for ( i = 0 ; i < path . length ; i ++ ) {
68
- value = path [ i ] . features instanceof tree . Value ?
69
- path [ i ] . features . value : path [ i ] . features ;
70
- path [ i ] = Array . isArray ( value ) ? value : [ value ] ;
71
- }
72
-
73
- // Trace all permutations to generate the resulting media-query.
74
- //
75
- // (a, b and c) with nested (d, e) ->
76
- // a and d
77
- // a and e
78
- // b and c and d
79
- // b and c and e
80
- this . features = new ( tree . Value ) ( this . permute ( path ) . map ( function ( path ) {
81
- path = path . map ( function ( fragment ) {
82
- return fragment . toCSS ? fragment : new ( tree . Anonymous ) ( fragment ) ;
83
- } ) ;
84
-
85
- for ( i = path . length - 1 ; i > 0 ; i -- ) {
86
- path . splice ( i , 0 , new ( tree . Anonymous ) ( "and" ) ) ;
63
+ var i , value ,
64
+ path = env . mediaPath . concat ( [ this ] ) ;
65
+
66
+ // Extract the media-query conditions separated with `,` (OR).
67
+ for ( i = 0 ; i < path . length ; i ++ ) {
68
+ value = path [ i ] . features instanceof tree . Value ?
69
+ path [ i ] . features . value : path [ i ] . features ;
70
+ path [ i ] = Array . isArray ( value ) ? value : [ value ] ;
87
71
}
88
72
89
- return new ( tree . Expression ) ( path ) ;
90
- } ) ) ;
91
-
92
- // Fake a tree-node that doesn't output anything.
93
- return new ( tree . Ruleset ) ( [ ] , [ ] ) ;
73
+ // Trace all permutations to generate the resulting media-query.
74
+ //
75
+ // (a, b and c) with nested (d, e) ->
76
+ // a and d
77
+ // a and e
78
+ // b and c and d
79
+ // b and c and e
80
+ this . features = new ( tree . Value ) ( this . permute ( path ) . map ( function ( path ) {
81
+ path = path . map ( function ( fragment ) {
82
+ return fragment . toCSS ? fragment : new ( tree . Anonymous ) ( fragment ) ;
83
+ } ) ;
84
+
85
+ for ( i = path . length - 1 ; i > 0 ; i -- ) {
86
+ path . splice ( i , 0 , new ( tree . Anonymous ) ( "and" ) ) ;
87
+ }
88
+
89
+ return new ( tree . Expression ) ( path ) ;
90
+ } ) ) ;
91
+
92
+ // Fake a tree-node that doesn't output anything.
93
+ return new ( tree . Ruleset ) ( [ ] , [ ] ) ;
94
94
} ,
95
95
permute : function ( arr ) {
96
96
if ( arr . length == 0 ) {
97
- return [ ] ;
97
+ return [ ] ;
98
98
} else if ( arr . length == 1 ) {
99
- return arr [ 0 ] ;
99
+ return arr [ 0 ] ;
100
100
} else {
101
- var result = [ ] ;
102
- var rest = this . permute ( arr . slice ( 1 ) ) ;
103
- for ( var i = 0 ; i < rest . length ; i ++ ) {
104
- for ( var j = 0 ; j < arr [ 0 ] . length ; j ++ ) {
105
- result . push ( [ arr [ 0 ] [ j ] ] . concat ( rest [ i ] ) ) ;
101
+ var result = [ ] ;
102
+ var rest = this . permute ( arr . slice ( 1 ) ) ;
103
+ for ( var i = 0 ; i < rest . length ; i ++ ) {
104
+ for ( var j = 0 ; j < arr [ 0 ] . length ; j ++ ) {
105
+ result . push ( [ arr [ 0 ] [ j ] ] . concat ( rest [ i ] ) ) ;
106
+ }
106
107
}
107
- }
108
- return result ;
108
+ return result ;
109
109
}
110
110
}
111
111
} ;
0 commit comments