diff --git a/assets/css/admin.css b/assets/css/admin.css index 56468ce8..4d25583a 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -146,6 +146,28 @@ table.widefat.sp-data-table input.name { width: auto; } +table.widefat.sp-data-table a.dashicons { + cursor: pointer; + height: 27px; + line-height: 27px; +} + +table.widefat.sp-data-table a.sp-edit-name { + -moz-opacity: 0; + opacity: 0; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; +} + +table.widefat.sp-data-table tr:hover a.sp-edit-name { + -moz-opacity: 1; + opacity: 1; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; +} + +table.widefat.sp-data-table a.sp-cancel { + color: #a00; +} + .sp-admin-config-table th, .sp-admin-config-table td { width: 20%; diff --git a/assets/js/admin.js b/assets/js/admin.js index 5183bda2..88604c2d 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -15,12 +15,6 @@ jQuery(document).ready(function($){ single_backstroke_delete: false }); - $('#poststuff #sp_detailsdiv .sp-current-team').on('change', function() { - $el = $(this).closest('#sp_detailsdiv').find('.sp-team'); - $el.find('option[value='+$(this).val()+']').attr('selected', false); - $el.trigger('chosen:updated'); - }); - // Auto key placeholder $("#poststuff #title").on("keyup", function() { $("#sp_key").attr("placeholder", $(this).val().replace(/[^a-z]/gi,"").toLowerCase()); @@ -75,6 +69,41 @@ jQuery(document).ready(function($){ // Activate self-cloning $(".sp-clone:last").find("select").change(); + // Name editor + $(".sp-data-table .sp-edit-name").click(function() { + $(this).closest(".sp-default-name").hide().siblings(".sp-custom-name").show().find(".sp-custom-name-input").focus(); + }); + + // Name editor save + $(".sp-data-table .sp-custom-name .sp-save").click(function() { + $val = $(this).siblings(".sp-custom-name-input").val(); + if($val == "") $val = $(this).siblings(".sp-custom-name-input").attr("placeholder"); + $(this).closest(".sp-custom-name").hide().siblings(".sp-default-name").show().find(".sp-default-name-input").html($val); + }); + + // Name editor cancel + $(".sp-data-table .sp-custom-name .sp-cancel").click(function() { + $(this).closest(".sp-custom-name").hide().siblings(".sp-default-name").show(); + }); + + // Prevent name editor input from submitting form + $(".sp-data-table .sp-custom-name .sp-custom-name-input").keypress(function(event) { + if(event.keyCode == 13){ + event.preventDefault(); + $(this).siblings(".sp-save").click(); + return false; + } + }); + + // Cancel name editor form on escape + $(".sp-data-table .sp-custom-name .sp-custom-name-input").keyup(function(event) { + if(event.keyCode == 27){ + event.preventDefault(); + $(this).siblings(".sp-cancel").click(); + return false; + } + }); + // Total stats calculator $(".sp-data-table .sp-total input").on("updateTotal", function() { index = $(this).parent().index(); diff --git a/functions.php b/functions.php index 142c6e72..111209be 100644 --- a/functions.php +++ b/functions.php @@ -773,12 +773,25 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) { $team_stats ): - if ( !$team_id ) continue; + if ( !$team_id ) + continue; + $div = get_term( $team_id, 'sp_season' ); + $default_name = sportspress_array_value( $team_stats, 'name', '' ); + if ( $default_name == null ) + $default_name = get_the_title( $team_id ); ?>