Lines of Code | 27 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const $ = jQuery; |
||
2 | |||
3 | export class Preview { |
||
4 | |||
5 | constructor( options ) { |
||
6 | this.options = options || {}; |
||
7 | this.options.context = this.options.context ? $( this.options.context ) : $( 'html' ); |
||
8 | this.$head = this.options.context.find( 'head' ); |
||
9 | } |
||
10 | |||
11 | /** |
||
12 | * Append styles to the head. |
||
13 | * |
||
14 | * @since 1.0.0 |
||
15 | */ |
||
16 | appendStyles( id, css ) { |
||
17 | let $style = this.$head.find( '#' + id ); |
||
18 | |||
19 | if ( ! $style.length ) { |
||
20 | $style = $( '<style>' ); |
||
21 | $style.attr( 'id', id ); |
||
22 | this.$head.append( $style ); |
||
23 | } |
||
24 | |||
25 | $style.html( css ); |
||
26 | } |
||
27 | } |
||
28 |