Target specific tables by adding a unique class name

Using the uniqid function of PHP (http://www.php.net/manual/en/function.uniqid.php)
This commit is contained in:
savvasha
2017-11-30 19:43:50 +02:00
parent a7ff15ff59
commit 8d2b504fb8
5 changed files with 29 additions and 20 deletions

View File

@@ -516,7 +516,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) {
* @subpackage Responsive * @subpackage Responsive
* @return void * @return void
*/ */
function sportspress_responsive_tables_css($vars) { function sportspress_responsive_tables_css($vars,$identity) {
$custom_css = '/* $custom_css = '/*
Max width before this PARTICULAR table gets nasty Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px 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) { (min-device-width: 768px) and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */ /* 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; display: block;
} }
/* Hide table headers (but not display: none;, for accessibility) */ /* Hide table headers (but not display: none;, for accessibility) */
table.sp-responsive-table thead tr { table.'.$identity.' thead tr {
position: absolute; position: absolute;
top: -9999px; top: -9999px;
left: -9999px; left: -9999px;
@@ -545,9 +545,9 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) {
text-align: center !important; 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" */ /* Behave like a "row" */
border: none; border: none;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
@@ -555,7 +555,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) {
padding-left: 50%; padding-left: 50%;
} }
table.sp-responsive-table td:before { table.'.$identity.' td:before {
/* Now like a table header */ /* Now like a table header */
position: absolute; position: absolute;
/* Top/left values mimic padding */ /* Top/left values mimic padding */
@@ -566,7 +566,7 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) {
white-space: nowrap; white-space: nowrap;
} }
/* Zebra striping */ /* Zebra striping */
table.sp-responsive-table tr:nth-of-type(odd) { table.'.$identity.' tr:nth-of-type(odd) {
background: #eee !important; background: #eee !important;
} }
@@ -575,13 +575,13 @@ if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) {
*/'; */';
$k=1; $k=1;
foreach ($vars as $label) { 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++; $k++;
} }
$dummystyle = 'sportspress-style-inline-'.$identity;
wp_register_style( 'sportspress-style-inline', false ); wp_register_style( $dummystyle, false );
wp_enqueue_style( 'sportspress-style-inline' ); wp_enqueue_style( $dummystyle );
wp_add_inline_style( 'sportspress-style-inline', $custom_css ); wp_add_inline_style( $dummystyle, $custom_css );
} }
} }

View File

@@ -93,13 +93,15 @@ if ( $show_title && false === $title && $id ):
$title = get_the_title( $id ); $title = get_the_title( $id );
endif; endif;
$labels = array(); $labels = array();
//Create a unique identifier based on the current time in microseconds
$identifier = uniqid('eventlist_');
?> ?>
<div class="sp-template sp-template-event-list"> <div class="sp-template sp-template-event-list">
<?php if ( $title ) { ?> <?php if ( $title ) { ?>
<h4 class="sp-table-caption"><?php echo $title; ?></h4> <h4 class="sp-table-caption"><?php echo $title; ?></h4>
<?php } ?> <?php } ?>
<div class="sp-table-wrapper"> <div class="sp-table-wrapper">
<table class="sp-event-list sp-event-list-format-<?php echo $title_format; ?> sp-data-table<?php if ( $paginated ) { ?> sp-paginated-table<?php } if ( $sortable ) { ?> sp-sortable-table<?php } if ( $responsive ) { ?> sp-responsive-table<?php } if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>" data-sp-rows="<?php echo $rows; ?>"> <table class="sp-event-list sp-event-list-format-<?php echo $title_format; ?> sp-data-table<?php if ( $paginated ) { ?> sp-paginated-table<?php } if ( $sortable ) { ?> sp-sortable-table<?php } if ( $responsive ) { echo ' sp-responsive-table '.$identifier; } if ( $scrollable ) { ?> sp-scrollable-table <?php } ?>" data-sp-rows="<?php echo $rows; ?>">
<thead> <thead>
<tr> <tr>
<?php <?php
@@ -451,7 +453,7 @@ $labels = array();
//var_dump($labels); //var_dump($labels);
// If responsive tables are enabled then load the inline css code // If responsive tables are enabled then load the inline css code
if ($responsive == true){ if ($responsive == true){
sportspress_responsive_tables_css($labels); sportspress_responsive_tables_css($labels,$identifier);
} }
if ( $id && $show_all_events_link ) if ( $id && $show_all_events_link )
echo '<div class="sp-calendar-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a></div>'; echo '<div class="sp-calendar-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a></div>';

