123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- define("dojox/form/Rating", [
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/dom-attr",
- "dojo/dom-class",
- "dojo/string",
- "dojo/query",
- "dijit/form/_FormWidget"
- ], function(declare, lang, domAttr, domClass, string, query, FormWidget){
-
- return declare("dojox.form.Rating", FormWidget,{
-
-
-
-
-
-
- templateString: null,
-
-
- numStars: 3,
-
-
- value: 0,
- constructor:function(/*Object*/params){
-
-
- lang.mixin(this, params);
-
-
-
-
-
- var tpl = '<div dojoAttachPoint="domNode" class="dojoxRating dijitInline">' +
- '<input type="hidden" value="0" dojoAttachPoint="focusNode" /><ul>${stars}</ul>' +
- '</div>';
-
- var starTpl = '<li class="dojoxRatingStar dijitInline" dojoAttachEvent="onclick:onStarClick,onmouseover:_onMouse,onmouseout:_onMouse" value="${value}"></li>';
- var rendered = "";
- for(var i = 0; i < this.numStars; i++){
- rendered += string.substitute(starTpl, {value:i+1});
- }
- this.templateString = string.substitute(tpl, {stars:rendered});
- },
- postCreate: function(){
- this.inherited(arguments);
- this._renderStars(this.value);
- },
- _onMouse: function(evt){
- if(this.hovering){
- var hoverValue = +domAttr.get(evt.target, "value");
- this.onMouseOver(evt, hoverValue);
- this._renderStars(hoverValue, true);
- }else{
- this._renderStars(this.value);
- }
- },
- _renderStars: function(value, hover){
-
- query(".dojoxRatingStar", this.domNode).forEach(function(star, i){
- if(i + 1 > value){
- domClass.remove(star, "dojoxRatingStarHover");
- domClass.remove(star, "dojoxRatingStarChecked");
- }else{
- domClass.remove(star, "dojoxRatingStar" + (hover ? "Checked" : "Hover"));
- domClass.add(star, "dojoxRatingStar" + (hover ? "Hover" : "Checked"));
- }
- });
- },
- onStarClick:function(/* Event */evt){
-
-
- var newVal = +domAttr.get(evt.target, "value");
- this.setAttribute("value", newVal == this.value ? 0 : newVal);
- this._renderStars(this.value);
- this.onChange(this.value);
- },
- onMouseOver: function(/*evt, value*/){
-
- },
- setAttribute: function(/*String*/key, /**/value){
-
- this.set(key, value);
- if(key=="value"){
- this._renderStars(this.value);
- this.onChange(this.value);
- }
- }
- });
- });
|