Customize Javascript for ratings section.

This topic contains 3 replies, has 3 voices, and was last updated by  Alex Rollin 5 years, 3 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #507969

    Cindy Sutton
    Expired Member
    Post count: 15

    What I would like to do is change the background color of this element:

    
    <span class="gd-rating-text" data-title="Select a rating">Select a rating</span>
    

    Dependent on the value of this input:

    
    <input type="hidden" id="geodir_overallrating" name="geodir_overallrating" value="0">
    

    Which is controlled by the hover/active state of the rating stars:

    
    <span class="gd-rating-wrap">
      <span class="gd-rating-foreground" style="width: 0%;">
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Terrible"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Poor"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Average"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Very Good"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Excellent"></i>				
      </span>
      <span class="gd-rating-background">
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Terrible"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Poor"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Average"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Very Good"></i>
        <i class="fas fa-star fa-fw" aria-hidden="true" title="Excellent"></i>
      </span>
    </span>
    

    I found the JS responsible for updating the text in the geodirectory.js file:

    
    // set the current star value and text
    $value = jQuery(this).closest('.gd-rating-input').find('input').val();
    if($value > 0){
      jQuery(this).closest('.gd-rating-input').find('.gd-rating-foreground').width( $value / $total * 100 + '%');
      jQuery(this).closest('.gd-rating-input').find('.gd-rating-text').text( jQuery(this).closest('.gd-rating-input').find('svg, img'+':eq('+ ($value - 1) +'), i'+':eq('+ ($value - 1) +')').attr("title"));
    }
    

    Is there a non-descructive way, contained within my theme, that I can add to this to change the background color as well? Thanks for the help!

    #508008

    Kiran
    Moderator
    Post count: 7069

    Hi,

    It is not possible to set background color for text without some javascript code customization.

    Kiran

    #508108

    Cindy Sutton
    Expired Member
    Post count: 15

    I understand that… I found the code in the geodirectory.js file where I can apply that as I said above but I don’t want to do it there cause it would get overwriten when the plugin gets updated. I want to know if there is a way I can override or add to it in my theme’s javascript.

    #508177

    Alex Rollin
    Moderator
    Post count: 27815

    Yes, you can use a plugin like code snippet so that you can continue to update the child theme and plugin.

    https://wpgeodirectory.com/docs-v2/faq/customizing/#custom-code

Viewing 4 posts - 1 through 4 (of 4 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount