diff --git a/README.md b/README.md index c9e0a15..26a5d82 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,15 @@ starrr $('.starrr').starrr() ``` +### Set rating on the fly +```html +
+``` + +```js +$('.starrr').starrr() +``` + ### With an existing rating ```js diff --git a/dist/starrr.css b/dist/starrr.css index 88bcbb4..c1fa4ec 100644 --- a/dist/starrr.css +++ b/dist/starrr.css @@ -1,8 +1,16 @@ .starrr { - display: inline-block; } - .starrr a { - font-size: 16px; - padding: 0 1px; - cursor: pointer; - color: #FFD119; - text-decoration: none; } + display: inline-block; +} + +.starrr a { + font-size: 16px; + padding: 0 1px; + cursor: pointer; + color: #FFD119; + text-decoration: none; +} + +.readonly { + cursor: default !important; + color: #ffe373 !important; +} diff --git a/dist/starrr.js b/dist/starrr.js index 45d4b4f..a14b52a 100644 --- a/dist/starrr.js +++ b/dist/starrr.js @@ -17,7 +17,14 @@ var slice = [].slice; this.$el = $el; this.createStars(); this.syncRating(); + + var attrRating = parseInt($(this)[0].$el.attr('starrr-rating')); + + if (typeof(attrRating) == 'number') + this.syncRating(attrRating) + if (this.options.readOnly) { + $(this)[0].$el.children().addClass('readonly') return; } this.$el.on('mouseover.starrr', 'a', (function(_this) { @@ -53,9 +60,6 @@ var slice = [].slice; }; Starrr.prototype.setRating = function(rating) { - if (this.options.rating === rating) { - rating = void 0; - } this.options.rating = rating; this.syncRating(); return this.$el.trigger('starrr:change', rating);