Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/prrashi/rateYo into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
prrashi committed Apr 10, 2017
2 parents 6e8f0d6 + 954cee9 commit 52dbeef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
6 changes: 6 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<div class="rateyo"></div>
<div class="rateyo"></div>
<div class="rateyo"></div>
<div class="rateyo"
data-rateyo-rating="50%"
data-rateyo-rtl="true"
data-rateyo-spacing="10px"
data-rateyo-rated-fill="#FF0000"
data-rateyo-num-stars="10"></div>
<script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../src/jquery.rateyo.js"></script>

Expand Down
57 changes: 43 additions & 14 deletions src/jquery.rateyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@
}

var hexValues = hexRegex.exec(hex),
r = parseInt(hexValues[1], 16),
g = parseInt(hexValues[2], 16),
b = parseInt(hexValues[3], 16);
r = parseInt(hexValues[1], 16),
g = parseInt(hexValues[2], 16),
b = parseInt(hexValues[3], 16);

return {r:r, g:g, b:b};
};
Expand All @@ -137,7 +137,7 @@

if (newVal.length === 1) {

newVal = "0" + newVal;
newVal = "0" + newVal;
}

return newVal;
Expand Down Expand Up @@ -168,11 +168,11 @@
return "#" + r + g + b;
}

function RateYo ($node, options) {
function RateYo ($node, options) {

/*
* The Contructor, whose instances are used by plugin itself
*/
/*
* The Contructor, whose instances are used by plugin itself
*/

// Storing the HTML element as a property, for future access
this.node = $node.get(0);
Expand Down Expand Up @@ -263,6 +263,14 @@

percent = options.rtl ? 100 - percent : percent;

if (percent < 0) {

percent = 0;
} else if (percent > 100) {

percent = 100;
}

$ratedGroup.css("width", percent + "%");
}

Expand Down Expand Up @@ -563,7 +571,7 @@

if (spacing > 0) {

/*
/*
* If there is spacing between stars, take the percentage of width covered
* and subtract the percentage of width covered by stars and spacing, to find
* how many stars are covered, the number of stars covered is the rating
Expand Down Expand Up @@ -604,7 +612,7 @@
calculatedRating = maxValue - calculatedRating;
}

return calculatedRating;
return parseFloat(calculatedRating);
}

function setReadOnly (newValue) {
Expand Down Expand Up @@ -827,10 +835,10 @@

method = setSpacing;
break;
case "rtl":
case "rtl":

method = setRtl;
break;
break;
case "onInit":

method = setOnInit;
Expand Down Expand Up @@ -1087,10 +1095,31 @@

var existingInstance = getInstance(this, rateYoInstances);

if (!existingInstance) {
if (existingInstance) {

return new RateYo($(this), $.extend({}, options));
return existingInstance;
}

var $node = $(this),
dataAttrs = {};

$.each($node.data(), function (key, value) {

if (key.indexOf("rateyo") !== 0) {

return;
}

var optionName = key.replace(/^rateyo/, "");

optionName = optionName[0].toLowerCase() + optionName.slice(1);

dataAttrs[optionName] = value;

delete options[optionName];
});

return new RateYo($(this), $.extend({}, dataAttrs, options));
});
}

Expand Down

0 comments on commit 52dbeef

Please sign in to comment.