| 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 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
var Rating = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiRating" : "dojox.mobile.Rating", [WidgetBase], { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
image: "", |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
numStars: 5, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
value: 0, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
alt: "", |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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(value){ |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
this._set("value", value); |
| 60 |
var h = this.imgNode.height; |
| 61 |
if(h == 0){ return; } |
| 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; |
| 67 |
}else if(i >= value){ |
| 68 |
left = w; |
| 69 |
}else{ |
| 70 |
left = w * 2; |
| 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(parent){ |
| 84 |
|
| 85 |
|
| 86 |
return parent; |
| 87 |
} |
| 88 |
}); |
| 89 |
|
| 90 |
return has("dojo-bidi") ? declare("dojox.mobile.Rating", [Rating, BidiRating]) : Rating; |
| 91 |
|
| 92 |
}); |