From 7f03ca39b98530d23c509cd125fb5a8e0ecd0949 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Fri, 24 Aug 2018 00:47:45 +1000 Subject: [PATCH] @savvasha commit from BitBucket --- assets/js/admin/sportspress-admin.js | 29 ++++++++++++--- assets/js/jquery.countdown.min.js | 22 ------------ assets/js/sportspress.js | 35 +++++++++++++++---- includes/admin/class-sp-admin-assets.php | 5 +-- includes/admin/class-sp-admin-dashboard.php | 2 +- .../admin/importers/class-sp-importer.php | 2 +- includes/class-sp-calendar.php | 2 +- includes/class-sp-frontend-scripts.php | 1 - templates/countdown.php | 2 +- 9 files changed, 58 insertions(+), 42 deletions(-) delete mode 100755 assets/js/jquery.countdown.min.js diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 6bc8c1b9..4d7641db 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -457,10 +457,31 @@ jQuery(document).ready(function($){ // Dashboard countdown $("#sportspress_dashboard_status .sp_status_list li.countdown").each(function() { - var $this = $(this), finalDate = $(this).data('countdown'); - $this.countdown(finalDate, function(event) { - $this.find('strong').html(event.strftime("%D "+localized_strings.days+" %H:%M:%S")); - }); + var $this = $(this); + // Get countdown time + var countDownDate = new Date($(this).data('countdown')).getTime(); + // Iterate every second + var x = setInterval(function() { + + // Get todays date and time + var now = new Date(); + + // Convert curent date and time to UTC + var tzDifference = now.getTimezoneOffset(); + var nowutc = new Date(now.getTime() + tzDifference * 60 * 1000); + + // Find the distance between now and the count down date + var distance = countDownDate - nowutc; + + // Time calculations for days, hours, minutes and seconds + var days = Math.floor(distance / (1000 * 60 * 60 * 24)); + var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); + var seconds = Math.floor((distance % (1000 * 60)) / 1000); + + // Output the result + $this.find('strong').html(days+" "+localized_strings.days+" "+('0' + hours).slice(-2)+":"+('0' + minutes).slice(-2)+":"+('0' + seconds).slice(-2)); + }, 1000); }); // Event format affects data diff --git a/assets/js/jquery.countdown.min.js b/assets/js/jquery.countdown.min.js deleted file mode 100755 index 99b36316..00000000 --- a/assets/js/jquery.countdown.min.js +++ /dev/null @@ -1,22 +0,0 @@ -/*! - * The Final Countdown for jQuery v2.2.0 (http://hilios.github.io/jQuery.countdown/) - * Copyright (c) 2016 Edson Hilios - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(a){if(a instanceof Date)return a;if(String(a).match(g))return String(a).match(/^[0-9]*$/)&&(a=Number(a)),String(a).match(/\-/)&&(a=String(a).replace(/\-/g,"/")),new Date(a);throw new Error("Couldn't cast `"+a+"` to a date object.")}function c(a){var b=a.toString().replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");return new RegExp(b)}function d(a){return function(b){var d=b.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(d)for(var f=0,g=d.length;f1?c:d}var f=[],g=[],h={precision:100,elapse:!1,defer:!1};g.push(/^[0-9]*$/.source),g.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g=new RegExp(g.join("|"));var i={Y:"years",m:"months",n:"daysToMonth",d:"daysToWeek",w:"weeks",W:"weeksToMonth",H:"hours",M:"minutes",S:"seconds",D:"totalDays",I:"totalHours",N:"totalMinutes",T:"totalSeconds"},j=function(b,c,d){this.el=b,this.$el=a(b),this.interval=null,this.offset={},this.options=a.extend({},h),this.firstTick=!0,this.instanceNumber=f.length,f.push(this),this.$el.data("countdown-instance",this.instanceNumber),d&&("function"==typeof d?(this.$el.on("update.countdown",d),this.$el.on("stoped.countdown",d),this.$el.on("finish.countdown",d)):this.options=a.extend({},h,d)),this.setFinalDate(c),this.options.defer===!1&&this.start()};a.extend(j.prototype,{start:function(){null!==this.interval&&clearInterval(this.interval);var a=this;this.update(),this.interval=setInterval(function(){a.update.call(a)},this.options.precision)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},toggle:function(){this.interval?this.stop():this.start()},pause:function(){this.stop()},resume:function(){this.start()},remove:function(){this.stop.call(this),f[this.instanceNumber]=null,delete this.$el.data().countdownInstance},setFinalDate:function(a){this.finalDate=b(a)},update:function(){if(0===this.$el.closest("html").length)return void this.remove();var a,b=new Date;return a=this.finalDate.getTime()-b.getTime(),a=Math.ceil(a/1e3),a=!this.options.elapse&&a<0?0:Math.abs(a),this.totalSecsLeft===a||this.firstTick?void(this.firstTick=!1):(this.totalSecsLeft=a,this.elapsed=b>=this.finalDate,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToWeek:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToMonth:Math.floor(this.totalSecsLeft/60/60/24%30.4368),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),weeksToMonth:Math.floor(this.totalSecsLeft/60/60/24/7)%4,months:Math.floor(this.totalSecsLeft/60/60/24/30.4368),years:Math.abs(this.finalDate.getFullYear()-b.getFullYear()),totalDays:Math.floor(this.totalSecsLeft/60/60/24),totalHours:Math.floor(this.totalSecsLeft/60/60),totalMinutes:Math.floor(this.totalSecsLeft/60),totalSeconds:this.totalSecsLeft},void(this.options.elapse||0!==this.totalSecsLeft?this.dispatchEvent("update"):(this.stop(),this.dispatchEvent("finish"))))},dispatchEvent:function(b){var c=a.Event(b+".countdown");c.finalDate=this.finalDate,c.elapsed=this.elapsed,c.offset=a.extend({},this.offset),c.strftime=d(this.offset),this.$el.trigger(c)}}),a.fn.countdown=function(){var b=Array.prototype.slice.call(arguments,0);return this.each(function(){var c=a(this).data("countdown-instance");if(void 0!==c){var d=f[c],e=b[0];j.prototype.hasOwnProperty(e)?d[e].apply(d,b.slice(1)):null===String(e).match(/^[$A-Z_][0-9A-Z_$]*$/i)?(d.setFinalDate.call(d,e),d.start()):a.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,e))}else new j(this,b[0],b[1])})}}); \ No newline at end of file diff --git a/assets/js/sportspress.js b/assets/js/sportspress.js index 0c03477c..4bb89dd7 100644 --- a/assets/js/sportspress.js +++ b/assets/js/sportspress.js @@ -16,13 +16,34 @@ function sp_viewport() { /* Countdown */ $("[data-countdown]").each(function() { - var $this = $(this), finalDate = $(this).data('countdown'); - $this.countdown(finalDate, function(event) { - $this.html(event.strftime("%D " + localized_strings.days + " " - + "%H " + localized_strings.hrs + " " - + "%M " + localized_strings.mins + " " - + "%S " + localized_strings.secs + "" )); - }); + var $this = $(this); + // Get countdown time + var countDownDate = new Date($(this).data('countdown')).getTime(); + // Iterate every second + var x = setInterval(function() { + + // Get todays date and time + var now = new Date(); + + // Convert curent date and time to UTC + var tzDifference = now.getTimezoneOffset(); + var nowutc = new Date(now.getTime() + tzDifference * 60 * 1000); + + // Find the distance between now and the count down date + var distance = countDownDate - nowutc; + + // Time calculations for days, hours, minutes and seconds + var days = Math.floor(distance / (1000 * 60 * 60 * 24)); + var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); + var seconds = Math.floor((distance % (1000 * 60)) / 1000); + + // Output the result + $this.html(""+('0' + days).slice(-2)+" " + localized_strings.days + " " + + ""+('0' + hours).slice(-2)+" " + localized_strings.hrs + " " + + ""+('0' + minutes).slice(-2)+" " + localized_strings.mins + " " + + ""+('0' + seconds).slice(-2)+" " + localized_strings.secs + "" ); + }, 1000); }); /* Scrollable Tables */ diff --git a/includes/admin/class-sp-admin-assets.php b/includes/admin/class-sp-admin-assets.php index 7000cca3..ac60ca03 100755 --- a/includes/admin/class-sp-admin-assets.php +++ b/includes/admin/class-sp-admin-assets.php @@ -82,8 +82,6 @@ class SP_Admin_Assets { wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true ); - wp_register_script( 'jquery-countdown', SP()->plugin_url() . '/assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.2.0', true ); - wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true ); wp_register_script( 'google-maps', '//tboy.co/maps_js' ); @@ -111,9 +109,8 @@ class SP_Admin_Assets { wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'jquery-tiptip' ); wp_enqueue_script( 'jquery-caret' ); - wp_enqueue_script( 'jquery-countdown' ); wp_enqueue_script( 'jquery-fitvids' ); - wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-countdown', 'jquery-fitvids' ), SP_VERSION, true ); + wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true ); $strings = apply_filters( 'sportspress_localized_strings', array( 'none' => __( 'None', 'sportspress' ), diff --git a/includes/admin/class-sp-admin-dashboard.php b/includes/admin/class-sp-admin-dashboard.php index cc6321bf..ccb392ee 100644 --- a/includes/admin/class-sp-admin-dashboard.php +++ b/includes/admin/class-sp-admin-dashboard.php @@ -75,7 +75,7 @@ class SP_Admin_Dashboard { $date = new DateTime( $next_event->post_date ); $interval = date_diff( $now, $date ); ?> -
  • +
  • %s until next event', 'sportspress' ), $interval->days . ' ' . __( 'days', 'sportspress' ) . ' ' . sprintf( '%02s:%02s:%02s', $interval->h, $interval->i, $interval->s ) ); ?> (post_title; ?>) diff --git a/includes/admin/importers/class-sp-importer.php b/includes/admin/importers/class-sp-importer.php index f793c719..45fad2c4 100644 --- a/includes/admin/importers/class-sp-importer.php +++ b/includes/admin/importers/class-sp-importer.php @@ -35,7 +35,7 @@ if ( class_exists( 'WP_Importer' ) ) { * Enqueue scripts */ public function admin_scripts() { - wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-countdown' ), SP_VERSION, true ); + wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true ); } /** diff --git a/includes/class-sp-calendar.php b/includes/class-sp-calendar.php index 119d24ca..d72dfc0c 100644 --- a/includes/class-sp-calendar.php +++ b/includes/class-sp-calendar.php @@ -276,7 +276,7 @@ class SP_Calendar extends SP_Secondary_Post { } if ( ! empty( $teams ) ) { - $args['meta_query'][] = array( + $args['meta_query'] = array( array( 'key' => 'sp_team', 'value' => $teams, diff --git a/includes/class-sp-frontend-scripts.php b/includes/class-sp-frontend-scripts.php index babae56d..cba914ce 100644 --- a/includes/class-sp-frontend-scripts.php +++ b/includes/class-sp-frontend-scripts.php @@ -72,7 +72,6 @@ class SP_Frontend_Scripts { // Scripts wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-datatables', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.10.4', true ); - wp_enqueue_script( 'jquery-countdown', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.2.0', true ); wp_enqueue_script( 'sportspress', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/sportspress.js', array( 'jquery' ), SP()->version, true ); // Localize scripts diff --git a/templates/countdown.php b/templates/countdown.php index d140ef16..0581be54 100644 --- a/templates/countdown.php +++ b/templates/countdown.php @@ -149,7 +149,7 @@ if ( $link_events ) $title = '= 10 ): ?> long-countdown"> -