circular-sliders-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +119 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circular-sliders-rails.gemspec +35 -0
- data/lib/circular/sliders/rails.rb +10 -0
- data/lib/circular/sliders/rails/version.rb +7 -0
- data/vendor/assets/javascripts/circular-sliders.js +205 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31122b5abeb5f8ae74e2d4c0a92484c5b3d153fe
|
4
|
+
data.tar.gz: 5e33f54ce5d044aa9c345c15ca90d5e8c1aa6182
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa19cb7891ee504f3cf0e6892115848ccb1d6b8bed5326771d280545c10bc2a4a04f34f53005f27086d40ee9f73489a34bf88370faf1cb839e569edeae97fe5f
|
7
|
+
data.tar.gz: dc712f92d0229db9cf2795ba551ea32a5b4a8cace9949f9196bba670f707850c4bf7230af1ebe23efd55bc53e67a4a1b3e69449b47465b83eaecdbc53bf5c07d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at speterlin@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Sebastian Peterlin
|
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,119 @@
|
|
1
|
+
# Circular Sliders for Rails
|
2
|
+
|
3
|
+
A Ruby on Rails gem which allows you to draw concentric responsive circular sliders with jQuery. Requires jQuery.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'circular-sliders-rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install circular-sliders-rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Include in your application.js file:
|
24
|
+
|
25
|
+
//= require circular-sliders
|
26
|
+
|
27
|
+
Create a canvas element in the view where you would like the sliders to go:
|
28
|
+
|
29
|
+
<canvas id="sliders" width="600" height="300" style="border:1px solid;"></canvas>
|
30
|
+
|
31
|
+
Use jQuery to add circular sliders to the canvas area. Pass slider settings as objects in an array. Create multiple sliders or just a single slider.
|
32
|
+
|
33
|
+
<script>
|
34
|
+
$('#sliders').sliders([
|
35
|
+
{
|
36
|
+
name: "Height",
|
37
|
+
color: "#FFDEAD",
|
38
|
+
centerX: 200,
|
39
|
+
centerY: 150,
|
40
|
+
minValue: 0,
|
41
|
+
maxValue: 250,
|
42
|
+
step: 0.5,
|
43
|
+
units: "cm",
|
44
|
+
radius: 60,
|
45
|
+
lineDashLength: 5,
|
46
|
+
lineDashSpacing: 5,
|
47
|
+
lineWidth: 5,
|
48
|
+
strokeColor: "#D3D3D3",
|
49
|
+
},
|
50
|
+
{
|
51
|
+
name: "Weight",
|
52
|
+
color: "#A52A2A",
|
53
|
+
minValue: 0,
|
54
|
+
maxValue: 150,
|
55
|
+
step: 5,
|
56
|
+
units: "kg",
|
57
|
+
lineDashLength: 5,
|
58
|
+
lineDashSpacing: 10,
|
59
|
+
lineWidth: 10,
|
60
|
+
strokeColor: "#D3D3D3",
|
61
|
+
},
|
62
|
+
{
|
63
|
+
name: "Waist size",
|
64
|
+
centerX: 400,
|
65
|
+
centerY: 150,
|
66
|
+
color: "#A0522D",
|
67
|
+
radius: 40,
|
68
|
+
minValue: 0,
|
69
|
+
maxValue: 50,
|
70
|
+
lineWidth: 10,
|
71
|
+
step: 2,
|
72
|
+
units: "cm",
|
73
|
+
ballColor: "#A0522D"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
name: "Shoe size",
|
77
|
+
minValue: 10,
|
78
|
+
maxValue: 60,
|
79
|
+
step: 1
|
80
|
+
}
|
81
|
+
]);
|
82
|
+
</script>
|
83
|
+
|
84
|
+
Slider settings:
|
85
|
+
|
86
|
+
| Name | Type | Default | Description |
|
87
|
+
| --------------- | ------ | ------------------------ | ---------------------------------------------------------------------- |
|
88
|
+
| name | String | Slider n | Name your slider |
|
89
|
+
| centerX | Float | Center of Canvas | Specify the x value of where you'd like the center of the slider to be |
|
90
|
+
| centerY | Float | Center of Canvas | Specify the y value of where you'd like the center of the slider to be |
|
91
|
+
| color | String | "#0000FF" | Specify the color of the arc fill |
|
92
|
+
| minValue | Float | 0 | The minimum value of your slider |
|
93
|
+
| maxValue | Float | 0 | The maximum value of your slider |
|
94
|
+
| step | Float | 10 | The amount the value is incremented |
|
95
|
+
| units | String | "" | The units your value is displayed in |
|
96
|
+
| radius | Float | 40 or (prevRadius +≈ 15) | The radius of your slider |
|
97
|
+
| lineDashLength | Float | 5 | The arc length of each dash of your slider |
|
98
|
+
| lineDashSpacing | Float | 5 | The arc spacing length of each dash of your slider |
|
99
|
+
| lineWidth | Float | 5 | The arc spacing length of each dash of your slider |
|
100
|
+
| strokeColor | String | "#D3D3D3" | The color of the dashes on the slider |
|
101
|
+
| ballColor | String | "#000000" | The color of the slider ball |
|
102
|
+
| textColor | String | "#000000" | The color of the slider label (name, value and units) |
|
103
|
+
|
104
|
+
Retrieve values of individual sliders by calling:
|
105
|
+
|
106
|
+
$('#sliders').data('slider_name');
|
107
|
+
|
108
|
+
<!-- ## Development -->
|
109
|
+
|
110
|
+
<!-- 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). -->
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/speterlin/circular-sliders-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
115
|
+
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
The gem is available as open source under the terms of the [MIT License](http://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 "circular/sliders/rails"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'circular/sliders/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "circular-sliders-rails"
|
8
|
+
spec.version = Circular::Sliders::Rails::VERSION
|
9
|
+
spec.authors = ["Sebastian Peterlin"]
|
10
|
+
spec.email = ["speterlin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Draw concentric circles and responsively set each value.}
|
13
|
+
spec.description = %q{A Ruby on Rails gem which allows you to draw concentric responsive circular sliders with jQuery. Requires jQuery.}
|
14
|
+
spec.homepage = "https://github.com/speterlin/circular-sliders-rails"
|
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'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
|
34
|
+
spec.add_dependency "rails", "~> 5.0"
|
35
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
(function ( $ ) {
|
2
|
+
|
3
|
+
var isMouseDown = false;
|
4
|
+
var selectedSlider = {};
|
5
|
+
var elem = null;
|
6
|
+
// if multiple canvases / containers would need to refactor
|
7
|
+
var canvas = null
|
8
|
+
var ctx = null;
|
9
|
+
// don't like having these as global variables
|
10
|
+
var sliders = [];
|
11
|
+
// [x,y]
|
12
|
+
var offset = [0,0];
|
13
|
+
|
14
|
+
$.fn.sliders = function(slidersOptions) {
|
15
|
+
elem = this;
|
16
|
+
// maybe refactor, add .each in case there are multiple selected canvases
|
17
|
+
canvas = this[0];
|
18
|
+
ctx = canvas.getContext("2d");
|
19
|
+
setOffset();
|
20
|
+
// maybe refactor and make centerX and centerY one variable [centerX, centerY]
|
21
|
+
var slidersCenterX = canvas.width / 2;
|
22
|
+
var slidersCenterY = canvas.height / 2;
|
23
|
+
// maybe refactor, add container option if there are multiple containers, could allow multiple containers / canvases in the future
|
24
|
+
var defaults = {
|
25
|
+
name: "Slider",
|
26
|
+
centerX: slidersCenterX,
|
27
|
+
centerY: slidersCenterY,
|
28
|
+
color: "#0000FF",
|
29
|
+
minValue: 0,
|
30
|
+
maxValue: 1000,
|
31
|
+
step: 10,
|
32
|
+
units: "",
|
33
|
+
radius: 40,
|
34
|
+
lineDashLength: 5,
|
35
|
+
lineDashSpacing: 5,
|
36
|
+
lineWidth: 5,
|
37
|
+
strokeColor: "#D3D3D3",
|
38
|
+
ballColor: "#000000",
|
39
|
+
textColor: "#000000"
|
40
|
+
}
|
41
|
+
for (var i = 0; i < slidersOptions.length; i++) {
|
42
|
+
defaults.name = "Slider " + (i + 1);
|
43
|
+
// maybe refactor, want previous centerX, centerY, and lineWidth and 10 pixels spacing between sliders
|
44
|
+
if (i > 0) {
|
45
|
+
defaults.centerX = sliders[i-1].centerX;
|
46
|
+
defaults.centerY = sliders[i-1].centerY;
|
47
|
+
defaults.radius = sliders[i-1].radius + sliders[i-1].lineWidth + 10;
|
48
|
+
}
|
49
|
+
var sliderSettings = $.extend( {}, defaults, slidersOptions[i] )
|
50
|
+
sliders.push(new Slider (sliderSettings));
|
51
|
+
// maybe refactor, visible if have it like this: elem.attr('data-'+sliders[i].name.split(" ").join("_"), sliders[i].minValue);
|
52
|
+
elem.data(sliders[i].name.split(" ").join("_"), sliders[i].minValue);
|
53
|
+
}
|
54
|
+
// maybe refactor, first slider by default selected
|
55
|
+
selectedSlider = sliders[0];
|
56
|
+
draw();
|
57
|
+
canvas.addEventListener("mousedown", handleMouseDown);
|
58
|
+
canvas.addEventListener("mouseup", handleMouseUp);
|
59
|
+
canvas.addEventListener("mousemove", handleMouseMove);
|
60
|
+
}
|
61
|
+
|
62
|
+
function Slider(settings) {
|
63
|
+
this.name = settings.name;
|
64
|
+
this.centerX = settings.centerX;
|
65
|
+
this.centerY = settings.centerY;
|
66
|
+
this.color = settings.color;
|
67
|
+
this.minValue = settings.minValue;
|
68
|
+
this.maxValue = settings.maxValue;
|
69
|
+
this.step = settings.step;
|
70
|
+
this.units = settings.units;
|
71
|
+
this.radius = settings.radius;
|
72
|
+
this.lineDashLength = settings.lineDashLength;
|
73
|
+
this.lineDashSpacing = settings.lineDashSpacing;
|
74
|
+
this.lineWidth = settings.lineWidth;
|
75
|
+
this.strokeColor = settings.strokeColor;
|
76
|
+
this.textColor = settings.textColor;
|
77
|
+
this.value = settings.minValue;
|
78
|
+
// ball starts at top of circle which is - pi / 2
|
79
|
+
this.angle = -(Math.PI / 2);
|
80
|
+
// maybe refactor
|
81
|
+
this.ball = new Ball (settings);
|
82
|
+
}
|
83
|
+
|
84
|
+
function Ball(sliderSettings) {
|
85
|
+
this.x = sliderSettings.centerX;
|
86
|
+
// ball starts at top of circle
|
87
|
+
this.y = sliderSettings.centerY - sliderSettings.radius;
|
88
|
+
this.radius = sliderSettings.lineWidth;
|
89
|
+
// this is not editable option but could be
|
90
|
+
this.color = sliderSettings.ballColor;
|
91
|
+
}
|
92
|
+
|
93
|
+
function draw () {
|
94
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
95
|
+
for (var i = 0; i < sliders.length; i++) {
|
96
|
+
drawSlider(sliders[i]);
|
97
|
+
drawBall(sliders[i]);
|
98
|
+
drawArc(sliders[i]);
|
99
|
+
drawText(sliders[i], i);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
function drawSlider(slider) {
|
104
|
+
ctx.beginPath();
|
105
|
+
ctx.arc(slider.centerX, slider.centerY, slider.radius, 0, Math.PI*2, false);
|
106
|
+
ctx.lineWidth = slider.lineWidth;
|
107
|
+
ctx.strokeStyle = slider.strokeColor;
|
108
|
+
ctx.setLineDash([slider.lineDashLength, slider.lineDashSpacing]);
|
109
|
+
ctx.stroke();
|
110
|
+
ctx.closePath();
|
111
|
+
}
|
112
|
+
|
113
|
+
function drawBall(slider) {
|
114
|
+
ctx.beginPath();
|
115
|
+
ctx.arc(slider.ball.x, slider.ball.y, slider.ball.radius, 0, Math.PI*2);
|
116
|
+
ctx.fillStyle = slider.ball.color;
|
117
|
+
ctx.fill();
|
118
|
+
ctx.closePath();
|
119
|
+
}
|
120
|
+
|
121
|
+
function drawArc (slider) {
|
122
|
+
// refactor - bug, gap in arc visible if you have a large circular slider, arc comes to edge of ball, does not finish inside ball, maybe change name of angleOffset variable
|
123
|
+
var angleOffset = slider.ball.radius / slider.radius
|
124
|
+
if (((Math.PI / 2) + slider.angle) < angleOffset) {
|
125
|
+
var endAngle = slider.angle
|
126
|
+
} else {
|
127
|
+
var endAngle = slider.angle - angleOffset;
|
128
|
+
}
|
129
|
+
ctx.beginPath();
|
130
|
+
ctx.arc(slider.centerX, slider.centerY, slider.radius, -(Math.PI / 2), endAngle, false);
|
131
|
+
ctx.lineWidth = slider.lineWidth;
|
132
|
+
ctx.strokeStyle = slider.color;
|
133
|
+
ctx.setLineDash([0, 0]);
|
134
|
+
ctx.stroke();
|
135
|
+
ctx.closePath();
|
136
|
+
}
|
137
|
+
|
138
|
+
function drawText (slider, count) {
|
139
|
+
ctx.font = "12px Arial";
|
140
|
+
ctx.fillStyle = slider.textColor;
|
141
|
+
ctx.fillText(slider.name + ": " + slider.value + " " + slider.units, 10, 20*(count+1));
|
142
|
+
}
|
143
|
+
|
144
|
+
function moveBall (mouseX, mouseY, slider) {
|
145
|
+
var dx = mouseX - slider.centerX;
|
146
|
+
var dy = mouseY - slider.centerY;
|
147
|
+
slider.angle = Math.atan(dy / dx);
|
148
|
+
if (dx < 0) { slider.angle += Math.PI };
|
149
|
+
slider.ball.x = slider.centerX + slider.radius * Math.cos(slider.angle);
|
150
|
+
slider.ball.y = slider.centerY + slider.radius * Math.sin(slider.angle);
|
151
|
+
slider.value = slider.minValue + (slider.maxValue - slider.minValue) * ((slider.angle + (Math.PI/2)) / (2 * Math.PI) );
|
152
|
+
// refactor - bug if give step value below 0.5
|
153
|
+
var roundedValue = round(slider.value, slider.step);
|
154
|
+
elem.data(slider.name.split(" ").join("_"), roundedValue);
|
155
|
+
slider.value = roundedValue;
|
156
|
+
draw();
|
157
|
+
}
|
158
|
+
|
159
|
+
function handleMouseDown(e) {
|
160
|
+
e.preventDefault();
|
161
|
+
isMouseDown = true;
|
162
|
+
setOffset();
|
163
|
+
// $(window).scrollLeft() and $(window).scrollTop() to account for page scrolling
|
164
|
+
mouseX = parseInt(e.clientX - offset[0] + $(window).scrollLeft());
|
165
|
+
mouseY = parseInt(e.clientY - offset[1] + $(window).scrollTop());
|
166
|
+
for (var i = 0; i < sliders.length; i++) {
|
167
|
+
if (onBall(mouseX, mouseY, sliders[i])) {
|
168
|
+
selectedSlider = sliders[i];
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
function handleMouseUp(e) {
|
174
|
+
e.preventDefault();
|
175
|
+
isMouseDown = false;
|
176
|
+
}
|
177
|
+
|
178
|
+
function handleMouseMove(e) {
|
179
|
+
if (!isMouseDown) {
|
180
|
+
return;
|
181
|
+
}
|
182
|
+
e.preventDefault();
|
183
|
+
setOffset();
|
184
|
+
mouseX = parseInt(e.clientX - offset[0] + $(window).scrollLeft());
|
185
|
+
mouseY = parseInt(e.clientY - offset[1] + $(window).scrollTop());
|
186
|
+
moveBall(mouseX, mouseY, selectedSlider);
|
187
|
+
}
|
188
|
+
|
189
|
+
function round(x, target) {
|
190
|
+
return Math.ceil(x/target) * target;
|
191
|
+
}
|
192
|
+
|
193
|
+
function onBall (x, y, slider) {
|
194
|
+
if (x > (slider.ball.x - slider.ball.radius) && x < (slider.ball.x + slider.ball.radius) && y > (slider.ball.y - slider.ball.radius) && y < (slider.ball.y + slider.ball.radius)) {
|
195
|
+
return true;
|
196
|
+
}
|
197
|
+
return false;
|
198
|
+
}
|
199
|
+
|
200
|
+
function setOffset() {
|
201
|
+
// refactor, need to call every time mouse is down or moves in case you have moved the canvas and offset positon is cached, could avoid having to call this if your project has no cache
|
202
|
+
offset = [canvas.offsetLeft, canvas.offsetTop];
|
203
|
+
}
|
204
|
+
|
205
|
+
}( jQuery ));
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: circular-sliders-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Peterlin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-28 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: A Ruby on Rails gem which allows you to draw concentric responsive circular
|
70
|
+
sliders with jQuery. Requires jQuery.
|
71
|
+
email:
|
72
|
+
- speterlin@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- circular-sliders-rails.gemspec
|
88
|
+
- lib/circular/sliders/rails.rb
|
89
|
+
- lib/circular/sliders/rails/version.rb
|
90
|
+
- vendor/assets/javascripts/circular-sliders.js
|
91
|
+
homepage: https://github.com/speterlin/circular-sliders-rails
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata:
|
95
|
+
allowed_push_host: https://rubygems.org
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Draw concentric circles and responsively set each value.
|
116
|
+
test_files: []
|