added classes and moved tinyMCE function out of the if else
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 15 Jun 2016 15:43:59 +0000 (11:43 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 15 Jun 2016 15:43:59 +0000 (11:43 -0400)
classes/glmPluginSupport.php
js/shortcodeBuilder.js

index 6dc8c57..deae9f9 100644 (file)
@@ -402,7 +402,7 @@ return; // Off for now ** Need to make this switchable in management
         $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes'];
         $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes'];
 
-        $glmcat = new GlmDataCategories($this->wpdb, $this->wpconfig);
+        $glmcat = new GlmDataCategories($this->wpdb, $this->config);
         $list = $glmcat->getListSortedParentChild();
         // get the each addOn slugs to pass to the config array later
         $addOns = $this->config['addOns'];
@@ -416,15 +416,16 @@ return; // Off for now ** Need to make this switchable in management
         foreach($addOnSlugs as $addOn){
             $shortCodeList[] = $this->config['addOns'][$addOn]['shortcodes'];
         }
+
         // loop through the shortcodes to pull out the shortcode names
         foreach($shortCodeList as $addonInfo) {
             foreach($addonInfo as $shortCode=>$value){
+//            echo "<pre>".print_r($value, true)."</pre>";
                 if(!is_array($shortCode)){
                     $shortCodes[] = $shortCode;
                 }
             }
         }
-
         //dropdown for shortcode names
         echo '<div id="categoryContainer" style="overflow: auto">';
         echo '<div id="shortcodeBuilder">';
index b3879f9..e5fa48c 100644 (file)
@@ -129,7 +129,10 @@ jQuery(document).ready(function ($) {
     }
 
     editor_shortcodes = get_tinymce_content();
-    
+    if(editor_shortcodes){
+        var number_of_categories = (editor_shortcodes.match(/category="(.*?)"/g) || []).length;
+    }
+    console.debug(number_of_categories);
     if(editor_shortcodes){
         if(editor_shortcodes.match(/category="(.*?)"/) !== null){
             category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
@@ -173,22 +176,22 @@ jQuery(document).ready(function ($) {
     * Category Selection
     */
    //////////////////////////////////////////////////////////////////////////////////////////////
-     var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content, empty_space;
+     var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content, empty_space, count;
    
     $('#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];
-                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;
                 }
@@ -260,13 +263,26 @@ jQuery(document).ready(function ($) {
     
     
     
-    
+    function insert_tag(text){
+        if(tinyMCE && tinyMCE.activeEditor)
+        {
+            tinyMCE.activeEditor.selection.setContent(text);
+        }
+            return false;
+    }
     
     /////////////////////////////////////////////////////////////////////////////////////////////////
     // INSERT SHORTCODE FUNCTION 
     /////////////////////////////////////////////////////////////////////////////////////////////////
     // generate the shortcode into a string and insert into the content upon clicking
     $("#generate").on("click", function () {
+        count = 0;
+        if(number_of_categories){
+            count = number_of_categories;
+            count++;
+        } else {
+            count++;
+        }
         // enforce the selection of a shortcode
         if(shortcodeDropdown){
             // set up properties for shortcode lists
@@ -304,7 +320,7 @@ jQuery(document).ready(function ($) {
                 }
             }
             // start the shortcode string that will be added to the tinymce editor
-            shortcodeString = '<div class="previewCodes" id="' + shortcodeDropdown + '"> [' + shortcodeDropdown;
+            shortcodeString = '<div class="previewCodes" id="' + shortcodeDropdown + '_'+ count + '"> [' + shortcodeDropdown;
             
             // populate the shortcode object
             for (var key in shortcodeValues) {
@@ -332,13 +348,7 @@ jQuery(document).ready(function ($) {
                 $('#content').val( textBefore + shortcodeString + textAfter );
                  
             } else if($("#content").css("display") === "none") {
-                function insert_tag(text){
-                    if(tinyMCE && tinyMCE.activeEditor)
-                    {
-                        tinyMCE.activeEditor.selection.setContent(text);
-                    }
-                        return false;
-                }
+    
                 insert_tag(shortcodeString);
             }
             } else {
@@ -377,28 +387,21 @@ jQuery(document).ready(function ($) {
        });
 
        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);
     });
     
     
@@ -434,7 +437,5 @@ jQuery(document).ready(function ($) {
         window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
     }
     window.onload = uncheckAll();
-     
-    
 });