Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 7d9fe731-5e54-0410-9b70-c3ef49213c18
  • Loading branch information
diego.alto committed Mar 12, 2009
1 parent 1085db0 commit e4c2dd1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
8 changes: 4 additions & 4 deletions index.html
@@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<title>jQuery Star Rating Plugin v2.61 (2009-01-23)</title> <title>jQuery Star Rating Plugin v2.62 (2009-03-12)</title>
<!--// documentation resources //--> <!--// documentation resources //-->
<script src="jquery-1.31.js" type="text/javascript"></script> <script src="jquery-1.31.js" type="text/javascript"></script>
<script src="documentation.js" type="text/javascript"></script> <script src="documentation.js" type="text/javascript"></script>
Expand Down Expand Up @@ -37,7 +37,7 @@
<td valign="middle"> <td valign="middle">
<h1>jQuery Star Rating Plugin</h1> <h1>jQuery Star Rating Plugin</h1>
<span style="cursor:help; background:#C00; padding:2px; color:#FFF;" title="Current Version"> <span style="cursor:help; background:#C00; padding:2px; color:#FFF;" title="Current Version">
v<strong>2.61</strong> v<strong>2.62</strong>
</span> </span>
</td> </td>
<td valign="middle" width="450" align="right"> <td valign="middle" width="450" align="right">
Expand Down Expand Up @@ -748,7 +748,7 @@ <h2>Download</h2>
<td valign="top"> <td valign="top">
<big> <big>
<img src="/@/download.gif" style="margin:0 5px 5px 0; float:left;"> <img src="/@/download.gif" style="margin:0 5px 5px 0; float:left;">
v<strong>2.61</strong> v<strong>2.62</strong>
<a href="http://jquery-star-rating-plugin.googlecode.com/svn/trunk/star-rating.zip"><strong>star-rating.zip</strong></a> <a href="http://jquery-star-rating-plugin.googlecode.com/svn/trunk/star-rating.zip"><strong>star-rating.zip</strong></a>
</big> </big>
</td> </td>
Expand Down Expand Up @@ -827,7 +827,7 @@ <h2>Alternative Download - From this website</h2>
<td valign="top" align="right">Full Package:</td> <td valign="top" align="right">Full Package:</td>
<td valign="top"> <td valign="top">
<img src="/@/download.gif" style="margin:0 5px 5px 0; float:left;"> <img src="/@/download.gif" style="margin:0 5px 5px 0; float:left;">
v<strong>2.61</strong> v<strong>2.62</strong>
<a href="star-rating.zip"><strong>star-rating.zip</strong></a> <a href="star-rating.zip"><strong>star-rating.zip</strong></a>
</td> </td>
</tr> </tr>
Expand Down
55 changes: 31 additions & 24 deletions jquery.rating.js
@@ -1,5 +1,5 @@
/* /*
### jQuery Star Rating Plugin v2.61 - 2009-01-23 ### ### jQuery Star Rating Plugin v2.62 - 2009-03-12 ###
* Home: http://www.fyneworks.com/jquery/star-rating/ * Home: http://www.fyneworks.com/jquery/star-rating/
* Code: http://code.google.com/p/jquery-star-rating-plugin/ * Code: http://code.google.com/p/jquery-star-rating-plugin/
* *
Expand Down Expand Up @@ -43,37 +43,38 @@
//callback: function(){}, // executed when a star is clicked //callback: function(){}, // executed when a star is clicked


// required properties: // required properties:
groups: {},// allows multiple star ratings on one page group: {},// holds details of a group of elements which form a star rating widget
calls: 0,// differentiates groups of the same name to be created on separate plugin calls
event: {// plugin event handlers event: {// plugin event handlers
fill: function(n, el, settings, state){ // fill to the current mouse position. 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), arguments]);
this.drain(n); this.drain(n);
$(el).prevAll('.star_group_'+n).andSelf().addClass('star_'+(state || 'hover')); $(el).prevAll('.star_group_'+n).andSelf().addClass('star_'+(state || 'hover'));
// focus handler, as requested by focusdigital.co.uk // focus handler, as requested by focusdigital.co.uk
var lnk = $(el).children('a'); val = lnk.text(); var lnk = $(el).children('a'); val = lnk.text();
if(settings.focus) settings.focus.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]); if(settings.focus) settings.focus.apply($.rating.group[n].valueElem[0], [val, lnk[0]]);
}, },
drain: function(n, el, settings) { // drain all the stars. drain: function(n, el, settings) { // drain all the stars.
//if(window.console) console.log(['drain', $(el), $(el).prevAll('.star_group_'+n), arguments]); //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'); $.rating.group[n].valueElem.siblings('.star_group_'+n).removeClass('star_on').removeClass('star_hover');
}, },
reset: function(n, el, settings){ // Reset the stars to the default index. reset: function(n, el, settings){ // Reset the stars to the default index.
if(!$($.rating.groups[n].current).is('.cancel')) if(!$($.rating.group[n].current).is('.cancel'))
$($.rating.groups[n].current).prevAll('.star_group_'+n).andSelf().addClass('star_on'); $($.rating.group[n].current).prevAll('.star_group_'+n).andSelf().addClass('star_on');
// blur handler, as requested by focusdigital.co.uk // blur handler, as requested by focusdigital.co.uk
var lnk = $(el).children('a'); val = lnk.text(); var lnk = $(el).children('a'); val = lnk.text();
if(settings.blur) settings.blur.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]); if(settings.blur) settings.blur.apply($.rating.group[n].valueElem[0], [val, lnk[0]]);
}, },
click: function(n, el, settings){ // Selected a star or cancelled click: function(n, el, settings){ // Selected a star or cancelled
$.rating.groups[n].current = el; $.rating.group[n].current = el;
var lnk = $(el).children('a'); val = lnk.text(); var lnk = $(el).children('a'); val = lnk.text();
// Set value // Set value
$.rating.groups[n].valueElem.val(val); $.rating.group[n].valueElem.val(val);
// Update display // Update display
$.rating.event.drain(n, el, settings); $.rating.event.drain(n, el, settings);
$.rating.event.reset(n, el, settings); $.rating.event.reset(n, el, settings);
// click callback, as requested here: http://plugins.jquery.com/node/1655 // click callback, as requested here: http://plugins.jquery.com/node/1655
if(settings.callback) settings.callback.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]); if(settings.callback) settings.callback.apply($.rating.group[n].valueElem[0], [val, lnk[0]]);
} }
}// plugin events }// plugin events
}; };
Expand All @@ -87,6 +88,9 @@
instanceSettings || {} /* just-in-time settings */ instanceSettings || {} /* just-in-time settings */
); );


