From: Anthony Talarico Date: Fri, 21 Oct 2016 19:32:54 +0000 (-0400) Subject: fixing shortcode builder code to recognize attributes in any order on page load so... X-Git-Tag: v2.8.0^2~2^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c8051208e7027fae04232da59f5497512b989bd0;p=WP-Plugins%2Fglm-member-db.git fixing shortcode builder code to recognize attributes in any order on page load so that the active boxes are populated with the respective attributes --- diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index bc1871ad..ca98637c 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -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] + ')' + 'X' + ''); }); + // 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('
' + + obj[0] + " (ID: " + obj[1] + ')' + 'X' + + '
'); + }); ///////////////////////////////////////////////////////////////////////////////////////////// /* * 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 ) {