Skip to content

Commit

Permalink
Merge pull request #110 from CherryFramework/fix/dynamic-css
Browse files Browse the repository at this point in the history
Fix/dynamic css
  • Loading branch information
cheh authored Oct 19, 2016
2 parents 9c56792 + 27d79e9 commit 0a6dadb
Showing 1 changed file with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ class Cherry_Dynamic_Css_Collector {
*/
private static $instance = null;

/**
* Holder for grabbed CSS
*
* @var array
*/
public static $grabbed_css = array();

/**
* Array with sorted css
*
Expand Down Expand Up @@ -74,9 +67,12 @@ function __construct( $handler_file = null ) {
*/
public function add_style( $selector, $style = array(), $media = array() ) {

self::$grabbed_css[ $selector ] = array(
'style' => $style,
'media' => $media,
$this->prepare_rule(
$selector,
array(
'style' => $style,
'media' => $media,
)
);

}
Expand Down Expand Up @@ -111,26 +107,20 @@ public function add_js_handler() {
*/
public function print_style() {

self::$grabbed_css = apply_filters(
self::$sorted_css = apply_filters(
'cherry_dynamic_css_collected_styles',
self::$grabbed_css
self::$sorted_css
);

if ( empty( self::$grabbed_css ) || ! is_array( self::$grabbed_css ) ) {
if ( empty( self::$sorted_css ) || ! is_array( self::$sorted_css ) ) {
return;
}

ob_start();

do_action( 'cherry_dynamic_css_before_print_collected' );

foreach ( self::$grabbed_css as $selector => $rule ) {
$this->prepare_rule( $selector, $rule );
}

if ( ! empty( self::$sorted_css ) ) {
array_walk( self::$sorted_css, array( $this, 'print_breakpoint' ) );
}
array_walk( self::$sorted_css, array( $this, 'print_breakpoint' ) );

do_action( 'cherry_dynamic_css_after_print_collected' );

Expand Down Expand Up @@ -260,16 +250,16 @@ public function breakpoint_name( $media ) {
}

if ( ! empty( $media['max'] ) ) {
$sep = true === $has_media ? ' and ' : '';
$has_media = true;
$sep = true === $has_media ? ' & ' : '';
$max = sprintf( '(max-width: %1$s)', esc_attr( $media['min'] ) );
$max = sprintf( '(max-width: %1$s)', esc_attr( $media['max'] ) );
}

if ( ! $has_media ) {
return 'all';
}

return sprintf( 'media %1$s%2$s', $min, $max );
return sprintf( 'media %1$s%3$s%2$s', $min, $max, $sep );
}

/**
Expand Down

0 comments on commit 0a6dadb

Please sign in to comment.