Files
yii/framework/web/js/source/jquery.rating.js.patch
2009-02-27 17:22:13 +00:00

60 lines
3.2 KiB
Diff

Index: jquery.rating.js
===================================================================
--- jquery.rating.js (revision 635)
+++ jquery.rating.js (working copy)
@@ -14,6 +14,9 @@
It transforms a set of radio type input elements to star rating type and remain the radio element name and value,
so could be integrated with your form. It acts as a normal radio button.
modified by : Logan Cai (cailongqun[at]yahoo.com.cn)
+
+ Last modified by Qiang Xue on Feb. 26, 2009
+ added support to allow input names like post[rating] (previously this won't work).
*/
/*# AVOID COLLISIONS #*/
@@ -46,20 +49,20 @@
groups: {},// allows multiple star ratings on one page
event: {// plugin event handlers
fill: function(n, el, settings, state){ // fill to the current mouse position.
- //if(window.console) console.log(['fill', $(el), $(el).prevAll('.star_group_'+n), arguments]);
+ //if(window.console) console.log(['fill', $(el), $(el).prevAll('.star_group_'+n.replace(/\[|\]/g, "_")), arguments]);
this.drain(n);
- $(el).prevAll('.star_group_'+n).andSelf().addClass('star_'+(state || 'hover'));
+ $(el).prevAll('.star_group_'+n.replace(/\[|\]/g, "_")).andSelf().addClass('star_'+(state || 'hover'));
// focus handler, as requested by focusdigital.co.uk
var lnk = $(el).children('a'); val = lnk.text();
if(settings.focus) settings.focus.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
},
drain: function(n, el, settings) { // drain all the stars.
- //if(window.console) console.log(['drain', $(el), $(el).prevAll('.star_group_'+n), arguments]);
- $.rating.groups[n].valueElem.siblings('.star_group_'+n).removeClass('star_on').removeClass('star_hover');
+ //if(window.console) console.log(['drain', $(el), $(el).prevAll('.star_group_'+n.replace(/\[|\]/g, "_")), arguments]);
+ $.rating.groups[n].valueElem.siblings('.star_group_'+n.replace(/\[|\]/g, "_")).removeClass('star_on').removeClass('star_hover');
},
reset: function(n, el, settings){ // Reset the stars to the default index.
if(!$($.rating.groups[n].current).is('.cancel'))
- $($.rating.groups[n].current).prevAll('.star_group_'+n).andSelf().addClass('star_on');
+ $($.rating.groups[n].current).prevAll('.star_group_'+n.replace(/\[|\]/g, "_")).andSelf().addClass('star_on');
// blur handler, as requested by focusdigital.co.uk
var lnk = $(el).children('a'); val = lnk.text();
if(settings.blur) settings.blur.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
@@ -99,8 +102,7 @@
////if(window.console) console.log([this.name, settings.half, settings.split], '#');
// Generate internal control ID
- // - ignore square brackets in element names
- var n = (this.name || 'unnamed-rating').replace(/\[|\]+/g, "_");
+ var n = (this.name || 'unnamed-rating');
// Grouping
if(!$.rating.groups[n]) $.rating.groups[n] = {count: 0};
@@ -150,7 +152,7 @@
};
// Remember group name so controls within the same container don't get mixed up
- $(eStar).addClass('star_group_'+n);
+ $(eStar).addClass('star_group_'+n.replace(/\[|\]/g, "_"));
// readOnly?
if($.rating.groups[n].readOnly)//{ //save a byte!