Update js
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 27 Apr 2016 20:20:55 +0000 (16:20 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 27 Apr 2016 20:20:55 +0000 (16:20 -0400)
check to see if the id are there first before running things

js/dashboard.js

index 86d7389..20a775f 100644 (file)
@@ -1,11 +1,13 @@
 (function(){
     console.info('Running GLM Event plugin js');
-    $('#glm-event-from').datepicker();
-    $('#glm-event-to').datepicker();
+    if ($('#glm-event-from').length > 0) {
+        $('#glm-event-from').datepicker();
+        $('#glm-event-to').datepicker();
+    }
     $('#glm-event-detail-backtosearch').click(function(){
         window.history.back();
     });
-    if ($('#eventDetail-map').length) {
+    if ($('#eventDetail-map').length > 0) {
         GLM_GeoMap.initialize();
         $('#map-dialog').dialog({
             height: 480,
         eventForm = $('#glm-member-event-search');
         eventForm.attr('action', '../wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&glm-event-pdf=1');
     });
-    var cache = {};
-    $("#glm-event-name").autocomplete({
-        minLength: 2,
-        source: function(request, response) {
-            var term = request.term;
-            if ( term in cache ) {
-                response( cache[term]);
-                return;
+    if ($('#glm-event-name').length > 0) {
+        var cache = {};
+        $("#glm-event-name").autocomplete({
+            minLength: 2,
+            source: function(request, response) {
+                var term = request.term;
+                if ( term in cache ) {
+                    response( cache[term]);
+                    return;
+                }
+                var url = '../wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=nameSearch';
+                $.getJSON( url, request, function(data, status, xhr){
+                    //cache[term] = data;
+                    response( data );
+                });
             }
-            var url = '../wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=nameSearch';
-            $.getJSON( url, request, function(data, status, xhr){
-                //cache[term] = data;
-                response( data );
-            });
-        }
-    });
+        });
+    }
 }).call(this);