javascripts/right-rater-src.js in right-rails-0.4.4 vs javascripts/right-rater-src.js in right-rails-0.5.0

- old
+ new

@@ -1,18 +1,18 @@ /** * Simple rating script * * Visit http://rightjs.org/ui/rater for details * - * Copyright (C) 2009 Nikolay V. Nemshilov aka St. + * Copyright (C) 2009-2010 Nikolay V. Nemshilov */ if (!self.RightJS) throw "Gimme RightJS"; /** * The Rating widget * - * Copyright (C) 2009 Nikolay V. Nemshilov aka St. + * Copyright (C) 2009-2010 Nikolay V. Nemshilov */ var Rater = new Class(Observer, { extend: { EVENTS: $w('change hover send'), @@ -26,17 +26,13 @@ url: null, // an url to send results with AJAX param: 'rate', // the value param name Xhr: null // additional Xhr options }, - - // searches and initializes rating units - rescan: function(scope) { - ($(scope)||document).select('div.right-rater').each(function(element) { - if (!element._rater) new Rater(element); - }); - } + + // DEPRECATED: searches and initializes rating units + rescan: function(scope) {} }, /** * basic constructor * @@ -49,10 +45,13 @@ this.element = (args[0] && !isHash(args[0])) ? $(args[0]) : null; this.$super(isHash(args.last()) ? args.last() : this.element ? eval('('+this.element.get('data-rater-options')+')') : null); if (!this.element) this.element = this.build(); + if (!this.options.value) + this.options.value = this.element.select('.right-rater-glow').length; + this.element._rater = this.init(); }, /** * Sets the element value @@ -239,10 +238,19 @@ }); /** * Document on-load trigger for units auto-discovery * - * Copyright (C) 2009 Nikolay V. Nemshilov aka St. + * Copyright (C) 2009-2010 Nikolay V. Nemshilov */ -document.onReady(function() { Rater.rescan(); }); +document.onMouseover(function(event) { + var target = event.target, element = [target].concat(target.parents()).first('hasClass', 'right-rater'); + + if (element) { + var rater = element._rater || new Rater(element); + if (target.parentNode === element) + target.fire('mouseover'); + } + +}); -document.write("<style type=\"text/css\">div.right-rater,div.right-rater div{margin:0;padding:0;background:none;border:none;display:inline-block;*display:inline;*zoom:1;font-family:Arial;font-size:110%}div.right-rater{width:6em;vertical-align:middle}div.right-rater div{width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.right-rater div.right-rater-glow{color:brown;text-shadow:#666 .05em .05em .15em}div.right-rater-disabled div{cursor:default}</style>"); +document.write("<style type=\"text/css\">div.right-rater,div.right-rater div{margin:0;padding:0;background:none;border:none;display:inline-block;*display:inline;*zoom:1;font-family:Arial;font-size:110%}div.right-rater{width:6em;height:1em;vertical-align:middle}div.right-rater div{float:left;width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.right-rater div.right-rater-glow{color:brown;text-shadow:#666 .05em .05em .15em}div.right-rater-disabled div{cursor:default}</style>"); \ No newline at end of file