PageSourceSearch

https://exitmusic.it/wp-content/plugins/etinet-wishlist-manager/assets/js/wcwl-frontend.js?ver=1.0.0

js exitmusic.it collected 2026-10-04 13:49:33 UTC 19,117 bytes, 614 lines download raw bytes

1jQuery(document).ready(function ($) {
2  // Delegazione eventi per pulsanti wishlist dinamici
3  console.log('wcwl-frontend.js caricato');
4
5  // Gestione click per utenti loggati
6  $(document).on(
7    'click',
8    '.wishlist-btn:not(.wishlist-login-required)',
9    function (e) {
10      console.log('Pulsante wishlist cliccato');
11      e.stopPropagation();
12      const wrapper = $(this).closest('.wishlist-wrapper');
13      const dropdown = wrapper.find('.wishlist-dropdown');
14      const productId = wrapper.data('product-id');
15
16      // Chiudi altri dropdown aperti
17      $('.wishlist-dropdown').not(dropdown).hide();
18
19      // Mostra/nascondi dropdown corrente
20      if (dropdown.is(':visible')) {
21        dropdown.hide();
22      } else {
23        dropdown.show();
24      }
25    }
26  );
27
28  // Gestione click per utenti NON loggati - reindirizza al login
29  $(document).on(
30    'click',
31    '.wishlist-btn.wishlist-login-required',
32    function (e) {
33      e.stopPropagation();
34      showWishlistNotification(
35        'Devi essere loggato per aggiungere prodotti alla wishlist',
36        true
37      );
38
39      // Reindirizza al login dopo un breve delay
40      setTimeout(() => {
41        window.location.href = '/mio-account/';
42      }, 1500);
43    }
44  );
45
46  // Chiudi dropdown quando si clicca fuori
47  $(document).on('click', function (e) {
48    if (!$(e.target).closest('.wishlist-wrapper').length) {
49      $('.wishlist-dropdown').hide();
50    }
51  });
52
53  // Chiudi dropdown con il pulsante close
54  $(document).on('click', '.wishlist-dropdown-close', function () {
55    $(this).closest('.wishlist-dropdown').hide();
56  });
57
58  // Mostra/nascondi form creazione wishlist
59  $(document).on('click', '.wishlist-show-create-form', function (e) {
60    e.preventDefault();
61    const footer = $(this).closest('.wishlist-dropdown-footer');
62    const form = footer.find('.wishlist-create-form');
63
64    $(this).hide();
65    form.show();
66    form.find('.wishlist-new-name').focus();
67  });
68
69  // Annulla creazione wishlist
70  $(document).on('click', '.wishlist-cancel-btn', function (e) {
71    e.preventDefault();
72    const footer = $(this).closest('.wishlist-dropdown-footer');
73    const form = footer.find('.wishlist-create-form');
74    const showButton = footer.find('.wishlist-show-create-form');
75
76    form.hide();
77    form.find('.wishlist-new-name').val('');
78    form.find('.wishlist-new-type').val('private');
79    showButton.show();
80  });
81
82  // Crea nuova wishlist dal popup
83  $(document).on('click', '.wishlist-create-btn', function (e) {
84    e.preventDefault();
85    const form = $(this).closest('.wishlist-create-form');
86    const name = form.find('.wishlist-new-name').val().trim();
87    const type = form.find('.wishlist-new-type').val();
88    const productId = $(this).closest('.wishlist-wrapper').data('product-id');
89    const button = $(this);
90
91    if (!name) {
92      showWishlistNotification('Inserisci un nome per la wishlist', true);
93      return;
94    }
95
96    $.ajax({
97      url: wcwl_ajax.ajax_url,
98      type: 'POST',
99      data: {
100        action: 'wcwl_create_wishlist',
101        nonce: wcwl_ajax.nonce,
102        name: name,
103        type: type,
104        product_id: productId,
105      },
106      beforeSend: function () {
107        button.text('Creando...').prop('disabled', true);
108      },
109      success: function (response) {
110        if (response.success) {
111          showWishlistNotification(response.data.message);
112
113          // Se il prodotto è stato aggiunto, aggiorna l'UI
114          if (response.data.product_added) {
115            const mainButton = button
116              .closest('.wishlist-wrapper')
117              .find('.wishlist-btn');
118            mainButton.addClass('wishlist-active added');
119            mainButton.find('.wishlist-heart').css('fill', '#ff4444');
120
121            setTimeout(() => {
122              mainButton.removeClass('added');
123            }, 600);
124          }
125
126          // Chiudi dropdown
127          setTimeout(() => {
128            $('.wishlist-dropdown').hide();
129          }, 1000);
130        } else {
131          showWishlistNotification(response.data, true);
132        }
133      },
134      error: function () {
135        showWishlistNotification('Errore nella creazione della wishlist', true);
136      },
137      complete: function () {
138        button.text('Crea').prop('disabled', false);
139      },
140    });
141  });
142
143  // Aggiungi prodotto alla wishlist
144  $(document).on('click', '.wishlist-add-btn', function () {
145    const item = $(this).closest('.wishlist-dropdown-item');
146    const wishlistId = item.data('wishlist-id');
147    const productId = $(this).closest('.wishlist-wrapper').data('product-id');
148    const button = $(this);
149
150    console.log('Aggiungendo prodotto', productId, 'alla wishlist', wishlistId);
151
152    $.ajax({
153      url: wcwl_ajax.ajax_url,
154      type: 'POST',
155      data: {
156        action: 'wcwl_add_to_wishlist',
157        nonce: wcwl_ajax.nonce,
158        product_id: productId,
159        wishlist_id: wishlistId,
160      },
161      beforeSend: function () {
162        button.text('Aggiungendo...').prop('disabled', true);
163      },
164      success: function (response) {
165        console.log('Risposta AJAX:', response);
166        if (response.success) {
167          // Aggiorna UI
168          item
169            .find('.wishlist-add-btn')
170            .replaceWith('<span class="wishlist-in-list">✓ Aggiunto</span>');
171
172          // Aggiorna stato del pulsante principale
173          const mainButton = button
174            .closest('.wishlist-wrapper')
175            .find('.wishlist-btn');
176          mainButton.addClass('wishlist-active added');
177          mainButton.find('.wishlist-heart').css('fill', '#ff4444');
178
179          // Mostra notifica
180          showWishlistNotification('Prodotto aggiunto alla wishlist!');
181
182          // Chiudi dropdown dopo un delay
183          setTimeout(() => {
184            $('.wishlist-dropdown').hide();
185          }, 1000);
186
187          // Rimuovi animazione dopo il completamento
188          setTimeout(() => {
189            mainButton.removeClass('added');
190          }, 600);
191        } else {
192          showWishlistNotification(response.data, true);
193          button.text('Aggiungi').prop('disabled', false);
194        }
195      },
196      error: function (xhr, status, error) {
197        console.error('Errore AJAX:', error);
198        showWishlistNotification(
199          "Errore durante l'aggiunta alla wishlist",
200          true
201        );
202        button.text('Aggiungi').prop('disabled', false);
203      },
204    });
205  });
206
207  // Rimuovi prodotto dalla wishlist (dal dropdown)
208  $(document).on('click', '.wishlist-remove-btn', function () {
209    const item = $(this).closest('.wishlist-dropdown-item');
210    const wishlistId = item.data('wishlist-id');
211    const productId = $(this).data('product-id');
212    const button = $(this);
213
214    $.ajax({
215      url: wcwl_ajax.ajax_url,
216      type: 'POST',
217      data: {
218        action: 'wcwl_remove_product_from_wishlist',
219        nonce: wcwl_ajax.nonce,
220        product_id: productId,
221        wishlist_id: wishlistId,
222      },
223      beforeSend: function () {
224        button.text('Rimuovendo...').prop('disabled', true);
225      },
226      success: function (response) {
227        if (response.success) {
228          // Aggiorna UI - cambia da "Rimuovi" a "Aggiungi"
229          button.replaceWith(
230            '<button class="wishlist-add-btn">Aggiungi</button>'
231          );
232
233          // Aggiorna stato del pulsante principale se non è più in nessuna wishlist
234          const mainButton = button
235            .closest('.wishlist-wrapper')
236            .find('.wishlist-btn');
237
238          // Controlla se il prodotto è ancora in altre wishlist
239          const hasOtherWishlists =
240            item
241              .siblings('.wishlist-dropdown-item')
242              .find('.wishlist-remove-btn').length > 0;
243
244          if (!hasOtherWishlists) {
245            mainButton.removeClass('wishlist-active');
246            mainButton.find('.wishlist-heart').css('fill', '#737373');
247          }
248
249          showWishlistNotification('Prodotto rimosso dalla wishlist!');
250
251          // Chiudi dropdown dopo un delay
252          setTimeout(() => {
253            $('.wishlist-dropdown').hide();
254          }, 1000);
255        } else {
256          showWishlistNotification(response.data, true);
257          button.text('Rimuovi').prop('disabled', false);
258        }
259      },
260      error: function (xhr, status, error) {
261        console.error('Errore AJAX:', error);
262        showWishlistNotification(
263          'Errore durante la rimozione dalla wishlist',
264          true
265        );
266        button.text('Rimuovi').prop('disabled', false);
267      },
268    });
269  });
270
271  // Funzione per mostrare notifiche
272  function showWishlistNotification(message, isError = false) {
273    // Rimuovi notifiche esistenti
274    $('.wishlist-notification').remove();
275
276    // Crea nuova notifica
277    const notification = $(
278      '<div class="wishlist-notification' +
279        (isError ? ' error' : '') +
280        '">' +
281        message +
282        '</div>'
283    );
284    $('body').append(notification);
285
286    // Mostra notifica
287    setTimeout(() => {
288      notification.addClass('show');
289    }, 100);
290
291    // Nascondi notifica dopo 3 secondi
292    setTimeout(() => {
293      notification.removeClass('show');
294      setTimeout(() => {
295        notification.remove();
296      }, 300);
297    }, 3000);
298  }
299
300  // Chiudi dropdown con ESC
301  $(document).on('keyup', function (e) {
302    if (e.keyCode === 27) {
303      // ESC
304      $('.wishlist-dropdown').hide();
305    }
306  });
307
308  // Creazione nuova wishlist (per le pagine di gestione)
309  $(document).on('click', '#wcwl-create-list', function () {
310    const name = $('#wcwl-new-list-name').val();
311    const type = $('#wcwl-new-list-type').val();
312
313    if (!name) {
314      alert('Inserisci un nome per la wishlist');
315      return;
316    }
317
318    $.ajax({
319      url: wcwl_ajax.ajax_url,
320      type: 'POST',
321      data: {
322        action: 'wcwl_create_wishlist',
323        nonce: wcwl_ajax.nonce,
324        name: name,
325        type: type,
326      },
327      success: function (response) {
328        if (response.success) {
329          location.reload();
330        } else {
331          alert(response.data);
332        }
333      },
334    });
335  });
336
337  // === GESTIONE PAGINA WISHLIST ===
338
339  // Toggle visualizzazione prodotti
340  $(document).on('click', '.wcwl-toggle-items', function () {
341    console.log('WCWL Debug: Toggle items cliccato');
342    const listItem = $(this).closest('.wcwl-list-item');
343    const container = listItem.find('.wcwl-items-container');
344    const icon = $(this).find('.wcwl-toggle-icon');
345    const wishlistId = listItem.data('list-id');
346
347    console.log('WCWL Debug: wishlistId:', wishlistId);
348    console.log('WCWL Debug: container trovato:', container.length);
349    console.log('WCWL Debug: container visibile:', container.is(':visible'));
350    console.log(
351      'WCWL Debug: loading element presente:',
352      container.find('.wcwl-loading').length
353    );
354
355    if (container.is(':visible')) {
356      container.slideUp();
357      icon.removeClass('rotated');
358    } else {
359      // Carica prodotti se non già caricati
360      if (container.find('.wcwl-loading').length) {
361        console.log('WCWL Debug: Chiamando loadWishlistItems');
362        loadWishlistItems(wishlistId, container);
363      } else {
364        console.log(
365          'WCWL Debug: Nessun elemento .wcwl-loading trovato, prodotti già caricati'
366        );
367      }
368      container.slideDown();
369      icon.addClass('rotated');
370    }
371  });
372
373  // Carica prodotti di una wishlist
374  function loadWishlistItems(wishlistId, container) {
375    console.log(
376      'WCWL Debug: loadWishlistItems chiamato per wishlist ID:',
377      wishlistId
378    );
379    console.log('WCWL Debug: AJAX URL:', wcwl_ajax.ajax_url);
380    console.log('WCWL Debug: Nonce:', wcwl_ajax.nonce);
381
382    $.ajax({
383      url: wcwl_ajax.ajax_url,
384      type: 'POST',
385      data: {
386        action: 'wcwl_load_wishlist_items',
387        nonce: wcwl_ajax.nonce,
388        wishlist_id: wishlistId,
389      },
390      success: function (response) {
391        console.log('WCWL Debug: AJAX response ricevuta:', response);
392        if (response.success) {
393          container.html(response.data);
394        } else {
395          console.log('WCWL Debug: AJAX error response:', response);
396          container.html(
397            '<div class="wcwl-error">Errore nel caricamento dei prodotti</div>'
398          );
399        }
400      },
401      error: function (xhr, status, error) {
402        console.log('WCWL Debug: AJAX request failed:', xhr, status, error);
403        container.html(
404          '<div class="wcwl-error">Errore nel caricamento dei prodotti</div>'
405        );
406      },
407    });
408  }
409
410  // Toggle tipo wishlist (privata/pubblica)
411  $(document).on('click', '.wcwl-toggle-type', function () {
412    const button = $(this);
413    const listItem = button.closest('.wcwl-list-item');
414    const wishlistId = listItem.data('list-id');
415    const currentType = button.data('current-type');
416    const newType = currentType === 'public' ? 'private' : 'public';
417
418    const confirmMessage =
419      newType === 'public'
420        ? 'Rendere questa wishlist pubblica? Sarà visibile a chiunque abbia il link.'
421        : 'Rendere questa wishlist privata? Il link di condivisione non funzionerà più.';
422
423    if (!confirm(confirmMessage)) return;
424
425    $.ajax({
426      url: wcwl_ajax.ajax_url,
427      type: 'POST',
428      data: {
429        action: 'wcwl_toggle_wishlist_type',
430        nonce: wcwl_ajax.nonce,
431        wishlist_id: wishlistId,
432        new_type: newType,
433      },
434      beforeSend: function () {
435        button.prop('disabled', true);
436      },
437      success: function (response) {
438        if (response.success) {
439          // Aggiorna UI
440          button.data('current-type', newType);
441          button.text(newType === 'public' ? '🔓' : '🔒');
442
443          const typeBadge = listItem.find('.wcwl-type-badge');
444          typeBadge.removeClass('public private').addClass(newType);
445          typeBadge.text(newType === 'public' ? 'Pubblica' : 'Privata');
446
447          // Gestisci sezione condivisione
448          if (newType === 'public' && response.data.share_url) {
449            const shareSection = listItem.find('.wcwl-share-section');
450            if (shareSection.length === 0) {
451              // Crea sezione condivisione
452              const shareHtml = `
453                <div class="wcwl-share-section">
454                  <label>Link di condivisione:</label>
455                  <div class="wcwl-share-controls">
456                    <input type="text" readonly value="${response.data.share_url}" class="wcwl-share-input">
457                    <button class="wcwl-copy-link" title="Copia link">📋</button>
458                    <button class="wcwl-regenerate-token" title="Rigenera link">🔄</button>
459                  </div>
460                  <small class="wcwl-share-note">Condividi questo link per permettere ad altri di vedere la tua wishlist</small>
461                </div>
462              `;
463              listItem.find('.wcwl-list-header').after(shareHtml);
464            }
465          } else if (newType === 'private') {
466            listItem.find('.wcwl-share-section').remove();
467          }
468
469          showWishlistNotification(response.data.message);
470        } else {
471          showWishlistNotification(response.data, true);
472        }
473      },
474      error: function () {
475        showWishlistNotification('Errore nel cambio di visibilità', true);
476      },
477      complete: function () {
478        button.prop('disabled', false);
479      },
480    });
481  });
482
483  // Elimina wishlist
484  $(document).on('click', '.wcwl-delete-list', function () {
485    const button = $(this);
486    const listItem = button.closest('.wcwl-list-item');
487    const wishlistId = listItem.data('list-id');
488    const wishlistName = listItem.find('h5').text().trim();
489
490    if (
491      !confirm(
492        `Sei sicuro di voler eliminare la wishlist "${wishlistName}"? Questa azione non può essere annullata.`
493      )
494    ) {
495      return;
496    }
497
498    $.ajax({
499      url: wcwl_ajax.ajax_url,
500      type: 'POST',
501      data: {
502        action: 'wcwl_delete_wishlist',
503        nonce: wcwl_ajax.nonce,
504        wishlist_id: wishlistId,
505      },
506      beforeSend: function () {
507        button.prop('disabled', true);
508      },
509      success: function (response) {
510        if (response.success) {
511          listItem.fadeOut(300, function () {
512            $(this).remove();
513            showWishlistNotification(response.data);
514          });
515        } else {
516          showWishlistNotification(response.data, true);
517          button.prop('disabled', false);
518        }
519      },
520      error: function () {
521        showWishlistNotification(
522          "Errore nell'eliminazione della wishlist",
523          true
524        );
525        button.prop('disabled', false);
526      },
527    });
528  });
529
530  // Rigenera token
531  $(document).on('click', '.wcwl-regenerate-token', function () {
532    const button = $(this);
533    const listItem = button.closest('.wcwl-list-item');
534    const wishlistId = listItem.data('list-id');
535
536    if (
537      !confirm(
538        'Rigenerare il link di condivisione? Il vecchio link non funzionerà più.'
539      )
540    ) {
541      return;
542    }
543
544    $.ajax({
545      url: wcwl_ajax.ajax_url,
546      type: 'POST',
547      data: {
548        action: 'wcwl_regenerate_token',
549        nonce: wcwl_ajax.nonce,
550        wishlist_id: wishlistId,
551      },
552      beforeSend: function () {
553        button.prop('disabled', true).text('🔄');
554      },
555      success: function (response) {
556        if (response.success) {
557          listItem.find('.wcwl-share-input').val(response.data.share_url);
558          showWishlistNotification(response.data.message);
559        } else {
560          showWishlistNotification(response.data, true);
561        }
562      },
563      error: function () {
564        showWishlistNotification('Errore nella rigenerazione del token', true);
565      },
566      complete: function () {
567        button.prop('disabled', false).text('🔄');
568      },
569    });
570  });
571
572  // Rimuovi prodotto dalla wishlist
573  $(document).on('click', '.wcwl-remove-item', function () {
574    const button = $(this);
575    const itemElement = button.closest('.wcwl-item');
576    const itemId = button.data('item-id');
577
578    $.ajax({
579      url: wcwl_ajax.ajax_url,
580      type: 'POST',
581      data: {
582        action: 'wcwl_remove_from_wishlist',
583        nonce: wcwl_ajax.nonce,
584        item_id: itemId,
585      },
586      beforeSend: function () {
587        button.prop('disabled', true);
588      },
589      success: function (response) {
590        if (response.success) {
591          itemElement.fadeOut(300, function () {
592            $(this).remove();
593          });
594          showWishlistNotification(response.data);
595        } else {
596          showWishlistNotification(response.data, true);
597          button.prop('disabled', false);
598        }
599      },
600      error: function () {
601        showWishlistNotification('Errore nella rimozione del prodotto', true);
602        button.prop('disabled', false);
603      },
604    });
605  });
606
607  // Copia link di condivisione
608  $(document).on('click', '.wcwl-copy-link', function () {
609    const input = $(this).siblings('.wcwl-share-input');
610    input.select();
611    document.execCommand('copy');
612    showWishlistNotification('Link copiato negli appunti!');
613  });
614});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.