source: Dev/trunk/src/client/dojox/mobile/Rating.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.0 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/lang",
4        "dojo/dom-construct",
5        "dijit/_WidgetBase",
6        "./iconUtils"
7], function(declare, lang, domConstruct, WidgetBase, iconUtils){
8
9        // module:
10        //              dojox/mobile/Rating
11
12        return declare("dojox.mobile.Rating", WidgetBase, {
13                // summary:
14                //              A widget that displays a rating, usually with stars.
15                // description:
16                //              This widget simply shows the specified number of stars. It is a
17                //              read-only widget, and has no editing capability.
18
19                // image: String
20                //              Path to a star image, which includes three stars, full star,
21                //              empty star, and half star, from left to right.
22                image: "",
23
24                // numStars: Number
25                //              The number of stars to show.
26                numStars: 5,
27
28                // value: Number
29                //              The current value of the Rating.
30                value: 0,
31
32                // alt: String
33                //              An alternate text for the icon image.
34                alt: "",
35
36                /* internal properties */
37               
38                // baseClass: String
39                //              The name of the CSS class of this widget.
40                baseClass: "mblRating",
41
42                buildRendering: function(){
43                        this.inherited(arguments);
44                        this.domNode.style.display = "inline-block";
45                        var img = this.imgNode = domConstruct.create("img");
46                        this.connect(img, "onload",
47                                lang.hitch(this, function(){ this.set("value", this.value); }));
48                        iconUtils.createIcon(this.image, null, img);
49                },
50
51                _setValueAttr: function(/*Number*/value){
52                        // summary:
53                        //              Sets the value of the Rating.
54                        // tags:
55                        //              private
56                        this._set("value", value);
57                        var h = this.imgNode.height;
58                        if(h == 0){ return; } // loading of image has not been completed yet
59                        domConstruct.empty(this.domNode);
60                        var i, left, w = this.imgNode.width / 3;
61                        for(i = 0; i < this.numStars; i++){
62                                if(i <= value - 1){
63                                        left = 0; // full
64                                }else if(i >= value){
65                                        left = w; // empty
66                                }else{
67                                        left = w * 2; // half
68                                }
69                                var parent = domConstruct.create("div", {
70                                        style: {"float": "left"}
71                                }, this.domNode);
72                                iconUtils.createIcon(this.image,
73                                        "0," + left + "," + w + "," + h, null, this.alt, parent);
74                        }
75                }
76        });
77});
Note: See TracBrowser for help on using the repository browser.