From 6201b1d3daf2fbbdf5508275fbcdba5d5865f470 Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Thu, 22 Jun 2017 15:14:15 -0700 Subject: [PATCH 1/9] Added support of html5 attributes Added support of html5 starrr-rating has added, now you can use this attribute to set rating directly from element just by simply inserting the attribute and setting its value starrr-rating="x" --- dist/starrr.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/dist/starrr.js b/dist/starrr.js index 45d4b4f..636f355 100644 --- a/dist/starrr.js +++ b/dist/starrr.js @@ -7,8 +7,8 @@ var slice = [].slice; rating: void 0, max: 5, readOnly: false, - emptyClass: 'fa fa-star-o', - fullClass: 'fa fa-star', + emptyClass: 'fa fa-star-o fa-2x', + fullClass: 'fa fa-star fa-2x', change: function(e, value) {} }; @@ -17,26 +17,32 @@ 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) { return; } - this.$el.on('mouseover.starrr', 'a', (function(_this) { + this.$el.on('mouseover.starrr', '.rating a, a', (function(_this) { return function(e) { return _this.syncRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('mouseout.starrr', (function(_this) { + this.$el.on('mouseout.starrr', '.rating a', (function(_this) { return function() { return _this.syncRating(); }; })(this)); - this.$el.on('click.starrr', 'a', (function(_this) { + this.$el.on('click.starrr', '.rating, a', (function(_this) { return function(e) { e.preventDefault(); return _this.setRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('starrr:change', this.options.change); + this.$el.on('starrr:change', '.rating', this.options.change); } Starrr.prototype.getStars = function() { @@ -53,9 +59,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); From 4f94c403615967c3ee04da0e3b2ce14792881c3e Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Thu, 22 Jun 2017 15:25:01 -0700 Subject: [PATCH 2/9] Knocked some ambiguities. --- dist/starrr.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/starrr.js b/dist/starrr.js index 636f355..6eee39d 100644 --- a/dist/starrr.js +++ b/dist/starrr.js @@ -7,8 +7,8 @@ var slice = [].slice; rating: void 0, max: 5, readOnly: false, - emptyClass: 'fa fa-star-o fa-2x', - fullClass: 'fa fa-star fa-2x', + emptyClass: 'fa fa-star-o', + fullClass: 'fa fa-star', change: function(e, value) {} }; @@ -26,23 +26,23 @@ var slice = [].slice; if (this.options.readOnly) { return; } - this.$el.on('mouseover.starrr', '.rating a, a', (function(_this) { + this.$el.on('mouseover.starrr', 'a', (function(_this) { return function(e) { return _this.syncRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('mouseout.starrr', '.rating a', (function(_this) { + this.$el.on('mouseout.starrr', (function(_this) { return function() { return _this.syncRating(); }; })(this)); - this.$el.on('click.starrr', '.rating, a', (function(_this) { + this.$el.on('click.starrr', 'a', (function(_this) { return function(e) { e.preventDefault(); return _this.setRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('starrr:change', '.rating', this.options.change); + this.$el.on('starrr:change', this.options.change); } Starrr.prototype.getStars = function() { From 1adb2d17b2584257151855fe283f1cd36c8b94c8 Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Thu, 22 Jun 2017 15:44:49 -0700 Subject: [PATCH 3/9] Imporvement in read only tag --- dist/starrr.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dist/starrr.js b/dist/starrr.js index 6eee39d..28fca59 100644 --- a/dist/starrr.js +++ b/dist/starrr.js @@ -7,8 +7,8 @@ var slice = [].slice; rating: void 0, max: 5, readOnly: false, - emptyClass: 'fa fa-star-o', - fullClass: 'fa fa-star', + emptyClass: 'fa fa-star-o fa-2x', + fullClass: 'fa fa-star fa-2x', change: function(e, value) {} }; @@ -24,25 +24,26 @@ var slice = [].slice; this.syncRating(attrRating) if (this.options.readOnly) { + $(this)[0].$el.children().addClass('readonly') return; } - this.$el.on('mouseover.starrr', 'a', (function(_this) { + this.$el.on('mouseover.starrr', '.rating a, a', (function(_this) { return function(e) { return _this.syncRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('mouseout.starrr', (function(_this) { + this.$el.on('mouseout.starrr', '.rating a', (function(_this) { return function() { return _this.syncRating(); }; })(this)); - this.$el.on('click.starrr', 'a', (function(_this) { + this.$el.on('click.starrr', '.rating, a', (function(_this) { return function(e) { e.preventDefault(); return _this.setRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('starrr:change', this.options.change); + this.$el.on('starrr:change', '.rating', this.options.change); } Starrr.prototype.getStars = function() { From b7181e2fee57cf220c2e9d71c8296906b920f97d Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Thu, 22 Jun 2017 15:45:43 -0700 Subject: [PATCH 4/9] Added readonly class --- dist/starrr.css | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/dist/starrr.css b/dist/starrr.css index 88bcbb4..2c920cf 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: not-allowed !important; + color: #ffe373 !important; +} From b1787ac784b3962d6c690ed21f05c4b067d393a6 Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Thu, 22 Jun 2017 15:50:38 -0700 Subject: [PATCH 5/9] Update starrr.js --- dist/starrr.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/starrr.js b/dist/starrr.js index 28fca59..a14b52a 100644 --- a/dist/starrr.js +++ b/dist/starrr.js @@ -7,8 +7,8 @@ var slice = [].slice; rating: void 0, max: 5, readOnly: false, - emptyClass: 'fa fa-star-o fa-2x', - fullClass: 'fa fa-star fa-2x', + emptyClass: 'fa fa-star-o', + fullClass: 'fa fa-star', change: function(e, value) {} }; @@ -27,23 +27,23 @@ var slice = [].slice; $(this)[0].$el.children().addClass('readonly') return; } - this.$el.on('mouseover.starrr', '.rating a, a', (function(_this) { + this.$el.on('mouseover.starrr', 'a', (function(_this) { return function(e) { return _this.syncRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('mouseout.starrr', '.rating a', (function(_this) { + this.$el.on('mouseout.starrr', (function(_this) { return function() { return _this.syncRating(); }; })(this)); - this.$el.on('click.starrr', '.rating, a', (function(_this) { + this.$el.on('click.starrr', 'a', (function(_this) { return function(e) { e.preventDefault(); return _this.setRating(_this.getStars().index(e.currentTarget) + 1); }; })(this)); - this.$el.on('starrr:change', '.rating', this.options.change); + this.$el.on('starrr:change', this.options.change); } Starrr.prototype.getStars = function() { From 2e625ddeac4a6ebf29b9edcb3ebb9015bdee2f3a Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Fri, 23 Jun 2017 06:26:40 -0700 Subject: [PATCH 6/9] Updated docs for html5 starrr-rating attribute --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c9e0a15..8ecb251 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,15 @@ starrr $('.starrr').starrr() ``` +### Set stars on the fly +```html +
+``` + +```js +$('.starrr').starrr() +``` + ### With an existing rating ```js From 970d8dbd47c9d711e0a042ce64484d765cfafcd3 Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Fri, 23 Jun 2017 10:38:45 -0700 Subject: [PATCH 7/9] Update starrr.css --- dist/starrr.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/starrr.css b/dist/starrr.css index 2c920cf..4665b1f 100644 --- a/dist/starrr.css +++ b/dist/starrr.css @@ -10,7 +10,7 @@ text-decoration: none; } -.readonly { - cursor: not-allowed !important; +.readonly .fa { + cursor: default !important; color: #ffe373 !important; } From 5ab6b630e3a01fe2d0d39132a77043500fa21102 Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Fri, 23 Jun 2017 10:42:12 -0700 Subject: [PATCH 8/9] Update starrr.css --- dist/starrr.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/starrr.css b/dist/starrr.css index 4665b1f..c1fa4ec 100644 --- a/dist/starrr.css +++ b/dist/starrr.css @@ -10,7 +10,7 @@ text-decoration: none; } -.readonly .fa { +.readonly { cursor: default !important; color: #ffe373 !important; } From a774fd90b63496b26c44f3b64fe143bf6aded321 Mon Sep 17 00:00:00 2001 From: Hamza AVvan Date: Fri, 1 Sep 2017 03:14:01 -0700 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ecb251..26a5d82 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ starrr $('.starrr').starrr() ``` -### Set stars on the fly +### Set rating on the fly ```html
```