From 70611ac98c597ece43c7ef78b714b91a3af5ac49 Mon Sep 17 00:00:00 2001 From: savvasha Date: Wed, 29 Nov 2017 17:34:37 +0200 Subject: [PATCH 1/9] Add responsiveness to tables For league tables, event lists, player lists, and box score (player performance). --- includes/sp-template-functions.php | 91 +++++++++++++++++++++++++++ templates/event-list.php | 29 ++++++++- templates/event-performance-table.php | 11 ++++ templates/league-table.php | 6 +- templates/player-list.php | 6 +- 5 files changed, 139 insertions(+), 4 deletions(-) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 7439d15f..85da7102 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -507,3 +507,94 @@ function sportspress_output_br_tag() {
get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false, 'link_venues' => get_option( 'sportspress_link_venues', 'yes' ) == 'yes' ? true : false, 'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false, + 'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false, 'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false, 'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_event_list_paginated', 'yes' ) == 'yes' ? true : false, @@ -91,6 +92,7 @@ if ( $show_title && false === $title && $id ): else $title = get_the_title( $id ); endif; +$labels = array(); ?>
@@ -102,70 +104,88 @@ endif; ' . __( 'Date', 'sportspress' ) . ''; + $labels[] = __( 'Date', 'sportspress' ); switch ( $title_format ) { case 'homeaway': if ( sp_column_active( $usecolumns, 'event' ) ) { echo '' . __( 'Home', 'sportspress' ) . ''; + $labels[] = __( 'Home', 'sportspress' ); } if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) { echo '' . __( 'Time/Results', 'sportspress' ) . ''; + $labels[] = __( 'Time/Results', 'sportspress' ); } elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) { echo '' . __( 'Results', 'sportspress' ) . ''; + $labels[] = __( 'Results', 'sportspress' ); } if ( sp_column_active( $usecolumns, 'event' ) ) { echo '' . __( 'Away', 'sportspress' ) . ''; + $labels[] = __( 'Away', 'sportspress' ); } if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) { echo '' . __( 'Time', 'sportspress' ) . ''; + $labels[] = __( 'Time', 'sportspress' ); } break; default: if ( sp_column_active( $usecolumns, 'event' ) ) { - if ( $title_format == 'teams' ) + if ( $title_format == 'teams' ){ echo '' . __( 'Teams', 'sportspress' ) . ''; - else + $labels[] = __( 'Teams', 'sportspress' ); + }else{ echo '' . __( 'Event', 'sportspress' ) . ''; + $labels[] = __( 'Event', 'sportspress' );} } switch ( $time_format ) { case 'separate': if ( sp_column_active( $usecolumns, 'time' ) ) echo '' . __( 'Time', 'sportspress' ) . ''; + $labels[] = __( 'Time', 'sportspress' ); if ( sp_column_active( $usecolumns, 'results' ) ) echo '' . __( 'Results', 'sportspress' ) . ''; + $labels[] = __( 'Results', 'sportspress' ); break; case 'time': if ( sp_column_active( $usecolumns, 'time' ) ) echo '' . __( 'Time', 'sportspress' ) . ''; + $labels[] = __( 'Time', 'sportspress' ); break; case 'results': if ( sp_column_active( $usecolumns, 'results' ) ) echo '' . __( 'Results', 'sportspress' ) . ''; + $labels[] = __( 'Results', 'sportspress' ); break; default: if ( sp_column_active( $usecolumns, 'time' ) ) echo '' . __( 'Time/Results', 'sportspress' ) . ''; + $labels[] = __( 'Time/Results', 'sportspress' ); } } if ( sp_column_active( $usecolumns, 'league' ) ) echo '' . __( 'League', 'sportspress' ) . ''; + $labels[] = __( 'League', 'sportspress' ); if ( sp_column_active( $usecolumns, 'season' ) ) echo '' . __( 'Season', 'sportspress' ) . ''; + $labels[] = __( 'Season', 'sportspress' ); if ( sp_column_active( $usecolumns, 'venue' ) ) echo '' . __( 'Venue', 'sportspress' ) . ''; + $labels[] = __( 'Venue', 'sportspress' ); if ( sp_column_active( $usecolumns, 'article' ) ) echo '' . __( 'Article', 'sportspress' ) . ''; + $labels[] = __( 'Article', 'sportspress' ); if ( sp_column_active( $usecolumns, 'day' ) ) echo '' . __( 'Match Day', 'sportspress' ) . ''; + $labels[] = __( 'Match Day', 'sportspress' ); do_action( 'sportspress_event_list_head_row', $usecolumns ); ?> @@ -428,6 +448,11 @@ endif;
' . __( 'View all events', 'sportspress' ) . ''; ?> diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index 51d5797e..dde714fa 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -20,6 +20,8 @@ if ( ! isset( $class ) ) $class = null; // Initialize arrays if ( ! isset( $lineups ) ) $lineups = array(); if ( ! isset( $subs ) ) $subs = array(); +$responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false; +$rlabels = array(); ?>
@@ -33,17 +35,21 @@ if ( ! isset( $subs ) ) $subs = array(); # + + + $label ): ?> + @@ -257,3 +263,8 @@ if ( ! isset( $subs ) ) $subs = array();
+ get_option( 'sportspress_table_show_title', 'yes' ) == 'yes' ? true : false, 'show_team_logo' => get_option( 'sportspress_table_show_logos', 'yes' ) == 'yes' ? true : false, 'link_posts' => null, + 'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false, 'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false, 'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_table_paginated', 'yes' ) == 'yes' ? true : false, @@ -60,7 +61,10 @@ $data = $table->data(); // The first row should be column labels $labels = $data[0]; - +// If responsive tables are enabled then load the inline css code +if ($responsive == true){ + responsive_tables_css($labels); +} // Remove the first row to leave us with the actual data unset( $data[0] ); diff --git a/templates/player-list.php b/templates/player-list.php index 2d709711..bd01ebd1 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -25,6 +25,7 @@ $defaults = array( 'link_posts' => get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false, 'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false, 'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false, + 'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false, 'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false, 'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_list_paginated', 'yes' ) == 'yes' ? true : false, @@ -55,7 +56,10 @@ $data = $list->data(); // The first row should be column labels $labels = $data[0]; - +// If responsive tables are enabled then load the inline css code +if ($responsive == true){ + responsive_tables_css($labels); +} // Remove the first row to leave us with the actual data unset( $data[0] ); From bc0ee7a295f82658ebfe5005f0b04f94de30d705 Mon Sep 17 00:00:00 2001 From: savvasha Date: Thu, 30 Nov 2017 07:00:24 +0200 Subject: [PATCH 2/9] Add Zebra striping to repsonsive tables --- includes/sp-template-functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 85da7102..ac8c59cb 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -565,6 +565,10 @@ if ( ! function_exists( 'responsive_tables_css' ) ) { padding-right: 10px; white-space: nowrap; } + /* Zebra striping */ + tr:nth-of-type(odd) { + background: #eee !important; + } /* Label the data From a7ff15ff59391035b5a67faae06fbc5cfaf087fe Mon Sep 17 00:00:00 2001 From: savvasha Date: Thu, 30 Nov 2017 19:22:53 +0200 Subject: [PATCH 3/9] Adding function prefix and extra table class 1) Add sportspress_ prefix to the function name. 2) Insert a new class selector to the responsive tables (sp-responsive-table) for future use. --- includes/sp-template-functions.php | 37 ++++++++------------------- templates/event-list.php | 4 +-- templates/event-performance-table.php | 4 +-- templates/league-table.php | 4 +-- templates/player-list.php | 4 +-- 5 files changed, 18 insertions(+), 35 deletions(-) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index ac8c59cb..40b3fae2 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -507,7 +507,7 @@ function sportspress_output_br_tag() {
- +
' . __( 'View all events', 'sportspress' ) . ''; diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index dde714fa..b06ce250 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -28,7 +28,7 @@ $rlabels = array();

