Initial commit for adding relative_date_range option to shortcodes
This commit is contained in:
@@ -70,7 +70,7 @@ class SP_Admin_Assets {
|
||||
/**
|
||||
* Enqueue scripts
|
||||
*/
|
||||
public function admin_scripts() {
|
||||
public function admin_scripts($hook) {
|
||||
global $wp_query, $post;
|
||||
|
||||
$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 );
|
||||
|
||||
// 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( 'chosen' );
|
||||
wp_enqueue_script( 'jquery-ui-core' );
|
||||
|
||||
@@ -387,17 +387,42 @@ class SP_AJAX {
|
||||
?>
|
||||
</label>
|
||||
</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' ); ?>
|
||||
→
|
||||
<?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>
|
||||
<?php _e( 'Date:', 'sportspress' ); ?>
|
||||
<select id="date" name="date">
|
||||
<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>
|
||||
<input type="checkbox" name="sp_date_relative" value="1" id="sp_date_relative" <?php checked( $date_relative ); ?>>
|
||||
<?php _e( 'Relative', 'sportspress' ); ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<label>
|
||||
<?php _e( 'Match Day:', 'sportspress' ); ?>
|
||||
@@ -1085,9 +1110,53 @@ class SP_AJAX {
|
||||
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>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
new SP_AJAX();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user