-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.starz.js
56 lines (43 loc) · 1.24 KB
/
jquery.starz.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
/**
* Starz - jQuery Plugin
* Pretty star rating stored in cookies
*
* Examples and documentation at: https://github.com/microtroll/jquery-starz
*
* Copyright (c) 2014 microtroll
*
* Version: 1.3.1
* Requires: jQuery v2+
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($) {
$.fn.extend({
starz: function(stars, initialRating) {
var elements = this;
return this.each(function() {
if (!initialRating) {
initialRating = 0;
}
var containerElement = this;
var container = $(this);
var starsCollection = [];
containerElement.rating = initialRating;
container.css('overflow', 'auto');
for (var starIdx = 0; starIdx < stars; starIdx++) {
var starElement = document.createElement('div');
var star = $(starElement);
starElement.rating = starIdx + 1;
star.addClass('ratings-star');
if (starIdx < initialRating) {
star.addClass('ratings-full');
}
container.append(star);
starsCollection.push(star);
}
});
}
});
})(jQuery);