From 5fe309e63fcc351a7d013526323b129c66d291fc Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 5 Feb 2019 21:12:16 -0500 Subject: [PATCH] adding comparison function compare objects in a a collection --- js/shortcodeBuilder.js | 43 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index 26990dc4..fc55e90c 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -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; }); }); -- 2.17.1