From c67629a0d635d04c0901b654e65ee16a65409659 Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 27 Nov 2020 11:17:53 -0600 Subject: [PATCH] Refined responsive table styles --- css/wp-strava.css | 4 ++++ readme.txt | 1 + src/WPStrava/Blocks/Activity.php | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/css/wp-strava.css b/css/wp-strava.css index 67bdb35..21f3090 100755 --- a/css/wp-strava.css +++ b/css/wp-strava.css @@ -70,6 +70,10 @@ only screen and (max-width: 760px), content: attr(data-label); } + .activity-details-table td { + text-align: right; + } + .activity-details-table-info, .activity-details-table-units { display: inline; } diff --git a/readme.txt b/readme.txt index 71c57cf..dcde601 100755 --- a/readme.txt +++ b/readme.txt @@ -118,6 +118,7 @@ On the WP-Strava settings page you cannot currently remove and add another athle = 2.5.0 = Fix missing translation domain on "Save Changes" in settings. https://wordpress.org/support/topic/small-fix-in-settings-php-function-print_clear_input +Refined styles for responsive tables https://wordpress.org/support/topic/responsive-strava-activity-table/ = 2.4.0 = diff --git a/src/WPStrava/Blocks/Activity.php b/src/WPStrava/Blocks/Activity.php index ceff6b0..2c1e596 100644 --- a/src/WPStrava/Blocks/Activity.php +++ b/src/WPStrava/Blocks/Activity.php @@ -5,6 +5,15 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { + /** + * Whether or not to enqueue styles (if shortcode is present). + * + * @var boolean + * @author Justin Foell + * @since 2.5.0 + */ + private $add_script = false; + /** * Register the wp-strava/activity block. * @@ -21,6 +30,7 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { 'render_callback' => array( $this, 'render_block' ), ) ); + add_action( 'wp_footer', array( $this, 'print_scripts' ) ); } /** @@ -37,6 +47,8 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { return $content; } + $this->add_script = true; + $matches = []; preg_match( '/\/activities\/([0-9].*)$/', $attributes['url'], $matches ); if ( $matches[1] ) { @@ -52,4 +64,16 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { } return $content; } + + /** + * Enqueue style if shortcode is being used. + * + * @author Justin Foell + * @since 2.5.0 + */ + public function print_scripts() { + if ( $this->add_script ) { + wp_enqueue_style( 'wp-strava-style' ); + } + } }