Skip to content

Commit

Permalink
Added classes and added mouseout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DrRoach committed Jan 8, 2015
1 parent 1d9cdf6 commit c204b13
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion rating.js
Expand Up @@ -19,10 +19,26 @@ rating.create = function(settings){
//Set the default name
this.name = settings.name || rating.name;

//Set the classes
var ratingClass = settings.ratingClass || {};
console.log(ratingClass);

var html = '<input type="hidden" name="'+this.name+'" value="'+this.defaultRating+'">';
//Create the ratings HTML
for(var i = 0; i < this.defaultRating; i++) {
html = html + '<img src="'+this.selectedIcon+'" data-position="'+(i+1)+'">';
html = html + '<img src="'+this.selectedIcon+'" data-position="'+(i+1)+'"';
for(var x = 0; x < ratingClass.length; x++) {
if(x === 0) {
html = html + ' class="';
}
html = html + ratingClass[x];
if(x+1 == ratingClass.length) {
html = html + '"';
} else {
html = html + ' ';
}
}
html = html + '>';
}
for(var i = 0; i < this.outOf - this.defaultRating; i++) {
html = html + '<img src="'+this.unselectedIcon+'" data-position="'+(this.defaultRating+i+1)+'">';
Expand All @@ -39,6 +55,17 @@ rating.create = function(settings){
});
});

$(settings.selector + ' img').on('mouseout', function() {
var selected = $(this).siblings('input[name='+rating.name+']').val();
$(settings.selector + ' img').each(function(i, e) {
if(i < selected) {
$(e).attr('src', rating.selectedIcon);
} else {
$(e).attr('src', rating.unselectedIcon);
}
});
});

$(settings.selector + ' img').on('click', function() {
$(this).siblings('input[name='+rating.name+']').val($(this).data('position'));
});
Expand Down

0 comments on commit c204b13

Please sign in to comment.