From: Anthony Talarico Date: Mon, 11 Feb 2019 20:02:25 +0000 (-0500) Subject: fixing issue with resetting the shortcode and retaining the array of previously selec... X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=7f9232de3a449080ddb873c642140b8de39bd05a;p=WP-Plugins%2Fglm-member-db.git fixing issue with resetting the shortcode and retaining the array of previously selected options --- diff --git a/css/admin.css b/css/admin.css index 48d9ecbb..0e4687eb 100755 --- a/css/admin.css +++ b/css/admin.css @@ -433,6 +433,9 @@ td.glm-nowrap { } .shortcode-string:hover, .edit-attribute{ background:#00C773; + color: white; + border-radius: 6px; + padding: 0 3px; } .delete-attribute{ position: absolute; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index 71d589ba..6aac3a78 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -12,13 +12,7 @@ jQuery(function ($) { class : "shortcode-end", text: ']', }); - var shortcodeAttributes = { - categories : {list:[], isList: true}, - regions : {list:[], isList: true}, - groups : {list:[], isList: true}, - views : {list:[], isList: false}, - blankstart : {list:[], isList: false}, - } + var shortcodeAttributes; function replaceNbsp(str) { var re = new RegExp(String.fromCharCode(160), "g"); return str.replace(re, " "); @@ -48,10 +42,16 @@ jQuery(function ($) { })); tile.appendTo(elHook); } - function setupAttributes(state){ $("#shortcode-preview").empty(); $(".shortcode-tile-container").empty(); + shortcodeAttributes = { + categories : {list:[], isList: true}, + regions : {list:[], isList: true}, + groups : {list:[], isList: true}, + views : {list:[], isList: false}, + blankstart : {list:[], isList: false}, + } shortcode_string.appendTo( $("#shortcode-preview")); shortcode_end.appendTo( $("#shortcode-preview")); for(var attribute in shortcodeAttributes ){ @@ -61,7 +61,6 @@ jQuery(function ($) { }).insertBefore( $(".shortcode-end")); } } - function checkDuplicates(object, list) { var objString = JSON.stringify(object); for( var i = 0; i < list.length; i++){ @@ -72,30 +71,24 @@ jQuery(function ($) { } return false; } - function updateShortcode(shortcodeData){ $("#"+shortcodeData.type+"-container").empty(); var ids = []; var item_string = ''; - shortcodeData.list.map( function(item){ ids.push(item.id); createShortcodeTile({id: item.id, name: item.name, type: item.type}, $("#"+item.type + "-container")) item_string = item.type+'="'+ids.join() + '"'; }); - shortcodeData['attribute'] = item_string; generateShortCodeAttribute(shortcodeData); } - setupAttributes(); - $(document).on("change", ".shortcode-selection",function(){ var id = $(this).val(); var name = $(this).find("option:selected").text(); var type = $(this).find("option:selected").data("type"); let record = {id: id, name: name, type: type}; - if(shortcodeAttributes[type].list.length == 0 || !checkDuplicates(record, shortcodeAttributes[type].list) && shortcodeAttributes[type].isList ){ shortcodeAttributes[type].list.push(record); }else if(!shortcodeAttributes[type].isList) { @@ -105,7 +98,6 @@ jQuery(function ($) { $("#"+type+"-string").removeClass("shortcode-no-space"); updateShortcode({list: shortcodeAttributes[type].list, type: type, isList: shortcodeAttributes[type].isList}); }); - $(".shortcode-button").on("click", function(){ var confirmation = $(this).children('div'); if( $(this).attr("id") == "copy-to-clipboard" ){ @@ -125,7 +117,6 @@ jQuery(function ($) { confirmation.toggleClass("confirmed"); }, 3000); }); - $(document).on("click", ".shortcode-string", function(){ $(this).addClass("edit-attribute"); if($(this).hasClass("edit-attribute")){ @@ -160,7 +151,6 @@ jQuery(function ($) { var updated = shortcodeAttributes[type].list.filter( function(item) { return item.id != id; }); - shortcodeAttributes[type].list = updated; if( shortcodeAttributes[type].list.length == 0) { $("#"+type+"-string").addClass("shortcode-no-space");