class : "shortcode-end",
text: ']',
});
- var shortcodeAttributes = {
- categories : {list:[], isList: true},
- regions : {list:[], isList: true},
- groups : {list:[], isList: true},
- views : {list:[], isList: false},
- blankstart : {list:[], isList: false},
- }
+ var shortcodeAttributes;
function replaceNbsp(str) {
var re = new RegExp(String.fromCharCode(160), "g");
return str.replace(re, " ");
}));
tile.appendTo(elHook);
}
-
function setupAttributes(state){
$("#shortcode-preview").empty();
$(".shortcode-tile-container").empty();
+ shortcodeAttributes = {
+ categories : {list:[], isList: true},
+ regions : {list:[], isList: true},
+ groups : {list:[], isList: true},
+ views : {list:[], isList: false},
+ blankstart : {list:[], isList: false},
+ }
shortcode_string.appendTo( $("#shortcode-preview"));
shortcode_end.appendTo( $("#shortcode-preview"));
for(var attribute in shortcodeAttributes ){
}).insertBefore( $(".shortcode-end"));
}
}
-
function checkDuplicates(object, list) {
var objString = JSON.stringify(object);
for( var i = 0; i < list.length; i++){
}
return false;
}
-
function updateShortcode(shortcodeData){
$("#"+shortcodeData.type+"-container").empty();
var ids = [];
var item_string = '';
-
shortcodeData.list.map( function(item){
ids.push(item.id);
createShortcodeTile({id: item.id, name: item.name, type: item.type}, $("#"+item.type + "-container"))
item_string = item.type+'="'+ids.join() + '"';
});
-
shortcodeData['attribute'] = item_string;
generateShortCodeAttribute(shortcodeData);
}
-
setupAttributes();
-
$(document).on("change", ".shortcode-selection",function(){
var id = $(this).val();
var name = $(this).find("option:selected").text();
var type = $(this).find("option:selected").data("type");
let record = {id: id, name: name, type: type};
-
if(shortcodeAttributes[type].list.length == 0 || !checkDuplicates(record, shortcodeAttributes[type].list) && shortcodeAttributes[type].isList ){
shortcodeAttributes[type].list.push(record);
}else if(!shortcodeAttributes[type].isList) {
$("#"+type+"-string").removeClass("shortcode-no-space");
updateShortcode({list: shortcodeAttributes[type].list, type: type, isList: shortcodeAttributes[type].isList});
});
-
$(".shortcode-button").on("click", function(){
var confirmation = $(this).children('div');
if( $(this).attr("id") == "copy-to-clipboard" ){
confirmation.toggleClass("confirmed");
}, 3000);
});
-
$(document).on("click", ".shortcode-string", function(){
$(this).addClass("edit-attribute");
if($(this).hasClass("edit-attribute")){
var updated = shortcodeAttributes[type].list.filter( function(item) {
return item.id != id;
});
-
shortcodeAttributes[type].list = updated;
if( shortcodeAttributes[type].list.length == 0) {
$("#"+type+"-string").addClass("shortcode-no-space");