🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:wishlist.js
/* =================================== VELORA - Wishlist Functionality =================================== */ (function($) { 'use strict'; const Wishlist = { init: function() { this.events(); this.checkStates(); }, events: function() { $(document).on('click', '.wishlist-btn', function(e) { e.preventDefault(); e.stopPropagation(); const $btn = $(this); const productId = $btn.data('product-id'); Wishlist.toggle(productId, $btn); }); $(document).on('click', '.remove-wishlist', function(e) { e.preventDefault(); const $btn = $(this); const productId = $btn.data('product-id'); Wishlist.remove(productId, $btn.closest('.product-card, .wishlist-item')); }); }, checkStates: function() { // Check which products are in wishlist (for logged in users) if (IS_LOGGED_IN) { $('.wishlist-btn').each(function() { const productId = $(this).data('product-id'); Wishlist.check(productId, $(this)); }); } }, check: function(productId, $btn) { $.ajax({ url: SITE_URL + 'ajax/wishlist.php', type: 'POST', data: { action: 'check', product_id: productId }, dataType: 'json', success: function(response) { if (response.in_wishlist) { $btn.addClass('active'); $btn.find('i').removeClass('far').addClass('fas'); } } }); }, toggle: function(productId, $btn) { if (!IS_LOGGED_IN) { toastr.warning('Please login to add to wishlist'); setTimeout(function() { window.location.href = SITE_URL + 'pages/login.php'; }, 1000); return; } $btn.prop('disabled', true); $.ajax({ url: SITE_URL + 'ajax/wishlist.php', type: 'POST', data: { action: 'toggle', product_id: productId }, dataType: 'json', success: function(response) { if (response.success) { if (response.action === 'added') { $btn.addClass('active'); $btn.find('i').removeClass('far').addClass('fas'); toastr.success('Added to wishlist'); } else { $btn.removeClass('active'); $btn.find('i').removeClass('fas').addClass('far'); toastr.info('Removed from wishlist'); } Wishlist.updateCount(response.count); } else { toastr.error(response.message || 'Failed to update wishlist'); } }, error: function() { toastr.error('Something went wrong'); }, complete: function() { $btn.prop('disabled', false); } }); }, remove: function(productId, $item) { if (!confirm('Remove from wishlist?')) return; $item.css('opacity', '0.5'); $.ajax({ url: SITE_URL + 'ajax/wishlist.php', type: 'POST', data: { action: 'remove', product_id: productId }, dataType: 'json', success: function(response) { if (response.success) { toastr.success('Removed from wishlist'); $item.fadeOut(300, function() { $(this).remove(); if ($('.wishlist-item').length === 0) { location.reload(); } }); Wishlist.updateCount(response.count); } else { toastr.error(response.message); $item.css('opacity', '1'); } }, error: function() { toastr.error('Failed to remove'); $item.css('opacity', '1'); } }); }, updateCount: function(count) { const $badge = $('.header-action .badge-count').first(); if (count > 0) { $badge.text(count).show(); } else { $badge.hide(); } } }; $(document).ready(function() { Wishlist.init(); }); })(jQuery);
Save Changes
Cancel
Create New File
Create New Folder