diff --git a/assets/css/admin.css b/assets/css/admin.css index 45ddf188..2e2af6e6 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -215,13 +215,13 @@ table.widefat.sp-data-table a.dashicons { line-height: 27px; } -table.widefat.sp-data-table a.sp-edit-name { +table.widefat.sp-data-table a.sp-edit { -moz-opacity: 0; opacity: 0; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; } -table.widefat.sp-data-table tr:hover a.sp-edit-name { +table.widefat.sp-data-table tr:hover a.sp-edit { -moz-opacity: 1; opacity: 1; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index a63a4c85..b60a57ff 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -45,6 +45,12 @@ jQuery(document).ready(function($){ $el.show(); }); + // 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(); + return false; + }); + // Tab switcher $(".sp-tab-panel").siblings(".sp-tab-bar").find("a").click(function() { $(this).closest("li").removeClass("wp-tab").addClass("wp-tab-active").siblings().removeClass("wp-tab-active").addClass("wp-tab").closest(".wp-tab-bar").siblings($(this).attr("href")).show().siblings(".wp-tab-panel").hide(); @@ -63,7 +69,6 @@ jQuery(document).ready(function($){ filter += ".sp-filter-"+filterval; }); } - console.log( filter ); $panel = $(this).closest(".sp-tab-select").siblings(".sp-tab-panel") $panel.find(".sp-post").hide(0, function() { $(this).find("input").prop("disabled", true); @@ -97,45 +102,64 @@ jQuery(document).ready(function($){ // Activate self-cloning $(".sp-clone:last").find("select").change(); - // Name editor - $(".sp-data-table .sp-default-name").click(function() { - $(this).hide().siblings(".sp-custom-name").show().find(".sp-custom-name-input").focus(); + // Custom value editor + $(".sp-data-table .sp-default-value").click(function() { + $(this).hide().siblings(".sp-custom-value").show().find(".sp-custom-value-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); + // Define custom value editor saving + $(".sp-data-table .sp-custom-value .sp-custom-value-input").on("saveInput", function() { + $val = $(this).val(); + if($val == "") $val = $(this).attr("placeholder"); + $(this).closest(".sp-custom-value").hide().siblings(".sp-default-value").show().find(".sp-default-value-input").html($val); }); - // Name editor cancel - $(".sp-data-table .sp-custom-name .sp-cancel").click(function() { - $val = $(this).closest(".sp-custom-name").siblings(".sp-default-name").find(".sp-default-name-input").html(); - $el = $(this).siblings(".sp-custom-name-input"); - if($val == $el.attr("placeholder")) $el.val(""); - else $el.val($val); - $(this).closest(".sp-custom-name").hide().siblings(".sp-default-name").show(); + // Define custom value editor cancellation + $(".sp-data-table .sp-custom-value .sp-custom-value-input").on("cancelInput", function() { + $val = $(this).closest(".sp-custom-value").siblings(".sp-default-value").find(".sp-default-value-input").html(); + if($val == $(this).attr("placeholder")) $(this).val(""); + else $(this).val($val); + $(this).closest(".sp-custom-value").hide().siblings(".sp-default-value").show(); }); - // Prevent name editor input from submitting form - $(".sp-data-table .sp-custom-name .sp-custom-name-input").keypress(function(event) { + // Custom value editor save + $(".sp-data-table .sp-custom-value .sp-save").click(function() { + $(this).siblings(".sp-custom-value-input").trigger("saveInput"); + }); + + // Custom value editor cancel + $(".sp-data-table .sp-custom-value .sp-cancel").click(function() { + $(this).siblings(".sp-custom-value-input").trigger("cancelInput"); + }); + + // Prevent custom value editor input from submitting form + $(".sp-data-table .sp-custom-value .sp-custom-value-input").keypress(function(event) { if(event.keyCode == 13){ event.preventDefault(); - $(this).siblings(".sp-save").click(); + $(this).trigger("saveInput"); return false; } }); - // Cancel name editor form on escape - $(".sp-data-table .sp-custom-name .sp-custom-name-input").keyup(function(event) { + // Cancel custom value editor form on escape + $(".sp-data-table .sp-custom-value .sp-custom-value-input").keyup(function(event) { if(event.keyCode == 27){ event.preventDefault(); - $(this).siblings(".sp-cancel").click(); + $(this).trigger("cancelInput"); return false; } }); + // Data table adjustments + $(".sp-table-adjustments input").change(function() { + matrix = $(this).attr("data-matrix"); + $el = $(this).closest(".sp-table-adjustments").siblings(".sp-table-values").find("input[data-matrix="+matrix+"]"); + placeholder = parseFloat($el.attr("data-placeholder")); + adjustment = parseFloat($(this).val()) - parseFloat($el.attr("data-adjustment")); + if(!isNaN(adjustment)) placeholder += adjustment; + $el.attr("placeholder", placeholder); + }); + // Data table keyboard navigation $(".sp-data-table tbody tr td input:text").keydown(function(event) { if(! $(this).parent().hasClass("chosen-search") && [37,38,39,40].indexOf(event.keyCode) > -1){ 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 183c6e89..de64d3bd 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 @@ -20,7 +20,8 @@ class SP_Meta_Box_Table_Data { */ public static function output( $post ) { list( $columns, $usecolumns, $data, $placeholders, $merged ) = sp_get_league_table_data( $post->ID, true ); - sp_edit_league_table( $columns, $usecolumns, $data, $placeholders ); + $adjustments = get_post_meta( $post->ID, 'sp_adjustments', true ); + sp_edit_league_table( $columns, $usecolumns, $data, $placeholders, $adjustments ); } /** @@ -28,6 +29,7 @@ class SP_Meta_Box_Table_Data { */ public static function save( $post_id, $post ) { 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() ) ); } } \ No newline at end of file diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index aba56051..2699a181 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -937,12 +937,16 @@ if ( !function_exists( 'sp_edit_calendar_table' ) ) { } if ( !function_exists( 'sp_edit_league_table' ) ) { - function sp_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) { + function sp_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array() ) { if ( is_array( $usecolumns ) ) $usecolumns = array_filter( $usecolumns ); $show_team_logo = get_option( 'sportspress_table_show_logos', false ); ?> -