adding comparison function compare objects in a a collection
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 6 Feb 2019 02:12:16 +0000 (21:12 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 6 Feb 2019 02:12:16 +0000 (21:12 -0500)
js/shortcodeBuilder.js

index 26990dc..fc55e90 100644 (file)
@@ -6,14 +6,47 @@
  */
 
 jQuery(function ($) {
-    var shortcode_start = "[glm-members-list ";
     
+    Object.compare = function (obj1, obj2) {
+        //Loop through properties in object 1
+        for (var p in obj1) {
+            //Check property exists on both objects
+            if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p)) return false;
+     
+            switch (typeof (obj1[p])) {
+                //Deep compare objects
+                case 'object':
+                    if (!Object.compare(obj1[p], obj2[p])) return false;
+                    break;
+                //Compare function code
+                case 'function':
+                    if (typeof (obj2[p]) == 'undefined' || (p != 'compare' && obj1[p].toString() != obj2[p].toString())) return false;
+                    break;
+                //Compare values
+                default:
+                    if (obj1[p] != obj2[p]) return false;
+            }
+        }
+     
+        //Check object 2 for any extra properties
+        for (var p in obj2) {
+            if (typeof (obj1[p]) == 'undefined') return false;
+        }
+        return true;
+    };
+
+    var shortcode_start     = "[glm-members-list ";
+    var shortcodeAttributes = {
+        categories  : [],
+        regions     : [],
+        groups      : []
+    }
 
     // build substrings that will be constructed with the main shortcode text
     $("#shortcode-categories").on("change", function(){
-        var categoryID      = $(this).val();
-        var categoryName    = $(this).find("option:selected").text();
-        
-        console.log( categoryName );
+        var categoryID              = $(this).val();
+        var categoryName            = $(this).find("option:selected").text();
+        let categoryRecord          = {};
+        categoryRecord[categoryID]  = categoryName;
     });
 });