-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating.js
executable file
·68 lines (59 loc) · 3.04 KB
/
rating.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(function($){
var config;
$.fn.extend({
rating: function(options){
var settings = {
number : 5, // stars
size : 24, // size stars
selected : 0 // selected stars
};
if(options)
$.extend(settings, options);
config = settings;
return this.each(function(){
var html = "<table class = 'rating " + (settings.selected>0?"rated":"") + "'><tr>";
var i = 0;
for(i=0; i<settings.selected; i++){
html += "<td><img src = 'img/star_on.png' width= '" + settings.size + "' height = '" + settings.size + "'></td>";
}
for(var j=i; j<settings.number; j++)
html += "<td><img src = 'img/star_off.png' width= '" + settings.size + "' height = '" + settings.size + "'></td>";
html += "</tr></table>";
$(this).html(html);
$('.rating td').css({'cursor': 'pointer'});
var self = this;
$(self).find('.rating td').hover(function(){
if($(self).find('.rated').length == 0){
$(self).find('.rating td').html("<img src = 'img/star_off.png' class = '' width= '" + settings.size + "' height = '" + settings.size + "'>");
var index = $(this).index();
$(self).find('.rating td').each(function(){
if($(this).index() <= index){
$(this).html("<img src = 'img/star_on.png' width= '" + settings.size + "' height = '" + settings.size + "'>");
}
});
}else
return;
} ,function(){
if($(self).find('.rated').length == 0)
$(self).find('.rating td').html("<img src = 'img/star_off.png' width= '" + settings.size + "' height = '" + settings.size + "'>");
else
return;
});
$(this).find('.rating').mouseleave(function(){
if($(this).find('.rated').length == 0)
$(this).find('.rating td').html("<img src = 'img/star_off.png' width= '" + settings.size + "' height = '" + settings.size + "'>");
});
$(this).find('.rating td').click(function(){
if($(this).parents('.rating').find('.rated').length == 0)
$(this).addClass('rated');
});
}); // END EACH
},// END function
quitRated: function(){
$(this).find('.rating td').removeClass('rated').html("<img src = 'img/star_off.png' width= '" + config.size + "' height = '" + config.size + "'>");
},
getRating: function(){
return $(this).find('.rated').index() + 1;
}
}); // END extend
})(jQuery);