-
+
@@ -266,5 +266,5 @@ $rlabels = array(); '; -$output .= '
' . '' . ''; +$output .= '
' . '' . ''; $data = $table->data(); @@ -63,7 +63,7 @@ $data = $table->data(); $labels = $data[0]; // If responsive tables are enabled then load the inline css code if ($responsive == true){ - responsive_tables_css($labels); + sportspress_responsive_tables_css($labels); } // Remove the first row to leave us with the actual data unset( $data[0] ); diff --git a/templates/player-list.php b/templates/player-list.php index bd01ebd1..78ab90f2 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -58,7 +58,7 @@ $data = $list->data(); $labels = $data[0]; // If responsive tables are enabled then load the inline css code if ($responsive == true){ - responsive_tables_css($labels); + sportspress_responsive_tables_css($labels); } // Remove the first row to leave us with the actual data unset( $data[0] ); @@ -211,7 +211,7 @@ foreach ( $groups as $group ): endif; $output .= '
' . - '
' . '' . ''; + '
' . '' . ''; if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ): if ( in_array( $orderby, array( 'number', 'name' ) ) ): From 8d2b504fb8b43a189b85bb637658444c752d988d Mon Sep 17 00:00:00 2001 From: savvasha Date: Thu, 30 Nov 2017 19:43:50 +0200 Subject: [PATCH 4/9] Target specific tables by adding a unique class name Using the uniqid function of PHP (http://www.php.net/manual/en/function.uniqid.php) --- includes/sp-template-functions.php | 24 ++++++++++++------------ templates/event-list.php | 6 ++++-- templates/event-performance-table.php | 6 ++++-- templates/league-table.php | 7 +++++-- templates/player-list.php | 6 ++++-- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 40b3fae2..90e834f4 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -516,7 +516,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { * @subpackage Responsive * @return void */ - function sportspress_responsive_tables_css($vars) { + function sportspress_responsive_tables_css($vars,$identity) { $custom_css = '/* Max width before this PARTICULAR table gets nasty This query will take effect for any screen smaller than 760px @@ -527,12 +527,12 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { (min-device-width: 768px) and (max-device-width: 1024px) { /* Force table to not be like tables anymore */ - table.sp-responsive-table, table.sp-responsive-table thead, table.sp-responsive-table tbody, table.sp-responsive-table th, table.sp-responsive-table td, table.sp-responsive-table tr { + table.'.$identity.', table.'.$identity.' thead, table.'.$identity.' tbody, table.'.$identity.' th, table.'.$identity.' td, table.'.$identity.' tr { display: block; } /* Hide table headers (but not display: none;, for accessibility) */ - table.sp-responsive-table thead tr { + table.'.$identity.' thead tr { position: absolute; top: -9999px; left: -9999px; @@ -545,9 +545,9 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { text-align: center !important; } - table.sp-responsive-table tr { border: 1px solid #ccc; } + table.'.$identity.' tr { border: 1px solid #ccc; } - table.sp-responsive-table td { + table.'.$identity.' td { /* Behave like a "row" */ border: none; border-bottom: 1px solid #eee; @@ -555,7 +555,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { padding-left: 50%; } - table.sp-responsive-table td:before { + table.'.$identity.' td:before { /* Now like a table header */ position: absolute; /* Top/left values mimic padding */ @@ -566,7 +566,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { white-space: nowrap; } /* Zebra striping */ - table.sp-responsive-table tr:nth-of-type(odd) { + table.'.$identity.' tr:nth-of-type(odd) { background: #eee !important; } @@ -575,13 +575,13 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { */'; $k=1; foreach ($vars as $label) { - $custom_css .= 'table.sp-responsive-table td:nth-of-type('.$k.'):before { content: "'.$label.'"; }'; + $custom_css .= 'table.'.$identity.' td:nth-of-type('.$k.'):before { content: "'.$label.'"; }'; $k++; } - - wp_register_style( 'sportspress-style-inline', false ); - wp_enqueue_style( 'sportspress-style-inline' ); - wp_add_inline_style( 'sportspress-style-inline', $custom_css ); + $dummystyle = 'sportspress-style-inline-'.$identity; + wp_register_style( $dummystyle, false ); + wp_enqueue_style( $dummystyle ); + wp_add_inline_style( $dummystyle, $custom_css ); } } \ No newline at end of file diff --git a/templates/event-list.php b/templates/event-list.php index 20cd448e..9fb86771 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -93,13 +93,15 @@ if ( $show_title && false === $title && $id ): $title = get_the_title( $id ); endif; $labels = array(); +//Create a unique identifier based on the current time in microseconds +$identifier = uniqid('eventlist_'); ?>

-
+
' . __( 'View all events', 'sportspress' ) . ''; diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index b06ce250..3b130985 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -22,13 +22,15 @@ if ( ! isset( $lineups ) ) $lineups = array(); if ( ! isset( $subs ) ) $subs = array(); $responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false; $rlabels = array(); +//Create a unique identifier based on the current time in microseconds +$identifier = uniqid('performance_'); ?>

-
+
@@ -266,5 +268,5 @@ $rlabels = array(); '; -$output .= '
' . '' . ''; +$output .= '
' . '' . ''; $data = $table->data(); @@ -63,7 +66,7 @@ $data = $table->data(); $labels = $data[0]; // If responsive tables are enabled then load the inline css code if ($responsive == true){ - sportspress_responsive_tables_css($labels); + sportspress_responsive_tables_css($labels,$identifier); } // Remove the first row to leave us with the actual data unset( $data[0] ); diff --git a/templates/player-list.php b/templates/player-list.php index 78ab90f2..cc145375 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -56,9 +56,11 @@ $data = $list->data(); // The first row should be column labels $labels = $data[0]; +//Create a unique identifier based on the current time in microseconds +$identifier = uniqid('playerlist_'); // If responsive tables are enabled then load the inline css code if ($responsive == true){ - sportspress_responsive_tables_css($labels); + sportspress_responsive_tables_css($labels,$identifier); } // Remove the first row to leave us with the actual data unset( $data[0] ); @@ -211,7 +213,7 @@ foreach ( $groups as $group ): endif; $output .= '
' . - '
' . '' . ''; + '
' . '' . ''; if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ): if ( in_array( $orderby, array( 'number', 'name' ) ) ): From 1c981a47e7c1c5f264b0ad7c6e63eb68a1bef110 Mon Sep 17 00:00:00 2001 From: savvasha Date: Thu, 14 Dec 2017 14:24:39 +0200 Subject: [PATCH 5/9] Set Zebra stripping by template And some fine tuning --- includes/sp-template-functions.php | 107 +++++++++++++++++++++++--- templates/event-list.php | 8 +- templates/event-performance-table.php | 7 +- templates/league-table.php | 8 +- templates/player-list.php | 7 +- 5 files changed, 113 insertions(+), 24 deletions(-) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 90e834f4..dc2493f5 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -516,7 +516,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { * @subpackage Responsive * @return void */ - function sportspress_responsive_tables_css($vars,$identity) { + function sportspress_responsive_tables_css( $vars, $identity, $theme = null ) { $custom_css = '/* Max width before this PARTICULAR table gets nasty This query will take effect for any screen smaller than 760px @@ -541,7 +541,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { width: auto !important; } - .sp-data-table .data-name { + .sp-data-table [class*="data"] { text-align: center !important; } @@ -552,7 +552,8 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { border: none; border-bottom: 1px solid #eee; position: relative; - padding-left: 50%; + padding-left: 50%; + vertical-align: middle; } table.'.$identity.' td:before { @@ -565,20 +566,106 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { padding-right: 10px; white-space: nowrap; } - /* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: #eee !important; - } /* Label the data - */'; + */ + '; $k=1; - foreach ($vars as $label) { - $custom_css .= 'table.'.$identity.' td:nth-of-type('.$k.'):before { content: "'.$label.'"; }'; + foreach ( $vars as $label ) { + $custom_css .= 'table.'.$identity.' td:nth-of-type('.$k.'):before { content: "'.$label.'"; } + '; $k++; } + switch ( $theme ) { + + case 'Emblem': + $custom_css .= '/* Zebra striping */ + table.'.$identity.' tr:nth-of-type(odd) { + background: rgba(65, 166, 42, 0.25); !important; + } + + /*table.'.$identity.' tr:nth-of-type(even) { + background: rgb(30, 118, 19); !important; + }*/'; + break; + case 'Courtside': + $custom_css .= '/* Zebra striping */ + table.'.$identity.' tr:nth-of-type(odd) { + background: #eee !important; + } + + table.'.$identity.' tr:nth-of-type(even) { + background: #fff !important; + } + + /* Make the links visible */ + .sp-data-table [class*="data"] a{ + color: #0f8bca; + } + + /* Small fix for padding */ + table.'.$identity.' td:last-child { + padding-right: 0.25em; + }'; + break; + case 'Premier': + $custom_css .= '/* Zebra striping */ + table.'.$identity.' tr:nth-of-type(odd) { + background: #eee !important; + } + + table.'.$identity.' tr:nth-of-type(even) { + background: #fff !important; + } + + /* Make the links visible */ + .sp-data-table [class*="data"] a{ + color: #0f8bca; + } + + /* Small fix for padding */ + table.'.$identity.' td:last-child { + padding-right: 0.25em; + }'; + break; + case 'Marquee': + $custom_css .= '/* Zebra striping */ + table.'.$identity.' tr:nth-of-type(odd) { + background: #f3f3f3 !important; + } + + /*table.'.$identity.' tr:nth-of-type(even) { + background: #fff !important; + }*/'; + break; + case 'Rookie': + $custom_css .= '/* Zebra striping */ + table.'.$identity.' tr:nth-of-type(odd) { + background: #eee !important; + } + + table.'.$identity.' tr:nth-of-type(even) { + background: #fff !important; + }'; + break; + case 'Football Club': + break; + default: + $custom_css .= '/* Zebra striping */ + table.'.$identity.' tr:nth-of-type(odd) { + background: #eee !important; + } + + table.'.$identity.' tr:nth-of-type(even) { + background: #fff !important; + }'; + break; + } + + $custom_css .= ' } '; + $dummystyle = 'sportspress-style-inline-'.$identity; wp_register_style( $dummystyle, false ); wp_enqueue_style( $dummystyle ); diff --git a/templates/event-list.php b/templates/event-list.php index 9fb86771..4bed2287 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -94,7 +94,7 @@ if ( $show_title && false === $title && $id ): endif; $labels = array(); //Create a unique identifier based on the current time in microseconds -$identifier = uniqid('eventlist_'); +$identifier = uniqid( 'eventlist_' ); ?>
@@ -450,10 +450,10 @@ $identifier = uniqid('eventlist_');
get( 'Name' ); + sportspress_responsive_tables_css( $labels, $identifier, $theme_name ); } if ( $id && $show_all_events_link ) echo ''; diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index 3b130985..e022ede2 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -23,7 +23,7 @@ if ( ! isset( $subs ) ) $subs = array(); $responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false; $rlabels = array(); //Create a unique identifier based on the current time in microseconds -$identifier = uniqid('performance_'); +$identifier = uniqid( 'performance_' ); ?>
@@ -267,6 +267,7 @@ $identifier = uniqid('performance_');
get( 'Name' ); + sportspress_responsive_tables_css( $rlabels, $identifier, $theme_name ); } diff --git a/templates/league-table.php b/templates/league-table.php index 793f4b6c..ca69d4e6 100644 --- a/templates/league-table.php +++ b/templates/league-table.php @@ -49,7 +49,7 @@ if ( $show_title && false === $title && $id ): endif; //Create a unique identifier based on the current time in microseconds -$identifier = uniqid('table_'); +$identifier = uniqid( 'table_' ); $output = ''; @@ -65,8 +65,9 @@ $data = $table->data(); // The first row should be column labels $labels = $data[0]; // If responsive tables are enabled then load the inline css code -if ($responsive == true){ - sportspress_responsive_tables_css($labels,$identifier); +if ( true == $responsive ){ + $theme_name = wp_get_theme()->get( 'Name' ); + sportspress_responsive_tables_css( $labels, $identifier, $theme_name ); } // Remove the first row to leave us with the actual data unset( $data[0] ); @@ -178,7 +179,6 @@ $output .= ''; if ( $show_full_table_link ) $output .= ''; - ?>
diff --git a/templates/player-list.php b/templates/player-list.php index cc145375..553a216b 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -57,10 +57,11 @@ $data = $list->data(); // The first row should be column labels $labels = $data[0]; //Create a unique identifier based on the current time in microseconds -$identifier = uniqid('playerlist_'); +$identifier = uniqid( 'playerlist_' ); // If responsive tables are enabled then load the inline css code -if ($responsive == true){ - sportspress_responsive_tables_css($labels,$identifier); +if ( true == $responsive ){ + $theme_name = wp_get_theme()->get( 'Name' ); + sportspress_responsive_tables_css( $labels, $identifier, $theme_name ); } // Remove the first row to leave us with the actual data unset( $data[0] ); From 7d08b40f9e01c7798cac0b840c99a426315a814b Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Mon, 18 Dec 2017 20:02:37 +1100 Subject: [PATCH 6/9] Simplify responsive styles to avoid theme-specific tweaks --- includes/sp-template-functions.php | 97 ++------------------------- templates/event-list.php | 3 +- templates/event-performance-table.php | 3 +- templates/league-table.php | 3 +- templates/player-list.php | 3 +- 5 files changed, 8 insertions(+), 101 deletions(-) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index dc2493f5..dba4907e 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -516,15 +516,14 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { * @subpackage Responsive * @return void */ - function sportspress_responsive_tables_css( $vars, $identity, $theme = null ) { + function sportspress_responsive_tables_css( $vars, $identity ) { $custom_css = '/* Max width before this PARTICULAR table gets nasty This query will take effect for any screen smaller than 760px and also iPads specifically. */ @media - only screen and (max-width: 760px), - (min-device-width: 768px) and (max-device-width: 1024px) { + only screen and (max-width: 800px) { /* Force table to not be like tables anymore */ table.'.$identity.', table.'.$identity.' thead, table.'.$identity.' tbody, table.'.$identity.' th, table.'.$identity.' td, table.'.$identity.' tr { @@ -541,16 +540,14 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { width: auto !important; } - .sp-data-table [class*="data"] { + .sp-data-table th, + .sp-data-table td { text-align: center !important; } - table.'.$identity.' tr { border: 1px solid #ccc; } - table.'.$identity.' td { /* Behave like a "row" */ border: none; - border-bottom: 1px solid #eee; position: relative; padding-left: 50%; vertical-align: middle; @@ -578,92 +575,6 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { $k++; } - switch ( $theme ) { - - case 'Emblem': - $custom_css .= '/* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: rgba(65, 166, 42, 0.25); !important; - } - - /*table.'.$identity.' tr:nth-of-type(even) { - background: rgb(30, 118, 19); !important; - }*/'; - break; - case 'Courtside': - $custom_css .= '/* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: #eee !important; - } - - table.'.$identity.' tr:nth-of-type(even) { - background: #fff !important; - } - - /* Make the links visible */ - .sp-data-table [class*="data"] a{ - color: #0f8bca; - } - - /* Small fix for padding */ - table.'.$identity.' td:last-child { - padding-right: 0.25em; - }'; - break; - case 'Premier': - $custom_css .= '/* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: #eee !important; - } - - table.'.$identity.' tr:nth-of-type(even) { - background: #fff !important; - } - - /* Make the links visible */ - .sp-data-table [class*="data"] a{ - color: #0f8bca; - } - - /* Small fix for padding */ - table.'.$identity.' td:last-child { - padding-right: 0.25em; - }'; - break; - case 'Marquee': - $custom_css .= '/* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: #f3f3f3 !important; - } - - /*table.'.$identity.' tr:nth-of-type(even) { - background: #fff !important; - }*/'; - break; - case 'Rookie': - $custom_css .= '/* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: #eee !important; - } - - table.'.$identity.' tr:nth-of-type(even) { - background: #fff !important; - }'; - break; - case 'Football Club': - break; - default: - $custom_css .= '/* Zebra striping */ - table.'.$identity.' tr:nth-of-type(odd) { - background: #eee !important; - } - - table.'.$identity.' tr:nth-of-type(even) { - background: #fff !important; - }'; - break; - } - $custom_css .= ' } '; $dummystyle = 'sportspress-style-inline-'.$identity; diff --git a/templates/event-list.php b/templates/event-list.php index 4bed2287..baf8029a 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -452,8 +452,7 @@ $identifier = uniqid( 'eventlist_' ); get( 'Name' ); - sportspress_responsive_tables_css( $labels, $identifier, $theme_name ); + sportspress_responsive_tables_css( $labels, $identifier ); } if ( $id && $show_all_events_link ) echo ''; diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index e022ede2..228f9bb5 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -268,6 +268,5 @@ $identifier = uniqid( 'performance_' ); get( 'Name' ); - sportspress_responsive_tables_css( $rlabels, $identifier, $theme_name ); + sportspress_responsive_tables_css( $rlabels, $identifier ); } diff --git a/templates/league-table.php b/templates/league-table.php index ca69d4e6..f2499ce3 100644 --- a/templates/league-table.php +++ b/templates/league-table.php @@ -66,8 +66,7 @@ $data = $table->data(); $labels = $data[0]; // If responsive tables are enabled then load the inline css code if ( true == $responsive ){ - $theme_name = wp_get_theme()->get( 'Name' ); - sportspress_responsive_tables_css( $labels, $identifier, $theme_name ); + sportspress_responsive_tables_css( $labels, $identifier ); } // Remove the first row to leave us with the actual data unset( $data[0] ); diff --git a/templates/player-list.php b/templates/player-list.php index 553a216b..d0fdb791 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -60,8 +60,7 @@ $labels = $data[0]; $identifier = uniqid( 'playerlist_' ); // If responsive tables are enabled then load the inline css code if ( true == $responsive ){ - $theme_name = wp_get_theme()->get( 'Name' ); - sportspress_responsive_tables_css( $labels, $identifier, $theme_name ); + sportspress_responsive_tables_css( $labels, $identifier ); } // Remove the first row to leave us with the actual data unset( $data[0] ); From cb52599d17fc8850e1c71f0b27a7efe12b94c545 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 19 Dec 2017 14:41:42 +0200 Subject: [PATCH 7/9] Simplify css inline code --- includes/sp-template-functions.php | 19 +++------ templates/event-list.php | 55 +++++++++------------------ templates/event-performance-table.php | 35 ++++++++--------- templates/league-table.php | 8 ++-- templates/player-list.php | 15 ++++---- 5 files changed, 54 insertions(+), 78 deletions(-) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index dba4907e..71bb7064 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -516,7 +516,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { * @subpackage Responsive * @return void */ - function sportspress_responsive_tables_css( $vars, $identity ) { + function sportspress_responsive_tables_css( $identity ) { $custom_css = '/* Max width before this PARTICULAR table gets nasty This query will take effect for any screen smaller than 760px @@ -526,7 +526,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { only screen and (max-width: 800px) { /* Force table to not be like tables anymore */ - table.'.$identity.', table.'.$identity.' thead, table.'.$identity.' tbody, table.'.$identity.' th, table.'.$identity.' td, table.'.$identity.' tr { + table.'.$identity.', table.'.$identity.' thead, table.'.$identity.' tfoot, table.'.$identity.' tbody, table.'.$identity.' th, table.'.$identity.' td, table.'.$identity.' tr { display: block; } @@ -556,6 +556,8 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { table.'.$identity.' td:before { /* Now like a table header */ position: absolute; + /* Label the data */ + content: attr(data-label); /* Top/left values mimic padding */ top: 6px; left: 6px; @@ -563,19 +565,8 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { padding-right: 10px; white-space: nowrap; } - - /* - Label the data - */ - '; - $k=1; - foreach ( $vars as $label ) { - $custom_css .= 'table.'.$identity.' td:nth-of-type('.$k.'):before { content: "'.$label.'"; } - '; - $k++; } - - $custom_css .= ' } '; + '; $dummystyle = 'sportspress-style-inline-'.$identity; wp_register_style( $dummystyle, false ); diff --git a/templates/event-list.php b/templates/event-list.php index baf8029a..7cd81a84 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -106,13 +106,11 @@ $identifier = uniqid( 'eventlist_' ); ' . __( 'Date', 'sportspress' ) . ''; - $labels[] = __( 'Date', 'sportspress' ); switch ( $title_format ) { case 'homeaway': if ( sp_column_active( $usecolumns, 'event' ) ) { echo '' . __( 'Home', 'sportspress' ) . ''; - $labels[] = __( 'Home', 'sportspress' ); } if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) { @@ -120,74 +118,59 @@ $identifier = uniqid( 'eventlist_' ); $labels[] = __( 'Time/Results', 'sportspress' ); } elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) { echo '' . __( 'Results', 'sportspress' ) . ''; - $labels[] = __( 'Results', 'sportspress' ); } if ( sp_column_active( $usecolumns, 'event' ) ) { echo '' . __( 'Away', 'sportspress' ) . ''; - $labels[] = __( 'Away', 'sportspress' ); } if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) { echo '' . __( 'Time', 'sportspress' ) . ''; - $labels[] = __( 'Time', 'sportspress' ); } break; default: if ( sp_column_active( $usecolumns, 'event' ) ) { if ( $title_format == 'teams' ){ echo '' . __( 'Teams', 'sportspress' ) . ''; - $labels[] = __( 'Teams', 'sportspress' ); }else{ echo '' . __( 'Event', 'sportspress' ) . ''; - $labels[] = __( 'Event', 'sportspress' );} } switch ( $time_format ) { case 'separate': if ( sp_column_active( $usecolumns, 'time' ) ) echo '' . __( 'Time', 'sportspress' ) . ''; - $labels[] = __( 'Time', 'sportspress' ); if ( sp_column_active( $usecolumns, 'results' ) ) echo '' . __( 'Results', 'sportspress' ) . ''; - $labels[] = __( 'Results', 'sportspress' ); break; case 'time': if ( sp_column_active( $usecolumns, 'time' ) ) echo '' . __( 'Time', 'sportspress' ) . ''; - $labels[] = __( 'Time', 'sportspress' ); break; case 'results': if ( sp_column_active( $usecolumns, 'results' ) ) echo '' . __( 'Results', 'sportspress' ) . ''; - $labels[] = __( 'Results', 'sportspress' ); break; default: if ( sp_column_active( $usecolumns, 'time' ) ) echo '' . __( 'Time/Results', 'sportspress' ) . ''; - $labels[] = __( 'Time/Results', 'sportspress' ); } } if ( sp_column_active( $usecolumns, 'league' ) ) echo '' . __( 'League', 'sportspress' ) . ''; - $labels[] = __( 'League', 'sportspress' ); if ( sp_column_active( $usecolumns, 'season' ) ) echo '' . __( 'Season', 'sportspress' ) . ''; - $labels[] = __( 'Season', 'sportspress' ); if ( sp_column_active( $usecolumns, 'venue' ) ) echo '' . __( 'Venue', 'sportspress' ) . ''; - $labels[] = __( 'Venue', 'sportspress' ); if ( sp_column_active( $usecolumns, 'article' ) ) echo '' . __( 'Article', 'sportspress' ) . ''; - $labels[] = __( 'Article', 'sportspress' ); if ( sp_column_active( $usecolumns, 'day' ) ) echo '' . __( 'Match Day', 'sportspress' ) . ''; - $labels[] = __( 'Match Day', 'sportspress' ); do_action( 'sportspress_event_list_head_row', $usecolumns ); ?> @@ -263,17 +246,17 @@ $identifier = uniqid( 'eventlist_' ); if ( $link_events ) $date_html = ''; - echo '' . $date_html . ''; + echo '' . $date_html . ''; switch ( $title_format ) { case 'homeaway': if ( sp_column_active( $usecolumns, 'event' ) ) { $team = array_shift( $teams_array ); - echo '' . $team . ''; + echo '' . $team . ''; } if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) { - echo ''; + echo ''; if ( $link_events ) echo ''; echo ''; } elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) { - echo ''; + echo ''; if ( $link_events ) echo ''; @@ -310,25 +293,25 @@ $identifier = uniqid( 'eventlist_' ); default: if ( sp_column_active( $usecolumns, 'event' ) ) { if ( $title_format == 'teams' ) { - echo '' . $teams_output . ''; + echo '' . $teams_output . ''; } else { $title_html = implode( ' ', $team_logos ) . ' ' . $event->post_title; if ( $link_events ) $title_html = ''; - echo '' . $title_html . ''; + echo '' . $title_html . ''; } } switch ( $time_format ) { case 'separate': if ( sp_column_active( $usecolumns, 'time' ) ) { - echo ''; + echo ''; if ( $link_events ) echo ''; echo ''; } if ( sp_column_active( $usecolumns, 'results' ) ) { - echo ''; + echo ''; if ( $link_events ) echo ''; @@ -350,7 +333,7 @@ $identifier = uniqid( 'eventlist_' ); break; case 'results': if ( sp_column_active( $usecolumns, 'results' ) ) { - echo ''; + echo ''; if ( $link_events ) echo '' . __( 'View all events', 'sportspress' ) . '
'; diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index 228f9bb5..d6deafbe 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -20,10 +20,14 @@ if ( ! isset( $class ) ) $class = null; // Initialize arrays if ( ! isset( $lineups ) ) $lineups = array(); if ( ! isset( $subs ) ) $subs = array(); + $responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false; -$rlabels = array(); //Create a unique identifier based on the current time in microseconds $identifier = uniqid( 'performance_' ); +// If responsive tables are enabled then load the inline css code +if ( true == $responsive && $mode == 'values' ){ + sportspress_responsive_tables_css( $identifier ); +} ?>
@@ -37,21 +41,19 @@ $identifier = uniqid( 'performance_' ); # - - + - + $label ): ?> - @@ -92,7 +94,7 @@ $identifier = uniqid( 'performance_' ); $number = sp_array_value( $row, 'number', ' ' ); // Player number - echo '' . $number . ''; + echo '' . $number . ''; } if ( $link_posts ): @@ -175,7 +177,7 @@ $identifier = uniqid( 'performance_' ); endif; if ( $mode == 'values' ): - $content .= '' . $value . ''; + $content .= '' . $value . ''; elseif ( intval( $value ) && $mode == 'icons' ): $performance_id = sp_array_value( $performance_ids, $key, null ); $icons = ''; @@ -190,7 +192,7 @@ $identifier = uniqid( 'performance_' ); $name .= ' ' . $position . ''; endif; - echo '' . $name . ''; + echo '' . $name . ''; if ( $mode == 'icons' ): echo '' . $content . ''; @@ -216,10 +218,10 @@ $identifier = uniqid( 'performance_' );  '; + echo ' '; } if ( $mode == 'values' ): - echo '' . __( 'Total', 'sportspress' ) . ''; + echo '' . __( 'Total', 'sportspress' ) . ''; endif; endif; @@ -243,7 +245,11 @@ $identifier = uniqid( 'performance_' ); endif; if ( $mode == 'values' ): - echo '' . $value . ''; + if ($key == 'position'){ + echo '' . $value . ''; + }else{ + echo '' . $value . ''; + } elseif ( intval( $value ) && $mode == 'icons' ): $performance_id = sp_array_value( $performance_ids, $key, null ); $icons = ''; @@ -264,9 +270,4 @@ $identifier = uniqid( 'performance_' );
- - \ No newline at end of file diff --git a/templates/league-table.php b/templates/league-table.php index f2499ce3..499a97fc 100644 --- a/templates/league-table.php +++ b/templates/league-table.php @@ -66,7 +66,7 @@ $data = $table->data(); $labels = $data[0]; // If responsive tables are enabled then load the inline css code if ( true == $responsive ){ - sportspress_responsive_tables_css( $labels, $identifier ); + sportspress_responsive_tables_css( $identifier ); } // Remove the first row to leave us with the actual data unset( $data[0] ); @@ -139,7 +139,7 @@ foreach ( $data as $team_id => $row ): $output .= ''; // Rank - $output .= '' . sp_array_value( $row, 'pos' ) . ''; + $output .= '' . sp_array_value( $row, 'pos' ) . ''; $name_class = ''; @@ -156,13 +156,13 @@ foreach ( $data as $team_id => $row ): $name = '' . $name . ''; endif; - $output .= '' . $name . ''; + $output .= '' . $name . ''; foreach( $labels as $key => $value ): if ( in_array( $key, array( 'pos', 'name' ) ) ) continue; if ( ! is_array( $columns ) || in_array( $key, $columns ) ) - $output .= '' . sp_array_value( $row, $key, '—' ) . ''; + $output .= '' . sp_array_value( $row, $key, '—' ) . ''; endforeach; $output .= ''; diff --git a/templates/player-list.php b/templates/player-list.php index d0fdb791..fc72d42e 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -56,11 +56,12 @@ $data = $list->data(); // The first row should be column labels $labels = $data[0]; + //Create a unique identifier based on the current time in microseconds $identifier = uniqid( 'playerlist_' ); // If responsive tables are enabled then load the inline css code if ( true == $responsive ){ - sportspress_responsive_tables_css( $labels, $identifier ); + sportspress_responsive_tables_css( $identifier ); } // Remove the first row to leave us with the actual data unset( $data[0] ); @@ -136,9 +137,9 @@ foreach ( $groups as $group ): // Rank or number if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ): if ( isset( $orderby ) && $orderby != 'number' ): - $tbody .= '' . ( $i + 1 ) . ''; + $tbody .= '' . ( $i + 1 ) . ''; else: - $tbody .= '' . sp_array_value( $row, 'number', ' ' ) . ''; + $tbody .= '' . sp_array_value( $row, 'number', ' ' ) . ''; endif; endif; @@ -168,7 +169,7 @@ foreach ( $groups as $group ): $name = '' . $name . ''; endif; - $tbody .= '' . $name . ''; + $tbody .= '' . $name . ''; if ( array_key_exists( 'team', $labels ) ): $team = sp_array_value( $row, 'team', get_post_meta( $id, 'sp_team', true ) ); @@ -176,7 +177,7 @@ foreach ( $groups as $group ): if ( $link_teams && false !== get_post_status( $team ) ): $team_name = '' . $team_name . ''; endif; - $tbody .= '' . $team_name . ''; + $tbody .= '' . $team_name . ''; endif; if ( array_key_exists( 'position', $labels ) ): @@ -187,14 +188,14 @@ foreach ( $groups as $group ): $position_term = get_term_by( 'id', $position, 'sp_position', ARRAY_A ); $positions = sp_array_value( $position_term, 'name', '—' ); endif; - $tbody .= '' . $positions . ''; + $tbody .= '' . $positions . ''; endif; foreach( $labels as $key => $value ): if ( in_array( $key, array( 'number', 'name', 'team', 'position' ) ) ) continue; if ( ! is_array( $columns ) || in_array( $key, $columns ) ) - $tbody .= '' . sp_array_value( $row, $key, '—' ) . ''; + $tbody .= '' . sp_array_value( $row, $key, '—' ) . ''; endforeach; $tbody .= ''; From 210122ad6702210ea36acf0145b99d7dedc4dc17 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 17 Jan 2018 10:50:25 +1100 Subject: [PATCH 8/9] Close brackets in event list template --- templates/event-list.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/event-list.php b/templates/event-list.php index 7cd81a84..2d7b33df 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -132,8 +132,9 @@ $identifier = uniqid( 'eventlist_' ); if ( sp_column_active( $usecolumns, 'event' ) ) { if ( $title_format == 'teams' ){ echo '' . __( 'Teams', 'sportspress' ) . ''; - }else{ + } else { echo '' . __( 'Event', 'sportspress' ) . ''; + } } switch ( $time_format ) { @@ -434,10 +435,11 @@ $identifier = uniqid( 'eventlist_' ); ' . __( 'View all events', 'sportspress' ) . ''; + } ?> From 3d6c4f417f367545d71ec7cb29476d90dcf781e7 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 17 Jan 2018 10:50:36 +1100 Subject: [PATCH 9/9] Add subtle border to table rows --- includes/sp-template-functions.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 71bb7064..c73ffa9d 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -536,6 +536,12 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) { top: -9999px; left: -9999px; } + + /* Add subtle border to table rows */ + table.'.$identity.' tbody tr { + border-top: 1px solid rgba(0, 0, 0, 0.1); + } + .sp-data-table .data-number, .sp-data-table .data-rank { width: auto !important; }