Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
home
/
getwphos
/
www
/
shellfish
/
wp-content
/
plugins
/
dealership
/
assets
/
js
/
File Content:
dealership.js
(function($,window){ "use strict"; $(function () { /* Enable or disable taxonomy */ var _ap_enable_disable_options = function($f_name, $f_value){ if(!$f_value || !$f_value.length){ $("form#dealership_my-account-add-product [data-field_type=taxonomy] [data-associate-from=" + $f_name+"]").prop("disabled", true); return; } var __ap_set_enable_disable_option = function($_f_value, $_disabled = true){ var __f_option = $("form#dealership_my-account-add-product [data-field_type=taxonomy] [data-associate-from=" + $f_name+"][data-associate~=" + $_f_value+"]"); var __main = $("form#dealership_my-account-add-product [data-field_type=taxonomy] [data-associate-from=" + $f_name+"]").closest(".field_type-taxonomy"); if(__f_option.length) { __main.find("[data-associate-from=" + $f_name + "]:not([data-associate~=" + $_f_value + "])").prop("disabled", true); __f_option.prop("disabled", false); }else{ __main.find("[data-associate-from="+ $f_name+"]").prop("disabled", true); if(__main.find("select").length){ __main.find("select").val(""); } } }; if(typeof $f_value === "object"){ var __main = $("form#dealership_my-account-add-product [data-field_type=taxonomy] [data-associate-from=" + $f_name+"]").closest(".field_type-taxonomy"); __main.find("[data-associate-from="+ $f_name+"]").prop("disabled", true); $.each($f_value, function(index, f_val){ __ap_set_enable_disable_option(f_val, false); }); }else{ __ap_set_enable_disable_option($f_value); } }; /* Ajax function to get metabox with acf fields */ var _ap_product_ajax = function($obj, $branch_slug){ if(typeof $obj === "undefined" || !$obj.length){ return; } $branch_slug = typeof $branch_slug !== "undefined"?$branch_slug:$obj.val(); if(typeof $branch_slug === "undefined" || !$branch_slug){ return; } var __ajax_loaded = false, __ajax_data = { "action": "dealership_load_custom_fields", "branch_slug": $branch_slug, // "post_type": "ap_product", }; if(typeof ap_product.post_id !== "undefined") { __ajax_data.post_id = ap_product.post_id; } if(typeof ap_product.custom_fields.nonce !== "undefined") { __ajax_data.nonce = ap_product.custom_fields.nonce; } $obj.data("__ajax_loaded", __ajax_loaded); if(!__ajax_loaded) { var _main_id = $("#dealership_my-account-add-product .dls-postboxes"); /* Insert loading after branch option */ if(!_main_id.find(">.dls-loading:first").length) { _main_id.prepend("<div class='uk-margin-small-top uk-flex uk-flex-center dls-loading' data-uk-spinner></div>"); } if(typeof $obj !== "undefined" && !$obj.next(".dls-loading").length) { $obj.after("<div class='uk-margin-small-top uk-flex uk-flex-center dls-loading' data-uk-spinner></div>"); } $.post(dealership.ajaxurl, __ajax_data, function (response) { var _html = response.data; _main_id.find("> .ap-acf_postbox-ajax").remove(); var __postbox = $(_html); __postbox.addClass("ap-acf_postbox-ajax"); if(_main_id.find("> .postbox.acf_postbox:not(.ap-acf_postbox-ajax)").length){ _main_id.find("> .postbox.acf_postbox:not(.ap-acf_postbox-ajax):last").after(__postbox); }else { _main_id.append(__postbox); } // // Reinitialize the editor: Remove the editor then add it back // if(_main_id.find(".acf_wysiwyg textarea").length) { // _main_id.find(".acf_wysiwyg textarea").each(function () { // var __textarea_id = $(this).attr("id"); // // $(this).closest(".uk-accordion-content").removeAttr("hidden"); // // // Reinitialize the editor: Remove the editor then add it back // tinymce.execCommand('mceRemoveEditor', false, __textarea_id); // tinymce.execCommand('mceAddEditor', false, __textarea_id); // // tinymce.execCommand('mceFocus', false, __textarea_id); // // tinymce.get(__textarea_id).setContent("Test"); // // tinymce.execCommand('mce-edit-focus', false, __textarea_id); // }); // } UIkit.util.on('[data-uk-accordion]', 'shown', function (event) { // do something $(event.target).find(".acf_wysiwyg textarea").each(function () { var __textarea_id = $(this).attr("id"); // Reinitialize the editor: Remove the editor then add it back tinymce.execCommand('mceRemoveEditor', false, __textarea_id); tinymce.execCommand('mceAddEditor', false, __textarea_id); }); }); if(typeof $obj !== "undefined" && $obj.next(".dls-loading").length){ $obj.next(".dls-loading").remove(); } if(_main_id.find(">.dls-loading:first").length) { _main_id.find(">.dls-loading:first").remove(); } __ajax_loaded = true; $obj.data("__ajax_loaded", __ajax_loaded); $obj.trigger("dealership/product/custom_field/ajax_completed", $(_main_id)); }, 'json'); } }; // Disable trigger valid postbox group of acf $(document).off("acf/update_field_groups"); $(document).on("change","#acf-field-ap_branch", function (e) { e.preventDefault(); _ap_product_ajax($(this)); }); _ap_product_ajax($("#acf-field-ap_branch")); var _dealership_custom_field_associate = function($mainObj) { $mainObj.find("[data-field_type=taxonomy]").each(function () { var __f = $(this), __f_name = $(this).attr("data-field_name"), __f_key = $(this).attr("data-field_key"), __f_control = $(this).find("#acf-field-" + __f_name); if (!__f_control.length) { __f_control = $(this).find("[name^=fields\\\[" + __f_key + "\\\]]"); } if (__f_control.length) { $.each(__f_control, function () { var __f_value = typeof $(this).val() !== "undefined" ? $(this).val() : ""; if (typeof $(this).prop("checked") !== "undefined" && !$(this).prop("checked")) { __f_value = ""; } _ap_enable_disable_options(__f_name, __f_value); }); } __f_control.off("change").on("change", function () { var __f_value = $(this).val(); if (!__f_value.length) { return; } if (typeof $(this).prop("checked") !== "undefined" && !$(this).prop("checked")) { __f_value = ""; } _ap_enable_disable_options(__f_name, __f_value); }); }); }; _dealership_custom_field_associate($("form#dealership_my-account-add-product")); $(document).on("dealership/product/custom_field/ajax_completed", "#acf-field-ap_branch", function(event, $resultObj){ _dealership_custom_field_associate($($resultObj)); }); $(window).load(function(){ setTimeout(function(){ // setup fields $(document).trigger('acf/setup_fields', [ $('.templaza-add-product') ]); }); }); }); })(jQuery, window);
Submit
FILE
FOLDER
Name
Size
Permission
Action
dealership.js
9046 bytes
0644
validation.js
7595 bytes
0644
N4ST4R_ID | Naxtarrr