Debian Codegraph @

dojox/mobile/Rating.js

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