• Resolved AlexanderCnb

    (@alexandercnb)


    If I understand the script correctly, it adds a class to the clicked element (thumbs-rating-voted). Would it be possible for it to also add a class to the non clicked element after there has been voted?

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ricard Torres

    (@quicoto)

    Absolutely, you just need to change the part of JavaScript to something like:

    if( type == 1){ thumbs_rating_class = ".thumbs-rating-up"; var other_class = ".thumbs-rating-down"; }
    else{ thumbs_rating_class = ".thumbs-rating-down"; var other_class = ".thumbs-rating-up"; }
    
    jQuery(new_container +  thumbs_rating_class ).addClass('thumbs-rating-voted');
    jQuery(new_container +  other_class ).addClass('other-class');
    Thread Starter AlexanderCnb

    (@alexandercnb)

    Thank you, but I can’t manage to get it working. Maybe I’m doing something wrong.

    In general.js I changed the below with your code

    if( type == 1){ thumbs_rating_class = ".thumbs-rating-up"; }
    else{ thumbs_rating_class = ".thumbs-rating-down";  }
    
    jQuery(new_container +  thumbs_rating_class ).addClass('thumbs-rating-voted');

    If I delete that section and don’t replace it, the class still gets added. When looking in thumbs-rating.php on line 94-95 it has this code:

    $link_up = '<span class="thumbs-rating-up'. ( (isset($thumbs_rating_up_count) && intval($thumbs_rating_up_count) > 0 ) ? ' thumbs-rating-voted' : '' ) .'" onclick="thumbs_rating_vote(' . $post_ID . ', 1);" data-text="' . __('Vote Up','thumbs-rating') . ' +">' . $thumbs_rating_up_count . '</span>';
    		$link_down = '<span class="thumbs-rating-down'. ( (isset($thumbs_rating_down_count) && intval($thumbs_rating_down_count) > 0 ) ? ' thumbs-rating-voted' : '' ) .'" onclick="thumbs_rating_vote(' . $post_ID . ', 2);" data-text="' . __('Vote Down','thumbs-rating') . ' -">' . $thumbs_rating_down_count . '</span>';

    Would adjusting something here help? When I change the text of the class thumbs-rating-voted, it also shows a different class in the browser after voting. While if I delete the addClass part in general.js it the class is still being added to the type that was voted on. Of course, I don’t understand javascript, so I might just be doing something wrong.

    Hope it’s not a problem for to rely on you for this.

    Plugin Author Ricard Torres

    (@quicoto)

    I’m having a hard time understanding what you’ve done.

    So you’re right we have to change both JavaScript and PHP.

    The JS handles the class after clicking and the php handles the class after reloading the page.

    I’m afraid I can not code it for you

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add class to non-clicked element’ is closed to new replies.