diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js
index 802601b5..7bea5462 100644
--- a/assets/js/admin/sportspress-admin.js
+++ b/assets/js/admin/sportspress-admin.js
@@ -25,6 +25,16 @@ jQuery(document).ready(function($){
// Activate auto key placeholder
$("#poststuff #title").keyup();
+ // Radio input toggle
+ $(".sp-radio-toggle").click(function() {
+ if($(this).data("sp-checked")) {
+ $(this).attr("checked", false );
+ $(this).data("sp-checked", false );
+ } else {
+ $(this).data("sp-checked", true );
+ }
+ });
+
// Table switcher
$(".sp-table-panel").siblings(".sp-table-bar").find("a").click(function() {
$(this).closest("li").find("a").addClass("current").closest("li").siblings().find("a").removeClass("current").closest(".sp-table-bar").siblings($(this).attr("href")).show().siblings(".sp-table-panel").hide();
diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-data.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-data.php
index 446b4f40..c524f64b 100644
--- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-data.php
+++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-table-data.php
@@ -22,13 +22,15 @@ class SP_Meta_Box_Table_Data {
$table = new SP_League_Table( $post );
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $table->data( true );
$adjustments = $table->adjustments;
- self::table( $columns, $usecolumns, $data, $placeholders, $adjustments );
+ $highlight = get_post_meta( $table->ID, 'sp_highlight', true );
+ self::table( $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight );
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
+ update_post_meta( $post_id, 'sp_highlight', sp_array_value( $_POST, 'sp_highlight', array() ) );
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
update_post_meta( $post_id, 'sp_adjustments', sp_array_value( $_POST, 'sp_adjustments', array() ) );
update_post_meta( $post_id, 'sp_teams', sp_array_value( $_POST, 'sp_teams', array() ) );
@@ -37,11 +39,12 @@ class SP_Meta_Box_Table_Data {
/**
* Admin edit table
*/
- public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array() ) {
+ public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
$show_team_logo = get_option( 'sportspress_table_show_logos', 'no' ) == 'yes' ? true : false;
?>
+
|
@@ -50,6 +53,7 @@ class SP_Meta_Box_Table_Data {
+ |
|
$label ): ?>
|
' . '';
$i = 0;
+$start = 0;
-if ( intval( $number ) > 0 )
+if ( intval( $number ) > 0 ):
$limit = $number;
-foreach( $data as $team_id => $row ):
+ // Trim table to center around highlighted team
+ if ( $highlight && sizeof( $data ) > $limit && array_key_exists( $highlight, $data ) ):
+
+ // Number of teams in the table
+ $size = sizeof( $data );
+
+ // Position of highlighted team in the table
+ $key = array_search( $highlight, array_keys( $data ) );
+
+ // Get starting position
+ $start = $key - ceil( $limit / 2 ) + 1;
+ if ( $start < 0 ) $start = 0;
+
+ // Trim table using starting position
+ $trimmed = array_slice( $data, $start, $limit, true );
+
+ // Move starting position if we are too far down the table
+ if ( sizeof( $trimmed ) < $limit && sizeof( $trimmed ) < $size ):
+ $offset = $limit - sizeof( $trimmed );
+ $start -= $offset;
+ if ( $start < 0 ) $start = 0;
+ $trimmed = array_slice( $data, $start, $limit, true );
+ endif;
+
+ // Replace data
+ $data = $trimmed;
+ endif;
+endif;
+
+// Loop through the teams
+foreach ( $data as $team_id => $row ):
if ( isset( $limit ) && $i >= $limit ) continue;
$name = sp_array_value( $row, 'name', null );
if ( ! $name ) continue;
- $output .= '';
+ // Generate tags for highlighted team
+ $before = $after = $class = '';
+ if ( $highlight == $team_id ):
+ $before = '';
+ $after = '';
+ $class = ' highlighted';
+ endif;
+
+ $output .= '
';
// Rank
- $output .= '| ' . ( $i + 1 ) . ' | ';
+ $output .= '' . $before . ( $start + 1 ) . $after . ' | ';
$name_class = '';
if ( $show_team_logo ):
if ( has_post_thumbnail( $team_id ) ):
$logo = get_the_post_thumbnail( $team_id, 'sportspress-fit-icon' );
- $name = '' . $logo . '' . $name;
+ $name = '' . $logo . '' . $before . $name . $after;
$name_class .= ' has-logo';
endif;
endif;
@@ -94,12 +136,13 @@ foreach( $data as $team_id => $row ):
if ( $key == 'name' )
continue;
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
- $output .= '' . sp_array_value( $row, $key, '—' ) . ' | ';
+ $output .= '' . $before . sp_array_value( $row, $key, '—' ) . $after . ' | ';
endforeach;
$output .= '
';
$i++;
+ $start++;
endforeach;