1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
Prado.WebUI.TRatingList = Class.create();
Prado.WebUI.TRatingList.prototype =
{
selectedIndex : -1,
initialize : function(options)
{
this.options = options;
this.element = $(options['ID']);
Element.addClassName(this.element,options.cssClass);
var width = options.total * options.dx;
this.element.style.width = width+"px";
Event.observe(this.element, 'mouseover', this.hover.bindEvent(this));
Event.observe(this.element, 'mouseout', this.recover.bindEvent(this));
Event.observe(this.element, 'click', this.click.bindEvent(this));
this._onMouseMoveEvent = this.mousemoved.bindEvent(this);
this.selectedIndex = options.pos;
this.radios = document.getElementsByName(options.field);
this.caption = CAPTION();
this.element.appendChild(this.caption);
this.showPosition(this.selectedIndex,false);
},
hover : function()
{
Event.observe(this.element, "mousemove", this._onMouseMoveEvent);
},
recover : function()
{
Event.stopObserving(this.element, "mousemove", this._onMouseMoveEvent);
this.showPosition(this.selectedIndex,false);
},
mousemoved : function(e)
{
this.updatePosition(e,true);
},
updatePosition : function(e, hovering)
{
var obj = Event.element(e);
var elementPos = Position.cumulativeOffset(obj);
var clientX = Event.pointerX(e) - elementPos[0];
var pos = parseInt(clientX / this.options.dx);
if(!hovering || this.options.pos != pos)
this.showPosition(pos, hovering)
},
click : function(ev)
{
this.updatePosition(ev,false);
this.selectedIndex = this.options.pos;
for(var i = 0; i < this.radios.length; i++)
this.radios[i].checked = (i == this.selectedIndex);
if(isFunction(this.options.onChange))
this.options.onChange(this, this.selectedIndex);
},
showPosition : function(pos, hovering)
{
if(pos >= this.options.total) return;
var dy = this.options.dy * (pos+1) + this.options.iy;
var dx = hovering ? this.options.hx + this.options.ix : this.options.ix;
this.element.style.backgroundPosition = "-"+dx+"px -"+dy+"px";
this.options.pos = pos;
this.caption.innerHTML = pos >= 0 ?
this.radios[this.options.pos].value : this.options.caption;
}
}
|