View File

@@ -22,13 +22,15 @@ if ( ! isset( $lineups ) ) $lineups = array();
if ( ! isset( $subs ) ) $subs = array(); if ( ! isset( $subs ) ) $subs = array();
$responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false; $responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false;
$rlabels = array(); $rlabels = array();
//Create a unique identifier based on the current time in microseconds
$identifier = uniqid('performance_');
?> ?>
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?><?php if ( isset( $class ) ) { echo ' ' . $class; } ?>"> <div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?><?php if ( isset( $class ) ) { echo ' ' . $class; } ?>">
<?php if ( $caption ): ?> <?php if ( $caption ): ?>
<h4 class="sp-table-caption"><?php echo $caption; ?></h4> <h4 class="sp-table-caption"><?php echo $caption; ?></h4>
<?php endif; ?> <?php endif; ?>
<div class="sp-table-wrapper"> <div class="sp-table-wrapper">
<table class="sp-event-performance sp-data-table<?php if ( $mode == 'values' ) { ?><?php if ( $scrollable ) { ?> sp-scrollable-table<?php }if ( $responsive ) { ?> sp-responsive-table<?php } ?><?php if ( $sortable ) { ?> sp-sortable-table<?php } ?><?php } ?>"> <table class="sp-event-performance sp-data-table<?php if ( $mode == 'values' ) { ?><?php if ( $scrollable ) { ?> sp-scrollable-table<?php }if ( $responsive ) { echo ' sp-responsive-table '.$identifier; } if ( $sortable ) { ?> sp-sortable-table<?php } ?><?php } ?>">
<thead> <thead>
<tr> <tr>
<?php if ( $mode == 'values' ): ?> <?php if ( $mode == 'values' ): ?>
@@ -266,5 +268,5 @@ $rlabels = array();
<?php <?php
// If responsive tables are enabled then load the inline css code // If responsive tables are enabled then load the inline css code
if ($responsive == true && $mode == 'values'){ if ($responsive == true && $mode == 'values'){
sportspress_responsive_tables_css($rlabels); sportspress_responsive_tables_css($rlabels,$identifier);
} }

View File

@@ -48,6 +48,9 @@ if ( $show_title && false === $title && $id ):
$title = get_the_title( $id ); $title = get_the_title( $id );
endif; endif;
//Create a unique identifier based on the current time in microseconds
$identifier = uniqid('table_');
$output = ''; $output = '';
if ( $title ) if ( $title )
@@ -55,7 +58,7 @@ if ( $title )
$output .= '<div class="sp-table-wrapper">'; $output .= '<div class="sp-table-wrapper">';
$output .= '<table class="sp-league-table sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ) . ( $responsive ? ' sp-responsive-table' : '' ). ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>'; $output .= '<table class="sp-league-table sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ) . ( $responsive ? ' sp-responsive-table '.$identifier : '' ). ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
$data = $table->data(); $data = $table->data();
@@ -63,7 +66,7 @@ $data = $table->data();
$labels = $data[0]; $labels = $data[0];
// If responsive tables are enabled then load the inline css code // If responsive tables are enabled then load the inline css code
if ($responsive == true){ 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 // Remove the first row to leave us with the actual data
unset( $data[0] ); unset( $data[0] );

View File

@@ -56,9 +56,11 @@ $data = $list->data();
// The first row should be column labels // The first row should be column labels
$labels = $data[0]; $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 tables are enabled then load the inline css code
if ($responsive == true){ 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 // Remove the first row to leave us with the actual data
unset( $data[0] ); unset( $data[0] );
@@ -211,7 +213,7 @@ foreach ( $groups as $group ):
endif; endif;
$output .= '<div class="sp-table-wrapper">' . $output .= '<div class="sp-table-wrapper">' .
'<table class="sp-player-list sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ). ( $responsive ? ' sp-responsive-table' : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>'; '<table class="sp-player-list sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ). ( $responsive ? ' sp-responsive-table '.$identifier : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ): if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
if ( in_array( $orderby, array( 'number', 'name' ) ) ): if ( in_array( $orderby, array( 'number', 'name' ) ) ):