starrr 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +101 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/starrr_generator.rb +8 -0
- data/lib/generators/templates/stars.coffee +66 -0
- data/lib/generators/templates/stars.scss +13 -0
- data/lib/starrr/version.rb +3 -0
- data/lib/starrr.rb +5 -0
- data/starrr.gemspec +37 -0
- data/vendor/assets/javascripts/starrr.js +98 -0
- data/vendor/assets/stylesheets/starrr.css +8 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d04658a56b183c0acc7de02a9a0eeb171e63f18ec378c71048c24b4de05570b1
|
4
|
+
data.tar.gz: 1900be95d8ff4da62bc8940f002fd27de885adf672313d7019665bacc44c3298
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e20677bf47a63bc84f151e0344f98a09622653b62fbb6df447356a14607b936bcf462d3cd6ec928be3f694111180a7e4ff17958af383595354b96e18371ad84f
|
7
|
+
data.tar.gz: 763a98f7e1120b1cbce1798d6f90edef67eb12a391090c1d101d2cd47408d86d64d0b26161b34a4d27aef8bfb31b545235ff3e7dc30a067df56b38d61741a84e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Sikandar Tariq
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Starrr
|
2
|
+
Simple star/rating input field.
|
3
|
+
|
4
|
+
Courtesy: https://github.com/dobtco/starrr
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'starrr'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install starrr
|
20
|
+
|
21
|
+
Generate starter code
|
22
|
+
|
23
|
+
$ rails g starrr core_extensions
|
24
|
+
|
25
|
+
Import javascript file
|
26
|
+
```js
|
27
|
+
//= require starrr.js
|
28
|
+
```
|
29
|
+
|
30
|
+
Import css file
|
31
|
+
```sass
|
32
|
+
@import "starrr";
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### Create the stars
|
38
|
+
|
39
|
+
```html
|
40
|
+
<div class='starrr'></div>
|
41
|
+
```
|
42
|
+
|
43
|
+
```js
|
44
|
+
$('.starrr').starrr()
|
45
|
+
```
|
46
|
+
|
47
|
+
### With an existing rating
|
48
|
+
|
49
|
+
```js
|
50
|
+
$('.starrr').starrr({
|
51
|
+
rating: 4
|
52
|
+
})
|
53
|
+
```
|
54
|
+
|
55
|
+
### With more than 5 stars
|
56
|
+
|
57
|
+
```js
|
58
|
+
$('.starrr').starrr({
|
59
|
+
max: 10
|
60
|
+
})
|
61
|
+
```
|
62
|
+
|
63
|
+
### Read-only
|
64
|
+
|
65
|
+
```js
|
66
|
+
$('.starrr').starrr({
|
67
|
+
readOnly: true
|
68
|
+
})
|
69
|
+
```
|
70
|
+
|
71
|
+
### Do something with the rating...
|
72
|
+
|
73
|
+
```js
|
74
|
+
$('.starrr').starrr({
|
75
|
+
change: function(e, value){
|
76
|
+
alert('new rating is ' + value)
|
77
|
+
}
|
78
|
+
})
|
79
|
+
```
|
80
|
+
|
81
|
+
Or if you prefer events:
|
82
|
+
|
83
|
+
```js
|
84
|
+
$('.starrr').on('starrr:change', function(e, value){
|
85
|
+
alert('new rating is ' + value)
|
86
|
+
})
|
87
|
+
```
|
88
|
+
|
89
|
+
## Development
|
90
|
+
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
92
|
+
|
93
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sikandartariq1/starrr.
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "starrr"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class StarrrGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
|
+
|
4
|
+
def copy_initializer_file
|
5
|
+
copy_file "stars.coffee", "app/assets/javascripts/stars.coffee"
|
6
|
+
copy_file "stars.scss", "app/assets/stylesheets/stars.coffee"
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
(($, window) ->
|
2
|
+
|
3
|
+
window.Starrr = class Starrr
|
4
|
+
defaults:
|
5
|
+
rating: undefined
|
6
|
+
max: 5
|
7
|
+
readOnly: false
|
8
|
+
emptyClass: 'material-icons star_border'
|
9
|
+
fullClass: 'material-icons star'
|
10
|
+
change: (e, value) ->
|
11
|
+
|
12
|
+
constructor: ($el, options) ->
|
13
|
+
@options = $.extend({}, @defaults, options)
|
14
|
+
@$el = $el
|
15
|
+
@createStars()
|
16
|
+
@syncRating()
|
17
|
+
|
18
|
+
return if @options.readOnly
|
19
|
+
|
20
|
+
@$el.on 'mouseover.starrr', 'a', (e) =>
|
21
|
+
@syncRating(@getStars().index(e.currentTarget) + 1)
|
22
|
+
|
23
|
+
@$el.on 'mouseout.starrr', =>
|
24
|
+
@syncRating()
|
25
|
+
|
26
|
+
@$el.on 'click.starrr', 'a', (e) =>
|
27
|
+
e.preventDefault()
|
28
|
+
@setRating(@getStars().index(e.currentTarget) + 1)
|
29
|
+
|
30
|
+
@$el.on 'starrr:change', @options.change
|
31
|
+
|
32
|
+
getStars: ->
|
33
|
+
@$el.find('a')
|
34
|
+
|
35
|
+
createStars: ->
|
36
|
+
@$el.append("<a href='#' />") for [1..@options.max]
|
37
|
+
|
38
|
+
setRating: (rating) ->
|
39
|
+
rating = undefined if @options.rating == rating
|
40
|
+
@options.rating = rating
|
41
|
+
@syncRating()
|
42
|
+
@$el.trigger('starrr:change', rating)
|
43
|
+
|
44
|
+
getRating: ->
|
45
|
+
@options.rating
|
46
|
+
|
47
|
+
syncRating: (rating) ->
|
48
|
+
rating ||= @options.rating
|
49
|
+
$stars = @getStars()
|
50
|
+
for i in [1..@options.max]
|
51
|
+
$stars.
|
52
|
+
eq(i - 1).
|
53
|
+
removeClass(if rating >= i then @options.emptyClass else @options.fullClass).
|
54
|
+
addClass(if rating >= i then @options.fullClass else @options.emptyClass)
|
55
|
+
|
56
|
+
# Define the plugin
|
57
|
+
$.fn.extend starrr: (option, args...) ->
|
58
|
+
@each ->
|
59
|
+
data = $(@).data('starrr')
|
60
|
+
|
61
|
+
if !data
|
62
|
+
$(@).data 'starrr', (data = new Starrr($(@), option))
|
63
|
+
if typeof option == 'string'
|
64
|
+
data[option].apply(data, args)
|
65
|
+
|
66
|
+
) window.jQuery, window
|
data/lib/starrr.rb
ADDED
data/starrr.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "starrr/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "starrr"
|
8
|
+
spec.version = Starrr::VERSION
|
9
|
+
spec.authors = ["Sikandar Tariq"]
|
10
|
+
spec.email = ["sikandar.tariq@thedevden.co"]
|
11
|
+
|
12
|
+
spec.summary = "1-5 (or 1-n) star rating in < 75 lines of code."
|
13
|
+
spec.description = "rails front-end library for star/rating input field"
|
14
|
+
spec.homepage = "https://github.com/sikandartariq1/starrr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
var slice = [].slice;
|
2
|
+
|
3
|
+
(function($, window) {
|
4
|
+
var Starrr;
|
5
|
+
window.Starrr = Starrr = (function() {
|
6
|
+
Starrr.prototype.defaults = {
|
7
|
+
rating: void 0,
|
8
|
+
max: 5,
|
9
|
+
readOnly: false,
|
10
|
+
emptyClass: 'fa fa-star-o',
|
11
|
+
fullClass: 'fa fa-star',
|
12
|
+
change: function(e, value) {}
|
13
|
+
};
|
14
|
+
|
15
|
+
function Starrr($el, options) {
|
16
|
+
this.options = $.extend({}, this.defaults, options);
|
17
|
+
this.$el = $el;
|
18
|
+
this.createStars();
|
19
|
+
this.syncRating();
|
20
|
+
if (this.options.readOnly) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
this.$el.on('mouseover.starrr', 'a', (function(_this) {
|
24
|
+
return function(e) {
|
25
|
+
return _this.syncRating(_this.getStars().index(e.currentTarget) + 1);
|
26
|
+
};
|
27
|
+
})(this));
|
28
|
+
this.$el.on('mouseout.starrr', (function(_this) {
|
29
|
+
return function() {
|
30
|
+
return _this.syncRating();
|
31
|
+
};
|
32
|
+
})(this));
|
33
|
+
this.$el.on('click.starrr', 'a', (function(_this) {
|
34
|
+
return function(e) {
|
35
|
+
e.preventDefault();
|
36
|
+
return _this.setRating(_this.getStars().index(e.currentTarget) + 1);
|
37
|
+
};
|
38
|
+
})(this));
|
39
|
+
this.$el.on('starrr:change', this.options.change);
|
40
|
+
}
|
41
|
+
|
42
|
+
Starrr.prototype.getStars = function() {
|
43
|
+
return this.$el.find('a');
|
44
|
+
};
|
45
|
+
|
46
|
+
Starrr.prototype.createStars = function() {
|
47
|
+
var j, ref, results;
|
48
|
+
results = [];
|
49
|
+
for (j = 1, ref = this.options.max; 1 <= ref ? j <= ref : j >= ref; 1 <= ref ? j++ : j--) {
|
50
|
+
results.push(this.$el.append("<a href='#' />"));
|
51
|
+
}
|
52
|
+
return results;
|
53
|
+
};
|
54
|
+
|
55
|
+
Starrr.prototype.setRating = function(rating) {
|
56
|
+
if (this.options.rating === rating) {
|
57
|
+
rating = void 0;
|
58
|
+
}
|
59
|
+
this.options.rating = rating;
|
60
|
+
this.syncRating();
|
61
|
+
return this.$el.trigger('starrr:change', rating);
|
62
|
+
};
|
63
|
+
|
64
|
+
Starrr.prototype.getRating = function() {
|
65
|
+
return this.options.rating;
|
66
|
+
};
|
67
|
+
|
68
|
+
Starrr.prototype.syncRating = function(rating) {
|
69
|
+
var $stars, i, j, ref, results;
|
70
|
+
rating || (rating = this.options.rating);
|
71
|
+
$stars = this.getStars();
|
72
|
+
results = [];
|
73
|
+
for (i = j = 1, ref = this.options.max; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) {
|
74
|
+
results.push($stars.eq(i - 1).removeClass(rating >= i ? this.options.emptyClass : this.options.fullClass).addClass(rating >= i ? this.options.fullClass : this.options.emptyClass));
|
75
|
+
}
|
76
|
+
return results;
|
77
|
+
};
|
78
|
+
|
79
|
+
return Starrr;
|
80
|
+
|
81
|
+
})();
|
82
|
+
return $.fn.extend({
|
83
|
+
starrr: function() {
|
84
|
+
var args, option;
|
85
|
+
option = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
86
|
+
return this.each(function() {
|
87
|
+
var data;
|
88
|
+
data = $(this).data('starrr');
|
89
|
+
if (!data) {
|
90
|
+
$(this).data('starrr', (data = new Starrr($(this), option)));
|
91
|
+
}
|
92
|
+
if (typeof option === 'string') {
|
93
|
+
return data[option].apply(data, args);
|
94
|
+
}
|
95
|
+
});
|
96
|
+
}
|
97
|
+
});
|
98
|
+
})(window.jQuery, window);
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: starrr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sikandar Tariq
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: rails front-end library for star/rating input field
|
42
|
+
email:
|
43
|
+
- sikandar.tariq@thedevden.co
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/generators/starrr_generator.rb
|
56
|
+
- lib/generators/templates/stars.coffee
|
57
|
+
- lib/generators/templates/stars.scss
|
58
|
+
- lib/starrr.rb
|
59
|
+
- lib/starrr/version.rb
|
60
|
+
- starrr.gemspec
|
61
|
+
- vendor/assets/javascripts/starrr.js
|
62
|
+
- vendor/assets/stylesheets/starrr.css
|
63
|
+
homepage: https://github.com/sikandartariq1/starrr
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.7.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: 1-5 (or 1-n) star rating in < 75 lines of code.
|
87
|
+
test_files: []
|