Visualizzazione dei risultati da 1 a 2 su 2

Hybrid View

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2014
    Messaggi
    13
    Aggiungo anche il codice javascript e la pagina php che controllano il sistema di valutazione:

    codice:
    $(document).ready(function() {
        $('.rate_widget').each(function(i) {
            var widget = this;
            var out_data = {
                widget_id : $(widget).attr('id'), fetch: 1
            };
                $.post(
                    'ratings.php',
                    out_data,
                    function(INFO) {
                        $(widget).data( 'fsr', INFO );
                        set_votes(widget);
                    },
                    'json'
                );
            });
    
            $('.ratings_stars').hover(
                // Handles the mouseover
                function() {
                    $(this).prevAll().andSelf().addClass('ratings_over');
                    $(this).nextAll().removeClass('ratings_vote'); 
                },
                // Handles the mouseout
                function() {
                    $(this).prevAll().andSelf().removeClass('ratings_over');
                    // can't use 'this' because it wont contain the updated data
                    set_votes($(this).parent());
                }
            );
            
            
            // This actually records the vote
            $('.ratings_stars').bind('click', function() {
                var star = this;
                var widget = $(this).parent();
                
                var clicked_data = {
                    clicked_on : $(star).attr('class'),
                    widget_id : $(star).parent().attr('id')
                };
                $.post(
                    'ratings.php',
                    clicked_data,
                    function(INFO) {
                        widget.data( 'fsr', INFO );
                        set_votes(widget);
                    },
                    'json'
                ); 
            });        
        });
    
        function set_votes(widget) {
            var avg = $(widget).data('fsr').whole_avg;
            var votes = $(widget).data('fsr').number_votes;
            var exact = $(widget).data('fsr').dec_avg;    
            window.console && console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes);
            
            $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
            $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote'); 
            $(widget).find('.total_votes').text(votes);
            $(widget).find('.avg_votes').text(exact);
        }
    Ultima modifica di epiandre; 07-04-2015 a 09:59

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.