1(function ($) { 2 "use strict"; 3 4 jQuery(document).ready(function ($) { 5 6 // get the post ID 7 const postID = document.querySelector('.newzin-post-reactions').getAttribute('post-id'); 8 9 // get cookie data 10 function newzinGetCookie(cname) { 11 let name = cname + "="; 12 let decodedCookie = decodeURIComponent(document.cookie); 13 let ca = decodedCookie.split(';'); 14 for (let i = 0; i < ca.length; i++) { 15 let c = ca[i]; 16 while (c.charAt(0) == ' ') { 17 c = c.substring(1); 18 } 19 if (c.indexOf(name) == 0) { 20 return c.substring(name.length, c.length); 21 } 22 } 23 return ""; 24 } 25 26 // store the cookie data 27 let postReactionValue = newzinGetCookie(`newzin_reaction_${postID}`); 28 29 // checking the post id and the value 30 if(postReactionValue && postReactionValue.split('-')[1] == postID) { 31 const postReaction = postReactionValue.split('-')[0]; 32 $(`.newzin-post-reaction[value="${postReaction}"]`).addClass('active'); 33 } 34 35 // check the vakye to run ajax and send the values 36 $('input[name="newzin-post-reaction"]').click(function () { 37 const radio = $(this); 38 39 const oldValue = $('.newzin-post-reaction.active').val(); 40 41 $('.newzin-post-reaction').removeClass('active'); 42 43 // if this was previously checked 44 if (radio.data('waschecked') == true) { 45 radio.prop('checked', false); 46 radio.data('waschecked', false); 47 } 48 else { 49 radio.data('waschecked', true); 50 } 51 52 // remove was checked from other radios 53 radio.siblings('input[type="radio"]').data('waschecked', false); 54 55 $('.newzin-post-reaction:checked').addClass('active'); 56 57 const newValue = $('.newzin-post-reaction.active').val(); 58 59 // ajax data 60 let data = { 61 'action': 'process_newzin_post_reactions', 62 'post_id': postID, 63 } 64 65 // check the post reaction value 66 if (oldValue && newValue) { 67 data['old_reaction'] = oldValue; 68 data['reaction'] = newValue; 69 document.cookie = `newzin_reaction_${postID}=${newValue}-${postID}`; 70 } else if (!oldValue && newValue) { 71 data['reaction'] = newValue; 72 document.cookie = `newzin_reaction_${postID}=${newValue}-${postID}`; 73 } else { 74 data['removed_reaction'] = oldValue; 75 document.cookie = `newzin_reaction_${postID}=`; 76 } 77 78 // ajax request 79 $.ajax({
80 type : "POST", 81 url: newzin_ajaxurl, // Since WP 2.8 ajaxurl is always defined and points to admin-ajax.php 82 data: data, 83 success:function(data) { 84 // This outputs the result of the ajax request (The Callback) 85 }, 86 error: function(errorThrown){ 87 window.alert(errorThrown); 88 } 89 }); 90 }); 91 92 }); 93})(jQuery);
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.