// load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet
if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){
- wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true);
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css');
+ wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true);
}
function custom_js_css() {
}
add_meta_box("shortcode_builder",
- "Shortcode Builder",
+ "Associate Shortcode Builder",
array($this,'shortcode_builder_markup'),
"page", 'normal', 'high'
);
}
//dropdown for shortcode names
+ echo '<div id="categoryContainer" style="overflow: auto">';
echo '<div id="shortcodeBuilder">';
echo '<select id="shortcodeDropdown">
<option value=""> Select Shortcode </option>';
if ( false !== strpos($code, 'members-list' ) ){
echo '<option value = "' . $code . '">' . 'Display Member List by Category' . '</option>';
} else if ( false !== strpos($code, 'packaging-list' ) ){
- echo '<option value = "' . $code . '">' . 'Packages' . '</option>';
+ echo '<option value = "' . $code . '">' . 'Display Packages' . '</option>';
}
}
}
echo '</select>';
- echo '<button id="listBtn" class="glm-button" type="button"> Select a Category </button>';
+// echo '<button id="showCategory" class="button" type="button"> Select a Category </button>';
/*
* Member DB Shortcode Attributes
*/
//dropdown for categories
- echo '<select id="category-scDropdown" name="category-scDropdown[]">';
- echo '<option> Select Category </option>';
+ echo '<select id="category-scDropdown" name="category-scDropdown[]" >';
+ echo '<option disabled> Select Category </option>';
foreach($list as $key=>$value){
if( ! empty($value['parent']['name'])){
echo '<option value='. $key .'>' . '   '.$value['name'] . '</option>';
}
echo '</select>';
- echo '<div id="showList" title="Member Categories ">';
+ echo '<div id="categoryBox" title="Member Categories ">';
foreach($list as $key=>$value){
if( ! empty($value['parent']['name'])){
- echo '<label class="checkList"><input class="categoryLists" type="checkbox" name="listBox" value='. $key . '>' . '   '. $value['name'] .'</label>';
+ echo '<label class="checkList" for="'.$value['name'].'"><input class="categoryLists" type="checkbox" name="listBox" value='. $key . '>' . '   '. $value['name'] .'</label>';
} else {
- echo '<label class="checkList"><input class="categoryLists" type="checkbox" name="listBox" value='. $key . '>' . ' '. $value['name'] .'</label>';
+ echo '<label class="checkList" for="'.$value['name'].'"><input class="categoryLists" type="checkbox" name="listBox" value='. $key . '>' . ' '. $value['name'] .'</label>';
}
}
echo '</div>';
// dropdown for blank start
echo '<select id="blank-start-scDropdown">';
- echo '<option> Hide List Until Searched</option>
+ echo '<option disabled> Hide List Until Searched</option>
<option value="False"> False </option>
<option value="True"> True </option>';
echo '</select>';
// dropdown for views
echo '<select id="view-scDropdown">';
- echo '<option> View </option>';
- echo '<option selected="selected" value="bars"> Bars </option>';
- echo '<option value="grid"> Grid </option>';
+ echo '<option disabled> View </option>';
+ echo '<option selected="selected" value="bars"> List View </option>';
+ echo '<option value="grid"> Grid View </option>';
echo '</select>';
// show list options 'scb' = shortcode builder acronym
// echo '<label class="checkDetails"><input class="showDetails" type="checkbox" name="detailBox" value='. $key . '>' . $key .'</label>';
// }
// }
-// echo '</div>';
// packaging addOn mark up
if(file_exists(GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){
// list and detail buttons to open dialog for member db 'show' attr options
-// echo '<button id="detailBtn" class="glm-button" type="button"> Show Detail Options </button>';
+// echo '<button id="detailBtn" class="glm-button" type="button"> Show Detail Options </button>';
- echo '<button id="generate" class="glm-button" type="button"> Insert Shortcode </button>';
+ 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="shortcode_preview_box" style="overflow: auto; clear: both;"></div>';
+ echo '</div>';
}
*
*/
jQuery(document).ready(function ($) {
-//
- var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString;
+
+ 'use strict';
+
+ var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString,
+ editor_shortcodes, category_id;
var shortcodeValues = {};
$("#showDetail").hide();
- $("#showList").hide();
- $("#listBtn").hide();
+ $("#categoryBox").hide();
+ $("#showCategory").hide();
$("#detailBtn").hide();
$("[id$=-scDropdown]").hide();
$("#packageListAttr").hide();
+ $(".scCategories").hide();
+
+ // reset checkboxes after page load
+ function uncheckAll() {
+ var w = document.getElementsByTagName('input');
+ for (var i = 0; i < w.length; i++){
+ if(w[i].type === 'checkbox'){
+ w[i].checked = false;
+ }
+ }
+ }
- // fire core events when switching between shortcodes
+ // fire core events and reset settings when switching between shortcodes
$("#shortcodeDropdown").on("change", function () {
// reset the dropdowns and checkbox if when switching shortcodes
document.getElementById('category-scDropdown').options[0].selected = 'selected';
document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
if($('#id-scDropdown').length)
document.getElementById('id-scDropdown').options[0].selected = 'selected';
- UncheckAll();
+
+ uncheckAll();
// delete the object properties to reset the object
shortcodeString = "";
shortcodeDropdown = $("#shortcodeDropdown option:selected").val();
if(shortcodeDropdown === "glm-members-list"){
- $("#listBtn").show();
+ $("#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();
}
if(shortcodeDropdown === "glm-member-detail") {
$("#detailBtn").show();
- $("#listBtn").hide();
+ $("#showCategory").hide();
$("#blank-start-scDropdown").show();
$("#category-scDropdown").hide();
$("#id-scDropdown").hide();
if(shortcodeDropdown === "glm-members-packaging-list"){
$("#blank-start-scDropdown").hide();
- $("#listBtn").hide();
+ $("#showCategory").hide();
$("#category-scDropdown").hide();
$("#detailBtn").hide();
$("#id-scDropdown").hide();
$("#packageListAttr").children().show();
$("[id^='packageList']").show();
$("#view-scDropdown").hide();
+ $(".scCategories").hide();
}
if (shortcodeDropdown === "glm-members-packaging-detail"){
$("#blank-start-scDropdown").hide();
- $("#listBtn").hide();
+ $("#showCategory").hide();
$("#category-scDropdown").hide();
$("#detailBtn").hide();
$("#id-scDropdown").show();
}
if (shortcodeDropdown === "glm-members-event-list"){
$("#blank-start-scDropdown").hide();
- $("#listBtn").hide();
+ $("#showCategory").hide();
$("#category-scDropdown").hide();
$("#detailBtn").hide();
$("[id^='packageList']").hide();
}
if (shortcodeDropdown === "glm-members-event-detail"){
$("#blank-start-scDropdown").hide();
- $("#listBtn").hide();
+ $("#showCategory").hide();
$("#category-scDropdown").hide();
$("#detailBtn").hide();
$("[id^='packageList']").hide();
}
if (shortcodeDropdown === "glm-members-event-front-add"){
$("#blank-start-scDropdown").hide();
- $("#listBtn").hide();
+ $("#showCategory").hide();
$("#category-scDropdown").hide();
$("#detailBtn").hide();
$("[id^='packageList']").hide();
$("#view-scDropdown").hide();
}
});
-
-
+
// shortcode attribute name from dropdowns containing '-scDropdown' in their ID
// Then append the values to the shortcode object
$("[id$=-scDropdown]").on("change", function () {
shortcodeValues[target] = targetVal;
});
// use jquery dialog to separate the checkbox lists
- $("#listBtn").on("click", function () {
- $("#showList").dialog().dialog("option", "width", 422 );
+ $("#showCategory").on("click", function () {
+ $("#categoryBox").dialog().dialog("option", "width", 450 );
});
$("#detailBtn").on("click", function () {
$("#showDetail").dialog().dialog("option", "width", 422);
});
-
+
+ function get_tinymce_content(){
+ if (jQuery("#wp-content-wrap").hasClass("tmce-active")){
+
+ var regExp = /\[([^)]+)\]/;
+
+ tinyMCE.triggerSave();
+
+ if(regExp.exec($('#content').val())){
+ editorContent = regExp.exec($('#content').val());
+ return editorContent[0];
+ } else {
+ return;
+ }
+
+ } 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
+ if(regExp.exec($("#content").val())){
+ 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(',');
+ }
+ }
+
+ 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();
+
+ $.each( category_names_ids, function (index, obj) {
+ $('#activeCategories').append('<div data-id="' + obj[1]
+ + '" class="glm-dynSelect-item glm-members-catgegory">'
+ + obj[0] + " (ID: " + obj[1] + ')' + '<span class="glm-dynSelect-delete catDelete">X</span>'
+ + '<input type="hidden" name="category[' + obj[0] + ']" value="' + obj[0] + '"></div>');
+ });
+
+ if(editor_shortcodes && editor_shortcodes.indexOf('category="') >= 0){
+ var index = editor_shortcodes.indexOf('category="');
+ } else if ( editor_shortcodes && editor_shortcodes.indexOf("category='") >= 0){
+ var index = editor_shortcodes.indexOf("category='");
+ }
+
+
+ /*
+ * Category Selection
+ */
+ var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content;
+
+ $('#category-scDropdown').change( function() {
+ editor_shortcodes = get_tinymce_content();
+
+ 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=');
+ }
+ }
+
+ // 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;
+ }
+ });
+
+ // Check if there's a parent
+// parentName = '';
+// if (catParent !== '') {
+// parentName = catParent + ': ';
+// }
+
+ // If not found, Add the category
+ if (!found) {
+ $('#activeCategories').append('<div data-id="' + catValue
+ + '" class="glm-dynSelect-item glm-members-catgegory">'
+ + catName.trim() + ' (ID: ' + catValue + ')' + '<span class="glm-dynSelect-delete catDelete">X</span>'
+ + '<input type="hidden" name="category[' + catValue + ']" value="' + catValue + '"></div>');
+ }
+
+ 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($("#content").css("display") !== "none"){
+ editor_content = content.val();
+ 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);
+ }
+
+ // Reset picklist
+ $('#category-scDropdown').val('Select Category');
+ });
+
// generate the shortcode into a string and insert into the content upon clicking
$("#generate").on("click", function () {
// enforce the selection of a shortcode
}
}
}
+
+ if(shortcodeString.match(/category="(.*?)"/) !== null){
+ category_id = shortcodeString.match(/category="(.*?)"/)[1];
+ category_id = category_id.split(',');
+ ids = category_id.join(',');
+ shortcodeString = shortcodeString.replace(ids, id_string);
+ }
shortcodeString += ']';
// insert shortcode at current cursor position
function insert_tag(text){
if(tinyMCE && tinyMCE.activeEditor)
{
+ console.log(tinyMCE.activeEditor.id);
tinyMCE.activeEditor.selection.setContent(text);
}
return false;
}
});
+ // 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.length = 0;
+
+ $.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($("#content").css("display") !== "none"){
+ editor_content = content.val();
+ 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);
+ }
+ });
+
// 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');
if(scd){
window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected';
if(members){
window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected';
}
- window.onload = UncheckAll();
-
- function UncheckAll(){
- var w = document.getElementsByTagName('input');
- for(var i = 0; i < w.length; i++){
- if(w[i].type === 'checkbox'){
- w[i].checked = false;
- }
- }
+ if(view){
+ window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
}
+ window.onload = uncheckAll();
+
+
});
\ No newline at end of file