st-rating.js
46 lines
| 1 | /** |
| 2 | * SureTriggers Rating JavaScript |
| 3 | * |
| 4 | * Handles rating link clicks and hiding functionality |
| 5 | */ |
| 6 | |
| 7 | (function($) { |
| 8 | 'use strict'; |
| 9 | |
| 10 | $(document).ready(function() { |
| 11 | // Handle rating link click |
| 12 | $('.suretriggers-rating-link').on('click', function(e) { |
| 13 | // Don't prevent the default action immediately |
| 14 | // Let the link open first, then handle our logic |
| 15 | |
| 16 | var $wrapper = $('#suretriggers-rating-wrapper'); |
| 17 | var self = this; |
| 18 | |
| 19 | // Add a small delay to allow the link to open |
| 20 | setTimeout(function() { |
| 21 | // Send AJAX request to mark rating as clicked |
| 22 | $.ajax({ |
| 23 | url: suretriggers_rating_ajax.ajax_url, |
| 24 | type: 'POST', |
| 25 | data: { |
| 26 | action: 'suretriggers_rating_clicked', |
| 27 | nonce: suretriggers_rating_ajax.nonce |
| 28 | }, |
| 29 | success: function(response) { |
| 30 | if (response.success) { |
| 31 | // Hide the rating with a smooth fade out |
| 32 | $wrapper.fadeOut(300, function() { |
| 33 | $(this).remove(); |
| 34 | }); |
| 35 | } |
| 36 | }, |
| 37 | error: function() { |
| 38 | // Silent fail - don't show error to user |
| 39 | console.log('Failed to mark rating as clicked'); |
| 40 | } |
| 41 | }); |
| 42 | }, 100); // Small delay to ensure link opens first |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | })(jQuery); |