From 70611ac98c597ece43c7ef78b714b91a3af5ac49 Mon Sep 17 00:00:00 2001 From: savvasha Date: Wed, 29 Nov 2017 17:34:37 +0200 Subject: [PATCH] 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] );