1jQuery( document ).ready( function ($) { 2 var penci_format_to_k = function ( num ) { 3 if ( num > 999 && num < 1000000 ) { 4 return ( num / 1000 ).toFixed( 1 ) + 'K'; 5 } 6 if ( num >= 1000000 ) { 7 return ( num / 1000000 ).toFixed( 1 ) + 'M'; 8 } 9 return num; 10 } 11 12 // Helper functions for localStorage management 13 var penci_like_storage = { 14 getKey: function( post_id, reaction ) { 15 reaction = reaction || 'like'; // Default to 'like' if undefined 16 return 'penci_like_' + post_id + '_' + reaction; 17 }, 18 isLiked: function( post_id, reaction ) { 19 var key = this.getKey( post_id, reaction ); 20 return localStorage.getItem( key ) === 'liked'; 21 }, 22 isUnLiked: function( post_id, reaction ) { 23 var key = this.getKey( post_id, reaction ); 24 return localStorage.getItem( key ) !== 'liked'; 25 }, 26 setLiked: function( post_id, reaction, liked ) { 27 var key = this.getKey( post_id, reaction ); 28 if ( liked ) { 29 localStorage.setItem( key, 'liked' ); 30 } else { 31 localStorage.setItem( key, 'unliked' ); 32 } 33 } 34 }; 35 36 // Restore like status on page load 37 var penci_restore_like_status = function() { 38 $( '.penci-post-like' ).each( function() { 39 var $this = $( this ), 40 post_id = $this.data( 'post_id' ), 41 reaction = $this.data( 'reaction' ) || 'like'; 42 43 if ( post_id && reaction && penci_like_storage.isLiked( post_id, reaction ) ) { 44 $this.addClass( 'liked' ); 45 $this.prop( 'title', 'Unlike' ); 46 } 47 48 if ( post_id && reaction && penci_like_storage.isUnLiked( post_id, reaction ) ) { 49 $this.removeClass( 'liked' ); 50 $this.prop( 'title', 'Like' ); 51 } 52 } ); 53 }; 54 55 // Restore like status when document is ready 56 penci_restore_like_status(); 57 58 jQuery( 'body' ).on( 'click', '.penci-post-like', function ( event ) { 59 event.preventDefault(); 60 var $this = jQuery( this ), 61 post_id = $this.data( "post_id" ), 62 reaction = $this.data( "reaction" ) || 'like', // Default to 'like' if undefined 63 like_text = $this.data( "like" ), 64 unlike_text = $this.data( "unlike" ), 65 $selector = $this.children('.dt-share' ); 66 if( $this.hasClass( 'single-like-button' ) ) { 67 $selector = $this.parent().find('.count-number-like'); 68 } 69 if ( $this.hasClass( 'penci-post-reaction' ) ) { 70 $selector = $this.closest( '.penci-post-reaction-item' ).find( '.dt-share' ); 71 } 72 var $like = parseInt( $selector.text() ); 73 74 if ( $this.hasClass( 'single-like-button' ) ) { 75 $selector = $( '.post-share-plike .count-number-like' ); 76 $this = $( '.single-like-button' ); 77 } 78 79 var is_liked = $this.hasClass( 'liked' ); 80 81 if ( is_liked ) { 82 $this.removeClass( 'liked' ); 83 $this.prop( 'title', 'Like' ); 84 $selector.html( ( $like - 1 ) ); 85 penci_like_storage.setLiked( post_id, reaction, false ); 86 } 87 else { 88 $this.addClass( 'liked' ); 89 $this.prop( 'title', 'Unlike' ); 90 $selector.html( ( $like + 1 ) ); 91 penci_like_storage.setLiked( post_id, reaction, true ); 92 } 93 94 jQuery.ajax( { 95 type: "post", 96 url : ajax_var_more.url, 97 data: "action=penci-post-like&nonce=" + ajax_var_more.nonce + "&penci_post_like=&post_id=" + post_id + "&reaction=" + reaction, 98 } ); 99 } ); 100 101 var $tagsShareBox = jQuery('.tags-share-box'); 102 var post_id = $tagsShareBox.data('id'); 103 var hasPostSharePlike = $tagsShareBox.find('.post-share-plike').length > 0; 104 var hasPenciPostReactions = jQuery('.penci-post-reactions').length > 0; 105 106 if ( typeof post_id !== 'undefined' && (hasPostSharePlike || hasPenciPostReactions) ) { 107 108 fetch( 109 ajax_var_more.rest_url + 'penci/v1/reactions/' + post_id, 110 { 111 method: 'GET', 112 credentials: 'same-origin', 113 headers: { 114 'X-WP-Nonce': ajax_var_more.wp_rest 115 } 116 } 117 ) 118 .then(function (response) { 119 return response.json(); 120 }) 121 .then(function (reacts) { 122 123 jQuery.each( reacts, function( reaction, count ) { 124 var $like_btn = jQuery('.penci-reaction-count[data-reaction="' + reaction + '"]'); 125 if ( $like_btn.length ) { 126 $like_btn.text( penci_format_to_k( count ) ); 127 } 128 }); 129 130 if ( jQuery('.count-number-like').length ) { 131 var total_likes = reacts.like ? reacts.like : 0; 132 jQuery('.count-number-like').text( penci_format_to_k( total_likes ) ); 133 } 134 135 }) 136 .catch(function (error) { 137 console.error('Penci reactions error:', error); 138 }); 139 } 140} );
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.