From 425f3c33b75d7136ed9f7b67461a741f0e07330a Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 15 Jun 2016 11:43:59 -0400 Subject: [PATCH] added classes and moved tinyMCE function out of the if else --- classes/glmPluginSupport.php | 5 ++-- js/shortcodeBuilder.js | 57 ++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 6dc8c57a..deae9f96 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -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 "
".print_r($value, true)."
"; if(!is_array($shortCode)){ $shortCodes[] = $shortCode; } } } - //dropdown for shortcode names echo '
'; echo '
'; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index b3879f9c..e5fa48cd 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -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 = '
[' + shortcodeDropdown; + shortcodeString = '
[' + 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(); - - }); -- 2.17.1