Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a bunch of small bugs

Made it so when you load a page, the stars are populated properly. Also
fixed the clear all box to actually clear out the stars.
  • Loading branch information...
commit 84a2308f727825a9acfc8e4a1ad9dbdd9bccd488 1 parent 52164e8
@dovy dovy authored
Showing with 19 additions and 14 deletions.
  1. +1 −1  default.html
  2. +18 −8 jquery.rating.js
  3. +0 −5 jquery.rating.pack.js
View
2  default.html
@@ -2,7 +2,7 @@
<head>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
- <script type="text/javascript" src="jquery.rating2.js"></script>
+ <script type="text/javascript" src="jquery.rating.js"></script>
<link rel="stylesheet" media="screen" type="text/css" href="jquery.rating.css" />
<script type="text/javascript">
View
26 jquery.rating.js
@@ -2,9 +2,14 @@
// rating Plugin
// By Chris Richards
// Last Update: 6/21/2011
-//
// Turns a select box into a star rating control.
//
+//
+// Updated by Dovy Paukstys 21 Sept. 2011
+// Fixed the click to clear out stars not working with newer jquery, but may not have ever worked.
+// Also fixed it so on a new page load it will properly populate the stars as they should be.
+//
+//
//Keeps '$' pointing to the jQuery version
(function ($) {
@@ -65,10 +70,9 @@
var elm = $(evt.target);
var value = settings.cancelValue;
//Are we over the Cancel or the star?
- if( elm.hasClass("ui-rating-cancel") )
- {
- //Clear all of the stars
- methods.empty(elm);
+ elm.parents(".content-box-content:first").removeClass('formerror');
+ if( elm.hasClass("ui-rating-cancel") ) {
+ methods.empty(elm, elm.parent());
}
else
{
@@ -97,18 +101,24 @@
{
var value = $(this).val();
methods.setValue(value, evt.data.container, evt.data.selectBox);
+ if (isDirty)
+ isDirty = true;
},
setValue: function(value, container, selectBox)
{
//Set a new target and let the method know the select has already changed.
var evt = {"target": null, "data": {}};
- evt.target = $(".ui-rating-star[value="+ value +"]", container);
+
+ evt.target = $(".ui-rating-star[title="+ value +"]", container);
evt.data.selectBox = selectBox;
evt.data.hasChanged = true;
methods.click(evt);
},
- empty: function(elm)
+ empty: function(elm, parent)
{
+ // Fix to remove all stars
+ parent.find('.ui-rating-star').removeClass('ui-rating-full');
+ parent.find('.ui-rating-star').addClass('ui-rating-empty');
//Clear all of the stars
elm.prop("className", "ui-rating-cancel ui-rating-cancel-empty")
.nextAll().prop("className", "ui-rating-star ui-rating-empty");
@@ -193,4 +203,4 @@
};
-})(jQuery);
+})(jQuery);
View
5 jquery.rating.pack.js
@@ -1,5 +0,0 @@
-// Chris Richards 2009
-// rating control for jQuery. version 1.07
-// Last Update 6/21/2011
-// http://zensoftware.org/
-(function(c){c.fn.rating=function(h){var d={showCancel:!0,cancelValue:null,cancelTitle:"Cancel",startValue:null,disabled:!1},e={hoverOver:function(a){a=c(a.target);a.hasClass("ui-rating-cancel")?a.addClass("ui-rating-cancel-full"):a.prevAll().andSelf().not(".ui-rating-cancel").addClass("ui-rating-hover")},hoverOut:function(a){a=c(a.target);a.hasClass("ui-rating-cancel")?a.addClass("ui-rating-cancel-empty").removeClass("ui-rating-cancel-full"):a.prevAll().andSelf().not(".ui-rating-cancel").removeClass("ui-rating-hover")}, click:function(a){var b=c(a.target),f=d.cancelValue;b.hasClass("ui-rating-cancel")?e.empty(b):(b.closest(".ui-rating-star").prevAll().andSelf().not(".ui-rating-cancel").prop("className","ui-rating-star ui-rating-full"),b.closest(".ui-rating-star").nextAll().not(".ui-rating-cancel").prop("className","ui-rating-star ui-rating-empty"),b.siblings(".ui-rating-cancel").prop("className","ui-rating-cancel ui-rating-cancel-empty"),f=b.attr("value"));a.data.hasChanged||c(a.data.selectBox).val(f).trigger("change")}, change:function(a){var b=c(this).val();e.setValue(b,a.data.container,a.data.selectBox)},setValue:function(a,b,d){var g={target:null,data:{}};g.target=c(".ui-rating-star[value="+a+"]",b);g.data.selectBox=d;g.data.hasChanged=!0;e.click(g)},empty:function(a){a.prop("className","ui-rating-cancel ui-rating-cancel-empty").nextAll().prop("className","ui-rating-star ui-rating-empty")}};return this.each(function(){var a=c(this),b,f;"select-one"===this.type&&!a.prop("hasProcessed")&&(h&&c.extend(d,h),a.hide(), a.prop("hasProcessed",!0),b=c("<div/>").prop({title:this.title,className:"ui-rating"}).insertAfter(a),c("option",a).each(function(){this.value!=""&&c("<a/>").prop({className:"ui-rating-star ui-rating-empty",title:c(this).text(),value:this.value}).appendTo(b)}),!0==d.showCancel&&c("<a/>").prop({className:"ui-rating-cancel ui-rating-cancel-empty",title:d.cancelTitle}).appendTo(b),0!==c("option:selected",a).size()?e.setValue(a.val(),b,a):(f=null!==d.startValue?d.startValue:d.cancelValue,e.setValue(f, b,a),a.val(f)),!0!==d.disabled&&a.prop("disabled")!==!0&&c(b).bind("mouseover",e.hoverOver).bind("mouseout",e.hoverOut).bind("click",{selectBox:a},e.click),a.bind("change",{selectBox:a,container:b},e.change))})}})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.