From 4595d8b6d8f267b459aed2426692a6a535dd4283 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 31 Jan 2019 21:03:43 -0500 Subject: [PATCH] working on new shortcode builder compatible with both wp < 5 and wp5+ --- css/admin.css | 5 +- js/shortcodeBuilder.js | 974 +------------------------------ views/admin/pages/shortcode.html | 29 +- 3 files changed, 26 insertions(+), 982 deletions(-) diff --git a/css/admin.css b/css/admin.css index 70c2c836..920afcf4 100755 --- a/css/admin.css +++ b/css/admin.css @@ -417,7 +417,10 @@ td.glm-nowrap { color: #000; cursor: pointer; } - +#shortcode-preview{ + border: 1px solid lightgrey; + height: 30px; +} /* Map Edit */ .glm-map-edit { width:90%; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index fbd32b00..26990dc4 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -5,975 +5,15 @@ * need to create a function for setting the editor content because it is duplicated a few times */ -jQuery(document).ready(function ($) { - - 'use strict'; - - var shortcodeDropdown, shortcodeCategory, blankStart, memberView, amenityGroups, listBox, detailBox, target, boxTarget, shortcodeString, - editor_shortcodes, category_id, groups_id, shortcodeValues = {}, editor_content, debug = false; - debug = true; - - - $("#showDetail").hide(); - $("#categoryBox").hide(); - $("#showCategory").hide(); - $("#detailBtn").hide(); - $("[id$=-scDropdown]").hide(); - $("#packageListAttr").hide(); - $('#activeCategories').hide(); - $('#activeGroups').hide(); - $('#activeRegions').hide(); - $('#glmRemoveShortCode').hide(); - -/* - * Change Main Shortcode - */ - // fire events and reset settings when switching between shortcodes - $("[id$=shortcodeDropdown]").on("change", function () { - - // reset the dropdowns and checkbox if when switching shortcodes - document.getElementById('category-scDropdown').options[0].selected = 'selected'; - if($('#blank-start-scDropdown').length) - document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; - if($('#id-scDropdown').length) - document.getElementById('id-scDropdown').options[0].selected = 'selected'; - - // delete the object properties to reset the object - shortcodeString = ""; - - for (var prop in shortcodeValues){ - delete shortcodeValues[prop]; - } - - // get the shortcode option name and hide / show necessary elements - shortcodeDropdown = $(".shortcodeDropdown option:selected").val(); - - // many of these are not necessary as much of the shortcode has been stripped - if(shortcodeDropdown === "glm-members-list"){ - $("#showCategory").show(); - $("#detailBtn").hide(); - $("#blank-start-scDropdown").show(); - $("#id-scDropdown").hide(); - $("#view-scDropdown").show(); - $("#map-opened-scDropdown").show(); - $("[id^='packageList']").hide(); - $("#category-scDropdown").show(); - $(".scCategories").show(); - $("#amenitygroup-scDropdown").show(); - $("#region-search-scDropdown").show(); - $('#activeCategories').show(); - $('#activeGroups').show(); - $('#activeRegions').show(); - } - if(shortcodeDropdown === "glm-members-packaging-list"){ - $("#blank-start-scDropdown").hide(); - $("#showCategory").hide(); - $("#category-scDropdown").hide(); - $("#detailBtn").hide(); - $("#id-scDropdown").hide(); - $("#packageListAttr").children().show(); - $("[id^='packageList']").show(); - $("#view-scDropdown").hide(); - $(".scCategories").hide(); - $("#amenitygroup-scDropdown").hide(); - $('#activeCategories').hide(); - $('#activeGroups').hide(); - } - }); - - // shortcode attribute name from dropdowns containing '-scDropdown' in their ID - // Then append the values to the shortcode object - $("[id$=-scDropdown]").on("change", function () { - target = $(this).attr("id").slice(0, -11); - var targetVal = $("#" + target + "-scDropdown option:selected").val(); - if ( target === 'amenitygroup' ) { - shortcodeValues['amenity-groups'] = targetVal; - } else { - shortcodeValues[target] = targetVal; - } - }); - // get shortcodes between square brackets - var regExp = /\[([^)]+)\]/; - - // function used to get everything out of the visual and text editors - function get_tinymce_content(){ - if (jQuery("#wp-content-wrap").hasClass("tmce-active")){ - - tinyMCE.triggerSave(); - - if(regExp.exec($('#content').val())){ - editor_content = regExp.exec($('#content').val()); - return editor_content[0]; - } else { - return; - } - } else { - // get the shortcode from the editor with [ ] as the delimiter - editor_content = regExp.exec($("#content").val()); - if(regExp.exec($("#content").val())){ - return editor_content[0]; - } - } - } - - // returned shortcode string after the editor content is filtered by the regex - editor_shortcodes = get_tinymce_content(); - - if(editor_shortcodes){ - // get the number of instances of shortcodes with the category option - var number_of_categories = (editor_shortcodes.match(/(\[glm-members-list .*?])/) || []).length; - if ( number_of_categories ) { - $('#glmRemoveShortCode').show(); - $('#generate').hide(); - } - } else { - $('#glmRemoveShortCode').hide(); - $('#generate').show(); - } - var regions_id, regions_id_string, regions_new_ids = new Array(), regions_empty_space, regions_missing; - if ( editor_shortcodes) { - if ( editor_shortcodes.match( /glm-members-list .*amenity-groups="(.*?)"/ ) !== null ) { - amenityGroups = editor_shortcodes.match( /glm-members-list .*amenity-groups="(.*?)"/ )[1]; - groups_id = amenityGroups.split(','); - } else if ( editor_shortcodes.match( /glm-members-list amenity-groups=""/ ) !== null ) { - groups_id = editor_shortcodes.match( /glm-members-list amenity-groups=""/ )[1]; - } - if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) { - blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1]; - } - if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) { - memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1]; - } - if(editor_shortcodes.match(/glm-members-list .*category="(.*?)"/) !== null){ - category_id = editor_shortcodes.match(/glm-members-list .*category="(.*?)"/)[1]; - category_id = category_id.split(','); - } else if (editor_shortcodes.match(/glm-members-list .*category=""/) !== null){ - category_id = editor_shortcodes.match(/glm-members-list .*category="(.*?)"/)[1]; - } - if(editor_shortcodes.match(/glm-members-list .*region-search="(.*?)"/) !== null){ - regions_id = editor_shortcodes.match(/glm-members-list .*region-search="(.*?)"/)[1]; - regions_id= regions_id.split(','); - } else if (editor_shortcodes.match(/glm-members-list .*region-search=""/) !== null){ - regions_id = editor_shortcodes.match(/glm-members-list .*region-search=""/)[1]; - } - if ( number_of_categories ) { - $('#shortcodeDropdown').val( 'glm-members-list' ); - } - } - - // find the category names from the category select - var category_names_ids = new Array(); - var categoryNames = $("#category-scDropdown>option").map(function() { - var index = $.inArray($(this).val(), category_id); - if(index !== -1 && index !== ""){ - category_names_ids.push([$(this).text(), $(this).val()]); - return $(this).text(); - } - }).get(); - - // add the category names to #activeCategories - $.each( category_names_ids, function (index, obj) { - $('#activeCategories').append('
' - + obj[0] + " (ID: " + obj[1] + ')' + 'X' - + '
'); - }); - - // find the group names from the group select - var group_names_ids = new Array(); - var groupNames = $("#amenitygroup-scDropdown>option").map(function() { - var index = $.inArray($(this).val(), groups_id); - if(index !== -1 && index !== ""){ - group_names_ids.push([$(this).text(), $(this).val()]); - return $(this).text(); - } - }).get(); - - // add the group names to #activeGroups - $.each( group_names_ids, function (index, obj) { - $('#activeGroups').append('
' - + obj[0] + " (ID: " + obj[1] + ')' + 'X' - + '
'); - }); - // Check if the group has already been added - var region_names_ids = new Array(); - var regionNames = $("#region-search-scDropdown>option").map(function() { - var index = $.inArray($(this).val(), regions_id); - if(index !== -1 && index !== ""){ - region_names_ids.push([$(this).text(), $(this).val()]); - return $(this).text(); - } - }).get(); - - // add the group names to #activeGroups - $.each( region_names_ids, function (index, obj) { - $('#activeRegions').append('
' - + obj[0] + " (ID: " + obj[1] + ')' + 'X' - + '
'); - }); - ///////////////////////////////////////////////////////////////////////////////////////////// - /* - * Category Selection these functions fire whenever the 'select category' dropdown is changed - */ - ////////////////////////////////////////////////////////////////////////////////////////////// - var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), empty_space, category_missing; - - $('#category-scDropdown').change( function() { - editor_shortcodes = get_tinymce_content(); - - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list category="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* category="(.*?)"/ ) ){ - category_missing = false; - ids = editor_shortcodes.match( /category="(.*?)"/ )[1]; - - if ( ids !== "" ) { - ids = ids.split(','); - - ids = ids.join(','); - empty_space = false; - } else { - - ids = 'category=""'; - - // this determines if the groups option is blank "" to determine if the jquery replace method works properly - empty_space = true; - } - } else { - category_missing = true; - empty_space = false; - } - } - - // Get the ID, name, and parent of the category - var catValue = $('#category-scDropdown').val(); - var catName = $('#category-scDropdown').find(':selected').text(); - var catParent = $('#category-scDropdown').find(':selected').attr('data-parent'); - - // Check if the category has already been added - var found = false; - $(".glm-members-catgegory").each( function() { - var id = $(this).attr('data-id'); - if (id === catValue) { - found = true; - } - }); - - // If not found, Add the category - if (!found) { - $('#activeCategories').append('
' - + catName.trim() + ' (ID: ' + catValue + ')' + 'X' - + '
'); - } - - // reset the id string after each set of iterations - id_string = ''; - - $.each($(".glm-dynSelect-item"), function () { - if($.inArray($(this).data("id"), new_ids) === -1){ - new_ids.push($(this).data("id")); - } - }); - - // if more than one category id in the array, join together with ',' otherwise set the id string to a single value - 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(); - if ( empty_space ) { - editor_content = editor_content.replace( ids, 'category="' + id_string + '"' ); - content.val( editor_content ); - } else if ( category_missing ) { - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - editor_content = editor_content.replace( shortcodeReg, '$1 category="' + id_string + '"$2' ); - content.val( editor_content ); - } else { - editor_content = editor_content.replace( 'category="' + ids, 'category="' + id_string ); - content.val( editor_content ); - } - } else if ( tinyMCE.activeEditor !== null ) { - 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 if ( category_missing ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - var catMatch = editor_content.match( shortcodeReg ); - editor_content = editor_content.replace( shortcodeReg, '$1 category="' + id_string + '"$2' ); - tinyMCE.activeEditor.setContent(editor_content); - } else { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('category="' + ids, 'category="' + id_string); - tinyMCE.activeEditor.setContent(editor_content); - } - } - - // Reset picklist - $('#category-scDropdown').val('Select Category'); - }); - - var group_ids, group_id_string, group_new_ids = new Array(), group_empty_space, group_missing; - - // Amenity Groups - // This fires when the groups select is changed - $('#amenitygroup-scDropdown').change(function(){ - editor_shortcodes = get_tinymce_content(); - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) ){ - group_missing = false; - groups_id = editor_shortcodes.match( /amenity-groups="(.*?)"/ )[1]; - - if ( groups_id !== "" ) { - groups_id = groups_id.split(','); - - group_ids = groups_id.join(','); - group_empty_space = false; - } else { - - group_ids = 'amenity-groups=""'; - - // this determines if the groups option is blank "" to determine if the jquery replace method works properly - group_empty_space = true; - } - } else { - group_missing = true; - group_empty_space = false; - } - } - - // Get the ID, name - var groupValue = $('#amenitygroup-scDropdown').val(); - var groupName = $('#amenitygroup-scDropdown').find(':selected').text(); - - // Check if the group has already been added - var found = false; - $(".glm-members-groups").each( function() { - var id = $(this).attr('data-id'); - if (id === groupValue) { - found = true; - } - }); - - // If not found, Add the group - if (!found) { - $('#activeGroups').append('
' - + groupName.trim() + ' (ID: ' + groupValue + ')' + 'X' - + '
'); - } - - // reset the id string after each set of iterations - group_id_string = ''; - - $.each($(".glm-group-dynSelect-item"), function () { - if($.inArray($(this).data("id"), group_new_ids) === -1){ - group_new_ids.push($(this).data("id")); - } - }); - - // if more than one category id in the array, join together with ',' otherwise set the id string to a single value - if ( group_new_ids.length > 1 ){ - group_id_string = group_new_ids.join(','); - } else if ( group_new_ids.length === 1 ) { - group_id_string = group_new_ids[0]; - } - - // replace the current content in either the visual or text editor and replace it with a filtered version of the groups - if ( $("#content").css("display") !== "none" ) { - editor_content = content.val(); - if ( group_empty_space ) { - editor_content = editor_content.replace( group_ids, 'amenity-groups="' + group_id_string + '"' ); - content.val( editor_content ); - } else if ( group_missing ) { - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - editor_content = editor_content.replace( shortcodeReg, '$1 amenity-groups="' + group_id_string + '"$2' ); - content.val( editor_content ); - } else { - editor_content = editor_content.replace( 'amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string ); - content.val( editor_content ); - } - } else if ( tinyMCE.activeEditor !== null ) { - if ( group_empty_space ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace(group_ids, 'amenity-groups="' + group_id_string + '"' ); - tinyMCE.activeEditor.setContent(editor_content); - } else if ( group_missing ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - var groupMatch = editor_content.match( shortcodeReg ); - editor_content = editor_content.replace( shortcodeReg, '$1 amenity-groups="' + group_id_string + '"$2' ); - tinyMCE.activeEditor.setContent(editor_content); - } else { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string); - tinyMCE.activeEditor.setContent(editor_content); - } - } - - // Reset picklist - $('#amenitygroup-scDropdown').val('Select Groups'); - }); - +jQuery(function ($) { + var shortcode_start = "[glm-members-list "; - $('#region-search-scDropdown').change(function(){ - editor_shortcodes = get_tinymce_content(); - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list region-search="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){ - regions_missing = false; - regions_id = editor_shortcodes.match( /region-search="(.*?)"/ )[1]; - - if ( regions_id !== "" ) { - regions_id = regions_id.split(','); - - regions_id = regions_id.join(','); - regions_empty_space = false; - } else { - - regions_id = 'region-search=""'; - - // this determines if the groups option is blank "" to determine if the jquery replace method works properly - regions_empty_space = true; - } - } else { - regions_missing = true; - regions_empty_space = false; - } - } - - // Get the ID, name - var regionsValue = $('#region-search-scDropdown').val(); - var regionsName = $('#region-search-scDropdown').find(':selected').text(); - // Check if the group has already been added - var found = false; - $(".glm-members-regions").each( function() { - var id = $(this).attr('data-id'); - if (id === regionsValue) { - found = true; - } - }); - - // If not found, Add the group - if (!found) { - $('#activeRegions').append('
' - + regionsName.trim() + ' (ID: ' + regionsValue + ')' + 'X' - + '
'); - } - - // reset the id string after each set of iterations - regions_id_string = ''; - - $.each($(".glm-regions-dynSelect-item"), function () { - if($.inArray($(this).data("id"), regions_new_ids) === -1){ - regions_new_ids.push($(this).data("id")); - } - }); - - // if more than one region id in the array, join together with ',' otherwise set the id string to a single value - if ( regions_new_ids.length > 1 ){ - regions_id_string = regions_new_ids.join(','); - } else if ( regions_new_ids.length === 1 ) { - regions_id_string = regions_new_ids[0]; - } - - // replace the current content in either the visual or text editor and replace it with a filtered version of the regions - if ( $("#content").css("display") !== "none" ) { - editor_content = content.val(); - if ( regions_empty_space ) { - editor_content = editor_content.replace( regions_id, 'region-search="' + regions_id_string + '"' ); - content.val( editor_content ); - } else if ( regions_missing ) { - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - editor_content = editor_content.replace( shortcodeReg, '$1 region-search="' + regions_id_string + '"$2' ); - content.val( editor_content ); - } else { - editor_content = editor_content.replace( 'region-search="' + regions_id, 'region-search="' + regions_id_string ); - content.val( editor_content ); - } - } else if ( tinyMCE.activeEditor !== null ) { - if ( regions_empty_space ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace(regions_id, 'region-search="' + regions_id_string + '"' ); - tinyMCE.activeEditor.setContent(editor_content); - } else if ( regions_missing ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - var regionsMatch = editor_content.match( shortcodeReg ); - editor_content = editor_content.replace( shortcodeReg, '$1 region-search="' + regions_id_string + '"$2' ); - tinyMCE.activeEditor.setContent(editor_content); - } else { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string); - tinyMCE.activeEditor.setContent(editor_content); - } - } - - // Reset picklist - $('#regions-scDropdown').val('Select Regions'); - }); - - // Blank Start change event - // These fire when the blank-start select is changed - var blank_start_id, blank_start_missing, blank_start_empty_space; - $('#blank-start-scDropdown').change(function(){ - editor_shortcodes = get_tinymce_content(); - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list blank-start="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ){ - blank_start_missing = false; - blank_start_id = editor_shortcodes.match( /blank-start="(.*?)"/ )[1]; - - if ( blank_start_id !== "" ) { - blank_start_id = blank_start_id.split(','); - - blank_start_id = blank_start_id.join(','); - blank_start_empty_space = false; - } else { - - blank_start_id = 'blank-start=""'; - - // this determines if the groups option is blank "" to determine if the jquery replace method works properly - blank_start_empty_space = true; - } - } else { - blank_start_missing = true; - blank_start_empty_space = false; - } - } - if ( $("#content").css("display") !== "none" ) { - editor_content = content.val(); - if ( blank_start_empty_space ) { - - editor_content = editor_content.replace( blank_start_id, 'blank-start="' + $(this).val() + '"' ); - content.val( editor_content ); - } else if ( blank_start_missing ) { - - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - var blankMatch = editor_content.match( shortcodeReg ); - - editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' ); - content.val( editor_content ); - - } else { - - editor_content = editor_content.replace( 'blank-start="' + blank_start_id, 'blank-start="' + $(this).val() ); - content.val( editor_content ); - } - } else if ( tinyMCE.activeEditor !== null ) { - if ( blank_start_empty_space ) { - - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace(blank_start_id, 'blank-start="' + $(this).val() + '"' ); - tinyMCE.activeEditor.setContent(editor_content); - } else if ( blank_start_missing ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - - var blankMatch = editor_content.match( shortcodeReg ); - editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' ); - tinyMCE.activeEditor.setContent(editor_content); - - } else { - - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('blank-start="' + blank_start_id, 'blank-start="' + $(this).val() ); - tinyMCE.activeEditor.setContent(editor_content); - } - } - }); - - // View dropdown - // These events fire when the View select is changed - var view_id, view_missing, view_empty_space; - $('#view-scDropdown').change(function(){ - editor_shortcodes = get_tinymce_content(); - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list view="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ){ - view_missing = false; - view_id = editor_shortcodes.match( /view="(.*?)"/ )[1]; - - if ( view_id !== "" ) { - view_id = view_id.split(','); - - view_id = view_id.join(','); - view_empty_space = false; - } else { - - view_id = 'view=""'; - - // this determines if the groups option is blank "" to determine if the jquery replace method works properly - view_empty_space = true; - } - } else { - view_missing = true; - view_empty_space = false; - } - } - if ( $("#content").css("display") !== "none" ) { - editor_content = content.val(); - if ( view_empty_space ) { - editor_content = editor_content.replace( view_id, 'view="' + $(this).val() + '"' ); - content.val( editor_content ); - } else if ( view_missing ) { - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' ); - content.val( editor_content ); - } else { - editor_content = editor_content.replace( 'view="' + view_id, 'view="' + $(this).val() ); - content.val( editor_content ); - } - } else if ( tinyMCE.activeEditor !== null ) { - if ( view_empty_space ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace(view_id, 'view="' + $(this).val() + '"' ); - tinyMCE.activeEditor.setContent(editor_content); - } else if ( view_missing ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; - var viewMatch = editor_content.match( shortcodeReg ); - - editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' ); - tinyMCE.activeEditor.setContent( editor_content ); - } else { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('view="' + view_id, 'view="' + $(this).val() ); - tinyMCE.activeEditor.setContent(editor_content); - } - } - }); - - function insert_tag( text ) { - if ( tinyMCE && tinyMCE.activeEditor ) { - tinyMCE.activeEditor.selection.setContent(text); - } - return false; - } - - // generate the shortcode into a string and insert into the content upon clicking - var replace_me, replace_with; - $("[id$=generate]").on("click", function () { - // enforce the selection of a shortcode - if ( shortcodeDropdown ) { - // set up properties for shortcode lists - // start the shortcode string that will be added to the tinymce editor - shortcodeString = '[' + shortcodeDropdown; - - // populate the shortcode object with all of the shortcode attributes and their values - for (var key in shortcodeValues) { - if (shortcodeValues.hasOwnProperty(key)) { - if(key !== "undefined"){ - shortcodeString += " " + key + '="' + shortcodeValues[key] +'"'; - } - } - } - - // add the list of category ids instead of the single value originally inserted - if ( shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* category="(.*?)"/ ) ) { - if(shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null ){ - category_id = shortcodeString.match( /glm-members-list category="(.*?)"/ )[1]; - } else if( shortcodeString.match( /glm-members-list .* category="(.*?)"/ ) !== null ){ - category_id = shortcodeString.match( /glm-members-list .* category="(.*?)"/ )[1]; - } - category_id = category_id.split(','); - ids = category_id.join(','); - replace_me = 'category="'+ids+'"'; - replace_with = 'category="'+id_string+'"'; - shortcodeString = shortcodeString.replace(replace_me, replace_with); - } - if( shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ ) ){ - if( shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null ){ - group_ids = shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ )[1]; - } else if( shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null){ - group_ids = shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ )[1]; - } - group_ids = group_ids.split(','); - group_ids = group_ids.join(','); - replace_me = 'amenity-groups="'+group_ids+'"'; - replace_with = 'amenity-groups="'+group_id_string+'"'; - shortcodeString = shortcodeString.replace(replace_me, replace_with); - } - if( shortcodeString.match( /glm-members-list region-search="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){ - if( shortcodeString.match( /glm-members-list region-search="(.*?)"/ ) !== null ){ - regions_id = shortcodeString.match( /glm-members-list region-search="(.*?)"/ )[1]; - }else if( shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){ - regions_id = shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ )[1]; - } - regions_id = regions_id.split(','); - regions_id = regions_id.join(','); - replace_me = 'region-search="'+regions_id+'"'; - replace_with = 'region-search="'+regions_id_string+'"'; - shortcodeString = shortcodeString.replace(replace_me, replace_with); - } - - shortcodeString += ']'; - - // insert shortcode at current cursor position - if ( $("#content").css("display") !== "none" ) { - var cursorPos = $('#content').prop( 'selectionStart' ); - var v = $('#content').val(); - var textBefore = v.substring(0, cursorPos ); - var textAfter = v.substring( cursorPos, v.length ); - $('#content').val( textBefore + shortcodeString + textAfter ); - - } else if( $("#content").css("display") === "none" ) { - - insert_tag( shortcodeString ); - } - } else { - alert("Please Select a Shortcode"); - } - $('#glmRemoveShortCode').show(); - $('#generate').hide(); - }); - - /** - * Deletes the shortcode. - */ - $('#glmRemoveShortCode').on('click', function(){ + // build substrings that will be constructed with the main shortcode text + $("#shortcode-categories").on("change", function(){ + var categoryID = $(this).val(); + var categoryName = $(this).find("option:selected").text(); - editor_shortcodes = get_tinymce_content(); - - var member_list_shortcodes = (editor_shortcodes.match(/glm-members-list/g) || []).length; - var member_package_shortcodes = (editor_shortcodes.match(/glm-members-packaging-list/g) || []).length; - if ( member_list_shortcodes ) { - // find the short code and remove it! - var shortcodeReg = /(\[glm-members-list .*?])/; - if ( $("#content").css("display") !== "none" ) { - editor_content = content.val(); - editor_content = editor_content.replace( shortcodeReg, '' ); - content.val( editor_content ); - } else if ( tinyMCE.activeEditor !== null ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace( shortcodeReg, '' ); - tinyMCE.activeEditor.setContent(editor_content); - } - - var shortcodeReg = /(\[glm-members-list .*?])/; - - $('.glm-dynSelect-item').remove(); - $('.glm-group-dynSelect-item').remove(); - $('.glm-regions-dynSelect-item').remove(); - $("#showDetail").hide(); - $("#categoryBox").hide(); - $("#showCategory").hide(); - $("#detailBtn").hide(); - $("[id$=-scDropdown]").hide(); - $("#packageListAttr").hide(); - $('#shortcodeDropdown').val('glm-members-list'); - window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; - reset_options(); - $('#shortcodeDropdown').change(); - $('#shortcodeDropdown').show(); - $('#activeCategories').hide(); - $('#activeGroups').hide(); - $('#activeRegions').hide(); - ids, groups_id, regions_id, id_string, group_id_string, regions_id_string = ''; - group_new_ids.length = 0; - new_ids.length = 0; - regions_new_ids.length = 0; - } else if ( member_package_shortcodes ) { - // find the short code and remove it! - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-packaging-list .*?])/; - editor_content = editor_content.replace( shortcodeReg, '' ); - tinyMCE.activeEditor.setContent(editor_content); - $("[id$=-scDropdown]").hide(); - } - $('#glmRemoveShortCode').hide(); - $('#generate').show(); - }); - - // 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 && editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null) || ( editor_shortcodes && editor_shortcodes.match(/glm-members-list .* category="(.*?)"/) !== null)){ - if( editor_shortcodes.match(/glm-members-list category="(.*?)"/) ){ - category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; - } else { - category_id = editor_shortcodes.match(/glm-members-list .* category="(.*?)"/)[1]; - } - - category_id = category_id.split(','); - ids = category_id.join(','); - } - - $(this).parent().remove(); - - // reset the array after each set of iterations - new_ids.length = 0; - - $.each($(".glm-dynSelect-item"), function () { - if($.inArray($(this).data("id"), new_ids) === -1){ - new_ids.push($(this).data("id")); - } - }); - - // create a string of id's from the array - id_string = new_ids.join(','); - - // get and replace current editor content - if($("#content").css("display") !== "none"){ - - editor_content = content.val(); - editor_content = editor_content.replace('category="' + ids, 'category="' + id_string ); - content.val(editor_content); - - } else if(tinyMCE.activeEditor !== null){ - - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('category="' + ids, 'category="' + id_string); - tinyMCE.activeEditor.setContent(editor_content); - } + console.log( categoryName ); }); - - $('.regionDelete').live('click', function() { - editor_shortcodes = get_tinymce_content(); - if( (editor_shortcodes && editor_shortcodes.match(/glm-members-list region-search="(.*?)"/) !== null) || (editor_shortcodes && editor_shortcodes.match(/glm-members-list .* region-search="(.*?)"/) !== null) ){ - if(editor_shortcodes.match(/glm-members-list region-search="(.*?)"/) ){ - regions_id = editor_shortcodes.match(/glm-members-list region-search="(.*?)"/)[1]; - } else { - regions_id = editor_shortcodes.match(/glm-members-list .* region-search="(.*?)"/)[1]; - } - regions_id = regions_id.split(','); - regions_id = regions_id.join(','); - } - - $(this).parent().remove(); - - // reset the array after each set of iterations - regions_new_ids.length = 0; - - $.each($(".glm-regions-dynSelect-item"), function () { - if($.inArray($(this).data("id"), regions_new_ids) === -1){ - regions_new_ids.push($(this).data("id")); - } - }); - - // create a string of id's from the array - regions_id_string = regions_new_ids.join(','); - - // get and replace current editor content - if($("#content").css("display") !== "none"){ - - editor_content = content.val(); - editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string ); - content.val(editor_content); - - } else if(tinyMCE.activeEditor !== null){ - - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string); - tinyMCE.activeEditor.setContent(editor_content); - } - }); - - // group delete - $('.groupDelete').live('click', function(){ - editor_shortcodes = get_tinymce_content(); - - if(editor_shortcodes && editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/) !== null){ - groups_id = editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/)[1]; - groups_id = groups_id.split(','); - group_ids = groups_id.join(','); - } else if(editor_shortcodes && editor_shortcodes.match(/glm-members-list amenity-groups="(.*?)"/) !== null){ - groups_id = editor_shortcodes.match(/glm-members-list amenity-groups="(.*?)"/)[1]; - groups_id = groups_id.split(','); - group_ids = groups_id.join(','); - } - - $(this).parent().remove(); - - // reset the array after each set of iterations - group_new_ids.length = 0; - - $.each($(".glm-group-dynSelect-item"), function () { - if($.inArray($(this).data("id"), group_new_ids) === -1){ - group_new_ids.push($(this).data("id")); - } - }); - - // create a string of id's from the array - group_id_string = group_new_ids.join(','); - - // get and replace current editor content - if($("#content").css("display") !== "none"){ - editor_content = content.val(); - editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string ); - content.val(editor_content); - } else if(tinyMCE.activeEditor !== null){ - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string); - tinyMCE.activeEditor.setContent(editor_content); - } - - }); - - // reset dropdowns and checkboxes to default values on page reload - var scd = document.getElementById('shortcodeDropdown'); - var catscd = document.getElementById('category-scDropdown'); - var blank = document.getElementById('blank-start-scDropdown'); - var list = document.getElementById('type-scList'); - var members = document.getElementById('member-scDropdown'); - var view = document.getElementById('view-scDropdown'); - var groups = document.getElementById('amenitygroup-scDropdown'); - var regions = document.getElementById('region-search-scDropdown'); - - if ( editor_shortcodes && number_of_categories) { - if ( number_of_categories ) { - $('#shortcodeDropdown').val('glm-members-list'); - $('#shortcodeDropdown').change(); - } else { - $('#shortcodeDropdown').val('glm-members-packaging-list'); - $('#shortcodeDropdown').change(); - } - $('#shortcodeDropdown').hide(); - $('#generate').hide(); - } else { - $('#shortcodeDropdown').val('glm-members-list'); - $('#shortcodeDropdown').change(); - $('#shortcodeDropdown').hide(); - } - function reset_options(){ - if ( scd && !editor_shortcodes && !number_of_categories) { - window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; - } - if ( catscd ) { - window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected'; - } - if ( blank ) { - if ( blankStart ) { - $('#blank-start-scDropdown').val( blankStart ); - } else { - window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; - } - } - if ( list ) { - window.onload = document.getElementById('type-scList').options[0].selected = 'selected'; - } - if ( members ) { - window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected'; - } - if ( view ) { - if ( memberView ) { - $('#view-scDropdown').val( memberView ); - } else { - window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected'; - } - } - if ( groups ) { - window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected'; - } - if ( regions ) { - window.onload = document.getElementById('region-search-scDropdown').options[0].selected = 'selected'; - } - } - reset_options(); }); diff --git a/views/admin/pages/shortcode.html b/views/admin/pages/shortcode.html index 32ca3570..cd14151a 100644 --- a/views/admin/pages/shortcode.html +++ b/views/admin/pages/shortcode.html @@ -1,39 +1,40 @@
+
- + {foreach $categories as $key => $value} {/foreach} - + - + - + {foreach $amenGroups as $group} {/foreach} - + {foreach $regions as $region} {/foreach} - - + +
Categories
Amenity Groups
-- 2.17.1