jQuery(document).ready(function ($) { // Betöltés az adatbázisból $.ajax({ url: ajax_object.ajax_url, method: "POST", data: { action: "get_heart_toggle_state", post_id: ajax_object.post_id, _ajax_nonce: ajax_object.nonce, }, success: function (response) { if (response.success) { var isChecked = response.data; $("#heart_enabled_field") .prop("checked", isChecked) .closest(".components-form-toggle") .toggleClass("is-checked", isChecked); } }, }); // Mentés az adatbázisba $("#heart_enabled_field").on("change", function () { var isChecked = $(this).is(":checked"); $(this) .closest(".components-form-toggle") .toggleClass("is-checked", isChecked); $.ajax({ url: ajax_object.ajax_url, method: "POST", data: { action: "save_heart_toggle_state", state: isChecked, post_id: ajax_object.post_id, _ajax_nonce: ajax_object.nonce, }, }); }); }); /* jQuery(document).ready(function($) { $('#heart_enabled_field').on('change', function() { if ($(this).is(':checked')) { $(this).closest('.components-form-toggle').addClass('is-checked'); } else { $(this).closest('.components-form-toggle').removeClass('is-checked'); } }); }); */