Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created September 22, 2009 21:15
Show Gist options
  • Save rmurphey/191449 to your computer and use it in GitHub Desktop.
Save rmurphey/191449 to your computer and use it in GitHub Desktop.
dojo.provide('myProject.Stars');
dojo.require('dijit._Widget');
dojo.declare('myProject.Stars', dijit._Widget, {
postCreate : function() {
this.stars = dojo.query('div', this.domNode)[0];
this.input = dojo.query('input', this.domNode)[0];
this.hoverConnections = [];
for (i=1; i<6; i++) {
var span = dojo.create('span', {
'data-value' : i,
'class' : 'star_helper'
});
this.hoverConnections.push(dojo.connect(span, 'onmouseover', this, '_update'));
this.hoverConnections.push(dojo.connect(span, 'onmouseout', this, '_reset'));
this.connect(span, 'onclick', '_vote');
dojo.place(span, this.stars, 'last');
}
},
_update : function(e) {
var val = dojo.attr(e.currentTarget, 'data-value');
dojo.attr(this.domNode, 'class', 'stars value_' + val);
},
_reset : function(e) {
dojo.attr(this.domNode, 'class', 'stars value_0');
},
_vote : function(e) {
dojo.forEach(this.hoverConnections, function(connection) {
dojo.disconnect(connection);
});
this._update(e);
this.input.value = dojo.attr(e.currentTarget, 'data-value');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment