Adding a way to update the trip count for all pages.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 17 May 2019 15:03:49 +0000 (11:03 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 17 May 2019 15:03:49 +0000 (11:03 -0400)
Calling the trip planner ajax page to grab the count when page loads.

index.php
js/allPages.js [new file with mode: 0644]
js/front.js

index 0f2b44f..936295b 100644 (file)
--- 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 (file)
index 0000000..726ecb7
--- /dev/null
@@ -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 );
+            }
+        });
+    }
+});
index 2473948..410bead 100644 (file)
@@ -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({