RP_Rave1_theme/template-parts/achievement.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-11-06 10:10:48 +00:00
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');
}
});
}); */