Permalink
Browse files

added disabledOnRate option

  • Loading branch information...
1 parent 805c1dc commit 21bc933047844d349b8b1973ddec091cc5e0998d @pilu committed May 5, 2008
Showing with 14 additions and 8 deletions.
  1. +0 −1 index.html
  2. +14 −7 javascripts/rating.js
View
@@ -13,7 +13,6 @@
document.observe('dom:loaded', function(event) {
new Rating({
onRate: function(element, value) {
- alert(element.id + " - " + value)
},
labelTemplate: "#{rate} #{text}",
resetDelay: 0.1
View
@@ -48,8 +48,10 @@ var Ratable = Class.create({
labelClassName: 'label',
labelValues: ['bad', 'not bad', 'good', 'very good', 'excellent'],
labelTemplate: "#{text}",
- resetDelay: 0.0
- }, arguments[1] || {});
+ resetDelay: 0.0,
+ disabledOnRate: true
+ }, arguments[1] || {});
+ this.disabled = false;
this.stars = new Array();
this.resettingTimeout = null;
this.label = this.element.down('.' + this.options.labelClassName);
@@ -80,15 +82,23 @@ var Ratable = Class.create({
},
handleMouseOver: function(event) {
+ if(this.disabled) return;
if(this.resettingTimeout) clearTimeout(this.resettingTimeout);
this.select();
this.updateLabel();
},
handleMouseOut: function(event) {
+ if(this.disabled) return;
this.resettingTimeout = this.deselect.bind(this).delay(this.options.resetDelay);
},
+ handleClick: function(event) {
+ if(this.disabled) return;
+ if(this.options.disabledOnRate) this.disabled = true;
+ this.options.onRate(this.element, this.getCurrentRating());
+ },
+
updateLabel: function() {
if(this.label) {
var rate = this.getCurrentRating();
@@ -104,11 +114,7 @@ var Ratable = Class.create({
deselect: function() {
this.reset();
this.element.removeClassName('selected');
- },
-
- handleClick: function(event) {
- this.options.onRate(this.element, this.getCurrentRating());
- },
+ },
getCurrentRating: function() {
var i;
@@ -119,6 +125,7 @@ var Ratable = Class.create({
},
selectStar: function(selected_star) {
+ if(this.disabled) return;
var found = false;
this.stars.each(function(star) {
found ? star.deselect() : star.select();

0 comments on commit 21bc933

Please sign in to comment.