Skeletal StyleTranslations class, CSS fixes

This commit is contained in:
Justin Foell
2020-11-02 10:53:53 -06:00
parent 7402f471fb
commit b617842c84
5 changed files with 64 additions and 6 deletions
+3 -3
View File
@@ -12,15 +12,15 @@
display: table;
margin: 0 auto;
}
#activity-details-table tr td {
.activity-details-table tr td {
padding: 5px;
}
#activity-details-table th {
.activity-details-table th {
padding: 5px;
text-align: center;
font-size: 0.8em;
}
#activity-details-table td {
.activity-details-table td {
text-align: center;
border: 1px solid #e7e7e7;
}
+9 -1
View File
@@ -41,6 +41,12 @@ class WPStrava {
*/
private $routes = null;
/**
* Style Translation object for responsive tables.
* @var WPStrava_StyleTranslations
*/
private $style_translations = null;
/**
* Private constructor (singleton).
*/
@@ -78,7 +84,9 @@ class WPStrava {
if ( is_admin() ) {
$this->settings->hook();
} else {
} else { // Front-end.
$this->style_translations = new WPStrava_StyleTranslations();
$this->style_translations->hook();
add_action( 'init', array( $this, 'register_shortcodes' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
}
+1 -1
View File
@@ -115,7 +115,7 @@ class WPStrava_ActivityRenderer {
}
return '
<table id="activity-details-table">
<table class="activity-details-table">
<thead>
<tr>
<th>' . __( 'Elapsed Time', 'wp-strava' ) . '</th>
+1 -1
View File
@@ -122,7 +122,7 @@ class WPStrava_RouteShortcode {
}
return '
<table id="activity-details-table">
<table class="activity-details-table">
<thead>
<tr>
<th>' . __( 'Est. Moving Time', 'wp-strava' ) . '</th>
+50
View File
@@ -0,0 +1,50 @@
<?php
class WPStrava_StyleTranslations {
/**
* Translations indexed by class.
* @var array
*/
private $style_translations = array();
/**
* Hook into wp_head.
*
* @author Justin Foell <justin@foell.org>
* @since 2.4
*/
public function hook() {
add_action( 'wp_head', array( $this, 'print_style_translations' ) );
}
/**
* Add translation text to column header, identified by class.
*
* @param [type] $class CSS class for table data (<td>).
* @param [type] $translation Text to add to column.
* @author Justin Foell <justin@foell.org>
* @since 2.4
*/
public function add_style_translation( $class, $translation ) {
$this->style_translations[ $class ] = $translation;
}
/**
* Print translatable strings as <style> in <head>.
*
* @author Justin Foell <justin@foell.org>
* @since 2.4
*/
public function print_style_translations() {
if ( empty( $this->style_translations ) ) {
return;
}
$style = '';
foreach ( $this->style_translations as $class => $translation ) {
$style .= ".{$class}:before { content: \"{$translation}\"; }\n";
}
echo "<style>\n{$style}</style>";
}
}