~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to media/js/jquery.sexy-vote.js

  • Committer: Holger Rapp
  • Date: 2009-02-25 16:55:36 UTC
  • Revision ID: sirver@kallisto.local-20090225165536-3abfhjx8qsgtzyru
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
jQuery.fn.sexyVote = function(config) {
2
 
    config = config || {};
3
 
    var defaults = {
4
 
        activeImageSrc: "active_star.gif",
5
 
        passiveImageSrc: "passive_star.gif",
6
 
        maxScore: 5,
7
 
        fn: new Function(),
8
 
        messages: [
9
 
            "Your vote have been saved.",
10
 
            "Very bad",
11
 
            "Bad",
12
 
            "Good, but could be better",
13
 
            "Good enough",
14
 
            "Very good"
15
 
        ]
16
 
    };   
17
 
    
18
 
    config = jQuery.extend(defaults, config);
19
 
    
20
 
  
21
 
    
22
 
    return this.each(function() {
23
 
        var $container = jQuery(this);
24
 
        
25
 
        for (var i = 0, num = config.maxScore * 2; i < num; ++i) {
26
 
            jQuery("<img />").appendTo($container);    
27
 
        }
28
 
        
29
 
        jQuery("<span />").appendTo($container);
30
 
        
31
 
        $container.find("img:even").
32
 
        attr("src", config.passiveImageSrc).
33
 
        css({display: "inline"}).
34
 
        bind("mouseover", function(e) {     
35
 
            var len = $container.find("img:even").index(e.target) + 1;
36
 
            
37
 
            $container.find("img:even").slice(0, len).css({display: "none"});
38
 
            
39
 
            $container.find("img:odd").slice(0, len).css({display: "inline"});
40
 
            
41
 
            $container.find("span").text(config.messages[len]);
42
 
            
43
 
            
44
 
        }).
45
 
        end().
46
 
        find("img:odd").
47
 
        attr("src", config.activeImageSrc).
48
 
        css({display: "none"}).
49
 
        bind("mouseout", function(e) {
50
 
 
51
 
            var len = $container.find("img:odd").
52
 
            index(e.target) + 1;
53
 
 
54
 
            $container.find("img:odd")
55
 
            .slice(0, len).
56
 
            css({display: "none"});
57
 
            $container.find("img:even").
58
 
            slice(0,  len).
59
 
            css({display: "inline"});
60
 
            
61
 
            $container.find("span").
62
 
            text("");
63
 
            
64
 
                
65
 
        }).
66
 
        bind("click", function(e) {
67
 
            $container.find("img").
68
 
            unbind("mouseover").
69
 
            unbind("mouseout").
70
 
            unbind("click");
71
 
            $container.find("span").
72
 
            text(config.messages[0]);
73
 
            config.fn.call(this, e, $container.find("img:odd").index(e.target) + 1);
74
 
        });
75
 
    });
76
 
};