shortcode builder features. dynamic category
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 15 Jun 2016 14:15:09 +0000 (10:15 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 15 Jun 2016 14:15:09 +0000 (10:15 -0400)
classes/glmPluginSupport.php
css/admin.css
js/shortcodeBuilder.js

index 8459a31..6dc8c57 100644 (file)
@@ -471,8 +471,8 @@ return; // Off for now ** Need to make this switchable in management
         // dropdown for blank start
         echo '<select id="blank-start-scDropdown">';
         echo  '<option disabled> Hide List Until Searched</option>
-        <option value="False"> False </option>
-        <option value="True"> True </option>';
+        <option value="False"> No </option>
+        <option value="True"> Yes </option>';
         echo '</select>';
 
         // dropdown for views
@@ -515,9 +515,10 @@ return; // Off for now ** Need to make this switchable in management
         echo '<button id="generate" class="button" type="button"> Insert Shortcode </button>';
         echo '</div>';
         
-        echo '<div id="activeCategories" class="glm-dynSelect-box scCategories" style="height: auto; overflow: auto;"></div>';
+        
+        echo '<div id="activeCategories" class="glm-dynSelect-box scCategories" style="height: auto; overflow: auto;"><div id="categoryTitle">Categories</div></div>';
 
-//      echo '<div id="shortcode_preview_box" style="overflow: auto; clear: both;"></div>';
+//        echo '<div id="shortcode_preview_box" style="overflow: auto; clear: both;"><div id="shortcodesTitle">Shortcodes</div></div>';
         echo '</div>';
 
     }
index dbab748..788a6b6 100644 (file)
@@ -349,6 +349,13 @@ input[type=submit], input[type=file] {
     width:50%;*/
     display: block;
 }
+#categoryTitle > span{
+    font-weight: bold;
+}
+#categoryTitle, #shortcodesTitle{
+    font-weight: bold;
+    font-size: 16px;
+    border-bottom: 2px #ddd solid;
 #shortcode_builder > h2::before{
     position: relative;
     top: 2px;
