jQuery(function( $ ) { var nume_variabila_local_storage_anunturi = "afl-favorite-anunturi"; var data_curenta = "2025-09-24"; var element_anunturi = localStorage.getItem(nume_variabila_local_storage_anunturi); //preluare id favorite din local storage var arr_anunturi = []; if (element_anunturi) { arr_anunturi = element_anunturi.split(';'); //vector cu anunturi favorite } var save_anunturi = ''; function show_fav() { $("span.star_selected").each(function() { //resetare anunturi care au star_selected (sunt selectate) $(this).removeClass('star_selected'); }); $("span.default_star").each(function() { //adaugare anunturi //alert($(this).attr('element')); if (arr_anunturi.indexOf($(this).attr('element'))>-1) { //alert($(this).attr('element')); $(this).addClass('star_selected'); } }); } $(document).ready(function() { show_fav(); //punere stelute la anunturi favorite $("span.default_star").click(function() { var element_id = $(this).attr('element'); if ($(this).hasClass('star_selected')) { //element selectat - se scoate din localStorage arr_anunturi.splice(arr_anunturi.indexOf(element_id),1); //scoatem element_id din lista de id-uri save_anunturi = arr_anunturi.join(';'); //alert(save_anunturi); localStorage.setItem(nume_variabila_local_storage_anunturi,save_anunturi); localStorage.setItem("Date_"+nume_variabila_local_storage_anunturi, data_curenta); $(this).removeClass('star_selected'); } else { //element neselectat - se adauga in localStorage arr_anunturi.push(element_id); //adaugam element_id in lista de id-uri save_anunturi = arr_anunturi.join(';'); //alert(save_anunturi); localStorage.setItem(nume_variabila_local_storage_anunturi,save_anunturi); localStorage.setItem("Date_"+nume_variabila_local_storage_anunturi, data_curenta); $(this).addClass('star_selected'); } var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log("Am setat in baza de date element_anunturiul"); console.log("Data pentru element_anunturi : " + data_curenta); } } var data_anunturi = "save_anunturi=1&save_fav_anunturi="+save_anunturi; xhttp.open("POST", "https://afacerilemn.ro/bw_skins/skin1/__general_components/js/actualizare_baza_date_favorite.php", true); xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhttp.send(data_anunturi); }); $("span.salveaza_anunt").click(function() { var element_id = $(this).attr('element'); if (arr_anunturi.indexOf(element_id)>-1) { //elementul este deja in lista, nu facem nimic } else { arr_anunturi.push(element_id); //adaugam element_id in lista de id-uri save_anunturi = arr_anunturi.join(';'); show_fav(); //punere stelute la anunturi favorite //alert(save_anunturi); localStorage.setItem(nume_variabila_local_storage_anunturi,save_anunturi); localStorage.setItem("Date_"+nume_variabila_local_storage_anunturi, data_curenta); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log("Am setat in baza de date element_anunturiul"); console.log("Data pentru element_anunturi : " + data_curenta); } } var data_anunturi = "save_anunturi=1&save_fav_anunturi="+save_anunturi; xhttp.open("POST", "https://afacerilemn.ro/bw_skins/skin1/__general_components/js/actualizare_baza_date_favorite.php", true); xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhttp.send(data_anunturi); } }); }); });