Cleaner league table team name editing

This commit is contained in:
Brian Miyaji
2014-02-19 11:57:31 +11:00
parent 924b8bcbcd
commit a4ca1af6a3
3 changed files with 72 additions and 8 deletions

View File

@@ -146,6 +146,28 @@ table.widefat.sp-data-table input.name {
width: auto; 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 th,
.sp-admin-config-table td { .sp-admin-config-table td {
width: 20%; width: 20%;

View File

@@ -15,12 +15,6 @@ jQuery(document).ready(function($){
single_backstroke_delete: false 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 // Auto key placeholder
$("#poststuff #title").on("keyup", function() { $("#poststuff #title").on("keyup", function() {
$("#sp_key").attr("placeholder", $(this).val().replace(/[^a-z]/gi,"").toLowerCase()); $("#sp_key").attr("placeholder", $(this).val().replace(/[^a-z]/gi,"").toLowerCase());
@@ -75,6 +69,41 @@ jQuery(document).ready(function($){
// Activate self-cloning // Activate self-cloning
$(".sp-clone:last").find("select").change(); $(".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 // Total stats calculator
$(".sp-data-table .sp-total input").on("updateTotal", function() { $(".sp-data-table .sp-total input").on("updateTotal", function() {
index = $(this).parent().index(); index = $(this).parent().index();

View File

@@ -773,12 +773,25 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) {
<?php <?php
$i = 0; $i = 0;
foreach ( $data as $team_id => $team_stats ): foreach ( $data as $team_id => $team_stats ):
if ( !$team_id ) continue; if ( !$team_id )
continue;
$div = get_term( $team_id, 'sp_season' ); $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 );
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td> <td>
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name" value="<?php echo sportspress_array_value( $team_stats, 'name', '' ); ?>" placeholder="<?php echo get_the_title( $team_id ); ?>"> <span class="sp-default-name">
<span class="sp-default-name-input"><?php echo $default_name; ?></span>
<a class="dashicons dashicons-edit sp-edit-name"></a>
</span>
<span class="hidden sp-custom-name">
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name sp-custom-name-input" value="<?php echo sportspress_array_value( $team_stats, 'name', '' ); ?>" placeholder="<?php echo get_the_title( $team_id ); ?>">
<a class="dashicons dashicons-no-alt sp-cancel"></a>
<a class="dashicons dashicons-yes sp-save"></a>
</span>
</td> </td>
<?php foreach( $columns as $column => $label ): <?php foreach( $columns as $column => $label ):
$value = sportspress_array_value( $team_stats, $column, '' ); $value = sportspress_array_value( $team_stats, $column, '' );