989 lines
44 KiB
JavaScript
989 lines
44 KiB
JavaScript
function wcpaInitMap()
|
|
{
|
|
var e = {
|
|
street_number: "short_name",
|
|
route: "long_name",
|
|
locality: "long_name",
|
|
administrative_area_level_1: "short_name",
|
|
country: "long_name",
|
|
postal_code: "short_name"
|
|
};
|
|
jQuery(".wcpa_type_placeselector").each(function ()
|
|
{
|
|
var a = jQuery(this).find(".wcpa_google_place").get(0),
|
|
t = jQuery(this),
|
|
r = new google.maps.places.Autocomplete(a),
|
|
i = new google.maps.Geocoder;
|
|
if (r.addListener("place_changed", function ()
|
|
{
|
|
var a = r.getPlace();
|
|
for (var i in e) jQuery("." + i, t).val(""), jQuery("." + i, t).removeAttr("disabled", "disabled");
|
|
for (var c = 0; c < a.address_components.length; c++)
|
|
{
|
|
var l = a.address_components[c].types[0];
|
|
if (e[l])
|
|
{
|
|
var o = a.address_components[c][e[l]];
|
|
jQuery("." + l, t).val(o)
|
|
}
|
|
}
|
|
a.geometry && (jQuery(".wcpa_lat", t).val(a.geometry.location.lat()), jQuery(".wcpa_lng", t).val(a.geometry.location.lng()))
|
|
}), t.find(".wcpa_map").length)
|
|
{
|
|
var c = new google.maps.Map(t.find(".wcpa_map").get(0),
|
|
{
|
|
center:
|
|
{
|
|
lat: 0,
|
|
lng: 0
|
|
},
|
|
zoom: 15
|
|
});
|
|
r.bindTo("bounds", c);
|
|
var l = new google.maps.Marker(
|
|
{
|
|
map: c,
|
|
draggable: !0,
|
|
anchorPoint: new google.maps.Point(0, -29)
|
|
});
|
|
jQuery.post("https://www.googleapis.com/geolocation/v1/geolocate?key=" + wcpa_global_vars.google_map_api, function (e)
|
|
{
|
|
c.setCenter(e.location), l.setVisible(!1), l.setPosition(e.location), l.setVisible(!0)
|
|
}), google.maps.event.addListener(l, "dragend", function ()
|
|
{
|
|
jQuery(".wcpa_lat", t).val(l.getPosition().lat()), jQuery(".wcpa_lng", t).val(l.getPosition().lng()), i.geocode(
|
|
{
|
|
latLng: l.getPosition()
|
|
}, function (a)
|
|
{
|
|
for (var r in e) jQuery("." + r, t).val(""), jQuery("." + r, t).removeAttr("disabled", "disabled");
|
|
if (a && a.length > 0)
|
|
{
|
|
jQuery(".wcpa_google_place", t).val(a[0].formatted_address), jQuery.wcpaIterate();
|
|
for (var i = 0; i < a[0].address_components.length; i++)
|
|
{
|
|
var c = a[0].address_components[i].types[0];
|
|
if (e[c])
|
|
{
|
|
var l = a[0].address_components[i][e[c]];
|
|
jQuery("." + c, t).val(l)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}), r.addListener("place_changed", function ()
|
|
{
|
|
l.setVisible(!1);
|
|
var e = r.getPlace();
|
|
e.geometry ? (e.geometry.viewport ? c.fitBounds(e.geometry.viewport) : (c.setCenter(e.geometry.location), c.setZoom(17)), l.setPosition(e.geometry.location), l.setVisible(!0)) : window.alert("No details available for input: '" + e.name + "'")
|
|
})
|
|
}
|
|
})
|
|
}
|
|
String.prototype.endsWith || (String.prototype.endsWith = function (e, a)
|
|
{
|
|
return (void 0 === a || a > this.length) && (a = this.length), this.substring(a - e.length, a) === e
|
|
}), String.prototype.startsWith || (String.prototype.startsWith = function (e, a)
|
|
{
|
|
return this.substr(!a || a < 0 ? 0 : +a, e.length) === e
|
|
}),
|
|
function ($)
|
|
{
|
|
function wcpa_show_val_error(e, a)
|
|
{
|
|
e.next(".wcpa_error_msg").length ? e.next(".wcpa_error_msg").html("<p>" + a + "</p>") : $('<div class="wcpa_error_msg"><p>' + a + "</p></div>").insertAfter(e)
|
|
}
|
|
|
|
function wcpa_remove_val_error(e)
|
|
{
|
|
e.next(".wcpa_error_msg").length && e.next(".wcpa_error_msg").remove()
|
|
}
|
|
|
|
function wcpa_product_image_update(e, a)
|
|
{
|
|
if (0 != a)
|
|
{
|
|
var t = a.data("image"),
|
|
r = {
|
|
image: t
|
|
};
|
|
$.extend(r,
|
|
{
|
|
image: t
|
|
}), e.wc_variations_image_update(r), e.data("wcpa_product_image", !0)
|
|
}
|
|
else 1 == e.data("wcpa_product_image") && (e.wc_variations_image_update(!1), e.data("wcpa_product_image", !1), e.find(".variations select").trigger("change"))
|
|
}
|
|
|
|
function wcpa_upload_file(e)
|
|
{
|
|
var a = e.prop("files")[0];
|
|
if (void 0 !== a)
|
|
{
|
|
"object" == typeof e.data("wcpa_ajx_upload") && e.data("wcpa_ajx_upload").abort();
|
|
var t = e.val().match(/([^\/\\]+)$/)[1],
|
|
r = e.parents(".wcpa_file_outer");
|
|
if (r.find(".wcpa_file_name").removeClass("wcpa_file_error").html(t), e.is(".wcpa_ajax_upload"))
|
|
{
|
|
var i = new FormData,
|
|
c = e.data("details");
|
|
i.append("wcpa_file", a), i.append("wcpa_file_details", JSON.stringify(c)), i.append("action", "wcpa_ajax_upload"), !0 === c.required && e.attr("required", "required");
|
|
var l = $.ajax(
|
|
{
|
|
type: "POST",
|
|
url: wcpa_global_vars.ajax_url,
|
|
xhr: function ()
|
|
{
|
|
var e = $.ajaxSettings.xhr();
|
|
return e.upload && e.upload.addEventListener("progress", function (e)
|
|
{
|
|
if (e.lengthComputable)
|
|
{
|
|
var a = Math.round(100 * e.loaded / e.total);
|
|
$("~ .wcpa_progress", r).css("width", a + "%")
|
|
}
|
|
}, !1), e
|
|
},
|
|
beforeSend: function ()
|
|
{
|
|
e.parent().addClass("wcpa_uploading"), e.parent().removeClass("wcpa_uploaded"), $("~ .wcpa_progress", r).show().css("width", 0), $("~ .wcpa_file_hidden", r).val(""), e.parents("form").find(".single_add_to_cart_button").addClass("wcpa_disable_cart");
|
|
var a = parseInt(e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count"));
|
|
isNaN(a) ? a = 1 : a++, e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count", a)
|
|
},
|
|
success: function (a)
|
|
{
|
|
$("~ .wcpa_progress", r).show().css("width", 100), e.parent().removeClass("wcpa_uploading"), $("~ .wcpa_progress", r).show(), e.val("");
|
|
var t = parseInt(e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count"));
|
|
isNaN(t) || 1 === t ? (t = 0, e.parents("form").find(".single_add_to_cart_button").removeClass("wcpa_disable_cart")) : t--, e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count", t), !0 === a.status ? (e.removeAttr("required"), $("~ .wcpa_progress", r).css("width", "100%"), $("~ .wcpa_file_hidden", r).val(a.file.file + "||" + a.file.file_name), e.parent().addClass("wcpa_uploaded")) : ($("~ .wcpa_progress", r).css("width", 0), r.find(".wcpa_file_name").addClass("wcpa_file_error").html(a.message))
|
|
},
|
|
error: function (a, t, i)
|
|
{
|
|
$("~ .wcpa_progress", r).show().css("width", 0);
|
|
var c = parseInt(e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count"));
|
|
isNaN(c) || 1 === c ? (c = 0, e.parents("form").find(".single_add_to_cart_button").removeClass("wcpa_disable_cart")) : c--, e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count", c), "abort" !== i && (e.val(""), r.find(".wcpa_file_name").addClass("wcpa_file_error").html(wcpa_global_vars.strings.ajax_upload_error)), e.parent().removeClass("wcpa_uploading")
|
|
},
|
|
async: !0,
|
|
data: i,
|
|
dataType: "json",
|
|
cache: !1,
|
|
contentType: !1,
|
|
processData: !1
|
|
});
|
|
e.data("wcpa_ajx_upload", l)
|
|
}
|
|
}
|
|
}
|
|
|
|
function regExpFromString(e, a)
|
|
{
|
|
let t = e.replace(/.*\/([gimuy]*)$/, "$1");
|
|
t === e && (t = "");
|
|
let r = "/" == e.charAt(0) ? e.replace(new RegExp("^/(.*?)/" + t + "$"), "$1") : e;
|
|
try
|
|
{
|
|
return "" == t && "/" !== e.charAt(0) && (t = a), new RegExp(r, t)
|
|
}
|
|
catch (e)
|
|
{
|
|
return null
|
|
}
|
|
}
|
|
$(document).on("click", ".single_add_to_cart_button", function (e)
|
|
{
|
|
$(this).is(".wcpa_disable_cart") && (alert(wcpa_global_vars.strings.ajax_file_upload), e.preventDefault())
|
|
});
|
|
|
|
wcpa_price = function (e)
|
|
{
|
|
return e.toFixed(wcpa_global_vars.wc_price_decimals).replace(".", wcpa_global_vars.wc_decimal_sep)
|
|
};
|
|
|
|
function exc_relations(ele_id, $form_outer)
|
|
{
|
|
void 0 === $form_outer && ($form_outer = !1);
|
|
var $element = $("#" + ele_id, $form_outer),
|
|
product_data = $form_outer.data("product");
|
|
if (0 == $element.length) return !1;
|
|
var $relation = $element.data("rules");
|
|
if (!$relation) return !1;
|
|
var $rules = $relation.rules;
|
|
$evel_str = "", $rules.forEach(function (e)
|
|
{
|
|
$evel_str += "(", e.rules.forEach(function (e)
|
|
{
|
|
$evel_str += "(", eval_relation(e.rules, $element, product_data, $form_outer) ? $evel_str += " true " : $evel_str += " false ", $evel_str += ") " + (!1 !== e.operator ? e.operator : "") + " "
|
|
}), e.length > 0 && ($evel_str = $evel_str.match(/\(.*\)/g)[0] + " "), $evel_str += ") " + (!1 !== e.operator ? e.operator : "") + " "
|
|
}), $rules.length > 0 && ($evel_str = $evel_str.match(/\(.*\)/g)[0]);
|
|
var result = !1;
|
|
try
|
|
{
|
|
result = eval($evel_str.replace(/or/gi, "||").replace(/and/gi, "&&"))
|
|
}
|
|
catch (e)
|
|
{
|
|
return !1
|
|
}
|
|
if (result)
|
|
if ("show" == $relation.action)
|
|
{
|
|
if (enable_fields($element), $element.is(":visible")) return !0;
|
|
$element.show().addClass("wcpa_cl_visible")
|
|
}
|
|
else
|
|
{
|
|
if (disable_fields($element), $element.removeClass("wcpa_cl_visible"), !$element.is(":visible")) return !0;
|
|
$element.hide()
|
|
}
|
|
else if ("show" == $relation.action)
|
|
{
|
|
if (disable_fields($element), $element.removeClass("wcpa_cl_visible"), !$element.is(":visible")) return !0;
|
|
$element.hide()
|
|
}
|
|
else
|
|
{
|
|
if (enable_fields($element), $element.is(":visible")) return !0;
|
|
$element.show().addClass("wcpa_cl_visible")
|
|
}
|
|
var related = $element.data("related");
|
|
null != related && related.forEach(function (e)
|
|
{
|
|
exc_relations(e, $form_outer)
|
|
}), $form_outer.trigger("wcpa.cl_updated"), iterate($element.parents(".wcpa_form_outer"))
|
|
}
|
|
|
|
function disable_fields(e)
|
|
{
|
|
e.find("select,input,file,textarea").attr("disabled", "disabled")
|
|
}
|
|
|
|
function enable_fields(e)
|
|
{
|
|
e.find("select,input,file,textarea").removeAttr("disabled"), e.is(".wcpa_type_color") && $(".wcpa_colorpicker", e).spectrum(
|
|
{
|
|
preferredFormat: "hex",
|
|
showInput: !0,
|
|
allowEmpty: !0
|
|
})
|
|
}
|
|
|
|
function eval_relation(e, a, t, r)
|
|
{
|
|
if ("quantity" === e.cl_field) var i = a.parents("form").find("input[name=quantity]");
|
|
else if ("attribute" === e.cl_field)
|
|
{
|
|
if (t.is_variable) i = (i = a.parents("form.variations_form").find(".variations select[name='attribute_" + e.cl_relation + "']").val()) ? [i] : [];
|
|
else i = void 0 !== t.product_attributes[e.cl_relation] ? t.product_attributes[e.cl_relation].value : []
|
|
}
|
|
else if ("stock_status" === e.cl_field)
|
|
{
|
|
(i = new Array).push(t.stock_status)
|
|
}
|
|
else if ("stock_quantity" === e.cl_field)
|
|
{
|
|
(i = new Array).push(t.stock_quantity)
|
|
}
|
|
else if ("custom_field" === e.cl_field)
|
|
{
|
|
(i = new Array).push(t.product_cfs)
|
|
}
|
|
else if ("product_ids" === e.cl_field)
|
|
{
|
|
(i = new Array).push(t.product_id)
|
|
}
|
|
else i = $("#" + e.cl_field, r);
|
|
if (!i.length) return !1;
|
|
if ("0" === e.cl_relation) return !1;
|
|
var c = Array();
|
|
if ($.inArray(e.cl_field, ["stock_status", "stock_quantity", "custom_field", "product_ids", "attribute"]) < 0 && (i.is(":visible") || $.inArray(i.data("type"), ["hidden"]) >= 0 || "quantity" == e.cl_field))
|
|
if ($.inArray(i.data("type"), ["text", "color", "hidden"]) >= 0) i.find("input").val() && c.push(i.find("input").val().toLowerCase().trim());
|
|
else if ($.inArray(i.data("type"), ["file"]) >= 0) i.find("input").val() ? c.push(i.find("input").val().split("\\").pop().toLowerCase()) : i.parents(".wcpa_form_item").length && ($temp = i.parents(".wcpa_form_item").find(".wcpa_file_hidden").val(), 2 === $temp.split("||").length && c.push($temp.split("||")[1].toLowerCase()));
|
|
else if ($.inArray(i.data("type"), ["number"]) >= 0) i.find("input").val() && c.push(parseFloat(i.find("input").val().toLowerCase().trim()));
|
|
else if ("quantity" === e.cl_field) i.val() && c.push(parseFloat(i.val().toLowerCase().trim()));
|
|
else if ($.inArray(i.data("type"), ["textarea"]) >= 0) i.find("textarea").val() && c.push(i.find("textarea").val().toLowerCase().trim());
|
|
else if ($.inArray(i.data("type"), ["checkbox-group", "radio-group"]) >= 0) c = i.find("input:checked").map(function ()
|
|
{
|
|
return $(this).hasClass("wcpa_other") ? $.inArray(e.cl_relation, ["contains", "not_contains", "starts_with", "ends_with"]) >= 0 ? $(this).val().replace("WCPAOTH ", "").toLowerCase() : "other" : $(this).val().toLowerCase()
|
|
}).get();
|
|
else if ($.inArray(i.data("type"), ["select"]) >= 0) i.find("select").val() && i.find("select").val().constructor === Array ? c = i.find("select").val().map(function (e)
|
|
{
|
|
return e.toLowerCase()
|
|
}) : i.find("select").val() && c.push(i.find("select").val().toLowerCase());
|
|
else if ($.inArray(i.data("type"), ["date", "datetime-local"]) >= 0)
|
|
{
|
|
if (i.find("input").val())
|
|
if ($.inArray(e.cl_relation, ["contains", "not_contains", "starts_with", "ends_with"]) >= 0) c.push(i.find("input").val().toLowerCase());
|
|
else "function" == typeof (l = wcpa_get_date_obj(i.find("input").val(), "wp")).getTime && c.push(l.getTime())
|
|
}
|
|
else if ($.inArray(i.data("type"), ["time"]) >= 0)
|
|
{
|
|
if (i.find("input").val())
|
|
if ($.inArray(e.cl_relation, ["contains", "not_contains", "starts_with", "ends_with"]) >= 0) c.push(i.find("input").val().toLowerCase());
|
|
else
|
|
{
|
|
var l = new Date("1/1/2018 " + i.find("input").val());
|
|
c.push(l.getTime())
|
|
}
|
|
}
|
|
else $.inArray(i.data("type"), ["image-group", "color-group"]) >= 0 && (c = i.find("input:checked").map(function ()
|
|
{
|
|
return $(this).hasClass("wcpa_other") ? $.inArray(e.cl_relation, ["contains", "not_contains", "starts_with", "ends_with"]) >= 0 ? $(this).val().replace("WCPAOTH ", "").toLowerCase() : "other" : $(this).val().toLowerCase()
|
|
}).get());
|
|
var o = !1;
|
|
if ("attribute" === e.cl_field) return !(!i || !i.length) && (c = i.map(function (e)
|
|
{
|
|
return e.toLowerCase()
|
|
}), o = e.cl_val.value ? e.cl_val.value : e.cl_val, $.inArray(o, c) >= 0);
|
|
if ("stock_status" === e.cl_field) c.push(t.stock_status);
|
|
else if ("stock_quantity" === e.cl_field) c.push(t.stock_quantity);
|
|
else if ("product_ids" === e.cl_field) c.push(t.product_id);
|
|
else if ("custom_field" === e.cl_field) return void 0 !== t.product_cfs["wcpa_pcf_" + e.cl_relation] && (c.push(t.product_cfs["wcpa_pcf_" + e.cl_relation].toLowerCase()), o = e.cl_val.value ? e.cl_val.value : e.cl_val, $.inArray(o, c) >= 0);
|
|
if (0 == c.length) switch (e.cl_relation)
|
|
{
|
|
case "is_empty":
|
|
return 0 === c.length || "" === c[0] || null === c[0];
|
|
case "is_not_empty":
|
|
return 0 !== c.length && "" !== c[0] && null !== c[0];
|
|
default:
|
|
return !1
|
|
}
|
|
if (e.cl_val && "stock_status" === e.cl_field) o = e.cl_val.value ? e.cl_val.value : e.cl_val;
|
|
else if (e.cl_val && "product_ids" === e.cl_field) o = (o = (e.cl_val.value ? e.cl_val.value : e.cl_val).split(/[ ,]+/)).map(function (e)
|
|
{
|
|
return parseInt(e, 10)
|
|
});
|
|
else if (e.cl_val && "quantity" === e.cl_field || "stock_quantity" === e.cl_field) o = parseInt(e.cl_val.value ? e.cl_val.value : e.cl_val);
|
|
else if (e.cl_val && "image-group" == i.data("type")) o = (e.cl_val.i ? e.cl_val.i : e.cl_val).toLowerCase();
|
|
else if (!e.cl_val || "date" != i.data("type") && "datetime-local" != i.data("type"))
|
|
if (e.cl_val && "time" == i.data("type"))
|
|
{
|
|
if ($.inArray(e.cl_relation, ["contains", "not_contains", "starts_with", "ends_with"]) >= 0) o = e.cl_val.toLowerCase();
|
|
else o = new Date("1/1/2018 " + e.cl_val).getTime()
|
|
}
|
|
else e.cl_val && "number" == i.data("type") ? o = parseFloat(e.cl_val.value ? e.cl_val.value : e.cl_val) : e.cl_val && (o = (e.cl_val.value ? e.cl_val.value : e.cl_val).toLowerCase());
|
|
else
|
|
{
|
|
if ($.inArray(e.cl_relation, ["contains", "not_contains", "starts_with", "ends_with"]) >= 0) o = e.cl_val.toLowerCase();
|
|
else o = wcpa_get_date_obj(e.cl_val).getTime()
|
|
}
|
|
switch (e.cl_relation)
|
|
{
|
|
case "is":
|
|
return $.inArray(o, c) >= 0;
|
|
case "is_not":
|
|
return !($.inArray(o, c) >= 0);
|
|
case "is_in":
|
|
return !!Array.isArray(o) && o.filter(function (e)
|
|
{
|
|
return $.inArray(e, c) >= 0
|
|
}).length > 0;
|
|
case "is_not_in":
|
|
return !!Array.isArray(o) && !(o.filter(function (e)
|
|
{
|
|
return $.inArray(e, c) >= 0
|
|
}).length > 0);
|
|
case "is_empty":
|
|
return 0 === c.length || "" === c[0] || null === c[0];
|
|
case "is_not_empty":
|
|
return 0 !== c.length && "" !== c[0] && null !== c[0];
|
|
case "is_greater":
|
|
for (var n = 0; n < c.length; n++)
|
|
if (parseFloat(c[n]) > parseFloat(o)) return !0;
|
|
return !1;
|
|
case "is_lessthan":
|
|
for (n = 0; n < c.length; n++)
|
|
if (parseFloat(c[n]) >= parseFloat(o)) return !1;
|
|
return !0;
|
|
case "is_greater_or_eqaul":
|
|
for (n = 0; n < c.length; n++)
|
|
if (parseFloat(c[n]) >= parseFloat(o)) return !0;
|
|
return !1;
|
|
case "is_lessthan_or_eqal":
|
|
for (n = 0; n < c.length; n++)
|
|
if (parseFloat(c[n]) > parseFloat(o)) return !1;
|
|
return !1;
|
|
case "contains":
|
|
for (n = 0; n < c.length; n++)
|
|
if (-1 !== c[n].indexOf(o)) return !0;
|
|
return !1;
|
|
case "not_contains":
|
|
for (n = 0; n < c.length; n++)
|
|
if (-1 !== c[n].indexOf(o)) return !1;
|
|
return !0;
|
|
case "starts_with":
|
|
for (n = 0; n < c.length; n++)
|
|
if (c[n].startsWith(o)) return !0;
|
|
return !1;
|
|
case "ends_with":
|
|
for (n = 0; n < c.length; n++)
|
|
if (c[n].endsWith(o)) return !0;
|
|
return !1;
|
|
case "date_is":
|
|
case "time_is":
|
|
return $.inArray(o, c) >= 0;
|
|
case "date_is_before":
|
|
case "time_is_before":
|
|
for (n = 0; n < c.length; n++)
|
|
if (parseFloat(c[n]) >= parseFloat(o)) return !1;
|
|
return !0;
|
|
case "date_is_after":
|
|
case "time_is_after":
|
|
for (n = 0; n < c.length; n++)
|
|
if (parseFloat(c[n]) > parseFloat(o)) return !0;
|
|
return !1
|
|
}
|
|
}
|
|
|
|
function iterate(e, a)
|
|
{
|
|
if (void 0 === a && (a = !0), a && $(".wcpa_form_item", e).data("wcpa_price", !1), e.data("wcpa_deps_counter", 0), wcpa_may_update_quantity(e), total_price = 0, total_fee = 0, $(".wcpa_has_price", e).each(function (a, t)
|
|
{
|
|
if (!($(this).parent().is(":visible") || $(this).parents(".wcpa_form_item").is(".wcpa_visible") || $(this).parents(".wcpa_form_item").is(".wcpa_visible_parent"))) return !0;
|
|
$(this).val();
|
|
if ($(this).is("select"))
|
|
{
|
|
$(this);
|
|
$(this).find("option").each(function ()
|
|
{
|
|
wcpa_update_price($(this), e.data("product"))
|
|
})
|
|
}
|
|
else wcpa_update_price($(this), e.data("product"))
|
|
}), e.data("wcpa_deps_counter") > 0) iterate(e, !1);
|
|
else
|
|
{
|
|
if ($(".wcpa_has_price", e).length)
|
|
{
|
|
var t = +e.data("product").wc_product_price,
|
|
r = +e.data("product").con_unit,
|
|
i = e.data("rules"),
|
|
c = parseInt(e.parents("form").find("input[name=quantity]").val());
|
|
if (i && !0 === i.pric_overide_base_price) var l = Math.max(t * r, total_price);
|
|
else if (i && !0 === i.pric_overide_base_price_if_gt_zero && total_price > 0) l = total_price;
|
|
else l = t * r + total_price;
|
|
wcpa_global_vars.change_price_as_quantity ? (e.next(".wcpa_price_summary").find(".wcpa_options_totals .price_value").text(wcpa_price((total_price - total_fee) * c + total_fee)), e.next(".wcpa_price_summary").find(".wcpa_product_totals .price_value").text(wcpa_price(t * c * r)), e.next(".wcpa_price_summary").find(".wcpa_totals .price_value").text(wcpa_price((l - total_fee) * c + total_fee))) : (e.next(".wcpa_price_summary").find(".wcpa_options_totals .price_value").text(wcpa_price(total_price)), e.next(".wcpa_price_summary").find(".wcpa_product_totals .price_value").text(wcpa_price(t * r)), e.next(".wcpa_price_summary").find(".wcpa_totals .price_value").text(wcpa_price(l < 0 ? 0 : l))), e.data("wcpa",
|
|
{
|
|
fee: total_fee,
|
|
price:
|
|
{
|
|
options: total_price,
|
|
product: t,
|
|
total: l
|
|
}
|
|
}), e.trigger("wcpa.price_updated")
|
|
}
|
|
if (wcpa_may_update_quantity(e), $(".wcpa_update_product_image", e).length)
|
|
{
|
|
var o = !1;
|
|
$($(".wcpa_update_product_image:checked", e).get().reverse()).each(function ()
|
|
{
|
|
if ($(this).parents(".wcpa_form_item").is(":visible") || $(this).parents(".wcpa_form_item").hasClass("wcpa_cl_visible")) return wcpa_product_image_update(e.parents("form"), $(this)), o = !0, !1
|
|
}), o || wcpa_product_image_update(e.parents("form"), !1)
|
|
}
|
|
}
|
|
}
|
|
|
|
function wcpa_may_update_quantity(e)
|
|
{
|
|
var a = $form_outer.data("rules");
|
|
if (a.bind_quantity)
|
|
{
|
|
var t = $("input[name=quantity]", $form_outer.parents("form"));
|
|
if (t.length)
|
|
{
|
|
t.attr("readonly", "readonly");
|
|
var r = calculate_price("custom", 1, a.quantity_bind_formula, 1, e, t),
|
|
i = t.val();
|
|
r > 0 ? t.val(r) : t.val(1), i != t.val() && t.trigger("change")
|
|
}
|
|
}
|
|
}
|
|
|
|
function wcpa_update_price(e, a)
|
|
{
|
|
var t = e.data("price"),
|
|
r = parseInt(e.parents("form").find("input[name=quantity]").val()),
|
|
i = 0,
|
|
c = 0;
|
|
if (!t) t = e.find(":selected").data("price");
|
|
t || (t = {
|
|
type: !1,
|
|
priceoptions: !1,
|
|
value: !1,
|
|
pricingType: !1,
|
|
taxpu: 1,
|
|
con_unit: 1,
|
|
is_show_price: !1
|
|
});
|
|
var l = e.val().trim();
|
|
$.inArray(t.type, ["radio-group", "checkbox-group", "image-group", "color-group"]) >= 0 && !e.is(":checked") && (l = !1), $.inArray(t.type, ["select"]) >= 0 && !e.is(":selected") && (l = !1), e.hasClass("wcpa_other") && $.inArray(t.type, ["radio-group", "checkbox-group", "image-group", "color-group"]) >= 0 && e.is(":checked") && (l = e.nextAll(".wcpa_other_val").val().trim()), $.inArray(t.type, ["paragraph", "header"]) >= 0 && (l = 1), $.inArray(t.type, ["file"]) >= 0 && "" == l && e.parents(".wcpa_form_item").find(".wcpa_file_hidden").length && "" !== e.parents(".wcpa_form_item").find(".wcpa_file_hidden").val() && (l = e.parents(".wcpa_form_item").find(".wcpa_file_hidden").val().split("||")[1]), i = calculate_price(t.pricingType, l, t.value, r, a, e, t), "custom" != t.pricingType && "percentage" != t.pricingType || t.taxpu && (i *= t.taxpu), t.con_unit && (i *= t.con_unit), void 0 !== t.is_show_price && 0 != t.is_show_price || (total_price += i);
|
|
var o = 1;
|
|
void 0 !== wcpa_global_vars.show_field_price_x_quantity && wcpa_global_vars.show_field_price_x_quantity && (o = r), void 0 !== t.is_fee && !0 === t.is_fee && (total_fee += i, o = 1), e.data("elem_price", i), e.is("option") ? (e.parent().find(":checked").each(function ()
|
|
{
|
|
c += $(this).data("elem_price") ? $(this).data("elem_price") : 0
|
|
}), e.parents(".wcpa_form_item").data("wcpa_price", c / (t.taxpu * t.con_unit)).find(".price_value").text(wcpa_price(c * o))) : "checkbox-group" == t.type ? (e.parents(".checkbox-group").find("input:checked").each(function ()
|
|
{
|
|
c += $(this).data("elem_price") ? $(this).data("elem_price") : 0
|
|
}), e.parents(".wcpa_form_item").data("wcpa_price", c / (t.taxpu * t.con_unit)).find(".price_value").text(wcpa_price(c * o))) : "radio-group" == t.type ? (e.parents(".radio-group ").find("input:checked").each(function ()
|
|
{
|
|
c += $(this).data("elem_price") ? $(this).data("elem_price") : 0
|
|
}), e.parents(".wcpa_form_item").data("wcpa_price", c / (t.taxpu * t.con_unit)).find(".price_value").text(wcpa_price(c * o))) : "image-group" == t.type ? (e.parents(".image-group ").find("input:checked").each(function ()
|
|
{
|
|
c += $(this).data("elem_price") ? $(this).data("elem_price") : 0
|
|
}), e.parents(".wcpa_form_item").data("wcpa_price", c / (t.taxpu * t.con_unit)).find(".price_value").text(wcpa_price(c * o))) : "color-group" == t.type ? (e.parents(".color-group ").find("input:checked").each(function ()
|
|
{
|
|
c += $(this).data("elem_price") ? $(this).data("elem_price") : 0
|
|
}), e.parents(".wcpa_form_item").data("wcpa_price", c / (t.taxpu * t.con_unit)).find(".price_value").text(wcpa_price(c * o))) : e.parents(".wcpa_form_item").data("wcpa_price", i / (t.taxpu * t.con_unit)).find(".price_value").text(wcpa_price(i * o))
|
|
}
|
|
|
|
function calculate_price(pricingType, value, price, quantity, $product_data, $ele, element_data)
|
|
{
|
|
if (void 0 === element_data) var element_data = {};
|
|
"custom" !== pricingType && (null !== price && !1 !== price && "string" == typeof price && (price = parseFloat(price.replace(wcpa_global_vars.wc_decimal_sep, "."))), isNaN(price) && (price = 0));
|
|
var elem_price = 0;
|
|
switch (pricingType)
|
|
{
|
|
case "fixed":
|
|
elem_price = value ? +price : 0;
|
|
break;
|
|
case "per_car":
|
|
var value_filtered = value;
|
|
if (void 0 !== element_data.excl_chars_frm_length && element_data.excl_chars_frm_length.length > 0)
|
|
if (void 0 !== element_data.excl_chars_frm_length_is_regex && element_data.excl_chars_frm_length_is_regex)
|
|
{
|
|
var exclude_chars = element_data.excl_chars_frm_length,
|
|
re = regExpFromString(exclude_chars, "gi");
|
|
value_filtered = value_filtered.replace(re, "")
|
|
}
|
|
else
|
|
{
|
|
var exclude_chars = element_data.excl_chars_frm_length.replace(/\\s/g, " ");
|
|
exclude_chars = exclude_chars.split("").map(function (e)
|
|
{
|
|
if (" " == e)
|
|
{
|
|
var a = new RegExp("\\s", "g");
|
|
value_filtered = value_filtered.replace(a, "")
|
|
}
|
|
else if ("." == e) value_filtered = value_filtered.replace(/\./, "");
|
|
else
|
|
{
|
|
a = new RegExp(e, "g");
|
|
value_filtered = value_filtered.replace(a, "")
|
|
}
|
|
return e
|
|
})
|
|
}
|
|
elem_price = value_filtered.length * price;
|
|
break;
|
|
case "multiply":
|
|
elem_price = value ? +price * (isNaN(value) ? 1 : value) : 0, elem_price < 0 && (elem_price = 0);
|
|
break;
|
|
case "custom":
|
|
if (!1 !== value && "" !== value && null !== value)
|
|
{
|
|
if ($ele_outer = $ele.parents(".wcpa_form_item"), "function" == typeof moment) var today = {
|
|
seconds: moment().unix()
|
|
};
|
|
else var today = {
|
|
seconds: wcpa_global_vars.today.seconds
|
|
};
|
|
var formula = price.replace(/{this.value}/g, value).replace(/{value}/g, value).replace(/{quantity}/g, quantity).replace(/{this.value.length}/g, value.length).replace(/{value.length}/g, value.length).replace(/{product_price}/g, $product_data.wc_product_price).replace(/{days}/g, date_data_from_field("days", $ele_outer)).replace(/{seconds}/g, date_data_from_field("seconds", $ele_outer)).replace(/{timestamp}/g, date_data_from_field("timestamp", $ele_outer)).replace(/{today.days}/g, wcpa_global_vars.today.days).replace(/{today.seconds}/g, today.seconds).replace(/{this.count}/g, get_data_from_field("count", $ele));
|
|
if (formula.match(/\{(\s)*?wcpa_pcf_([^}]*)}/))
|
|
{
|
|
var cf_matches = formula.match(/\{(\s)*?wcpa_pcf_([^}]*)}/g);
|
|
for (var i in cf_matches)
|
|
{
|
|
var mat = cf_matches[i].match(/\{(\s)*?([^}]*)}/);
|
|
if (void 0 !== mat[2] && "string" == typeof mat[2] && void 0 !== $product_data.product_cfs[mat[2].trim()])
|
|
{
|
|
var myReg = new RegExp(mat[0]);
|
|
formula = formula.replace(myReg, $product_data.product_cfs[mat[2].trim()])
|
|
}
|
|
else
|
|
{
|
|
var myReg = new RegExp(mat[0]);
|
|
formula = formula.replace(myReg, 0)
|
|
}
|
|
}
|
|
}
|
|
if (formula.match(/\{(\s)*?field\.([^}]*)}/))
|
|
{
|
|
var matches = formula.match(/\{(\s)*?field\.([^}]*)}/g);
|
|
for (var i in matches)
|
|
{
|
|
var mat = matches[i].match(/\{(\s)*?field\.([^}]*)}/);
|
|
if (void 0 !== mat[2] && "string" == typeof mat[2])
|
|
{
|
|
var ele = mat[2].split(".");
|
|
if (ele.length > 1 && $.inArray(ele[1], ["value", "price", "count", "days", "seconds", "timestamp"]) >= 0)
|
|
{
|
|
var $ele = $("#" + ele[0]);
|
|
if ($ele.length)
|
|
{
|
|
var val = 0;
|
|
if ($ele.is(":visible") || "hidden" == $ele.data("type")) switch (ele[1])
|
|
{
|
|
case "price":
|
|
if ($ele.find(".wcpa_has_price").length)
|
|
{
|
|
if (void 0 === $ele.data("wcpa_price") || !1 === $ele.data("wcpa_price"))
|
|
{
|
|
elem_price = 0;
|
|
var wcpa_deps_counter = $ele.parents(".wcpa_form_outer").data("wcpa_deps_counter");
|
|
return wcpa_deps_counter = void 0 === wcpa_deps_counter ? 0 : wcpa_deps_counter, wcpa_deps_counter += 1, $ele.parents(".wcpa_form_outer").data("wcpa_deps_counter", wcpa_deps_counter), elem_price
|
|
}
|
|
val = $ele.data("wcpa_price")
|
|
}
|
|
break;
|
|
case "value":
|
|
switch ($ele.data("type"))
|
|
{
|
|
case "select":
|
|
val = $ele.find("select").val() ? $ele.find("select").val() : 0;
|
|
break;
|
|
case "textarea":
|
|
val = $ele.find("textarea").val() ? $ele.find("textarea").val() : 0;
|
|
break;
|
|
case "checkbox-group":
|
|
case "radio-group":
|
|
case "color-group":
|
|
case "image-group":
|
|
val = 0, $ele.find("input:checked").length ? 1 == $ele.find("input:checked").length ? isNaN($ele.find("input:checked").val()) ? val = $ele.find("input:checked").val() : val += parseFloat($ele.find("input:checked").val()) : $ele.find("input:checked").each(function (e)
|
|
{
|
|
if (isNaN($(this).val()))
|
|
{
|
|
if (0 == e) return val = $(this).val(), !1
|
|
}
|
|
else val += parseFloat($(this).val())
|
|
}) : val = 0;
|
|
break;
|
|
default:
|
|
val = $ele.find("input").val() ? $ele.find("input").val() : 0
|
|
}
|
|
if (void 0 !== ele[2]) switch (ele[2])
|
|
{
|
|
case "length":
|
|
val = val.length
|
|
}
|
|
break;
|
|
case "count":
|
|
switch ($ele.data("type"))
|
|
{
|
|
case "select":
|
|
val = $ele.find("select").val() ? 1 : 0;
|
|
break;
|
|
case "textarea":
|
|
val = $ele.find("textarea").val() ? 1 : 0;
|
|
break;
|
|
case "checkbox-group":
|
|
case "radio-group":
|
|
case "color-group":
|
|
case "image-group":
|
|
val = 0, val = $ele.find("input:checked").length ? 1 == $ele.find("input:checked").length ? 1 : $ele.find("input:checked").length : 0;
|
|
break;
|
|
default:
|
|
val = $ele.find("input").val() ? 1 : 0
|
|
}
|
|
break;
|
|
case "days":
|
|
case "seconds":
|
|
case "timestamp":
|
|
switch ($ele.data("type"))
|
|
{
|
|
case "date":
|
|
case "datetime-local":
|
|
val = date_data_from_field(ele[1], $ele);
|
|
break;
|
|
default:
|
|
val = 0
|
|
}
|
|
}
|
|
}
|
|
else var val = 0;
|
|
var myReg = new RegExp(mat[0]);
|
|
formula = isNaN(val) ? formula.replace(myReg, "'" + val + "'") : formula.replace(myReg, val)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
try
|
|
{
|
|
elem_price = eval(formula)
|
|
}
|
|
catch (e)
|
|
{
|
|
elem_price = 0
|
|
}
|
|
}
|
|
else elem_price = 0;
|
|
break;
|
|
case "percentage":
|
|
elem_price = value ? price * $product_data.wc_product_price / 100 : 0
|
|
}
|
|
return elem_price
|
|
}
|
|
|
|
function wcpa_get_date_obj(e, a)
|
|
{
|
|
return a = void 0 !== a && a, "function" == typeof moment ? "wp" == a ? moment(e, wcpa_global_vars.date_format_js + " " + wcpa_global_vars.time_format_js).toDate() : !1 !== a ? moment(e, a).toDate() : moment(e).toDate() : new Date(e)
|
|
}
|
|
|
|
function date_data_from_field(e, a)
|
|
{
|
|
var t = 0;
|
|
switch (a.data("type"))
|
|
{
|
|
case "date":
|
|
case "datetime-local":
|
|
case "time":
|
|
if ("days" == e) t = "function" != typeof (r = wcpa_get_date_obj(a.find("input").val(), "wp")).getTime || isNaN(r.getTime()) ? 0 : (r.getTime() - new Date("1970/01/01").getTime()) / 864e5;
|
|
else if ("timestamp" == e || "seconds" == e)
|
|
{
|
|
var r;
|
|
t = "function" != typeof (r = wcpa_get_date_obj(a.find("input").val(), "wp")).getTime || isNaN(r.getTime()) ? 0 : (r.getTime() - new Date("1970/01/01").getTime()) / 1e3
|
|
}
|
|
break;
|
|
default:
|
|
t = 0
|
|
}
|
|
return t
|
|
}
|
|
|
|
function get_data_from_field(e, a)
|
|
{
|
|
switch ($ele_outer = a.parents(".wcpa_form_item"), val = 0, $ele_outer.data("type"))
|
|
{
|
|
case "select":
|
|
"count" == e && (val = $ele_outer.find("select").val() ? 1 : 0);
|
|
break;
|
|
case "textarea":
|
|
"count" == e && (val = a.val() ? 1 : 0);
|
|
break;
|
|
case "checkbox-group":
|
|
case "radio-group":
|
|
case "color-group":
|
|
case "image-group":
|
|
"count" == e && (val = 0, $ele_outer.find("input:checked").length ? 1 == $ele_outer.find("input:checked").length ? val = 1 : val = $ele_outer.find("input:checked").length : val = 0);
|
|
break;
|
|
default:
|
|
"count" == e && (val = $ele_outer.find("input").val() ? 1 : 0)
|
|
}
|
|
return val
|
|
}
|
|
|
|
function preview_image()
|
|
{
|
|
jQuery(".wcpa_type_image-group .wcpa_image .wcpa_img_mag").on("click", function (e)
|
|
{
|
|
var a = $(this).parents(".wcpa_image").find("label").text(),
|
|
t = a || "";
|
|
jQuery("body").append("<div id='wcpa_img_popup_outer'><div class='wcpa_img_popup'><img src='" + $(this).attr("data-src") + "' alt='Image preview' />" + t + "</div></div>"), jQuery("#wcpa_img_popup_outer").fadeIn("fast").on("click", function ()
|
|
{
|
|
$(this).fadeOut("fast").remove()
|
|
})
|
|
}), jQuery(".wcpa_img_preview .wcpa_image img,.wcpa_cart_img_preview img").hover(function (e)
|
|
{
|
|
var a = $(this).parent(".wcpa_image").find("label").text(),
|
|
t = a || "";
|
|
jQuery("body").append("<div id='wcpa_img_preview'><img src='" + $(this).attr("src") + "' alt='Image preview' />" + t + "</div>"), jQuery("#wcpa_img_preview").css("top", e.pageY - 10 + "px").css("left", e.pageX - 30 - jQuery("#wcpa_img_preview").width() + "px").fadeIn("fast")
|
|
}, function ()
|
|
{
|
|
jQuery("#wcpa_img_preview").remove()
|
|
}), jQuery(".wcpa_img_preview .wcpa_image img,.wcpa_cart_img_preview img").mousemove(function (e)
|
|
{
|
|
var a = $(window).scrollTop() + $(window).height(),
|
|
t = e.pageY + jQuery("#wcpa_img_preview").height(),
|
|
r = e.pageY - jQuery("#wcpa_img_preview").height();
|
|
if ($(window).scrollTop() - r < t - a) var i = e.pageY - 10 - jQuery("#wcpa_img_preview").height();
|
|
else i = e.pageY + 10;
|
|
if (e.pageX - jQuery("#wcpa_img_preview").width() < 0 && $(window).width() - (e.pageX + jQuery("#wcpa_img_preview").width()) > e.pageX - jQuery("#wcpa_img_preview").width()) var c = e.pageX + 30;
|
|
else c = e.pageX - 30 - jQuery("#wcpa_img_preview").width();
|
|
jQuery("#wcpa_img_preview").css("top", i + "px").css("left", c + "px")
|
|
})
|
|
}
|
|
$.wcpaInit = function ()
|
|
{
|
|
preview_image(), $(".cart_item.wcpa_bind_quantity.wcpa_cart_has_fields .quantity .qty").attr("readonly", "readonly"), $(".wcpa_form_outer").each(function ()
|
|
{
|
|
if ($form_outer = $(this), void 0 !== $form_outer.data("wcpa")) return !0;
|
|
("undefined" != typeof wcpa_global_vars && ($(".wcpa_datepicker", $form_outer).length && $(".wcpa_datepicker", $form_outer).each(function ()
|
|
{
|
|
var e = $(this).data("dpconf");
|
|
null == e && (e = {}), $(this).datetimepicker($.extend(
|
|
{
|
|
timepicker: !1,
|
|
validateOnBlur: !1,
|
|
scrollInput: !1,
|
|
dayOfWeekStart: wcpa_global_vars.start_of_week,
|
|
format: wcpa_global_vars.date_format
|
|
}, e))
|
|
}), $(".wcpa_datetimepicker", $form_outer).length && $(".wcpa_datetimepicker", $form_outer).each(function ()
|
|
{
|
|
var e = $(this).data("dpconf");
|
|
null == e && (e = {}), $(this).datetimepicker($.extend(
|
|
{
|
|
format: wcpa_global_vars.date_format + " " + wcpa_global_vars.time_format,
|
|
validateOnBlur: !1,
|
|
dayOfWeekStart: wcpa_global_vars.start_of_week,
|
|
scrollInput: !1,
|
|
step: 15
|
|
}, e))
|
|
}), $(".wcpa_timepicker", $form_outer).length && $(".wcpa_timepicker", $form_outer).each(function ()
|
|
{
|
|
var e = $(this).data("dpconf");
|
|
null == e && (e = {}), $(this).datetimepicker($.extend(
|
|
{
|
|
datepicker: !1,
|
|
format: wcpa_global_vars.time_format,
|
|
validateOnBlur: !1,
|
|
scrollInput: !1,
|
|
step: 15
|
|
}, e))
|
|
}), $(".wcpa_colorpicker", $form_outer).length && $(".wcpa_colorpicker", $form_outer).spectrum(
|
|
{
|
|
preferredFormat: "hex",
|
|
showInput: !0,
|
|
allowEmpty: !0
|
|
}), void 0 !== $.datetimepicker && "" !== document.documentElement.lang && $.datetimepicker.setLocale(document.documentElement.lang.substring(0, 2))), $(".wcpa_type_checkbox-group .wcpa_has_val_rules input,\n .wcpa_type_radio-group .wcpa_has_val_rules input,\n .wcpa_type_image-group .wcpa_has_val_rules input,\n \n .wcpa_type_color-group .wcpa_has_val_rules input", $form_outer).on("change", function ()
|
|
{
|
|
$item = $(this).parents(".wcpa_has_val_rules"), $rules = $item.data("val_rules"), void 0 !== $rules.selection && void 0 !== $rules.selection.min && $rules.selection.min > 0 && $("input[type=checkbox]:checked", $item).length <= $rules.selection.min && wcpa_remove_val_error($item), void 0 !== $rules.selection && void 0 !== $rules.selection.max && $rules.selection.max > 0 && $("input[type=checkbox]:checked", $item).length > $rules.selection.max && (wcpa_show_val_error($item, wcpa_global_vars.strings.sel_max_req_error.replace("%d", $rules.selection.max)), $(this).prop("checked", !1))
|
|
}), $form_outer.parents("form").on("submit", function (e)
|
|
{
|
|
var a = !0;
|
|
if ($(".wcpa_datepicker", $(this)).each(function ()
|
|
{
|
|
-1 !== $(this).val().indexOf("__") && "required" == $(this).attr("required") && (wcpa_show_val_error($(this), wcpa_global_vars.strings.field_is_requied), a = !1)
|
|
}), $(".wcpa_has_val_rules", $(this)).each(function ()
|
|
{
|
|
$item = $(this), $rules = $item.data("val_rules"), void 0 !== $rules.selection && void 0 !== $rules.selection.max && $rules.selection.max > 0 && $("input[type=checkbox]:checked", $item).length > $rules.selection.max && (wcpa_show_val_error($item, wcpa_global_vars.strings.sel_max_req_error.replace("%d", $rules.selection.max)), a = !1), void 0 !== $rules.selection && void 0 !== $rules.selection.min && $rules.selection.min > 0 && $("input[type=checkbox]:checked", $item).length < $rules.selection.min && (wcpa_show_val_error($item, wcpa_global_vars.strings.sel_min_req_error.replace("%d", $rules.selection.min)), a = !1)
|
|
}), 0 == a) return e.preventDefault(), alert(wcpa_global_vars.strings.fix_val_errors), !1
|
|
}), $(".wcpa_type_checkbox-group .wcpa_required input,\n .wcpa_type_radio-group .wcpa_required input,\n .wcpa_type_image-group .wcpa_required input,\n \n .wcpa_type_color-group .wcpa_required input", $form_outer).on("change", function ()
|
|
{
|
|
var e = $(this).parents(".wcpa_form_item");
|
|
$(".wcpa_required input[type=checkbox]", e).length ? 0 != $(".wcpa_required input[type=checkbox]:checked", e).not(".wcpa_other").length || 0 != $(".wcpa_required .wcpa_other_val", e).length && "" != $(".wcpa_required .wcpa_other_val", e).val() ? $(".wcpa_required input[type=checkbox]:first", e).removeAttr("required") : $(".wcpa_required input[type=checkbox]:first", e).attr("required", "required") : $(".wcpa_required input[type=radio]", e).length && (0 != $(".wcpa_required input[type=radio]:checked", e).not(".wcpa_other").length || 0 != $(".wcpa_required .wcpa_other_val", e).length && "" != $(".wcpa_required .wcpa_other_val", e).val() ? ($(".wcpa_required input[type=radio]:first", e).removeAttr("required"), $(".wcpa_required .wcpa_other_val", e).removeAttr("required")) : ($(".wcpa_required input[type=radio]:first", e).attr("required", "required"), $(".wcpa_required input[type=radio].wcpa_other", e).is(":checked") && $(".wcpa_required .wcpa_other_val", e).attr("required", "required")))
|
|
}), $(".wcpa_file_custom", $form_outer).on("keyup change", function ()
|
|
{
|
|
wcpa_upload_file($(this))
|
|
}), $(".wcpa_allowed_chars", $form_outer).on("keyup change", function ()
|
|
{
|
|
for (var e = jQuery(this).val(), a = "", t = regExpFromString($(this).data("validation").allowed_chars, "i"), r = "", i = 0; i < e.length; i++)
|
|
if (t.test(e.charAt(i))) a += e.charAt(i);
|
|
else
|
|
{
|
|
r += e.charAt(i);
|
|
var c = wcpa_global_vars.strings.character_not_valid.replace("%s", r);
|
|
"undefined" != typeof $error_ele && $error_ele.remove(), $error_ele = $('<div class="wcpa_error_msg"><p>' + c + "</p></div>").insertAfter($(this)), setTimeout(function ()
|
|
{
|
|
$error_ele.fadeOut(1e3, function ()
|
|
{
|
|
jQuery(this).remove()
|
|
})
|
|
}, 1500)
|
|
}
|
|
jQuery(this).val(a)
|
|
}), $(".image-group .wcpa_image img", $form_outer).on("click", function ()
|
|
{
|
|
var e = $("#" + $(this).attr("attrfor"));
|
|
e.prop("checked", !e.prop("checked")), e.trigger("change")
|
|
}), $(".color-group .wcpa_color label", $form_outer).on("click", function ()
|
|
{
|
|
var e = $("#" + $(this).attr("for")),
|
|
a = e.prop("checked");
|
|
setTimeout(function ()
|
|
{
|
|
a && (e.prop("checked", !1), e.trigger("change"))
|
|
}, 0), e.trigger("change")
|
|
}), $(".wcpa_other_val", $form_outer).on("keyup change", function ()
|
|
{
|
|
$.trim($(this).val()).length > 0 ? $(this).siblings(".wcpa_other").val("WCPAOTH " + $(this).val()) : $(this).siblings(".wcpa_other").val("")
|
|
}), "undefined" != typeof wcpa_global_vars && $form_outer.data("product").is_variable) && ($form_outer.parents("form").find(".single_variation_wrap").on("show_variation", function (e, a)
|
|
{
|
|
var t = $form_outer.data("product");
|
|
t.wc_product_price = a.display_price, t.stock_status = a.stock_status, t.stock_quantity = a.stock_quantity, $form_outer.data("product", t), iterate($form_outer)
|
|
}), $form_outer.parents("form").on("reset_data", function (e)
|
|
{
|
|
var a = $form_outer.data("product");
|
|
a.wc_product_price = a.wc_product_price_default, $form_outer.data("product", a), iterate($form_outer)
|
|
}), $form_outer.parents("form").on("reset_image", function (e)
|
|
{
|
|
setTimeout(function ()
|
|
{
|
|
iterate($form_outer)
|
|
}, 0)
|
|
}), $form_outer.parents("form").on("woocommerce_variation_has_changed", function (e)
|
|
{
|
|
var a = $(this).find(".wcpa_form_outer"),
|
|
t = a.data("attrrelated");
|
|
null != t && t.forEach(function (e)
|
|
{
|
|
exc_relations(e, a)
|
|
})
|
|
}));
|
|
if ($(".wcpa_has_price,.wcpa_has_price ~ .wcpa_other_val,.wcpa_has_price_related input,.wcpa_has_price_related select,.wcpa_has_price_related textarea", $form_outer).on("keyup change", function ()
|
|
{
|
|
iterate($(this).parents(".wcpa_form_outer"))
|
|
var price = jQuery(this).closest(".wcpa_form_item").find(".wcpa_priceouter.text").html();
|
|
if(price != 'Dopłata:<span class="wcpa_price"><span class="price_value">0.00</span><span class="woocommerce-Price-currencySymbol">zł</span></span>') {
|
|
jQuery(this).closest(".wcpa_form_item").find(".wcpa_priceouter.text").show();
|
|
} else {
|
|
jQuery(this).closest(".wcpa_form_item").find(".wcpa_priceouter.text").hide();
|
|
}
|
|
}), $(".wcpa_update_product_image", $form_outer).on("keyup change", function ()
|
|
{
|
|
iterate($(this).parents(".wcpa_form_outer"))
|
|
}), $("input[name=quantity]", $form_outer.parents("form")).length)
|
|
{
|
|
var e = $form_outer.data("qntyrelated");
|
|
null != e && e.forEach(function (e)
|
|
{
|
|
exc_relations(e, $form_outer)
|
|
})
|
|
}
|
|
$("input[name=quantity]", $form_outer.parents("form")).on("keyup change", function ()
|
|
{
|
|
var e = $form_outer.data("qntyrelated");
|
|
null != e && e.forEach(function (e)
|
|
{
|
|
exc_relations(e, $form_outer)
|
|
}), iterate($form_outer)
|
|
}), $(".wcpa_has_relation input,.wcpa_has_relation select,.wcpa_has_relation textarea", $form_outer).on("keyup change", function ()
|
|
{
|
|
var e = $(this).parents(".wcpa_form_outer"),
|
|
a = $(this).parents(".wcpa_has_relation").data("related");
|
|
null != a && a.forEach(function (a)
|
|
{
|
|
exc_relations(a, e)
|
|
})
|
|
}), $(".wcpa_has_relation", $form_outer).each(function ()
|
|
{
|
|
var e = $(this).data("related");
|
|
null != e && e.forEach(function (e)
|
|
{
|
|
exc_relations(e, $form_outer)
|
|
})
|
|
}), $form_outer.data("wcpa",
|
|
{}), iterate($form_outer);
|
|
var a = $form_outer.data("attrrelated");
|
|
null != a && a.forEach(function (e)
|
|
{
|
|
exc_relations(e, $form_outer)
|
|
}), $(".variations_form .variations").length && setTimeout(function ()
|
|
{
|
|
$(".variations_form .variations select").trigger("change")
|
|
}, 0), wcpa_may_update_quantity($form_outer)
|
|
})
|
|
}, $(document).ready(function ()
|
|
{
|
|
$.wcpaInit()
|
|
}), $.wcpaIterate = function ()
|
|
{
|
|
$(".wcpa_form_outer").each(function ()
|
|
{
|
|
iterate($(this))
|
|
})
|
|
}
|
|
}(jQuery), wcpa_global_vars.wcpa_init_triggers.length && jQuery(document).on(wcpa_global_vars.wcpa_init_triggers.join(" "), function ()
|
|
{
|
|
jQuery.wcpaInit()
|
|
});
|