From 0fe87c61714ee98567f15957e16bfa187a440752 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 17 May 2019 11:03:49 -0400 Subject: [PATCH] Adding a way to update the trip count for all pages. Calling the trip planner ajax page to grab the count when page loads. --- index.php | 19 +++++++++++++++++++ js/allPages.js | 20 ++++++++++++++++++++ js/front.js | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 js/allPages.js diff --git a/index.php b/index.php index 0f2b44f..936295b 100644 --- a/index.php +++ b/index.php @@ -236,3 +236,22 @@ ${GLM_MEMBERS_ITINERARY_PLUGIN_PREFIX."updateChecker"}->declareCredentials(array */ require_once GLM_MEMBERS_ITINERARY_PLUGIN_SETUP_PATH.'/permissions.php'; +// Setup a script to load on all pages in the front end. +if ( !is_admin() ) { + add_action( + 'wp_enqueue_scripts', + function(){ + wp_enqueue_script( + 'itineraryFrontEnd', + GLM_MEMBERS_ITINERARY_PLUGIN_URL . '/js/allPages.js' + ); + wp_localize_script( + 'itineraryFrontEnd', + 'ititenarySettings', + array( + 'base_url' => home_url() + ) + ); + } + ); +} diff --git a/js/allPages.js b/js/allPages.js new file mode 100644 index 0000000..726ecb7 --- /dev/null +++ b/js/allPages.js @@ -0,0 +1,20 @@ +jQuery(document).ready(function($){ + // If there's an span with class of trip-counter + // then update it. + var tripCounters = $('.trip-counter'); + var base_url = ititenarySettings.base_url; + if ( tripCounters.length > 0 ) { + $.ajax({ + url: base_url + '/wp-admin/admin-ajax.php', + cache: false, + data: { + action: 'glm_members_admin_ajax', + glm_action: 'itineraryList', + }, + dataType: 'html', + success: function(count){ + $(".trip-counter").html( count ); + } + }); + } +}); diff --git a/js/front.js b/js/front.js index 2473948..410bead 100644 --- a/js/front.js +++ b/js/front.js @@ -8,7 +8,7 @@ jQuery('.glm-planner-button').on('click', function(e){ var ref_page = jQuery(this).data('refpage'); var button = jQuery(this); var load_page = jQuery(this).data('loadpage'); - var is_view = jQuery(this).data('view'); + var is_view = jQuery(this).data('view'); if ( !is_view ) { jQuery.ajax({ -- 2.17.1