fixing issue with resetting the shortcode and retaining the array of previously selec...
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 11 Feb 2019 20:02:25 +0000 (15:02 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 11 Feb 2019 20:02:25 +0000 (15:02 -0500)
css/admin.css
js/shortcodeBuilder.js

index 48d9ecb..0e4687e 100755 (executable)
@@ -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;
index 71d589b..6aac3a7 100644 (file)
@@ -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");