purty-color-picker 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 +50 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/purty/color/picker.rb +9 -0
- data/lib/purty/color/picker/version.rb +7 -0
- data/purty-color-picker.gemspec +27 -0
- data/vendor/assets/javascripts/color-picker.js +281 -0
- data/vendor/assets/stylesheets/color-picker.css +90 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 50d5ce52cc9c8a0f65af3f99642394d338f3fcc0
|
|
4
|
+
data.tar.gz: 9996a342d82248a95d4c284abbc3273d683909f3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: accb1baf4f95e1a9303a50320da95dd8f27183ffcc0826d845487f1bda08577a9bea07a0ae688671fa06fe16920c49d86bbef0748ae7d3eb97472cf14be3ac3b
|
|
7
|
+
data.tar.gz: ccc5891c0f57df53109fa05acd9f699d2a9bf5a30aa32778362a17552c52da77c748576eca3a7c330b991c78fa6e56efad68b54881718139bc717ca5a00db26a
|
data/.gitignore
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
|
14
|
+
# .env
|
|
15
|
+
|
|
16
|
+
## Specific to RubyMotion:
|
|
17
|
+
.dat*
|
|
18
|
+
.repl_history
|
|
19
|
+
build/
|
|
20
|
+
*.bridgesupport
|
|
21
|
+
build-iPhoneOS/
|
|
22
|
+
build-iPhoneSimulator/
|
|
23
|
+
|
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
25
|
+
#
|
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
29
|
+
#
|
|
30
|
+
# vendor/Pods/
|
|
31
|
+
|
|
32
|
+
## Documentation cache and generated files:
|
|
33
|
+
/.yardoc/
|
|
34
|
+
/_yardoc/
|
|
35
|
+
/doc/
|
|
36
|
+
/rdoc/
|
|
37
|
+
|
|
38
|
+
## Environment normalization:
|
|
39
|
+
/.bundle/
|
|
40
|
+
/vendor/bundle
|
|
41
|
+
/lib/bundler/man/
|
|
42
|
+
|
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
45
|
+
# Gemfile.lock
|
|
46
|
+
# .ruby-version
|
|
47
|
+
# .ruby-gemset
|
|
48
|
+
|
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
50
|
+
.rvmrc
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at norbert.forman@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
purty-color-picker (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.2.5)
|
|
10
|
+
rake (10.5.0)
|
|
11
|
+
rspec (3.5.0)
|
|
12
|
+
rspec-core (~> 3.5.0)
|
|
13
|
+
rspec-expectations (~> 3.5.0)
|
|
14
|
+
rspec-mocks (~> 3.5.0)
|
|
15
|
+
rspec-core (3.5.3)
|
|
16
|
+
rspec-support (~> 3.5.0)
|
|
17
|
+
rspec-expectations (3.5.0)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.5.0)
|
|
20
|
+
rspec-mocks (3.5.0)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.5.0)
|
|
23
|
+
rspec-support (3.5.0)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
bundler (~> 1.13)
|
|
30
|
+
purty-color-picker!
|
|
31
|
+
rake (~> 10.0)
|
|
32
|
+
rspec (~> 3.0)
|
|
33
|
+
|
|
34
|
+
BUNDLED WITH
|
|
35
|
+
1.13.1
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Norbert Forman
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Norbert Forman
|
|
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,42 @@
|
|
|
1
|
+
# Purty Color Picker
|
|
2
|
+
|
|
3
|
+
This gem embeddes the Purty Color Picker in the Rails asset pipeline.
|
|
4
|
+
|
|
5
|
+
A super lightweight visual HSL, RGB and hex color picker with a responsive, touch-friendly and customizable UI. Based on the Lightweight & Touch-enabled jQuery Color Picker Plugin - Purty Picker from [jaydenseric](https://github.com/jaydenseric/Purty-Picker)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'purty-color-picker'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install purty-color-picker
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Browser Support
|
|
28
|
+
|
|
29
|
+
For modern browsers (IE10+ and recent versions of Chrome, Safari, Firefox), mostly due to the use of CSS3 linear gradients. Support for older browsers should be possible with a few modifications.
|
|
30
|
+
|
|
31
|
+
## Dependencies
|
|
32
|
+
|
|
33
|
+
Requires [jQuery](https://github.com/jquery/jquery) or [Zepto](https://github.com/madrobby/zepto) with core and event modules.
|
|
34
|
+
|
|
35
|
+
## Contributing
|
|
36
|
+
|
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/norbertforman/purty-color-picker. 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.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
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 "purty/color/picker"
|
|
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,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'purty/color/picker/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "purty-color-picker"
|
|
8
|
+
spec.version = Purty::Color::Picker::VERSION
|
|
9
|
+
spec.authors = ["Norbert Forman"]
|
|
10
|
+
spec.email = ["norbert.forman@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{This gem embeddes the Purty Color Picker in the Rails asset pipeline.}
|
|
13
|
+
spec.description = %q{A super lightweight visual HSL, RGB and hex color picker with a responsive, touch-friendly and customizable UI.}
|
|
14
|
+
spec.homepage = "https://github.com/norbertforman/purty-color-picker"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
end
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Purty Picker Copyright 2013 Jayden Seric (MIT license).
|
|
4
|
+
|
|
5
|
+
A super lightweight visual HSL, RGB and hex color picker with a responsive, touch-friendly and customizable UI.
|
|
6
|
+
|
|
7
|
+
Requires jQuery or Zepto with core and event modules.
|
|
8
|
+
|
|
9
|
+
https://github.com/jaydenseric/Purty-Picker
|
|
10
|
+
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// DOM ready
|
|
14
|
+
$(function() {
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
//-------------------------------------------- Color conversions
|
|
18
|
+
|
|
19
|
+
//---------------------- Convert HSL to RGB
|
|
20
|
+
|
|
21
|
+
// Source: http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
|
|
22
|
+
|
|
23
|
+
function HSLToRGB(h, s, l) {
|
|
24
|
+
h /= 360;
|
|
25
|
+
s /= 100;
|
|
26
|
+
l /= 100;
|
|
27
|
+
var r, g, b;
|
|
28
|
+
if (s == 0) {
|
|
29
|
+
r = g = b = l; // Achromatic
|
|
30
|
+
} else {
|
|
31
|
+
var hueToRGB = function(p, q, t) {
|
|
32
|
+
if (t < 0) t += 1;
|
|
33
|
+
if (t > 1) t -= 1;
|
|
34
|
+
if (t < 1/6) return p + (q - p) * 6 * t;
|
|
35
|
+
if (t < 1/2) return q;
|
|
36
|
+
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
|
|
37
|
+
return p;
|
|
38
|
+
};
|
|
39
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s,
|
|
40
|
+
p = 2 * l - q;
|
|
41
|
+
r = hueToRGB(p, q, h + 1/3);
|
|
42
|
+
g = hueToRGB(p, q, h);
|
|
43
|
+
b = hueToRGB(p, q, h - 1/3);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
red : Math.round(r * 255),
|
|
47
|
+
green : Math.round(g * 255),
|
|
48
|
+
blue : Math.round(b * 255)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//---------------------- Convert RGB to HSL
|
|
53
|
+
|
|
54
|
+
// Source: http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
|
|
55
|
+
|
|
56
|
+
function RGBToHSL(r, g, b) {
|
|
57
|
+
r /= 255,
|
|
58
|
+
g /= 255,
|
|
59
|
+
b /= 255;
|
|
60
|
+
var max = Math.max(r, g, b),
|
|
61
|
+
min = Math.min(r, g, b);
|
|
62
|
+
var h, s, l = (max + min) / 2;
|
|
63
|
+
if (max == min) {
|
|
64
|
+
h = s = 0; // Achromatic
|
|
65
|
+
} else {
|
|
66
|
+
var d = max - min;
|
|
67
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
68
|
+
switch(max) {
|
|
69
|
+
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
|
70
|
+
case g: h = (b - r) / d + 2; break;
|
|
71
|
+
case b: h = (r - g) / d + 4; break;
|
|
72
|
+
}
|
|
73
|
+
h /= 6;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
hue : Math.round(h * 360),
|
|
77
|
+
saturation : Math.round(s * 100),
|
|
78
|
+
luminosity : Math.round(l * 100)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//---------------------- Convert RGB to Hex
|
|
83
|
+
|
|
84
|
+
// Source: http://stackoverflow.com/a/5624139
|
|
85
|
+
|
|
86
|
+
function RGBToHex(r, g, b) {
|
|
87
|
+
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//---------------------- Convert hex to RGB
|
|
91
|
+
|
|
92
|
+
// Source: http://stackoverflow.com/a/11508164
|
|
93
|
+
|
|
94
|
+
function hexToRGB(hex) {
|
|
95
|
+
var bigInt = parseInt(hex.replace('#', ''), 16),
|
|
96
|
+
r = (bigInt >> 16) & 255,
|
|
97
|
+
g = (bigInt >> 8) & 255,
|
|
98
|
+
b = bigInt & 255;
|
|
99
|
+
return {
|
|
100
|
+
red : r,
|
|
101
|
+
green : g,
|
|
102
|
+
blue : b
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//---------------------- Convert hex to HSL
|
|
107
|
+
|
|
108
|
+
function hexToHSL(hex) {
|
|
109
|
+
var RGB = hexToRGB(hex);
|
|
110
|
+
return RGBToHSL(RGB.red, RGB.green, RGB.blue);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//---------------------- Convert HSL to hex
|
|
114
|
+
|
|
115
|
+
function HSLToHex(h, s, l) {
|
|
116
|
+
var RGB = HSLToRGB(h, s, l);
|
|
117
|
+
return RGBToHex(RGB.red, RGB.green, RGB.blue);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//-------------------------------------------- Setup each color picker
|
|
121
|
+
|
|
122
|
+
$.each($('.color-picker'), function() {
|
|
123
|
+
|
|
124
|
+
//---------------------- Find componenets
|
|
125
|
+
|
|
126
|
+
var $picker = $(this),
|
|
127
|
+
$formatInput = $picker.find('.format'),
|
|
128
|
+
$colorInput = $picker.find('.color'),
|
|
129
|
+
$luminosityInput = $picker.find('input[type=range]'),
|
|
130
|
+
$spectrum = $picker.find('.spectrum'),
|
|
131
|
+
$pin = $picker.find('.pin');
|
|
132
|
+
|
|
133
|
+
//---------------------- Get current color in HSL
|
|
134
|
+
|
|
135
|
+
function getHSL() {
|
|
136
|
+
var position = $picker.find('.pin').position(),
|
|
137
|
+
width = $spectrum.width(),
|
|
138
|
+
height = $spectrum.height();
|
|
139
|
+
return {
|
|
140
|
+
hue : Math.round(position.left / width * 360),
|
|
141
|
+
saturation : Math.round(position.top / height * 100),
|
|
142
|
+
luminosity : $luminosityInput.val()
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//---------------------- Output color in desired format
|
|
147
|
+
|
|
148
|
+
function updateColorInput() {
|
|
149
|
+
var HSL = getHSL();
|
|
150
|
+
switch ($formatInput.val()) {
|
|
151
|
+
case 'HSL':
|
|
152
|
+
$colorInput.val('hsl(' + HSL.hue + ', ' + HSL.saturation + '%, ' + HSL.luminosity + '%)');
|
|
153
|
+
break;
|
|
154
|
+
case 'RGB':
|
|
155
|
+
var RGB = HSLToRGB(HSL.hue, HSL.saturation, HSL.luminosity);
|
|
156
|
+
$colorInput.val('rgb(' + RGB.red + ', ' + RGB.green + ', ' + RGB.blue + ')');
|
|
157
|
+
break;
|
|
158
|
+
case 'Hex':
|
|
159
|
+
$colorInput.val(HSLToHex(HSL.hue, HSL.saturation, HSL.luminosity));
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
// Trigger color picker change event for custom callbacks
|
|
163
|
+
$picker.trigger('change');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
//---------------------- Set color format
|
|
167
|
+
|
|
168
|
+
$formatInput.on('change', function() {
|
|
169
|
+
updateColorInput();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
//---------------------- Set color
|
|
173
|
+
|
|
174
|
+
$colorInput.on('change', function() {
|
|
175
|
+
// Get the color values in HSL format
|
|
176
|
+
var HSL;
|
|
177
|
+
switch ($formatInput.val()) {
|
|
178
|
+
case 'HSL':
|
|
179
|
+
var values = $(this).val().match(/\d+/g);
|
|
180
|
+
HSL = {
|
|
181
|
+
hue : values[0],
|
|
182
|
+
saturation : values[1],
|
|
183
|
+
luminosity : values[2]
|
|
184
|
+
};
|
|
185
|
+
break;
|
|
186
|
+
case 'RGB':
|
|
187
|
+
var values = $(this).val().match(/\d+/g);
|
|
188
|
+
HSL = RGBToHSL(values[0], values[1], values[2]);
|
|
189
|
+
break;
|
|
190
|
+
case 'Hex':
|
|
191
|
+
HSL = hexToHSL($(this).val());
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
// Set the luminosity
|
|
195
|
+
$luminosityInput.val(HSL.luminosity);
|
|
196
|
+
setLuminosity(HSL.luminosity);
|
|
197
|
+
// Place the pin
|
|
198
|
+
$pin.css({
|
|
199
|
+
left : HSL.hue / 360 * 100 + '%',
|
|
200
|
+
top : HSL.saturation + '%'
|
|
201
|
+
});
|
|
202
|
+
// Trigger color picker change event for custom callbacks
|
|
203
|
+
$picker.trigger('change');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
//---------------------- Set luminosity
|
|
207
|
+
|
|
208
|
+
//---------- Set the luminosity spectrum overlay
|
|
209
|
+
|
|
210
|
+
function setLuminosity(luminosity) {
|
|
211
|
+
var color,
|
|
212
|
+
alpha;
|
|
213
|
+
if (luminosity <= 50) {
|
|
214
|
+
color = '0, 0, 0';
|
|
215
|
+
alpha = 1 - luminosity / 100 * 2;
|
|
216
|
+
} else {
|
|
217
|
+
color = '255, 255, 255';
|
|
218
|
+
alpha = luminosity / 100 * 2 - 1;
|
|
219
|
+
}
|
|
220
|
+
// Apply luminosity to the spectrum
|
|
221
|
+
$spectrum.children().css('background-color', 'rgba(' + color + ', ' + alpha + ')');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//---------- Luminosity input interaction
|
|
225
|
+
|
|
226
|
+
$luminosityInput.on('change', function() {
|
|
227
|
+
setLuminosity($(this).val());
|
|
228
|
+
updateColorInput();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
//---------------------- Set hue, saturation via pin
|
|
232
|
+
|
|
233
|
+
//---------- Move the pin
|
|
234
|
+
|
|
235
|
+
var movePin = function(event) {
|
|
236
|
+
var bounds = $spectrum[0].getBoundingClientRect(),
|
|
237
|
+
x = event.clientX - bounds.left,
|
|
238
|
+
y = event.clientY - bounds.top;
|
|
239
|
+
// Prevent dragging pin outside spectrum area horizontally
|
|
240
|
+
if (x < 0) x = 0;
|
|
241
|
+
else if (x > bounds.width) x = bounds.width;
|
|
242
|
+
// Prevent dragging pin outside spectrum area vertically
|
|
243
|
+
if (y < 0) y = 0;
|
|
244
|
+
else if (y > bounds.height) y = bounds.height;
|
|
245
|
+
// Place the pin
|
|
246
|
+
$pin.css({
|
|
247
|
+
left : x / bounds.width * 100 + '%',
|
|
248
|
+
top : y / bounds.height * 100 + '%'
|
|
249
|
+
});
|
|
250
|
+
// Output new color value
|
|
251
|
+
updateColorInput();
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
//---------- Pin interaction
|
|
255
|
+
|
|
256
|
+
$spectrum.on('mousedown', function(event) {
|
|
257
|
+
event.preventDefault();
|
|
258
|
+
movePin(event);
|
|
259
|
+
$spectrum.addClass('active');
|
|
260
|
+
$(document).on('mousemove', movePin);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
$(document).on('mouseup', function() {
|
|
264
|
+
$spectrum.removeClass('active');
|
|
265
|
+
$(document).off('mousemove', movePin);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
$spectrum.on('touchmove touchstart', movePin);
|
|
269
|
+
|
|
270
|
+
//---------------------- Output color preview
|
|
271
|
+
|
|
272
|
+
$picker.on('change', function() {
|
|
273
|
+
$colorInput.css('background-color', $colorInput.val()).toggleClass('dark', $luminosityInput.val() <= 50);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
//---------------------- Initialize this color picker
|
|
277
|
+
|
|
278
|
+
$colorInput.trigger('change');
|
|
279
|
+
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* Purty Picker Copyright 2013 Jayden Seric (MIT license): https://github.com/jaydenseric/Purty-Picker */
|
|
2
|
+
/* Core: No touchy! */
|
|
3
|
+
.color-picker .spectrum {
|
|
4
|
+
position: relative;
|
|
5
|
+
/* To position pin, luminosity filter */
|
|
6
|
+
background: linear-gradient(gray, transparent), linear-gradient(90deg, red, #ff2b00, #ff5500, #ff8000, #ffaa00, #ffd500, yellow, #d4ff00, #aaff00, #80ff00, #55ff00, #2bff00, lime, #00ff2b, #00ff55, #00ff80, #00ffaa, #00ffd5, cyan, #00d4ff, #00aaff, #007fff, #0055ff, #002bff, blue, #2a00ff, #5500ff, #7f00ff, #aa00ff, #d400ff, magenta, #ff00d4, #ff00aa, #ff0080, #ff0055, #ff002b, red);
|
|
7
|
+
-webkit-user-select: none;
|
|
8
|
+
-moz-user-select: none;
|
|
9
|
+
-ms-user-select: none;
|
|
10
|
+
user-select: none;
|
|
11
|
+
/* Prevent pin interaction causing content selection */
|
|
12
|
+
cursor: crosshair;
|
|
13
|
+
}
|
|
14
|
+
.color-picker .spectrum.active {
|
|
15
|
+
cursor: none;
|
|
16
|
+
}
|
|
17
|
+
.color-picker .spectrum.active .pin {
|
|
18
|
+
cursor: none;
|
|
19
|
+
}
|
|
20
|
+
.color-picker .spectrum > div {
|
|
21
|
+
/* Luminosity filter */
|
|
22
|
+
position: absolute;
|
|
23
|
+
left: 0;
|
|
24
|
+
right: 0;
|
|
25
|
+
top: 0;
|
|
26
|
+
bottom: 0;
|
|
27
|
+
}
|
|
28
|
+
.color-picker .spectrum .pin {
|
|
29
|
+
position: absolute;
|
|
30
|
+
cursor: move;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Customization: Default skin */
|
|
34
|
+
.color-picker {
|
|
35
|
+
margin: 20px;
|
|
36
|
+
padding: 11px;
|
|
37
|
+
border: 1px solid #e3e3e3;
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
background-color: #f5f5f5;
|
|
40
|
+
}
|
|
41
|
+
.color-picker .color,
|
|
42
|
+
.color-picker .luminosity {
|
|
43
|
+
-moz-box-sizing: border-box;
|
|
44
|
+
box-sizing: border-box;
|
|
45
|
+
display: block;
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
.color-picker .format {
|
|
49
|
+
display: block;
|
|
50
|
+
margin: 0 auto 10px auto;
|
|
51
|
+
}
|
|
52
|
+
.color-picker .color {
|
|
53
|
+
-webkit-appearance: none;
|
|
54
|
+
border: 0;
|
|
55
|
+
border-radius: 2px;
|
|
56
|
+
padding: 10px;
|
|
57
|
+
text-align: center;
|
|
58
|
+
font-size: 11px;
|
|
59
|
+
letter-spacing: 1px;
|
|
60
|
+
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
|
61
|
+
color: rgba(0, 0, 0, 0.6);
|
|
62
|
+
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
|
|
63
|
+
transition: color 0.2s;
|
|
64
|
+
}
|
|
65
|
+
.color-picker .color.dark {
|
|
66
|
+
color: rgba(255, 255, 255, 0.7);
|
|
67
|
+
}
|
|
68
|
+
.color-picker .spectrum {
|
|
69
|
+
height: 150px;
|
|
70
|
+
/* Arbitary but required */
|
|
71
|
+
overflow: hidden;
|
|
72
|
+
/* Prevent pin overflowing container */
|
|
73
|
+
border-radius: 2px;
|
|
74
|
+
margin: 10px 0;
|
|
75
|
+
}
|
|
76
|
+
.color-picker .spectrum > div {
|
|
77
|
+
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
|
|
78
|
+
}
|
|
79
|
+
.color-picker .spectrum .pin {
|
|
80
|
+
margin-left: -4px;
|
|
81
|
+
margin-top: -4px;
|
|
82
|
+
width: 4px;
|
|
83
|
+
height: 4px;
|
|
84
|
+
border: 2px solid white;
|
|
85
|
+
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
|
|
86
|
+
border-radius: 100%;
|
|
87
|
+
}
|
|
88
|
+
.color-picker .luminosity {
|
|
89
|
+
margin: 0;
|
|
90
|
+
}
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: purty-color-picker
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Norbert Forman
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-09-17 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.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
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
|
+
description: A super lightweight visual HSL, RGB and hex color picker with a responsive,
|
|
56
|
+
touch-friendly and customizable UI.
|
|
57
|
+
email:
|
|
58
|
+
- norbert.forman@gmail.com
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- CODE_OF_CONDUCT.md
|
|
65
|
+
- Gemfile
|
|
66
|
+
- Gemfile.lock
|
|
67
|
+
- LICENSE
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- lib/purty/color/picker.rb
|
|
74
|
+
- lib/purty/color/picker/version.rb
|
|
75
|
+
- purty-color-picker.gemspec
|
|
76
|
+
- vendor/assets/javascripts/color-picker.js
|
|
77
|
+
- vendor/assets/stylesheets/color-picker.css
|
|
78
|
+
homepage: https://github.com/norbertforman/purty-color-picker
|
|
79
|
+
licenses:
|
|
80
|
+
- MIT
|
|
81
|
+
metadata: {}
|
|
82
|
+
post_install_message:
|
|
83
|
+
rdoc_options: []
|
|
84
|
+
require_paths:
|
|
85
|
+
- lib
|
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
requirements: []
|
|
97
|
+
rubyforge_project:
|
|
98
|
+
rubygems_version: 2.4.3
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
101
|
+
summary: This gem embeddes the Purty Color Picker in the Rails asset pipeline.
|
|
102
|
+
test_files: []
|