/** * Rating widget for RightJS * http://rightjs.org/ui/rater * * Copyright (C) 2009-2010 Nikolay Nemshilov */ var Rater=RightJS.Rater=function(h,b){var g=b.$,k=b.$w,l=b.Xhr,m=b.isString,n=b.isNumber,i=new (function(a,e){if(!e){e=a;a="DIV"}var f=new b.Wrapper(b.Element.Wrappers[a]||b.Element,{initialize:function(d,c){this.key=d;var j=[{"class":"rui-"+d}];this instanceof b.Input||this instanceof b.Form||j.unshift(a);this.$super.apply(this,j);if(b.isString(c))c=b.$(c);if(c instanceof b.Element){this._=c._;if("$listeners"in c)c.$listeners=c.$listeners;c={}}this.setOptions(c,this);return this},setOptions:function(d, c){c=c||this;b.Options.setOptions.call(this,b.Object.merge(d,eval("("+(c.get("data-"+this.key)||"{}")+")")));return this}});f=new b.Wrapper(f,e);b.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})({include:{assignTo:function(a){var e=b(function(d,c){if(d=g(d))d[d.setValue?"setValue":"update"](c.target.getValue())}).curry(a),f=b(function(d,c){(d=g(d))&&d.onChange&&d.onChange(b(function(){this.setValue(d.value())}).bind(c))}).curry(a);if(g(a)){e({target:this});f(this)}else g(h).onReady(b(function(){e({target:this}); f(this)}.bind(this)));return this.onChange(e)}},extend:{version:"2.0.0",EVENTS:k("change hover send"),Options:{html:"★",size:5,value:null,update:null,disabled:false,disableOnVote:false,url:null,param:"rate",Xhr:null}},initialize:function(a){this.$super("rater",a).on({click:this._clicked,mouseover:this._hovered,mouseout:this._left});if(this.empty())for(a=0;a"+this.options.html+"");a=this.options;if(a.value===null)a.value=this.find(".active").length; this.setValue(a.value);a.disabled&&this.disable();a.update&&this.assignTo(a.update)},setValue:function(a){if(!this.disabled()){a=m(a)?b(a).toInt():a;a=n(a)?b(a).round():0;a=b(a).max(this.options.size);a=b(a).min(0);this.highlight(a);if(this.value!=a)this.fire("change",this.value=a,this)}return this},getValue:function(){return this.value},send:function(){if(this.options.url){this.request=(new l(this.options.url,this.options.Xhr)).send(this.options.param+"="+this.value);this.fire("send",this.value, this)}return this},disable:function(){return this.addClass("rui-rater-disabled")},enable:function(){return this.removeClass("rui-rater-disabled")},disabled:function(){return this.hasClass("rui-rater-disabled")},_hovered:function(a){a=this.children().indexOf(a.target);if(!this.disabled()&&a>-1){this.highlight(a+1);this.fire("hover",a+1,this)}},_clicked:function(a){a=this.children().indexOf(a.target);if(!this.disabled()&&a>-1){this.setValue(a+1);this.options.disableOnVote&&this.disable();this.send()}}, _left:function(){this.setValue(this.value)},highlight:function(a){this.children().each(function(e,f){e[a-1div.rui-rater,div.rui-rater div{margin:0;padding:0;background:none;border:none;display:inline-block; *display:inline; *zoom:1;font-family:Arial;font-size:110%}div.rui-rater{width:6em;height:1em;vertical-align:middle}div.rui-rater div{float:left;width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.rui-rater div.active{color:brown;text-shadow:#666 .05em .05em .15em}div.rui-rater-disabled div{cursor:default}'); return i}(document,RightJS);