'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();
}
}
+
+
+
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // 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
$(".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();
$("#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 () {
$("#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())){
} 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
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];
}
}
}
+
+
+
+
+
+
+ /////////////////////////////////////////////////////////////////////////////////////////////
/*
* 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;
+ }
}
}
}
});
- // Check if there's a parent
-// parentName = '';
-// if (catParent !== '') {
-// parentName = catParent + ': ';
-// }
// If not found, Add the category
if (!found) {
}
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;
}
}
// 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) {
ids = category_id.join(',');
shortcodeString = shortcodeString.replace(ids, id_string);
}
- shortcodeString += ']';
+ shortcodeString += '] </div>';
// insert shortcode at current cursor position
if($("#content").css("display") !== "none"){
function insert_tag(text){
if(tinyMCE && tinyMCE.activeEditor)
{
- console.log(tinyMCE.activeEditor.id);
tinyMCE.activeEditor.selection.setContent(text);
}
return false;
}
});
+
+
+
+
+
+
+ /////////////////////////////////////////////////////////////////
+ // 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();
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');
if(view){
window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
}
- window.onload = uncheckAll();
+ window.onload = uncheckAll();
-});
\ No newline at end of file
+});
+