index b2ac987..b3879f9 100644 (file)
@@ -8,8 +8,7 @@ jQuery(document).ready(function ($) {
     'use strict';
 
     var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString,
-    editor_shortcodes, category_id;
-    var shortcodeValues = {};
+    editor_shortcodes, category_id, shortcodeValues = {};
     $("#showDetail").hide();
     $("#categoryBox").hide();
     $("#showCategory").hide();
@@ -28,6 +27,12 @@ jQuery(document).ready(function ($) {
       }
     }
     
+    
+    
+    
+    /////////////////////////////////////////////////////////////////////////////////////////
+    // CHANGE MAIN SHORTCODE 
+    /////////////////////////////////////////////////////////////////////////////////////////
    // fire core events and reset settings when switching between shortcodes
     $("#shortcodeDropdown").on("change", function () {
         // reset the dropdowns and checkbox if when switching shortcodes
@@ -60,16 +65,6 @@ jQuery(document).ready(function ($) {
             $(".scCategories").show();
         }
         
-        if(shortcodeDropdown === "glm-member-detail") {
-            $("#detailBtn").show();
-            $("#showCategory").hide();
-            $("#blank-start-scDropdown").show();
-            $("#category-scDropdown").hide();  
-            $("#id-scDropdown").hide();
-            $("[id^='packageList']").hide();
-            $("#view-scDropdown").hide();
-        } 
-        
         if(shortcodeDropdown === "glm-members-packaging-list"){
             $("#blank-start-scDropdown").hide();
             $("#showCategory").hide();
@@ -81,46 +76,17 @@ jQuery(document).ready(function ($) {
             $("#view-scDropdown").hide();
              $(".scCategories").hide();
         } 
-        
-        if (shortcodeDropdown === "glm-members-packaging-detail"){
-            $("#blank-start-scDropdown").hide();
-            $("#showCategory").hide();
-            $("#category-scDropdown").hide();
-            $("#detailBtn").hide();
-            $("#id-scDropdown").show();
-            $("[id^='packageList']").hide();
-            $("#view-scDropdown").hide();
-        }
-        if (shortcodeDropdown === "glm-members-event-list"){
-            $("#blank-start-scDropdown").hide();
-            $("#showCategory").hide();
-            $("#category-scDropdown").hide();
-            $("#detailBtn").hide();
-            $("[id^='packageList']").hide();
-             $("#id-scDropdown").hide();
-             $("#view-scDropdown").hide();
-        }
-        if (shortcodeDropdown === "glm-members-event-detail"){
-            $("#blank-start-scDropdown").hide();
-            $("#showCategory").hide();
-            $("#category-scDropdown").hide();
-            $("#detailBtn").hide();
-            $("[id^='packageList']").hide();
-            $("#id-scDropdown").hide();
-            $("#view-scDropdown").hide();
-            $("#view-scDropdown").hide();
-        }
-        if (shortcodeDropdown === "glm-members-event-front-add"){
-            $("#blank-start-scDropdown").hide();
-            $("#showCategory").hide();
-            $("#category-scDropdown").hide();
-            $("#detailBtn").hide();
-            $("[id^='packageList']").hide();
-            $("#id-scDropdown").hide();
-            $("#view-scDropdown").hide();
-        }
-    });
 
+    });
+    
+    
+    
+    
+    
+    
+    ////////////////////////////////////////////////////////////////////
+    //  GET ATTRIBUTES
+    /////////////////////////////////////////////////////////////////////
      // shortcode attribute name from dropdowns containing '-scDropdown' in their ID
      // Then append the values to the shortcode object
      $("[id$=-scDropdown]").on("change", function () {
@@ -136,11 +102,10 @@ jQuery(document).ready(function ($) {
         $("#showDetail").dialog().dialog("option", "width", 422);
     });
     
+    var regExp = /\[([^)]+)\]/;
     function get_tinymce_content(){
         if (jQuery("#wp-content-wrap").hasClass("tmce-active")){
             
-            var regExp = /\[([^)]+)\]/;
-            
             tinyMCE.triggerSave();
             
             if(regExp.exec($('#content').val())){
@@ -153,7 +118,7 @@ jQuery(document).ready(function ($) {
         } else {
             
             // get the shortcode from the editor with [ ] as the delimiters
-            var regExp = /\[([^)]+)\]/;
+
             var editorContent = regExp.exec($("#content").val());
             
             // getting an array as the value from the previous reExp, will need to investigate
@@ -161,15 +126,16 @@ jQuery(document).ready(function ($) {
                 return editorContent[0];
             }
         }
-    }      
+    }
 
     editor_shortcodes = get_tinymce_content();
-    console.debug(editor_shortcodes);
     
     if(editor_shortcodes){
         if(editor_shortcodes.match(/category="(.*?)"/) !== null){
             category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
             category_id = category_id.split(',');
+        } else if (editor_shortcodes.match(/category=""/) !== null){
+            category_id = editor_shortcodes.match(/category="(.*?)"/)[1];       
         }
     }
 
@@ -196,20 +162,36 @@ jQuery(document).ready(function ($) {
     }
     
     
+    
+    
+    
+    
+    
+    
+    /////////////////////////////////////////////////////////////////////////////////////////////
    /*
     * Category Selection
     */
-     var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content;
-
+   //////////////////////////////////////////////////////////////////////////////////////////////
+     var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content, empty_space;
+   
     $('#category-scDropdown').change( function() {
        editor_shortcodes = get_tinymce_content();
-
+        console.debug(editor_shortcodes);
        if(editor_shortcodes){
             if(editor_shortcodes.match(/category="(.*?)"/) !== null){
                 category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
-                category_id = category_id.split(',');
-                ids = category_id.join(',');
-                editor_category_index = editor_shortcodes.indexOf('category=');
+                console.debug(category_id + "1");
+                if(category_id !== ""){
+                    category_id = category_id.split(',');
+                    console.debug(category_id + "2");
+                    ids = category_id.join(',');
+                    empty_space = false;
+                } else {
+                    console.debug(category_id + "3");
+                    ids = 'category=""';
+                    empty_space = true;
+                }
             }
         }
  
@@ -227,11 +209,6 @@ jQuery(document).ready(function ($) {
            }
        });
 
-       // Check if there's a parent
-//       parentName = '';
-//       if (catParent !== '') {
-//           parentName = catParent + ': ';
-//       }
 
        // If not found, Add the category
        if (!found) {
@@ -242,44 +219,69 @@ jQuery(document).ready(function ($) {
        }
        
        id_string = '';
+        
        $.each($(".glm-dynSelect-item"), function () {
            if($.inArray($(this).data("id"), new_ids) === -1){
                new_ids.push($(this).data("id"));
            }
-       });
-       
-       id_string = new_ids.join(',');
-       
+       });   
+        
+       if ( new_ids.length > 1){
+           id_string = new_ids.join(',');
+       } else if ( new_ids.length === 1) {
+           id_string = new_ids[0];
+       }
+
        if($("#content").css("display") !== "none"){
            editor_content = content.val();
-           editor_content = editor_content.replace(ids, id_string);
-           content.val(editor_content);
+           if(empty_space){
+                editor_content = editor_content.replace(ids, 'category="' + id_string + '"');
+                content.val(editor_content);
+           } else {
+               editor_content = editor_content.replace(ids, id_string);
+               content.val(editor_content);
+           }
        } else if(tinyMCE.activeEditor !== null){
-           editor_content = tinyMCE.get('content').getContent({format: 'raw'});
-           editor_content = editor_content.replace(ids, id_string);
-           tinyMCE.activeEditor.setContent(editor_content);
+           if(empty_space){
+                editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+                editor_content = editor_content.replace(ids, 'category="' + id_string + '"');
+                tinyMCE.activeEditor.setContent(editor_content);
+           } else {
+                editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+                editor_content = editor_content.replace(ids, id_string);
+                tinyMCE.activeEditor.setContent(editor_content);
+           }
        }
 
        // Reset picklist
        $('#category-scDropdown').val('Select Category');
     });
     
+    
+    
+    
+    
+    
+    /////////////////////////////////////////////////////////////////////////////////////////////////
+    // INSERT SHORTCODE FUNCTION 
+    /////////////////////////////////////////////////////////////////////////////////////////////////
     // generate the shortcode into a string and insert into the content upon clicking
     $("#generate").on("click", function () {
         // enforce the selection of a shortcode
         if(shortcodeDropdown){
             // set up properties for shortcode lists
             if(shortcodeDropdown === "glm-members-list"){
-            var listValues = $('input[name="listBox"]:checkbox:checked').map(function() {
-                 boxTarget = $(this).attr("class").slice(0, -5);
-                return this.value;
-            }).get();
-
-            var listString = "";
-                listValues.forEach(function(value){
-                    listString += value + ",";
-                });
+                var listValues = $('input[name="listBox"]:checkbox:checked').map(function() {
+                     boxTarget = $(this).attr("class").slice(0, -5);
+                    return this.value;
+                }).get();
+                
                 
+                var listString = "";
+                    listValues.forEach(function(value){
+                        listString += value + ",";
+                    });
+
                 if(listValues !== ""){
                     listString = listString.replace(/,\s*$/, "");
                     shortcodeValues[boxTarget] = listString;
@@ -302,7 +304,7 @@ jQuery(document).ready(function ($) {
                 }
             }
             // start the shortcode string that will be added to the tinymce editor
-            shortcodeString = "[" + shortcodeDropdown;
+            shortcodeString = '<div class="previewCodes" id="' + shortcodeDropdown + '"> [' + shortcodeDropdown;
             
             // populate the shortcode object
             for (var key in shortcodeValues) {
@@ -319,7 +321,7 @@ jQuery(document).ready(function ($) {
                 ids = category_id.join(',');
                 shortcodeString = shortcodeString.replace(ids, id_string);
             }
-            shortcodeString += ']';
+            shortcodeString += '] </div>';
 
             // insert shortcode at current cursor position
              if($("#content").css("display") !== "none"){
@@ -333,7 +335,6 @@ jQuery(document).ready(function ($) {
                 function insert_tag(text){
                     if(tinyMCE && tinyMCE.activeEditor)
                     {
-                        console.log(tinyMCE.activeEditor.id);
                         tinyMCE.activeEditor.selection.setContent(text);
                     }
                         return false;
@@ -345,16 +346,25 @@ jQuery(document).ready(function ($) {
         }
     });
 
+    
+    
+    
+    
+    
+    
+    /////////////////////////////////////////////////////////////////
+    // DELETE CATEGORY
+    /////////////////////////////////////////////////////////////////
     // Action to de-select a category and dynamically adjust the shortcode categories in the editor
     $('.catDelete').live('click', function() {
-       
+
        editor_shortcodes = get_tinymce_content();
 
        if(editor_shortcodes.match(/category="(.*?)"/) !== null){
             category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
             category_id = category_id.split(',');
             ids = category_id.join(',');
-       }   
+       }
 
        $(this).parent().remove();
        
@@ -365,20 +375,38 @@ jQuery(document).ready(function ($) {
                new_ids.push($(this).data("id"));
            }
        });
-       
+
        id_string = new_ids.join(',');
-        
+        if(id_string === ""){
+            id_string = "";
+//            ids = 'category=""';
+        }
+
        if($("#content").css("display") !== "none"){
            editor_content = content.val();
+           if(ids === ""){
+               console.debug("test1");
+           }
            editor_content = editor_content.replace(ids, id_string);
            content.val(editor_content);
        } else if(tinyMCE.activeEditor !== null){
            editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+           if(ids === ""){
+               console.debug("test");
+           }
            editor_content = editor_content.replace(ids, id_string);
            tinyMCE.activeEditor.setContent(editor_content);
        }
+
+        console.debug(id_string);
     });
     
+    
+    
+    
+    
+    ///////////////////////////////////////////////////////////////////////////
+    // MAINENANCE
     // reset dropdowns and checkboxes to default values on page reload
     var scd = document.getElementById('shortcodeDropdown');
     var catscd = document.getElementById('category-scDropdown');
@@ -405,7 +433,8 @@ jQuery(document).ready(function ($) {
     if(view){
         window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
     }
-   window.onload = uncheckAll();
+    window.onload = uncheckAll();
      
     
-}); 
\ No newline at end of file
+}); 
+