File tree 3 files changed +15
-5
lines changed
3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,21 @@ addonCSSOM(nano);
8
8
9
9
const rule = nano . createRule ( '.test_cssom_rule' ) ;
10
10
rule . style . color = 'red' ;
11
+ rule . style . borderColor = 'red' ;
12
+ rule . selectorText = '.test_cssom_rule2' ;
11
13
console . log ( 'rule' , rule ) ;
14
+ for ( let i = 0 ; i < rule . style . length ; i ++ ) {
15
+ console . log ( rule . style [ i ] ) ;
16
+ }
12
17
13
18
const atrule = nano . createRule ( '.test_cssom_atrule' , '@media only screen and (max-width: 600px)' ) ;
14
19
atrule . style . color = 'blue' ;
15
20
console . log ( 'atrule' , atrule ) ;
16
21
17
22
storiesOf ( 'Addons/CSSOM' , module )
18
23
. add ( 'rule' , ( ) =>
19
- h ( 'div' , { className : 'test_cssom_rule ' } , 'Hello world' )
24
+ h ( 'div' , { className : 'test_cssom_rule2 ' } , 'Hello world' )
20
25
)
21
26
. add ( 'with @media at rule' , ( ) =>
22
- h ( 'div' , { className : 'test_cssom_rule test_cssom_atrule' } , 'Hello world' )
27
+ h ( 'div' , { className : 'test_cssom_atrule' } , 'Hello world' )
23
28
)
Original file line number Diff line number Diff line change @@ -8,10 +8,13 @@ exports.addon = function (renderer) {
8
8
// CSSOM support only browser environment.
9
9
if ( ! renderer . client ) return ;
10
10
11
+ // Style sheet for media queries.
12
+ document . head . appendChild ( renderer . msh = document . createElement ( 'style' ) ) ;
13
+
11
14
renderer . createRule = function ( selector , prelude ) {
12
15
var rawCss = selector + '{}' ;
13
16
if ( prelude ) rawCss = prelude + '{' + rawCss + '}' ;
14
- var sheet = renderer . sh . sheet ;
17
+ var sheet = prelude ? renderer . msh . sheet : renderer . sh . sheet ;
15
18
var index = sheet . insertRule ( rawCss , sheet . cssRules . length ) ;
16
19
var rule = ( sheet . cssRules || sheet . rules ) [ index ] ;
17
20
@@ -23,7 +26,9 @@ exports.addon = function (renderer) {
23
26
// If rule has media query (it has prelude), move style (CSSStyleDeclaration)
24
27
// object to the "top" to normalize it with a rule without the media
25
28
// query, so that both rules have `.style` property available.
26
- rule . style = ( rule . cssRules || rule . rules ) [ 0 ] . style ;
29
+ var selectorRule = ( rule . cssRules || rule . rules ) [ 0 ] ;
30
+ rule . style = selectorRule . style ;
31
+ rule . styleMap = selectorRule . styleMap ;
27
32
}
28
33
29
34
return rule ;
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ exports.addon = function (renderer) {
48
48
} ,
49
49
remove : function ( ) {
50
50
for ( var selectorTemplate in rules )
51
- rules [ selectorTemplate ] . remove ( ) ;
51
+ renderer . sh . deleteRule ( rule . index ) ;
52
52
}
53
53
} ;
54
54
You can’t perform that action at this time.
0 commit comments