Initial commit for adding relative_date_range option to shortcodes

This commit is contained in:
savvasha
2017-12-17 20:41:28 +02:00
parent 5705d35e5b
commit 40c2aaba05
2 changed files with 84 additions and 14 deletions

View File

@@ -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="<?php echo $date_from ? $date_from : date_i18n( 'Y-m-d' ); ?>" size="10">
:
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" 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="<?php echo '' !== $date_past ? $date_past : 7; ?>">
<?php _e( 'days', 'sportspress' ); ?>
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_future" value="<?php echo '' !== $date_future ? $date_future : 7; ?>">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label> <label>
<?php _e( 'Date:', 'sportspress' ); ?> <input type="checkbox" name="sp_date_relative" value="1" id="sp_date_relative" <?php checked( $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' ); ?>
@@ -1084,10 +1109,54 @@ class SP_AJAX {
// Send the shortcode to the editor // Send the shortcode to the editor
window.send_to_editor( shortcode ); window.send_to_editor( shortcode );
} }
</script>
<script>
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> </script>
<?php <?php
} }
} }
new SP_AJAX(); new SP_AJAX();