';
html += ' | ';
html += ' | ';
html += '';
html += '+';
html += 'x';
html += ' | ';
html += '
';
return html;
}
function add_new_option_row(elm){
var ptable = $(elm).closest('table');
var optionsSize = ptable.find('tbody tr').length;
if(optionsSize > 0){
ptable.find('tbody tr:last').after(prepare_option_row_html(null));
}else{
ptable.find('tbody').append(prepare_option_row_html(null));
}
}
function remove_option_row(elm){
var ptable = $(elm).closest('table');
$(elm).closest('tr').remove();
var optionsSize = ptable.find('tbody tr').length;
if(optionsSize == 0){
ptable.find('tbody').append(prepare_option_row_html(null));
}
}
/*------------------------------------
*---- OPTIONS FUNCTIONS - END -------
*------------------------------------*/
return {
openNewFieldForm : open_new_field_form,
openEditFieldForm : open_edit_field_form,
openCopyFieldForm : open_copy_field_form,
fieldTypeChangeListner : field_type_change_listner,
addNewOptionRow : add_new_option_row,
removeOptionRow : remove_option_row,
save_field : save_field,
};
}(window.jQuery, window, document));
function thwcfdOpenNewFieldForm(sectionName, checkout_type){
checkout_type = typeof checkout_type !== 'undefined' ? checkout_type : 'classic';
thwcfd_settings_field.openNewFieldForm(sectionName, checkout_type);
}
function thwcfdOpenEditFieldForm(elm, rowId, checkout_type){
checkout_type = typeof checkout_type !== 'undefined' ? checkout_type : 'classic';
thwcfd_settings_field.openEditFieldForm(elm, rowId, checkout_type);
}
function thwcfdOpenCopyFieldForm(elm, rowId, checkout_type){
checkout_type = typeof checkout_type !== 'undefined' ? checkout_type : 'classic';
thwcfd_settings_field.openCopyFieldForm(elm, rowId, checkout_type);
}
function thwcfdFieldTypeChangeListner(elm){
thwcfd_settings_field.fieldTypeChangeListner(elm);
}
function thwcfdAddNewOptionRow(elm){
thwcfd_settings_field.addNewOptionRow(elm);
}
function thwcfdRemoveOptionRow(elm){
thwcfd_settings_field.removeOptionRow(elm);
}
function thwcfdSaveField(elm){
thwcfd_settings_field.save_field(elm);
}
var thwcfd_settings_section = (function($, window, document) {
'use strict';
var MSG_INVALID_NAME = 'NAME/ID must begin with a lowercase letter ([a-z]) and may be followed by any number of lowercase letters, digits ([0-9]) and underscores ("_")';
var BLOCK_SECTION_FORM_FIELDS = {
name : {name : 'name', label : 'Name/ID', type : 'text', required : 1},
position : {name : 'position', label : 'Display Position', type : 'hidden', value: 'set_from_block'},
cssclass : {name : 'cssclass', label : 'CSS Class', type : 'text'},
show_title : {name : 'show_title', label : 'Show section title in checkout page.', type : 'checkbox', value : 'yes', checked : true},
title : {name : 'title', label : 'Title', type : 'text'},
title_class : {name : 'title_class', label : 'Title Class', type : 'text'},
subtitle : {name : 'subtitle', label : 'Subtitle', type : 'text'},
};
var RESERVED_SECTION_NAMES = ['address', 'contact', 'order'];
function open_edit_section_form(valueJson, checkout_type){
open_section_form(checkout_type, 'edit', valueJson);
}
function open_section_form(checkout_type, type, valueJson){
var popup = $("#thwcfd_section_form_pp");
var form = $("#thwcfd_section_form");
populate_section_form( checkout_type,popup, form, type, valueJson);
thwcfd_base.form_wizard_open(popup);
}
function populate_section_form(checkout_type, popup, form, type, valueJson){
var title = type === 'edit' ? 'Edit Section' : 'New Section';
popup.find('.wizard-title').text(title);
form.find('.err_msgs').html('');
form.find("input[name=i_name]").prop("readonly", false);
form.find("input[name=s_action]").val(type);
form.find("input[name=s_name]").val('');
form.find("input[name=s_name_copy]").val('');
form.find("input[name=i_position_old]").val('');
form.find("input[name=i_rules]").val('');
form.find("input[name=i_rules_ajax]").val('');
form.find("input[name=i_repeat_rules]").val('');
//var current_section_form_fields = checkout_type === 'block' ? BLOCK_SECTION_FORM_FIELDS : SECTION_FORM_FIELDS;
var current_section_form_fields = BLOCK_SECTION_FORM_FIELDS;
if(type === 'new'){
set_form_field_values(form, current_section_form_fields, false);
}else{
set_form_field_values(form, current_section_form_fields, valueJson);
if(type === 'copy'){
var sNameCopy = valueJson ? valueJson['name'] : '';
form.find("input[name=i_name]").val("");
form.find("input[name=s_name_copy]").val(sNameCopy);
}else{
form.find("input[name=i_name]").prop("readonly", true);
}
form.find("select[name=i_position_old]").val(valueJson.position);
setTimeout(function(){form.find("select[name=i_position]").focus();}, 1);
}
}
function set_form_field_values(form, fields, valuesJson){
var sname = valuesJson && valuesJson['name'] ? valuesJson['name'] : '';
$.each( fields, function( name, field ) {
var type = field['type'];
if(valuesJson){
var value = valuesJson[name] ? valuesJson[name] : '';
}else{
var value = valuesJson[name] ? valuesJson[name] : field['value'];
}
var multiple = field['multiple'] ? field['multiple'] : 0;
if(type === 'checkbox'){
if(!valuesJson && field['checked']){
value = field['checked'];
}
}
thwcfd_base.set_property_field_value(form, type, name, value, multiple);
});
var prop_form = $('#section_prop_form_'+sname);
var rulesAction = valuesJson && valuesJson['rules_action'] ? valuesJson['rules_action'] : 'show';
var rulesActionAjax = valuesJson && valuesJson['rules_action_ajax'] ? valuesJson['rules_action_ajax'] : 'show';
var conditionalRules = prop_form.find(".f_rules").val();
var conditionalRulesAjax = prop_form.find(".f_rules_ajax").val();
}
function save_section(elm){
var popup = $("#thwcfd_section_form_pp");
var form = $("#thwcfd_section_form");
var result = validate_section(form, popup);
if(result){
form.submit();
}
}
function validate_section(form, popup){
var name = form.find("input[name=i_name]").val();
var title = form.find("input[name=i_title]").val();
var positionElement = form.find("select[name=i_position]");
var position = positionElement.length ? positionElement.val() : form.find("input[name=i_position]").val() || '';
name = name ? name : '';
position = position ? position : '';
var err_msgs = '';
if(name.trim() == ''){
err_msgs = 'Name/ID is required';
}else if(!thwcfd_base.isHtmlIdValid(name)){
err_msgs = MSG_INVALID_NAME;
}else if(RESERVED_SECTION_NAMES.indexOf(name) !== -1){
err_msgs = 'The provided Name/ID is already used for the default section. Please use a different name.';
}else if(title.trim() == ''){
err_msgs = 'Title is required';
}
if(err_msgs != ''){
form.find('.err_msgs').html(err_msgs);
thwcfd_base.form_wizard_start(popup);
return false;
}
return true;
}
return {
openEditSectionForm : open_edit_section_form,
save_section : save_section,
};
}(window.jQuery, window, document));
function thwcfdOpenEditSectionForm(section, checkout_type){
checkout_type = typeof checkout_type !== 'undefined' ? checkout_type : 'classic';
thwcfd_settings_section.openEditSectionForm(section, checkout_type);
}
function thwcfdSaveSection(elm){
thwcfd_settings_section.save_section(elm);
}
var thwcfd_settings = (function($, window, document) {
'use strict';
var _wp$i18n = wp.i18n;
var __ = _wp$i18n.__;
var _x = _wp$i18n._x;
var _n = _wp$i18n._n;
var _nx = _wp$i18n._nx;
$(function() {
var settings_form = $('#thwcfd_checkout_fields_form');
thwcfd_base.setupSortableTable(settings_form, '#thwcfd_checkout_fields', '0');
thwcfd_base.setup_tiptip_tooltips();
thwcfd_base.setup_form_wizard();
});
$(document).keypress(function(e) {
if ($("#thwcfd_field_form_pp").is(':visible') && (e.keycode == 13 || e.which == 13)) {
e.preventDefault();
thwcfdSaveField(this);
}
});
$(document).ready(function(e){
var feature_popup = $(".thwcfd-pro-discount-popup");
var feature_popup_wrapper = $(".thwcfd-pro-discount-popup-wrapper");
if (feature_popup.length > 0) {
$('body').css('overflow','hidden');
feature_popup[0].style.display = "flex";
}
});
$(document).ready(function(){
const referrerUrl = document.referrer;
var clicked = false;
if (referrerUrl.includes('thwcfd-welcome')) {
$("#infoBox").show();
clicked = true;
}else{
clicked = false;
$("#infoBox").hide();
}
$("#th_info_container").on("click", function(){
if (!clicked) {
$("#infoBox").show();
} else {
$("#infoBox").hide();
}
clicked = !clicked;
});
$("#th_info_container").on("mouseenter", function(){
if (!clicked) {
$("#infoBox").show();
}
});
// Hide on mouseleave only if not clicked
$("#th_info_container").on("mouseleave", function(){
if (!clicked) {
$("#infoBox").hide();
}
});
});
function select_all_fields(elm){
var checkAll = $(elm).prop('checked');
$('#thwcfd_checkout_fields tbody input:checkbox[name=select_field]').prop('checked', checkAll);
}
function remove_selected_fields(){
$('#thwcfd_checkout_fields tbody tr').removeClass('strikeout');
$('#thwcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
var row = $(this).closest('tr');
if(!row.hasClass("strikeout")){
row.addClass("strikeout");
}
row.find(".f_deleted").val(1);
//row.find(".f_edit_btn").prop('disabled', true);
});
}
function enable_disable_selected_fields(enabled){
$('#thwcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function(){
var row = $(this).closest('tr');
if(enabled == 0){
if(!row.hasClass("thpladmin-disabled")){
row.addClass("thpladmin-disabled");
}
}else{
row.removeClass("thpladmin-disabled");
}
//row.find(".f_edit_btn").prop('disabled', enabled == 1 ? false : true);
row.find(".td_enabled").html(enabled == 1 ? '