fixing shortcode builder code to recognize attributes in any order on page load so...
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 21 Oct 2016 19:32:54 +0000 (15:32 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 21 Oct 2016 19:32:54 +0000 (15:32 -0400)
js/shortcodeBuilder.js

index bc1871a..ca98637 100644 (file)
@@ -123,7 +123,6 @@ jQuery(document).ready(function ($) {
         // get the number of instances of shortcodes with the category option
         var number_of_categories = (editor_shortcodes.match(/(\[glm-members-list .*?])/) || []).length;
         if ( number_of_categories ) {
-            console.log("Test");
             $('#glmRemoveShortCode').show();
             $('#generate').hide();
         }
@@ -131,10 +130,10 @@ jQuery(document).ready(function ($) {
         $('#glmRemoveShortCode').hide();
         $('#generate').show();
     }
-
-    if ( editor_shortcodes && number_of_categories) {
-        if ( editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null ) {
-            amenityGroups = editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ )[1];
+    var regions_id, regions_id_string, regions_new_ids = new Array(), regions_empty_space, regions_missing;
+    if ( editor_shortcodes) {
+        if ( editor_shortcodes.match( /glm-members-list .*amenity-groups="(.*?)"/ ) !== null ) {
+            amenityGroups = editor_shortcodes.match( /glm-members-list .*amenity-groups="(.*?)"/ )[1];
             groups_id = amenityGroups.split(',');
         } else if ( editor_shortcodes.match( /glm-members-list amenity-groups=""/ ) !== null ) {
             groups_id = editor_shortcodes.match( /glm-members-list amenity-groups=""/ )[1];
@@ -145,15 +144,17 @@ jQuery(document).ready(function ($) {
         if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) {
             memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1];
         }
-        if(editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null){
-
-            // return the category option from the shortcode
-            category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
-
-            // pull the ID numbers from the returned category string
+        if(editor_shortcodes.match(/glm-members-list .*category="(.*?)"/) !== null){
+            category_id = editor_shortcodes.match(/glm-members-list .*category="(.*?)"/)[1];
             category_id = category_id.split(',');
-        } else if (editor_shortcodes.match(/glm-members-list category=""/) !== null){
-            category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
+        } else if (editor_shortcodes.match(/glm-members-list .*category=""/) !== null){
+            category_id = editor_shortcodes.match(/glm-members-list .*category="(.*?)"/)[1];
+        }
+        if(editor_shortcodes.match(/glm-members-list .*region-search="(.*?)"/) !== null){
+            regions_id = editor_shortcodes.match(/glm-members-list .*region-search="(.*?)"/)[1];
+            regions_id= regions_id.split(',');
+        } else if (editor_shortcodes.match(/glm-members-list .*region-search=""/) !== null){
+            regions_id = editor_shortcodes.match(/glm-members-list .*region-search=""/)[1];
         }
         if ( number_of_categories ) {
             $('#shortcodeDropdown').val( 'glm-members-list' );
@@ -195,7 +196,23 @@ jQuery(document).ready(function ($) {
            + obj[0] + " (ID: " + obj[1] + ')' + '<span class="glm-group-dynSelect-delete groupDelete">X</span>'
            + '<input type="hidden" name="group[' + obj[0] + ']" value="' + obj[0] + '"></div>');
     });
+    // Check if the group has already been added
+    var region_names_ids = new Array();
+    var regionNames = $("#region-search-scDropdown>option").map(function() {
+        var index = $.inArray($(this).val(), regions_id);
+        if(index !== -1 && index !== ""){
+            region_names_ids.push([$(this).text(), $(this).val()]);
+            return $(this).text();
+        }
+    }).get();
 
+     // add the group names to #activeGroups
+    $.each( region_names_ids, function (index, obj) {
+        $('#activeRegions').append('<div data-id="' + obj[1]
+           + '" class="glm-regions-dynSelect-item glm-members-regions">'
+           + obj[0] + " (ID: " + obj[1] + ')' + '<span class="glm-dynSelect-delete regionDelete">X</span>'
+           + '<input type="hidden" name="group[' + obj[0] + ']" value="' + obj[0] + '"></div>');
+    });
     /////////////////////////////////////////////////////////////////////////////////////////////
    /*
     * Category Selection  these functions fire whenever the 'select category' dropdown is changed
@@ -404,7 +421,7 @@ jQuery(document).ready(function ($) {
        $('#amenitygroup-scDropdown').val('Select Groups');
     });
     
-    var regions_id, regions_id_string, regions_new_ids = new Array(), regions_empty_space, regions_missing;
+    
     $('#region-search-scDropdown').change(function(){
        editor_shortcodes = get_tinymce_content();
        if ( editor_shortcodes ) {