Merge branch 'tweak-relative-date-in-shortcodes'

This commit is contained in:
Brian Miyaji
2018-04-29 09:52:06 +10:00
2 changed files with 132 additions and 27 deletions

View File

@@ -28,7 +28,7 @@ class SP_Admin_Assets {
/** /**
* Enqueue styles * Enqueue styles
*/ */
public function admin_styles() { public function admin_styles( $hook ) {
// Sitewide menu CSS // Sitewide menu CSS
wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION ); wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION );
@@ -59,7 +59,7 @@ class SP_Admin_Assets {
wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION ); wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION );
} }
if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) ) { if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array('post.php', 'post-new.php') ) ) {
wp_enqueue_style( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' ); wp_enqueue_style( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION ); wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION );
} }
@@ -70,7 +70,7 @@ class SP_Admin_Assets {
/** /**
* Enqueue scripts * Enqueue scripts
*/ */
public function admin_scripts() { public function admin_scripts($hook) {
global $wp_query, $post; global $wp_query, $post;
$screen = get_current_screen(); $screen = get_current_screen();
@@ -101,7 +101,8 @@ class SP_Admin_Assets {
wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true ); wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true );
// SportsPress admin pages // SportsPress admin pages
if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' )) { if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array($hook, array('post.php', 'post-new.php') ) ) {
wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'chosen' ); wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-core' );

View File

@@ -387,17 +387,42 @@ class SP_AJAX {
?> ?>
</label> </label>
</p> </p>
<p> <div class="sp-date-selector">
<p><?php _e( 'Date:', 'sportspress' ); ?>
<?php
$args = array(
'name' => 'date',
'id' => 'date',
'selected' => $date,
);
sp_dropdown_dates( $args );
?>
</p>
<div class="sp-date-range">
<p class="sp-date-range-absolute">
<input type="text" class="sp-datepicker-from" name="sp_date_from" value="default" size="10">
:
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="default" size="10">
</p>
<p class="sp-date-range-relative">
<?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="default">
<?php _e( 'days', 'sportspress' ); ?>
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_future" value="default">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label> <label>
<?php _e( 'Date:', 'sportspress' ); ?> <input type="checkbox" name="sp_date_relative" value="0" id="sp_date_relative">
<select id="date" name="date"> <?php _e( 'Relative', 'sportspress' ); ?>
<option value="default"><?php _e( 'Default', 'sportspress' ); ?></option>
<option value=""><?php _e( 'All', 'sportspress' ); ?></option>
<option value="w"><?php _e( 'This week', 'sportspress' ); ?></option>
<option value="day"><?php _e( 'Today', 'sportspress' ); ?></option>
</select>
</label> </label>
</p> </p>
</div>
</div>
<p> <p>
<label> <label>
<?php _e( 'Match Day:', 'sportspress' ); ?> <?php _e( 'Match Day:', 'sportspress' ); ?>
@@ -556,17 +581,42 @@ class SP_AJAX {
?> ?>
</label> </label>
</p> </p>
<p> <div class="sp-date-selector">
<p><?php _e( 'Date:', 'sportspress' ); ?>
<?php
$args = array(
'name' => 'date',
'id' => 'date',
'selected' => $date,
);
sp_dropdown_dates( $args );
?>
</p>
<div class="sp-date-range">
<p class="sp-date-range-absolute">
<input type="text" class="sp-datepicker-from" name="sp_date_from" value="default" size="10">
:
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="default" size="10">
</p>
<p class="sp-date-range-relative">
<?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="default">
<?php _e( 'days', 'sportspress' ); ?>
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_future" value="default">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label> <label>
<?php _e( 'Date:', 'sportspress' ); ?> <input type="checkbox" name="sp_date_relative" value="0" id="sp_date_relative">
<select id="date" name="date"> <?php _e( 'Relative', 'sportspress' ); ?>
<option value="default"><?php _e( 'Default', 'sportspress' ); ?></option>
<option value=""><?php _e( 'All', 'sportspress' ); ?></option>
<option value="w"><?php _e( 'This week', 'sportspress' ); ?></option>
<option value="day"><?php _e( 'Today', 'sportspress' ); ?></option>
</select>
</label> </label>
</p> </p>
</div>
</div>
<p> <p>
<label> <label>
<?php _e( 'Match Day:', 'sportspress' ); ?> <?php _e( 'Match Day:', 'sportspress' ); ?>
@@ -1030,6 +1080,11 @@ class SP_AJAX {
args.venue = $div.find('[name=venue]').val(); args.venue = $div.find('[name=venue]').val();
args.status = $div.find('[name=status]').val(); args.status = $div.find('[name=status]').val();
args.date = $div.find('[name=date]').val(); args.date = $div.find('[name=date]').val();
args.date_from = $div.find('[name=sp_date_from]').val();
args.date_to = $div.find('[name=sp_date_to]').val();
args.date_past = $div.find('[name=sp_date_past]').val();
args.date_future = $div.find('[name=sp_date_future]').val();
args.date_relative = $div.find('[name=sp_date_relative]:checked').length;
args.day = $div.find('[name=day]').val(); args.day = $div.find('[name=day]').val();
args.number = $div.find('[name=number]').val(); args.number = $div.find('[name=number]').val();
args.order = $div.find('[name=order]').val(); args.order = $div.find('[name=order]').val();
@@ -1044,6 +1099,11 @@ class SP_AJAX {
args.venue = $div.find('[name=venue]').val(); args.venue = $div.find('[name=venue]').val();
args.status = $div.find('[name=status]').val(); args.status = $div.find('[name=status]').val();
args.date = $div.find('[name=date]').val(); args.date = $div.find('[name=date]').val();
args.date_from = $div.find('[name=sp_date_from]').val();
args.date_to = $div.find('[name=sp_date_to]').val();
args.date_past = $div.find('[name=sp_date_past]').val();
args.date_future = $div.find('[name=sp_date_future]').val();
args.date_relative = $div.find('[name=sp_date_relative]:checked').length;
args.day = $div.find('[name=day]').val(); args.day = $div.find('[name=day]').val();
args.number = $div.find('[name=number]').val(); args.number = $div.find('[name=number]').val();
args.orderby = $div.find('[name=orderby]').val(); args.orderby = $div.find('[name=orderby]').val();
@@ -1092,9 +1152,53 @@ class SP_AJAX {
window.send_to_editor( shortcode ); window.send_to_editor( shortcode );
} }
</script> </script>
<script type="text/javascript">
jQuery(document).ready(function($){
// Datepicker
$(".sp-datepicker").datepicker({
dateFormat : "yy-mm-dd"
});
$(".sp-datepicker-from").datepicker({
dateFormat : "yy-mm-dd",
onClose: function( selectedDate ) {
$(this).closest(".sp-date-selector").find(".sp-datepicker-to").datepicker("option", "minDate", selectedDate);
}
});
$(".sp-datepicker-to").datepicker({
dateFormat : "yy-mm-dd",
onClose: function( selectedDate ) {
$(this).closest(".sp-date-selector").find(".sp-datepicker-from").datepicker("option", "maxDate", selectedDate);
}
});
// Show or hide datepicker
$(".sp-date-selector select").change(function() {
if ( $(this).val() == "range" ) {
$(this).closest(".sp-date-selector").find(".sp-date-range").show();
} else {
$(this).closest(".sp-date-selector").find(".sp-date-range").hide();
}
});
$(".sp-date-selector select").trigger("change");
// Toggle date range selectors
$(".sp-date-relative input").change(function() {
$relative = $(this).closest(".sp-date-relative").siblings(".sp-date-range-relative").toggle(0, $(this).attr("checked"));
$absolute = $(this).closest(".sp-date-relative").siblings(".sp-date-range-absolute").toggle(0, $(this).attr("checked"));
if ($(this).attr("checked")) {
$relative.show();
$absolute.hide();
} else {
$absolute.show();
$relative.hide();
}
});
$(".sp-date-selector input").trigger("change");
});
</script>
<?php <?php
} }
} }
new SP_AJAX(); new SP_AJAX();