";
$(".social_icons_table_rows").append(social_icon_html);
init_icon_picker();
});
$("body").on("click", ".social_icon_delete", function () {
$(this).parents("tr").remove();
});
// Open module add/edit swal
function edit_module(module) {
mtnc_swal
.fire({
title: false,
html: edit_module_html(module),
confirmButtonText: "Save changes",
showCancelButton: true,
showCloseButton: true,
className: "mntc-edit-module",
width: 1000,
onRender: function () {
jscolor.install();
init_icon_picker();
$(".datepicker").each(function () {
$(this).AnyTime_noPicker();
options = { format: $(this).data("format") ? $(this).data("format") : "%Y-%m-%d %H:%i", firstDOW: 1, earliest: $(this).data("earliest") == "now" ? new Date() : "", labelTitle: $(this).data("title") ? $(this).data("title") : "Select a Date & Time" };
$(this).AnyTime_picker(options);
});
$(".summernote").summernote({
height: 140,
});
},
preConfirm: () => {
form = mtnc_swal.getContent();
return edit_module_save(module, form);
},
})
.then(function (result) {
if (result.dismiss || typeof result.value == "undefined") {
module_id = module.attr("id");
if (!theme.modules.hasOwnProperty(module_id)) {
$("#" + module_id).remove();
$(".mtnc-theme-builder").sortable("refresh").trigger("update");
if ($("#mtnc-theme-builder-layout li").length == 0) {
$("#mtnc-theme-builder-layout").addClass("empty");
} else {
$("#mtnc-theme-builder-layout").removeClass("empty");
}
}
}
});
} // edit_module
// Switch tabs in edit popup
$("body").on("click", ".mtnc-swal-tabs li", function () {
var tab = $(this).data("tab");
$(".mtnc-swal-tabs li").removeClass("active");
$(this).addClass("active");
$(".mtnc-swal-tab").hide();
$('.mtnc-swal-tab[data-tab="' + tab + '"]').show();
});
// Refresh modules list
function refresh_modules() {
html = "";
for (id in theme.modules_order) {
if (theme.modules[theme.modules_order[id]]) {
html += print_module_html(theme.modules_order[id], theme.modules[theme.modules_order[id]]);
} else {
delete theme.modules_order[id];
}
}
$("#mtnc-theme-builder-modules").find("li").removeClass("module-used");
$("#mtnc-theme-builder-layout").html(html);
if ($("#mtnc-theme-builder-layout li").length == 0) {
$("#mtnc-theme-builder-layout").addClass("empty");
} else {
$("#mtnc-theme-builder-layout").removeClass("empty");
}
} // refresh_modules
// Build HTML to display in module list
function print_module_html(module, module_data) {
html = '
';
html += ' ';
html += '' + module_data.name + "";
html += '
' + module_data.name + "";
html += '';
html += '';
html += '';
html += '';
html += "";
return html;
} // print_module_html
// Build module edit HTML for swal popup
function edit_module_html($module) {
module_id = $module.attr("id");
module_type = $module.data("type");
var html = "";
//Print module name
if (theme.modules.hasOwnProperty(module_id)) {
html += "
" + theme.modules[module_id].name + "
";
} else {
module_type = $module.data("type");
html += "
" + module_types[module_type].name + "
";
}
//Generate tab buttons
html += '
';
for (group in module_types[module_type].groups) {
var tab_classes = [];
if (module_types[module_type].groups[group].active) {
tab_classes.push("active");
}
if (module_types[module_type].groups[group].class) {
tab_classes.push(module_types[module_type].groups[group].class);
}
html += '
";
//Loop though all groups and create a tab for each group
for (group in module_types[module_type].groups) {
html += '
";
//Loop through each field in the group (we loop though the default field definitions in case any new fields have been added to that group)
for (field in module_types[module_type].groups[group].fields) {
//Check if the current module has values for this field or if it's a new field, we use it's defaults
if (theme.modules.hasOwnProperty(module_id) && theme.modules[module_id].groups.hasOwnProperty(group) && theme.modules[module_id].groups[group].fields.hasOwnProperty(field)) {
//Set all field properties from the default module definitions in case module definitions have changed (i.e chande field from text to textarea) but we keep all user set properties
for (field_property in module_types[module_type].groups[group].fields[field]) {
//Ignore value properties controlled by the user
if (field_property != "value" && field_property != "unit_value" && field_property != "icons" && !(field_property = "options" && field == "audience")) {
theme.modules[module_id].groups[group].fields[field][field_property] = module_types[module_type].groups[group].fields[field][field_property];
}
}
html += get_field_html(theme.modules[module_id].groups[group].fields[field]);
} else {
html += get_field_html(module_types[module_type].groups[group].fields[field]);
}
}
html += "
";
}
html += "
";
return html;
} // edit_module_html
// Save module data from swal popup and refresh modules list
function edit_module_save($module, form) {
module_id = $module.attr("id");
module_type = $module.data("type");
// If module doesn't exist in theme object, add it now
if (!theme.modules.hasOwnProperty(module_id)) {
theme.modules[module_id] = $.extend(true, {}, module_types[module_type]);
}
//Clone module definitions so we don't change original object
var module_types_clone = $.extend(true, {}, module_types[module_type]);
//Go over each field in the module definition in case new fields have been added
for (group in module_types_clone.groups) {
for (field in module_types_clone.groups[group].fields) {
theme.modules[module_id].groups[group].fields[field] = get_field_value(module_types_clone.groups[group].fields[field], form);
}
}
refresh_modules();
return true;
} // edit_module_save
// Get field value from swal HTML when saving
function get_field_value(field, form) {
switch (field.type) {
case "text":
case "number":
case "image":
case "color":
case "select":
case "select_mc_audience":
case "date_time":
case "font":
case "range":
field.value = $(form)
.find("#" + field.name)
.val();
if (field.units) {
field.unit_value = $(form)
.find("#" + field.name + "_unit")
.val();
}
if (field.type == "select_mc_audience") {
field.options = {};
$(form)
.find("#" + field.name + " option")
.each(function () {
field.options[$(this).val()] = $(this).text();
});
}
break;
case "textarea":
case "code":
field.value = $(form)
.find("#" + field.name)
.val();
break;
case "toggle":
field.value = $(form)
.find("#" + field.name)
.is(":checked");
break;
case "multioption":
for (option in field.values) {
field.values[option].selected = $(form)
.find("#" + field.name + "_" + option)
.is(":checked");
}
break;
case "radio":
field.value = $(form)
.find('[name="' + field.name + '"]:checked')
.val();
break;
case "socialicons":
field.icons = {};
var icon_index = 0;
$(form)
.find(".social_icons_table_rows tr")
.each(function () {
field.icons[icon_index] = { icon: $(this).find(".social_icon_icon").val(), url: $(this).find(".social_icon_url").val() };
icon_index++;
});
break;
default:
break;
}
return field;
} // get_field_value
$("#content_overlay").change(function () {
if ($(this).is(":checked")) {
$(".overlay_parameters").fadeIn();
} else {
$(".overlay_parameters").fadeOut();
}
});
// css and html editor
function getEditor($editorID, $textareaID, $mode) {
if ($("#" + $editorID).length > 0) {
var editor = ace.edit($editorID),
$textarea = $("#" + $textareaID).hide();
editor.getSession().setValue($textarea.val());
editor.getSession().on("change", function () {
$textarea.val(editor.getSession().getValue());
});
editor.getSession().setMode("ace/mode/" + $mode);
//editor.setTheme( 'ace/theme/xcode' );
editor.getSession().setUseWrapMode(true);
editor.getSession().setWrapLimitRange(null, null);
editor.renderer.setShowPrintMargin(null);
editor.session.setUseSoftTabs(null);
}
}
getEditor("custom_css_editor", "custom_css", "css");
// Generate HTML for add/edit for a single field
function get_field_html(field) {
html = '
';
if (!field.nolabel) {
if (field.hasOwnProperty("image_label")) {
html += ' ';
} else {
html += ' ";
}
html += '
';
}
switch (field.type) {
case "label":
html += "";
break;
case "text":
html += '';
break;
case "textarea":
html += '";
break;
case "code":
html += '";
break;
case "date_time":
html += '';
break;
case "select":
case "select_mc_audience":
var select_options_count = 0;
var select_options_html = "";
for (oid in field.options) {
select_options_html += '";
select_options_count++;
}
html += '";
if (field.type == "select_mc_audience") {
html += '
Refresh Audiences
';
}
break;
case "number":
html += '';
if (field.units) {
html += '";
}
break;
case "image":
html += '
';
html += '';
if (field.value && field.value.length > 0) {
html += '
';
} else {
html += '
';
}
html += '';
if (field.value && field.value.length > 0) {
html += '';
}
html += "
";
html += '
';
html += "
";
html += "
";
break;
case "color":
html += '';
break;
case "range":
html += '
';
html += '';
html += "
";
html += '' + field.value + "";
if (field.units) {
html += '";
} else {
html += field.unit;
}
html += "";
break;
case "toggle":
html += '
';
html += '';
html += '';
html += "
";
break;
case "multioption":
for (value in field.values) {
html += '";
}
break;
case "radio":
for (value in field.values) {
html += '";
}
break;
case "font":
html += '";
html += '
This is how the content font is going to look!
';
break;
case "socialicons":
html += '
';
html += '
URL
Icon
';
html += '';
for (icon in field.icons) {
html += "
";
html += '
';
html += '
';
html += '
';
html += '
';
html += "
";
}
html += "";
html += "
";
html += "
";
break;
default:
break;
}
if (!field.nolabel) {
if (field.desc) {
html += '
' + field.desc + "
";
}
html += "
";
}
html += "
";
return html;
} // get_field_html
$(document).on("click", ".refresh_mailchimp_audience", function (e) {
e.preventDefault();
var mailchimp_api_key = $(this).parents(".mtnc-swal-tab").find("#api_key").val();
$button = $(this);
$button.addClass("mtnc-btn-loading");
$.post({
url: ajaxurl,
data: {
action: "mtnc_action",
_ajax_nonce: mtnc.nonce_action,
mtnc_action: "refresh_mailchimp_audiences",
api_key: mailchimp_api_key,
},
})
.always(function (data) {
$button.removeClass("mtnc-btn-loading");
})
.done(function (data) {
if (data.success) {
var $el = $button.siblings("select");
$el.empty(); // remove old options
var list_count = 0;
$.each(data.data, function (key, option) {
list_count++;
$el.append($("").attr("value", option.val).text(option.label));
});
if (list_count > 0) {
$el.removeClass("disabled");
} else {
$el.addClass("disabled");
}
}
})
.fail(function (data) {
mtnc_swal.fire({ type: "error", title: mtnc.undocumented_error });
});
});
//Google font preview
$(document).on("change", ".mtnc-bunny-fonts", function () {
var $font = $(this);
changeFont($font);
});
function changeFont($font) {
var $fontValue = $font.val();
reloadFont($fontValue);
$font.parent().find("h3").css("font-family", $fontValue);
}
function reloadFont($fontValue) {
baseFonts = ["Arial", "Helvetica", "Georgia", "Times New Roman", "Tahoma", "Verdana", "Geneva"];
if (baseFonts.indexOf($fontValue) != -1) {
return;
}
WebFont.load({
google: {
families: [$fontValue],
},
});
}
$("#background_type")
.change(function (e) {
$("#design-background .background-type").hide();
$("#design-background .background-type-" + $(this).val()).show();
})
.trigger("change");
$("body")
.on("input", 'input[type="range"]', function (e) {
$(this).parents(".mtnc-swal-input-wrapper").find(".range_value").html(this.value);
})
.trigger("change");
$("#background_image_filter")
.on("change", function (e) {
filter = $(this).val();
image = $("#background-preview img");
if (!image.length) {
return;
}
$(image).removeClass();
$(image).addClass(filter);
})
.trigger("change");
$("#background_video_filter")
.on("change", function (e) {
filter = $(this).val();
video = $("#video-preview");
video_fallback = $("#video-fallback-preview img");
$(video).removeClass().addClass(filter);
$(video_fallback).removeClass().addClass(filter).addClass(filter);
})
.trigger("change");
$("#background_video")
.on("change keyup click", function (e) {
video_url = $(this).val();
preview = $("#video-preview .video-container");
if (video_url == preview.data("video-id")) {
return;
}
if (video_url) {
video = '';
} else {
video = "";
}
preview.data("video-id", video_url);
preview.html(video);
})
.trigger("change");
$(document).on("click", ".mtnc-upload", function (e) {
e.preventDefault();
getUploader("Select Image", $(this));
});
// Removing photo from the canvas and emptying the text field
$(document).on("click", ".mtnc-remove-image", function (e) {
e.preventDefault();
$(this).parent().parent().find("input").val("");
$(this).parent().parent().find(".mtnc-preview-area").html("Select an image or upload a new one");
$(this).hide();
});
var custom_uploader;
$(document).on("click", ".mtnc-image-upload-button", function (e) {
e.preventDefault();
getUploader("Select Image", $(this));
});
$(document).on("click", ".mtnc-image-upload-remove", function (e) {
e.preventDefault();
$(this).parents(".mtnc-image-upload-wrapper").children(".mtnc-image-upload-input").val("");
$(this).parent().css("background-image", "");
$(this)
.parent()
.prepend('');
$(this).parent().children(".mtnc-image-upload-remove").remove();
});
$("body").on("click", ".media-frame-router .media-router .media-menu-item", function () {
$(".media-button-select").show();
$(".mtnc-media-button-select").hide();
});
$("body").on("click", ".mtnc-media-button-select", function () {
$(".mtnc-media-button-select").attr("disabled", "disabled");
if ($(".media-menu-item.active").hasClass("mtnc-unsplash-images")) {
var mtnc_unsplash_id = "";
var image_input_id = $(this).data("id");
$(".mtnc-unsplash-image-selected").each(function () {
mtnc_unsplash_id = $(this).data("id");
mtnc_unsplash_url = $(this).data("url");
mtnc_unsplash_name = $(this).data("name");
});
if (mtnc_unsplash_id != "") {
$(".media-modal-content .media-frame-content").html('