jQuery: Gmail Star?

后端 未结 5 1562
暖寄归人
暖寄归人 2021-01-30 19:26

I was wondering if anyone had any good tutorials around creating a gmail inbox star (favorite) ?

EDIT:

I guess I want to create something just like the stackover

5条回答
  •  有刺的猬
    2021-01-30 19:31

    I'm assuming you want less of a "rating" system (as mentioned in the other answers) and more of a "add this to favorites" system?

    Something like this should get you started in the right direction. Others, feel free to chime in with other best-practices if you have them.

    foo.html

    
      
        
        
        
      
      
    
        
          Make it a favorite!
        
        
          Make it a favorite!
        
    
      
    
    

    jquery.make_favorite.js

    (function($){
      $.fn.make_favorite = function(){
    
        var callback = function(response){
          console.log(response);
        };
    
        return this.each(function(){
    
          $(this).click(function(){
            var params = {
              item_type:  $(this).attr('href').match(/\w+/)[0],  // 'article'
              item_id:    $(this).attr('href').match(/\d+/)[0]   // 15
            };
    
            $.post('/favorite.php', params, callback, 'json');
    
            // stop event propagation
            return false;
          });
        });
      };
    })(jQuery);
    

    favorite.php

     true, 'message' => 'Huzza!');
    }
    else {
      $response = array('ok' => false, 'message' => mysql_error());
    }
    
    // the magic?
    echo json_encode($response);
    
    ?>
    

提交回复
热议问题