// increment plugin calls
$.rating.calls++;

// loop through each matched element // loop through each matched element
this.each(function(i){ this.each(function(i){


Expand All @@ -95,28 +99,31 @@
instanceSettings || {} /* current call settings */, instanceSettings || {} /* current call settings */,
($.metadata? $(this).metadata(): ($.meta?$(this).data():null)) || {} /* metadata settings */ ($.metadata? $(this).metadata(): ($.meta?$(this).data():null)) || {} /* metadata settings */
); );

////if(window.console) console.log([this.name, settings.half, settings.split], '#'); ////if(window.console) console.log([this.name, settings.half, settings.split], '#');


// Generate internal control ID // Generate internal control ID
// - ignore square brackets in element names // - ignore square brackets in element names
var n = (this.name || 'unnamed-rating').replace(/\[|\]+/g, "_"); var n = (this.name || 'unnamed-rating').replace(/\[|\]+/g, "_");


// differentiate groups of the same name on separate plugin calls
// SEE: http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=5
n = $.rating.calls +'_'+ n;

// Grouping // Grouping
if(!$.rating.groups[n]) $.rating.groups[n] = {count: 0}; if(!$.rating.group[n]) $.rating.group[n] = {count: 0};
i = $.rating.groups[n].count; $.rating.groups[n].count++; i = $.rating.group[n].count; $.rating.group[n].count++;


// Accept readOnly setting from 'disabled' property // Accept readOnly setting from 'disabled' property
$.rating.groups[n].readOnly = $.rating.groups[n].readOnly || settings.readOnly || $(this).attr('disabled'); $.rating.group[n].readOnly = $.rating.group[n].readOnly || settings.readOnly || $(this).attr('disabled');


// Things to do with the first element... // Things to do with the first element...
if(i == 0){ if(i == 0){
// Create value element (disabled if readOnly) // Create value element (disabled if readOnly)
$.rating.groups[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '/>'); $.rating.group[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '/>');
// Insert value element into form // Insert value element into form
$(this).before($.rating.groups[n].valueElem); $(this).before($.rating.group[n].valueElem);


if($.rating.groups[n].readOnly || settings.required){ if($.rating.group[n].readOnly || settings.required){
// DO NOT display 'cancel' button // DO NOT display 'cancel' button
} }
else{ else{
Expand Down Expand Up @@ -153,7 +160,7 @@
$(eStar).addClass('star_group_'+n); $(eStar).addClass('star_group_'+n);


// readOnly? // readOnly?
if($.rating.groups[n].readOnly)//{ //save a byte! if($.rating.group[n].readOnly)//{ //save a byte!
// Mark star as readOnly so user can customize display // Mark star as readOnly so user can customize display
$(eStar).addClass('star_readonly'); $(eStar).addClass('star_readonly');
//} //save a byte! //} //save a byte!
Expand All @@ -167,10 +174,10 @@
.click(function(){ $.rating.event.click(n, this, settings); }); .click(function(){ $.rating.event.click(n, this, settings); });
//}; //save a byte! //}; //save a byte!


////if(window.console) console.log(['###', n, this.checked, $.rating.groups[n].initial]); ////if(window.console) console.log(['###', n, this.checked, $.rating.group[n].initial]);
if(this.checked) $.rating.groups[n].current = eStar; if(this.checked) $.rating.group[n].current = eStar;


//remove this checkbox // remove this checkbox - values will be stored in a hidden field
$(this).remove(); $(this).remove();


// reset display if last element // reset display if last element
Expand All @@ -179,12 +186,12 @@
}); // each element }); // each element


// initialize groups... // initialize groups...
for(n in $.rating.groups)//{ not needed, save a byte! for(n in $.rating.group)//{ not needed, save a byte!
(function(c, v, n){ if(!c) return; (function(c, v, n){ if(!c) return;
$.rating.event.fill(n, c, instanceSettings || {}, 'on'); $.rating.event.fill(n, c, instanceSettings || {}, 'on');
$(v).val($(c).children('a').text()); $(v).val($(c).children('a').text());
}) })
($.rating.groups[n].current, $.rating.groups[n].valueElem, n); ($.rating.group[n].current, $.rating.group[n].valueElem, n);
//}; not needed, save a byte! //}; not needed, save a byte!


return this; // don't break the chain... return this; // don't break the chain...
Expand Down
4 changes: 2 additions & 2 deletions jquery.rating.pack.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added star-rating.zip
Binary file not shown.

0 comments on commit e4c2dd1

Please sign in to comment.