From ef3136801f9008e5d67c8da508746b9266ec41e7 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Fri, 24 Jan 2014 00:05:45 +1100 Subject: [PATCH] Responsive tables and individual content filters --- admin/hooks/admin-menu.php | 24 ++- admin/hooks/register-activation-hook.php | 214 +++++++++---------- admin/hooks/the-content.php | 82 +++---- admin/post-types/event.php | 2 + admin/post-types/list.php | 1 + admin/templates/event-details.php | 5 +- admin/templates/event-players.php | 5 +- admin/templates/event-results.php | 7 +- admin/templates/league-table.php | 5 +- admin/templates/player-league-statistics.php | 5 +- admin/templates/player-list.php | 5 +- admin/templates/player-metrics.php | 5 +- admin/templates/team-columns.php | 5 +- assets/css/sportspress.css | 52 +++++ assets/js/sportspress.js | 105 +++++++-- readme.txt | 9 +- sportspress.php | 4 +- 17 files changed, 339 insertions(+), 196 deletions(-) diff --git a/admin/hooks/admin-menu.php b/admin/hooks/admin-menu.php index 33777f87..690ed8e3 100644 --- a/admin/hooks/admin-menu.php +++ b/admin/hooks/admin-menu.php @@ -18,20 +18,28 @@ function sportspress_admin_menu( $position ) { endif; // Remove "Venues" and "Positions" links from Media submenu - $submenu['upload.php'] = array_filter( $submenu['upload.php'], 'sportspress_admin_menu_remove_venues' ); - $submenu['upload.php'] = array_filter( $submenu['upload.php'], 'sportspress_admin_menu_remove_positions' ); + if ( isset( $submenu['upload.php'] ) ): + $submenu['upload.php'] = array_filter( $submenu['upload.php'], 'sportspress_admin_menu_remove_venues' ); + $submenu['upload.php'] = array_filter( $submenu['upload.php'], 'sportspress_admin_menu_remove_positions' ); + endif; // Remove "Leagues" and "Seasons" links from Events submenu - $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], 'sportspress_admin_menu_remove_leagues' ); - $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], 'sportspress_admin_menu_remove_seasons' ); + if ( isset( $submenu['edit.php?post_type=sp_event'] ) ): + $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], 'sportspress_admin_menu_remove_leagues' ); + $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], 'sportspress_admin_menu_remove_seasons' ); + endif; // Remove "Leagues" and "Seasons" links from Players submenu - $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], 'sportspress_admin_menu_remove_leagues' ); - $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], 'sportspress_admin_menu_remove_seasons' ); + if ( isset( $submenu['edit.php?post_type=sp_player'] ) ): + $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], 'sportspress_admin_menu_remove_leagues' ); + $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], 'sportspress_admin_menu_remove_seasons' ); + endif; // Remove "Leagues" and "Seasons" links from Staff submenu - $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], 'sportspress_admin_menu_remove_leagues' ); - $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], 'sportspress_admin_menu_remove_seasons' ); + if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ): + $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], 'sportspress_admin_menu_remove_leagues' ); + $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], 'sportspress_admin_menu_remove_seasons' ); + endif; } add_action( 'admin_menu', 'sportspress_admin_menu' ); diff --git a/admin/hooks/register-activation-hook.php b/admin/hooks/register-activation-hook.php index 2962bcdc..e0898643 100644 --- a/admin/hooks/register-activation-hook.php +++ b/admin/hooks/register-activation-hook.php @@ -1,119 +1,111 @@ add_cap( 'read_sp_events' ); - $role->add_cap( 'read_private_sp_events' ); - $role->add_cap( 'edit_sp_event' ); - $role->add_cap( 'edit_sp_events' ); - $role->add_cap( 'edit_published_sp_events' ); - $role->add_cap( 'edit_private_sp_events' ); - $role->add_cap( 'edit_others_sp_events' ); - $role->add_cap( 'delete_sp_event' ); - $role->add_cap( 'delete_published_sp_events' ); - $role->add_cap( 'delete_private_sp_events' ); - $role->add_cap( 'delete_others_sp_events' ); - $role->add_cap( 'publish_sp_events' ); - - // Calendars - $role->add_cap( 'read_sp_calendars' ); - $role->add_cap( 'read_private_sp_calendars' ); - $role->add_cap( 'edit_sp_calendar' ); - $role->add_cap( 'edit_sp_calendars' ); - $role->add_cap( 'edit_published_sp_calendars' ); - $role->add_cap( 'edit_private_sp_calendars' ); - $role->add_cap( 'edit_others_sp_calendars' ); - $role->add_cap( 'delete_sp_calendar' ); - $role->add_cap( 'delete_published_sp_calendars' ); - $role->add_cap( 'delete_private_sp_calendars' ); - $role->add_cap( 'delete_others_sp_calendars' ); - $role->add_cap( 'publish_sp_calendars' ); - - // Teams - $role->add_cap( 'read_sp_teams' ); - $role->add_cap( 'read_private_sp_teams' ); - $role->add_cap( 'edit_sp_team' ); - $role->add_cap( 'edit_sp_teams' ); - $role->add_cap( 'edit_published_sp_teams' ); - $role->add_cap( 'edit_private_sp_teams' ); - $role->add_cap( 'edit_others_sp_teams' ); - $role->add_cap( 'delete_sp_team' ); - $role->add_cap( 'delete_published_sp_teams' ); - $role->add_cap( 'delete_private_sp_teams' ); - $role->add_cap( 'delete_others_sp_teams' ); - $role->add_cap( 'publish_sp_teams' ); - - // League Tables - $role->add_cap( 'read_sp_tables' ); - $role->add_cap( 'read_private_sp_tables' ); - $role->add_cap( 'edit_sp_table' ); - $role->add_cap( 'edit_sp_tables' ); - $role->add_cap( 'edit_published_sp_tables' ); - $role->add_cap( 'edit_private_sp_tables' ); - $role->add_cap( 'edit_others_sp_tables' ); - $role->add_cap( 'delete_sp_table' ); - $role->add_cap( 'delete_published_sp_tables' ); - $role->add_cap( 'delete_private_sp_tables' ); - $role->add_cap( 'delete_others_sp_tables' ); - $role->add_cap( 'publish_sp_tables' ); - - // Players - $role->add_cap( 'read_sp_players' ); - $role->add_cap( 'read_private_sp_players' ); - $role->add_cap( 'edit_sp_player' ); - $role->add_cap( 'edit_sp_players' ); - $role->add_cap( 'edit_published_sp_players' ); - $role->add_cap( 'edit_private_sp_players' ); - $role->add_cap( 'edit_others_sp_players' ); - $role->add_cap( 'delete_sp_player' ); - $role->add_cap( 'delete_published_sp_players' ); - $role->add_cap( 'delete_private_sp_players' ); - $role->add_cap( 'delete_others_sp_players' ); - $role->add_cap( 'publish_sp_players' ); - - // Player Lists - $role->add_cap( 'read_sp_lists' ); - $role->add_cap( 'read_private_sp_lists' ); - $role->add_cap( 'edit_sp_list' ); - $role->add_cap( 'edit_sp_lists' ); - $role->add_cap( 'edit_published_sp_lists' ); - $role->add_cap( 'edit_private_sp_lists' ); - $role->add_cap( 'edit_others_sp_lists' ); - $role->add_cap( 'delete_sp_list' ); - $role->add_cap( 'delete_published_sp_lists' ); - $role->add_cap( 'delete_private_sp_lists' ); - $role->add_cap( 'delete_others_sp_lists' ); - $role->add_cap( 'publish_sp_lists' ); - - // Staff - $role->add_cap( 'read_sp_staffs' ); - $role->add_cap( 'read_private_sp_staffs' ); - $role->add_cap( 'edit_sp_staff' ); - $role->add_cap( 'edit_sp_staffs' ); - $role->add_cap( 'edit_published_sp_staffs' ); - $role->add_cap( 'edit_private_sp_staffs' ); - $role->add_cap( 'edit_others_sp_staffs' ); - $role->add_cap( 'delete_sp_staff' ); - $role->add_cap( 'delete_published_sp_staffs' ); - $role->add_cap( 'delete_private_sp_staffs' ); - $role->add_cap( 'delete_others_sp_staffs' ); - $role->add_cap( 'publish_sp_staffs' ); - - // Settings - $role->add_cap( 'read_sp_configs' ); - $role->add_cap( 'read_private_sp_configs' ); - $role->add_cap( 'edit_sp_config' ); - $role->add_cap( 'edit_sp_configs' ); - $role->add_cap( 'edit_published_sp_configs' ); - $role->add_cap( 'edit_private_sp_configs' ); - $role->add_cap( 'edit_others_sp_configs' ); - $role->add_cap( 'delete_sp_config' ); - $role->add_cap( 'delete_published_sp_configs' ); - $role->add_cap( 'delete_private_sp_configs' ); - $role->add_cap( 'delete_others_sp_configs' ); - $role->add_cap( 'publish_sp_configs' ); + foreach( $admin_capabilities as $capability ): + $role->add_cap( $capability ); + endforeach; // Team Manager remove_role( 'sp_team_manager' ); diff --git a/admin/hooks/the-content.php b/admin/hooks/the-content.php index c67a2c10..c459a415 100644 --- a/admin/hooks/the-content.php +++ b/admin/hooks/the-content.php @@ -1,66 +1,68 @@ ID, 'sp_player', false ); remove_meta_box( 'sp_seasondiv', 'sp_list', 'side' ); + remove_meta_box( 'sp_leaguediv', 'sp_list', 'side' ); add_meta_box( 'sp_playerdiv', __( 'Players', 'sportspress' ), 'sportspress_list_player_meta', 'sp_list', 'side', 'high' ); if ( $players && $players != array(0) ): diff --git a/admin/templates/event-details.php b/admin/templates/event-details.php index 4e5e0000..130549fd 100644 --- a/admin/templates/event-details.php +++ b/admin/templates/event-details.php @@ -24,7 +24,8 @@ if ( !function_exists( 'sportspress_event_details' ) ) { $output = '

' . __( 'Details', 'sportspress' ) . '

'; - $output .= ''; + $output .= '
' . + '
'; $i = 0; @@ -39,7 +40,7 @@ if ( !function_exists( 'sportspress_event_details' ) ) { endforeach; - $output .= '
'; + $output .= ''; return apply_filters( 'sportspress_event_details', $output ); diff --git a/admin/templates/event-players.php b/admin/templates/event-players.php index 999dd732..b78f0856 100644 --- a/admin/templates/event-players.php +++ b/admin/templates/event-players.php @@ -21,7 +21,8 @@ if ( !function_exists( 'sportspress_event_players' ) ) { $output .= '

' . get_the_title( $team_id ) . '

'; - $output .= '' . '' . ''; + $output .= '
' . + '
' . '' . ''; $output .= ''; $output .= ''; @@ -93,7 +94,7 @@ if ( !function_exists( 'sportspress_event_players' ) ) { endif; - $output .= '
#' . __( 'Player', 'sportspress' ) . '
'; + $output .= '' . ''; endforeach; diff --git a/admin/templates/event-results.php b/admin/templates/event-results.php index ab430259..81141921 100644 --- a/admin/templates/event-results.php +++ b/admin/templates/event-results.php @@ -47,14 +47,15 @@ if ( !function_exists( 'sportspress_event_results' ) ) { $output .= '

' . __( 'Results', 'sportspress' ) . '

'; - $output .= ''; - $output .= ''; + $output .= '
' . + '
' . __( 'Team', 'sportspress' ) . '
' . + ''; foreach( $result_labels as $key => $label ): $output .= ''; endforeach; $output .= '' . '' . ''; $output .= $table_rows; - $output .= '
' . __( 'Team', 'sportspress' ) . '' . $label . '
'; + $output .= '' . '' . ''; endif; diff --git a/admin/templates/league-table.php b/admin/templates/league-table.php index ca06a60e..86709501 100644 --- a/admin/templates/league-table.php +++ b/admin/templates/league-table.php @@ -25,7 +25,8 @@ if ( !function_exists( 'sportspress_league_table' ) ) { $title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id ); $output = '

' . $title . '

' . - '' . '' . ''; + '
' . + '
' . '' . ''; $data = sportspress_get_league_table_data( $id ); @@ -73,7 +74,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) { endforeach; - $output .= '' . '
'; + $output .= '' . '' . ''; return apply_filters( 'sportspress_league_table', $output ); diff --git a/admin/templates/player-league-statistics.php b/admin/templates/player-league-statistics.php index 6b2b52f4..46e0fdfb 100644 --- a/admin/templates/player-league-statistics.php +++ b/admin/templates/player-league-statistics.php @@ -21,7 +21,8 @@ if ( !function_exists( 'sportspress_player_league_statistics' ) ) { return false; $output = '

' . $league->name . '

' . - '' . '' . ''; + '
' . + '
' . '' . ''; foreach( $labels as $key => $label ): $output .= ''; @@ -45,7 +46,7 @@ if ( !function_exists( 'sportspress_player_league_statistics' ) ) { endforeach; - $output .= '' . '
' . $label . '
'; + $output .= '' . '' . ''; return apply_filters( 'sportspress_player_league_statistics', $output ); diff --git a/admin/templates/player-list.php b/admin/templates/player-list.php index af945f98..2a1ef355 100644 --- a/admin/templates/player-list.php +++ b/admin/templates/player-list.php @@ -7,7 +7,8 @@ if ( !function_exists( 'sportspress_player_list' ) ) { $data = sportspress_get_player_list_data( $id ); - $output = '' . '' . ''; + $output = '
' . + '
' . '' . ''; // The first row should be column labels $labels = $data[0]; @@ -49,7 +50,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) { endforeach; - $output .= '' . '
'; + $output .= '' . '' . ''; return apply_filters( 'sportspress_player_list', $output ); diff --git a/admin/templates/player-metrics.php b/admin/templates/player-metrics.php index e978596e..75eb722c 100644 --- a/admin/templates/player-metrics.php +++ b/admin/templates/player-metrics.php @@ -18,7 +18,8 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) { $data = array_merge( $common, $metrics ); - $output = '' . ''; + $output = '
' . + '
' . ''; $i = 0; @@ -30,7 +31,7 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) { endforeach; - $output .= '' . '
'; + $output .= '' . '' . ''; return apply_filters( 'sportspress_player_metrics', $output ); diff --git a/admin/templates/team-columns.php b/admin/templates/team-columns.php index f94097ee..ff0f2c03 100644 --- a/admin/templates/team-columns.php +++ b/admin/templates/team-columns.php @@ -27,7 +27,8 @@ if ( !function_exists( 'sportspress_team_columns' ) ) { unset( $data[0] ); $output .= '

' . $league->name . '

' . - '' . '' . ''; + '
' . + '
' . '' . ''; foreach( $labels as $key => $label ): $output .= ''; @@ -51,7 +52,7 @@ if ( !function_exists( 'sportspress_team_columns' ) ) { endforeach; - $output .= '' . '
' . $label . '
'; + $output .= '' . '' . ''; endforeach; diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index 5dc473c3..e0fb7b15 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -35,4 +35,56 @@ /* Google Maps */ .sp-google-map { height: 320px; +} + +@media only screen and (max-width: 40em) { + .sp-responsive-table { + margin-bottom: 0; + } + + .sp-pinned-table { + position: absolute; + left: 0; + top: 0; + width: 50%; + overflow: hidden; + overflow-x: scroll; + } + .sp-pinned-table table { + border-right: none; + border-left: none; + width: 100%; + } + .sp-pinned-table table th, + .sp-pinned-table table td { + white-space: nowrap; + } + .sp-pinned-table td:last-child { + border-bottom: 0; + } + + .sp-responsive-table-wrapper { + position: relative; + overflow: hidden; + background: #fff; + } + .sp-responsive-table-wrapper .scrollable { + margin-left: 50%; + } + .sp-responsive-table-wrapper .scrollable { + overflow: scroll; + overflow-y: hidden; + } + + .sp-responsive-table td, + .sp-responsive-table th { + position: relative; + white-space: nowrap; + overflow: hidden; + } + .sp-responsive-table .data-number, + .sp-responsive-table .data-name, + .sp-responsive-.sp-pinned-table td { + display: none; + } } \ No newline at end of file diff --git a/assets/js/sportspress.js b/assets/js/sportspress.js index 92be39b2..da494139 100644 --- a/assets/js/sportspress.js +++ b/assets/js/sportspress.js @@ -1,21 +1,98 @@ +function viewport() { + var e = window, a = 'inner'; + if (!('innerWidth' in window )) { + a = 'client'; + e = document.documentElement || document.body; + } + return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }; +} + (function($) { - // Data Tables - $(".sp-data-table").dataTable({ - "aaSorting": [], - "bAutoWidth": false, - "bFilter": false, - "bInfo": false, - "bPaginate": false, - "bSort": true, - "oLanguage": { - "oAria": { - "sSortAscending": "", - "sSortDescending": "" - } - } + // Data tables + if (viewport().width > 640) { + $(".sp-data-table").dataTable({ + "aaSorting": [], + "bAutoWidth": false, + "bFilter": false, + "bInfo": false, + "bPaginate": false, + "bSort": true, + "oLanguage": { + "oAria": { + "sSortAscending": "", + "sSortDescending": "" + } + } + }); + } + + // Responsive tables + var switched = false; + var updateTables = function() { + if ((viewport().width <= 640) && !switched ){ + switched = true; + $(".sp-responsive-table").each(function(i, element) { + splitTable($(element)); + }); + return true; + } + else if (switched && (viewport().width > 640)) { + switched = false; + $(".sp-responsive-table").each(function(i, element) { + unsplitTable($(element)); + }); + } + }; + + $(window).load(updateTables); + $(window).on("redraw",function(){switched=false;updateTables();}); // An event to listen for + $(window).on("resize", updateTables); + + + function splitTable(original) + { + original.wrap("
"); + + var copy = original.clone(); + copy.find("td:not(.data-number):not(.data-name), th:not(.data-number):not(.data-name)").css("display", "none"); + copy.removeClass("sp-responsive-table"); + + original.closest(".sp-responsive-table-wrapper").append(copy); + copy.wrap("
"); + original.wrap("
"); + + setCellHeights(original, copy); + } + + function unsplitTable(original) { + original.closest(".sp-responsive-table-wrapper").find(".sp-pinned-table").remove(); + original.unwrap(); + original.unwrap(); + } + + function setCellHeights(original, copy) { + var tr = original.find('tr'), + tr_copy = copy.find('tr'), + heights = []; + + tr.each(function (index) { + var self = $(this), + tx = self.find('th, td'); + + tx.each(function () { + var height = $(this).outerHeight(true); + heights[index] = heights[index] || 0; + if (height > heights[index]) heights[index] = height; + }); + }); + tr_copy.each(function (index) { + $(this).height(heights[index]); + }); + } + // Google Maps function initialize_google_maps() { $maps = $('.sp-google-map'); diff --git a/readme.txt b/readme.txt index fbb4d458..44d6968a 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,10 @@ === SportsPress === Contributors: themeboy Tags: sports, sports journalism, teams, team management, fixtures, results, standings, league tables, leagues, reporting, themeboy, wordpress sports, configurable +Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=support@themeboy.com&item_name=Donation+for+SportsPress Requires at least: 3.5 Tested up to: 3.8 -Stable tag: 0.1.10 +Stable tag: 0.2 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -12,17 +13,17 @@ SportsPress is a flexible sports management plugin that adds team management fun == Installation == = Minimum Requirements = -* WordPress 3.5 or greater +* WordPress 3.5 or greater (WordPress 3.8 recommended) * PHP version 5.2.4 or greater * MySQL version 5.0 or greater -= Automatic installation = += Automatic Installation = Automatic installation is the easiest option as WordPress handles the file transfers itself and you don’t even need to leave your web browser. To do an automatic install of SportsPress, log in to your WordPress admin panel, navigate to the Plugins menu and click Add New. In the search field type “SportsPress” and click Search Plugins. Once you’ve found our sports plugin you can view details about it such as the the point release, rating and description. Most importantly of course, you can install it by simply clicking Install Now. After clicking that link you will be asked if you’re sure you want to install the plugin. Click yes and WordPress will automatically complete the installation. -= Manual installation = += Manual Installation = The manual installation method involves downloading our sports plugin and uploading it to your webserver via your favorite FTP application. diff --git a/sportspress.php b/sportspress.php index d2e5700e..e4a1c576 100644 --- a/sportspress.php +++ b/sportspress.php @@ -6,7 +6,7 @@ Plugin Name: SportsPress Plugin URI: http://themeboy.com/sportspress Description: Manage your club and its players, staff, events, league tables, and player lists. -Version: 0.1.10 +Version: 0.2 Author: ThemeBoy Author URI: http://themeboy.com/ License: GPLv3 @@ -18,7 +18,7 @@ if ( !function_exists( 'add_action' ) ) { exit; } -define( 'SPORTSPRESS_VERSION', '0.1.10' ); +define( 'SPORTSPRESS_VERSION', '0.2' ); define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ );