root / trunk / web / dojo / dojox / form / Rating.js
History | View | Annotate | Download (1.9 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.form.Rating"]){ |
||
9 | dojo._hasResource["dojox.form.Rating"]=true; |
||
10 | dojo.provide("dojox.form.Rating");
|
||
11 | dojo.require("dijit.form._FormWidget");
|
||
12 | dojo.declare("dojox.form.Rating",dijit.form._FormWidget,{templateString:null,numStars:3,value:0,constructor:function(_1){ |
||
13 | dojo.mixin(this,_1);
|
||
14 | var _2="<div dojoAttachPoint=\"domNode\" class=\"dojoxRating dijitInline\">"+"<input type=\"hidden\" value=\"0\" dojoAttachPoint=\"focusNode\" /><ul>${stars}</ul>"+"</div>"; |
||
15 | var _3="<li class=\"dojoxRatingStar dijitInline\" dojoAttachEvent=\"onclick:onStarClick,onmouseover:_onMouse,onmouseout:_onMouse\" value=\"${value}\"></li>"; |
||
16 | var _4=""; |
||
17 | for(var i=0;i<this.numStars;i++){ |
||
18 | _4+=dojo.string.substitute(_3,{value:i+1}); |
||
19 | } |
||
20 | this.templateString=dojo.string.substitute(_2,{stars:_4}); |
||
21 | },postCreate:function(){ |
||
22 | this.inherited(arguments); |
||
23 | this._renderStars(this.value); |
||
24 | },_onMouse:function(_5){ |
||
25 | if(this._hovering){ |
||
26 | var _6=+dojo.attr(_5.target,"value"); |
||
27 | this.onMouseOver(_5,_6);
|
||
28 | this._renderStars(_6,true); |
||
29 | }else{
|
||
30 | this._renderStars(this.value); |
||
31 | } |
||
32 | },_renderStars:function(_7,_8){ |
||
33 | dojo.query(".dojoxRatingStar",this.domNode).forEach(function(_9,i){ |
||
34 | if(i+1>_7){ |
||
35 | dojo.removeClass(_9,"dojoxRatingStarHover");
|
||
36 | dojo.removeClass(_9,"dojoxRatingStarChecked");
|
||
37 | }else{
|
||
38 | dojo.removeClass(_9,"dojoxRatingStar"+(_8?"Checked":"Hover")); |
||
39 | dojo.addClass(_9,"dojoxRatingStar"+(_8?"Hover":"Checked")); |
||
40 | } |
||
41 | }); |
||
42 | },onStarClick:function(_a){ |
||
43 | var _b=+dojo.attr(_a.target,"value"); |
||
44 | this.setAttribute("value",_b==this.value?0:_b); |
||
45 | this._renderStars(this.value); |
||
46 | this.onChange(this.value); |
||
47 | },onMouseOver:function(){ |
||
48 | },setAttribute:function(_c,_d){ |
||
49 | this.inherited("setAttribute",arguments); |
||
50 | if(_c=="value"){ |
||
51 | this._renderStars(this.value); |
||
52 | this.onChange(this.value); |
||
53 | } |
||
54 | }}); |
||
55 | } |