kolor-picker 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +9 -9
- data/.rspec +1 -1
- data/.travis.yml +10 -11
- data/CHANGELOG.md +24 -2
- data/README.md +4 -2
- data/app/assets/javascripts/kolor-picker.js +33 -33
- data/app/assets/javascripts/kolor-picker/color-sampler.js +219 -213
- data/app/assets/javascripts/kolor-picker/jqColorPicker.min.js +0 -1
- data/app/assets/javascripts/kolor-picker/kolor-picker.js +191 -175
- data/app/assets/stylesheets/kolor-picker.css +11 -7
- data/app/assets/stylesheets/kolor-picker/color-sampler.css +57 -54
- data/lib/kolor-picker/builder.rb +1 -1
- data/lib/kolor-picker/engine.rb +11 -11
- data/lib/kolor-picker/helper.rb +2 -6
- data/lib/kolor-picker/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de43ee703e906ebab3459e9ae6ac87a32213cf9870761c7eea767f275983ba53
|
4
|
+
data.tar.gz: 7ba8eedc16eace6ffd306c827d3a7f956c3b3ddc7475df45cef0c4157c64e08b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e56b89145281bebec5021355f6bed4b8716ac7149e9f511a629852874485fb0854c3a124b1766227a09c7e05f2f0d995f5dd36fcbe87e2f41c12f7f89e9fc5f3
|
7
|
+
data.tar.gz: '09096bf9ead89593dffa323103bfaa470a39bcee44f77ce46e2cb735efcfbc2343499302512ae9b22a6689361276386feab23cac698e4bffd39c3e54fb6df86c'
|
data/.gitignore
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.3.0
|
4
|
-
- 2.2.4
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
- COVERALLS=1
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3.0
|
4
|
+
- 2.2.4
|
5
|
+
before_install: gem install bundler
|
6
|
+
branches:
|
7
|
+
only:
|
8
|
+
- master
|
9
|
+
env:
|
10
|
+
- COVERALLS=1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# Change Log
|
2
2
|
|
3
|
-
|
3
|
+
## v0.1.4 / 2021-07-15
|
4
|
+
### Upgraded
|
5
|
+
- kolor-picker to v0.3.0
|
6
|
+
|
7
|
+
## v0.1.3 / 2017-06-10
|
8
|
+
### Removed
|
9
|
+
- jqColorPicker map.
|
10
|
+
|
11
|
+
## v0.1.2 / 2016-10-15
|
12
|
+
### Changed
|
13
|
+
- Upgraded color-sampler to v0.1.6
|
14
|
+
- trigger change event.
|
15
|
+
|
16
|
+
## v0.1.1 / 2016-05-10
|
17
|
+
### Changed
|
18
|
+
- Upgraded kolor-picker to v0.2.1
|
19
|
+
- Restructured helper and widget.
|
20
|
+
### Fixed
|
21
|
+
- missing value.
|
22
|
+
|
23
|
+
## v0.1.0 / 2016-04-19
|
24
|
+
### Added
|
25
|
+
- Created project
|
data/README.md
CHANGED
@@ -41,12 +41,14 @@ You can use `colorpicker_tag` and `colorpicker`.
|
|
41
41
|
```ERB
|
42
42
|
<%= colorpicker_tag(name, default_color, kolor_picker_options, html_options) %>
|
43
43
|
<%= colorpicker_tag(:color, 'red', {:doRender => false}, {:class => 'color'}) %>
|
44
|
+
<%= colorpicker_tag(:color) %>
|
44
45
|
|
45
46
|
or form builder
|
46
47
|
|
47
48
|
<% form_for @item do |f| %>
|
48
|
-
<%= f.colorpicker(method,
|
49
|
-
<%= f.colorpicker(:color,
|
49
|
+
<%= f.colorpicker(method, kolor_picker_options, html_options) %>
|
50
|
+
<%= f.colorpicker(:color, {:doRender => false}, {:class => 'color'}) %>
|
51
|
+
<%= f.colorpicker(:color) %>
|
50
52
|
<% end %>
|
51
53
|
```
|
52
54
|
|
@@ -1,33 +1,33 @@
|
|
1
|
-
//= require kolor-picker/jqColorPicker.min
|
2
|
-
//= require kolor-picker/color-sampler
|
3
|
-
//= require kolor-picker/kolor-picker
|
4
|
-
|
5
|
-
(function ($) {
|
6
|
-
var colorPicker = $();
|
7
|
-
|
8
|
-
$(document).on('ready page:load', function () {
|
9
|
-
$('[data-kolor-picker]').each(function () {
|
10
|
-
var element = $(this);
|
11
|
-
var options = element.data('kolor-picker') || {};
|
12
|
-
options.onSelect = function (color) {
|
13
|
-
element.val(color);
|
14
|
-
};
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
});
|
20
|
-
});
|
21
|
-
|
22
|
-
$(document).on('page:before-unload', function() {
|
23
|
-
if (!colorPicker.length) {
|
24
|
-
colorPicker = $('.cp-color-picker');
|
25
|
-
}
|
26
|
-
});
|
27
|
-
|
28
|
-
$(document).on('page:load', function() {
|
29
|
-
if (colorPicker.length) {
|
30
|
-
$('body').append(colorPicker);
|
31
|
-
}
|
32
|
-
});
|
33
|
-
})(jQuery);
|
1
|
+
//= require kolor-picker/jqColorPicker.min
|
2
|
+
//= require kolor-picker/color-sampler
|
3
|
+
//= require kolor-picker/kolor-picker
|
4
|
+
|
5
|
+
(function ($) {
|
6
|
+
var colorPicker = $();
|
7
|
+
|
8
|
+
$(document).on('ready page:load', function () {
|
9
|
+
$('[data-widget-kolor-picker]').each(function () {
|
10
|
+
var element = $(this);
|
11
|
+
var options = element.data('widget-kolor-picker') || {};
|
12
|
+
options.onSelect = function (color) {
|
13
|
+
element.val(color).change();
|
14
|
+
};
|
15
|
+
element.addClass('kolor-picker-input')
|
16
|
+
.attr('autocomplete', 'off')
|
17
|
+
.kolorPicker(options)
|
18
|
+
.wrap('<span class="kolor-picker-wrapper" />');
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
$(document).on('page:before-unload', function() {
|
23
|
+
if (!colorPicker.length) {
|
24
|
+
colorPicker = $('.cp-color-picker');
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
$(document).on('page:load', function() {
|
29
|
+
if (colorPicker.length) {
|
30
|
+
$('body').append(colorPicker);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
})(jQuery);
|
@@ -1,213 +1,219 @@
|
|
1
|
-
/*!
|
2
|
-
* [color-sampler]{@link https://github.com/emn178/color-sampler}
|
3
|
-
*
|
4
|
-
* @version 0.1.
|
5
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
6
|
-
* @copyright Chen, Yi-Cyuan 2015-2016
|
7
|
-
* @license MIT
|
8
|
-
*/
|
9
|
-
(function ($, window, document) {
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var KEY = 'color-sampler';
|
13
|
-
var SELECTOR = ':' + KEY;
|
14
|
-
var INACCURACY = 5;
|
15
|
-
var init = false, preview, previewPixels = [], previewing = false, interval = 200,
|
16
|
-
timer, observations = $();
|
17
|
-
|
18
|
-
$.expr[':'][KEY] = function (element) {
|
19
|
-
return $(element).data(KEY) !== undefined;
|
20
|
-
};
|
21
|
-
|
22
|
-
function Sampler(canvas, options) {
|
23
|
-
this.canvas = $(canvas);
|
24
|
-
this.options = options || {};
|
25
|
-
this.enabled = true;
|
26
|
-
this.context = canvas.getContext("2d");
|
27
|
-
this.resize();
|
28
|
-
this.canvas.on('mousemove', this.onMousemove.bind(this));
|
29
|
-
this.canvas.on('mouseout', this.onMouseout.bind(this));
|
30
|
-
this.canvas.on('click', this.onClick.bind(this));
|
31
|
-
}
|
32
|
-
|
33
|
-
Sampler.prototype.resize = function () {
|
34
|
-
var canvas = this.canvas;
|
35
|
-
this.bounds = {
|
36
|
-
left: parseInt(canvas.css('padding-left')) || 0,
|
37
|
-
top: parseInt(canvas.css('padding-top')) || 0,
|
38
|
-
right: canvas.width(),
|
39
|
-
bottom: canvas.height()
|
40
|
-
};
|
41
|
-
};
|
42
|
-
|
43
|
-
Sampler.prototype.onMousemove = function (e) {
|
44
|
-
if (!this.enabled) {
|
45
|
-
return;
|
46
|
-
}
|
47
|
-
var canvas = this.canvas;
|
48
|
-
var bounds = this.bounds;
|
49
|
-
var x = e.offsetX - bounds.left;
|
50
|
-
var y = e.offsetY - bounds.top;
|
51
|
-
this.inRange = x
|
52
|
-
if (!this.inRange && (x < -INACCURACY || y < -INACCURACY || x >= bounds.right + INACCURACY || y >= bounds.bottom + INACCURACY)) {
|
53
|
-
hidePreview();
|
54
|
-
return;
|
55
|
-
}
|
56
|
-
preview.css({
|
57
|
-
left: (e.pageX + 5) + 'px',
|
58
|
-
top: (e.pageY + 5) + 'px'
|
59
|
-
});
|
60
|
-
var pixels = this.setupPreview(x, y);
|
61
|
-
showPreview();
|
62
|
-
this.color = previewPixels[60].css('background-color');
|
63
|
-
if ($.isFunction(this.options.onPreview)) {
|
64
|
-
this.options.onPreview.call(canvas, this.color);
|
65
|
-
}
|
66
|
-
this.canvas.trigger('sampler:preview', this.color);
|
67
|
-
};
|
68
|
-
|
69
|
-
Sampler.prototype.setupPreview = function (centralX, centralY) {
|
70
|
-
var startX = centralX - 5;
|
71
|
-
var startY = centralY - 5;
|
72
|
-
var data = this.context.getImageData(startX, startY, 11, 11).data;
|
73
|
-
for (var i = 0, j = 0; i < data.length; i += 4, ++j) {
|
74
|
-
var y = parseInt(j / 11) + startY;
|
75
|
-
var x = j % 11 + startX;
|
76
|
-
if (x
|
77
|
-
previewPixels[j].css('background-color', 'white');
|
78
|
-
} else {
|
79
|
-
var color =
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
this.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
};
|
104
|
-
|
105
|
-
Sampler.prototype.
|
106
|
-
if (
|
107
|
-
|
108
|
-
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}
|
125
|
-
|
126
|
-
function
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
1
|
+
/*!
|
2
|
+
* [color-sampler]{@link https://github.com/emn178/color-sampler}
|
3
|
+
*
|
4
|
+
* @version 0.1.6
|
5
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
6
|
+
* @copyright Chen, Yi-Cyuan 2015-2016
|
7
|
+
* @license MIT
|
8
|
+
*/
|
9
|
+
(function ($, window, document) {
|
10
|
+
'use strict';
|
11
|
+
|
12
|
+
var KEY = 'color-sampler';
|
13
|
+
var SELECTOR = ':' + KEY;
|
14
|
+
var INACCURACY = 5;
|
15
|
+
var init = false, preview, previewPixels = [], previewing = false, interval = 200,
|
16
|
+
timer, observations = $();
|
17
|
+
|
18
|
+
$.expr[':'][KEY] = function (element) {
|
19
|
+
return $(element).data(KEY) !== undefined;
|
20
|
+
};
|
21
|
+
|
22
|
+
function Sampler(canvas, options) {
|
23
|
+
this.canvas = $(canvas);
|
24
|
+
this.options = options || {};
|
25
|
+
this.enabled = true;
|
26
|
+
this.context = canvas.getContext("2d");
|
27
|
+
this.resize();
|
28
|
+
this.canvas.on('mousemove', this.onMousemove.bind(this));
|
29
|
+
this.canvas.on('mouseout', this.onMouseout.bind(this));
|
30
|
+
this.canvas.on('click', this.onClick.bind(this));
|
31
|
+
}
|
32
|
+
|
33
|
+
Sampler.prototype.resize = function () {
|
34
|
+
var canvas = this.canvas;
|
35
|
+
this.bounds = {
|
36
|
+
left: parseInt(canvas.css('padding-left')) || 0,
|
37
|
+
top: parseInt(canvas.css('padding-top')) || 0,
|
38
|
+
right: canvas.width(),
|
39
|
+
bottom: canvas.height()
|
40
|
+
};
|
41
|
+
};
|
42
|
+
|
43
|
+
Sampler.prototype.onMousemove = function (e) {
|
44
|
+
if (!this.enabled) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
var canvas = this.canvas;
|
48
|
+
var bounds = this.bounds;
|
49
|
+
var x = e.offsetX - bounds.left;
|
50
|
+
var y = e.offsetY - bounds.top;
|
51
|
+
this.inRange = this.checkInRange(x, y);
|
52
|
+
if (!this.inRange && (x < -INACCURACY || y < -INACCURACY || x >= bounds.right + INACCURACY || y >= bounds.bottom + INACCURACY)) {
|
53
|
+
hidePreview();
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
preview.css({
|
57
|
+
left: (e.pageX + 5) + 'px',
|
58
|
+
top: (e.pageY + 5) + 'px'
|
59
|
+
});
|
60
|
+
var pixels = this.setupPreview(x, y);
|
61
|
+
showPreview();
|
62
|
+
this.color = previewPixels[60].css('background-color');
|
63
|
+
if ($.isFunction(this.options.onPreview)) {
|
64
|
+
this.options.onPreview.call(canvas, this.color);
|
65
|
+
}
|
66
|
+
this.canvas.trigger('sampler:preview', this.color);
|
67
|
+
};
|
68
|
+
|
69
|
+
Sampler.prototype.setupPreview = function (centralX, centralY) {
|
70
|
+
var startX = centralX - 5;
|
71
|
+
var startY = centralY - 5;
|
72
|
+
var data = this.context.getImageData(startX, startY, 11, 11).data;
|
73
|
+
for (var i = 0, j = 0; i < data.length; i += 4, ++j) {
|
74
|
+
var y = parseInt(j / 11) + startY;
|
75
|
+
var x = j % 11 + startX;
|
76
|
+
if (!this.checkInRange(x, y)) {
|
77
|
+
previewPixels[j].css('background-color', 'white');
|
78
|
+
} else {
|
79
|
+
var color = Array.prototype.slice.call(data, i, i + 4);
|
80
|
+
color[3] = Math.min(color[3] / 100, 1);
|
81
|
+
color = 'rgba(' + color.join(',') + ')';
|
82
|
+
previewPixels[j].css('background-color', color);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
Sampler.prototype.checkInRange = function (x, y) {
|
88
|
+
return x >= 0 && y >= 0 && x < this.bounds.right && y < this.bounds.bottom;
|
89
|
+
};
|
90
|
+
|
91
|
+
Sampler.prototype.onMouseout = function () {
|
92
|
+
hidePreview();
|
93
|
+
};
|
94
|
+
|
95
|
+
Sampler.prototype.onClick = function (e) {
|
96
|
+
if (!this.color || !this.enabled || !this.inRange) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
if ($.isFunction(this.options.onSelect)) {
|
100
|
+
this.options.onSelect.call(this.canvas, this.color);
|
101
|
+
}
|
102
|
+
this.canvas.trigger('sampler:select', this.color);
|
103
|
+
};
|
104
|
+
|
105
|
+
Sampler.prototype.detect = function () {
|
106
|
+
if (this.canvas.width() != this.bounds.right || this.canvas.height() != this.bounds.bottom) {
|
107
|
+
this.resize();
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
Sampler.prototype.enable = function (enabled) {
|
112
|
+
if (enabled === undefined) {
|
113
|
+
enabled = true;
|
114
|
+
}
|
115
|
+
this.enabled = enabled;
|
116
|
+
};
|
117
|
+
|
118
|
+
Sampler.prototype.disable = function (disabled) {
|
119
|
+
if (disabled === undefined) {
|
120
|
+
disabled = true;
|
121
|
+
}
|
122
|
+
this.enabled = !disabled;
|
123
|
+
hidePreview();
|
124
|
+
};
|
125
|
+
|
126
|
+
function resize() {
|
127
|
+
$(SELECTOR).each(function () {
|
128
|
+
$(this).data(KEY).resize();
|
129
|
+
});
|
130
|
+
}
|
131
|
+
|
132
|
+
function createPreview() {
|
133
|
+
preview = $('<div class="color-sampler-preview"/>');
|
134
|
+
var table = $('<table/>');
|
135
|
+
preview.append(table);
|
136
|
+
for (var y = 0; y < 11; ++y) {
|
137
|
+
var tr = $('<tr>');
|
138
|
+
for (var x = 0; x < 11; ++x) {
|
139
|
+
var td = $('<td></td>').attr('x', x).attr('y', y);
|
140
|
+
previewPixels.push(td);
|
141
|
+
tr.append(td);
|
142
|
+
}
|
143
|
+
table.append(tr);
|
144
|
+
}
|
145
|
+
$('body').append(preview);
|
146
|
+
}
|
147
|
+
|
148
|
+
function showPreview() {
|
149
|
+
if (previewing) {
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
previewing = true;
|
153
|
+
preview.addClass('active');
|
154
|
+
}
|
155
|
+
|
156
|
+
function hidePreview() {
|
157
|
+
if (!previewing) {
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
previewing = false;
|
161
|
+
preview.removeClass('active');
|
162
|
+
}
|
163
|
+
|
164
|
+
function detect() {
|
165
|
+
observations = observations.filter(SELECTOR);
|
166
|
+
observations.each(function () {
|
167
|
+
$(this).data(KEY).detect();
|
168
|
+
});
|
169
|
+
if (observations.length === 0) {
|
170
|
+
timer = clearInterval(timer);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
var PublicMethods = ['enable', 'disable', 'resize'];
|
175
|
+
$.fn.colorSampler = function (method, options) {
|
176
|
+
var sampler, isString = typeof (method) == 'string';
|
177
|
+
this.filter('canvas').each(function () {
|
178
|
+
if (isString) {
|
179
|
+
if ($.inArray(method, PublicMethods) != -1) {
|
180
|
+
sampler = $(this).data(KEY);
|
181
|
+
if (sampler) {
|
182
|
+
sampler[method].apply(sampler, options);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
} else {
|
186
|
+
options = method;
|
187
|
+
sampler = new Sampler(this, options);
|
188
|
+
$(this).data(KEY, sampler);
|
189
|
+
|
190
|
+
if (!init) {
|
191
|
+
init = true;
|
192
|
+
createPreview();
|
193
|
+
$(document).ready(function () {
|
194
|
+
$(window).bind('resize', resize);
|
195
|
+
});
|
196
|
+
}
|
197
|
+
|
198
|
+
observations = observations.add(this);
|
199
|
+
if (interval && !timer) {
|
200
|
+
timer = setInterval(detect, interval);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
});
|
204
|
+
return this;
|
205
|
+
};
|
206
|
+
|
207
|
+
$.colorSamper = {};
|
208
|
+
|
209
|
+
$.colorSamper.setInterval = function (v) {
|
210
|
+
if (v == interval || !$.isNumeric(v) || v < 0) {
|
211
|
+
return;
|
212
|
+
}
|
213
|
+
interval = v;
|
214
|
+
timer = clearInterval(timer);
|
215
|
+
if (interval > 0) {
|
216
|
+
timer = setInterval(detect, interval);
|
217
|
+
}
|
218
|
+
};
|
219
|
+
})(jQuery, window, document);
|
@@ -1,4 +1,3 @@
|
|
1
1
|
/*! tinyColorPicker - v1.0.4 2016-04-14 */
|
2
2
|
|
3
3
|
!function(a,b){"object"==typeof exports?module.exports=b(a):"function"==typeof define&&define.amd?define("colors",[],function(){return b(a)}):a.Colors=b(a)}(this,function(a,b){"use strict";function c(a,c,d,f,g){if("string"==typeof c){var c=v.txt2color(c);d=c.type,p[d]=c[d],g=g!==b?g:c.alpha}else if(c)for(var h in c)a[d][h]=k(c[h]/l[d][h][1],0,1);return g!==b&&(a.alpha=k(+g,0,1)),e(d,f?a:b)}function d(a,b,c){var d=o.options.grey,e={};return e.RGB={r:a.r,g:a.g,b:a.b},e.rgb={r:b.r,g:b.g,b:b.b},e.alpha=c,e.equivalentGrey=n(d.r*a.r+d.g*a.g+d.b*a.b),e.rgbaMixBlack=i(b,{r:0,g:0,b:0},c,1),e.rgbaMixWhite=i(b,{r:1,g:1,b:1},c,1),e.rgbaMixBlack.luminance=h(e.rgbaMixBlack,!0),e.rgbaMixWhite.luminance=h(e.rgbaMixWhite,!0),o.options.customBG&&(e.rgbaMixCustom=i(b,o.options.customBG,c,1),e.rgbaMixCustom.luminance=h(e.rgbaMixCustom,!0),o.options.customBG.luminance=h(o.options.customBG,!0)),e}function e(a,b){var c,e,k,q=b||p,r=v,s=o.options,t=l,u=q.RND,w="",x="",y={hsl:"hsv",rgb:a},z=u.rgb;if("alpha"!==a){for(var A in t)if(!t[A][A]){a!==A&&(x=y[A]||"rgb",q[A]=r[x+"2"+A](q[x])),u[A]||(u[A]={}),c=q[A];for(w in c)u[A][w]=n(c[w]*t[A][w][1])}z=u.rgb,q.HEX=r.RGB2HEX(z),q.equivalentGrey=s.grey.r*q.rgb.r+s.grey.g*q.rgb.g+s.grey.b*q.rgb.b,q.webSave=e=f(z,51),q.webSmart=k=f(z,17),q.saveColor=z.r===e.r&&z.g===e.g&&z.b===e.b?"web save":z.r===k.r&&z.g===k.g&&z.b===k.b?"web smart":"",q.hueRGB=v.hue2RGB(q.hsv.h),b&&(q.background=d(z,q.rgb,q.alpha))}var B,C,D,E=q.rgb,F=q.alpha,G="luminance",H=q.background;return B=i(E,{r:0,g:0,b:0},F,1),B[G]=h(B,!0),q.rgbaMixBlack=B,C=i(E,{r:1,g:1,b:1},F,1),C[G]=h(C,!0),q.rgbaMixWhite=C,s.customBG&&(D=i(E,H.rgbaMixCustom,F,1),D[G]=h(D,!0),D.WCAG2Ratio=j(D[G],H.rgbaMixCustom[G]),q.rgbaMixBGMixCustom=D,D.luminanceDelta=m.abs(D[G]-H.rgbaMixCustom[G]),D.hueDelta=g(H.rgbaMixCustom,D,!0)),q.RGBLuminance=h(z),q.HUELuminance=h(q.hueRGB),s.convertCallback&&s.convertCallback(q,a),q}function f(a,b){var c={},d=0,e=b/2;for(var f in a)d=a[f]%b,c[f]=a[f]+(d>e?b-d:-d);return c}function g(a,b,c){return(m.max(a.r-b.r,b.r-a.r)+m.max(a.g-b.g,b.g-a.g)+m.max(a.b-b.b,b.b-a.b))*(c?255:1)/765}function h(a,b){for(var c=b?1:255,d=[a.r/c,a.g/c,a.b/c],e=o.options.luminance,f=d.length;f--;)d[f]=d[f]<=.03928?d[f]/12.92:m.pow((d[f]+.055)/1.055,2.4);return e.r*d[0]+e.g*d[1]+e.b*d[2]}function i(a,c,d,e){var f={},g=d!==b?d:1,h=e!==b?e:1,i=g+h*(1-g);for(var j in a)f[j]=(a[j]*g+c[j]*h*(1-g))/i;return f.a=i,f}function j(a,b){var c=1;return c=a>=b?(a+.05)/(b+.05):(b+.05)/(a+.05),n(100*c)/100}function k(a,b,c){return a>c?c:b>a?b:a}var l={rgb:{r:[0,255],g:[0,255],b:[0,255]},hsv:{h:[0,360],s:[0,100],v:[0,100]},hsl:{h:[0,360],s:[0,100],l:[0,100]},alpha:{alpha:[0,1]},HEX:{HEX:[0,16777215]}},m=a.Math,n=m.round,o={},p={},q={r:.298954,g:.586434,b:.114612},r={r:.2126,g:.7152,b:.0722},s=function(a){this.colors={RND:{}},this.options={color:"rgba(204, 82, 37, 0.8)",grey:q,luminance:r,valueRanges:l},t(this,a||{})},t=function(a,d){var e,f=a.options;u(a);for(var g in d)d[g]!==b&&(f[g]=d[g]);e=f.customBG,f.customBG="string"==typeof e?v.txt2color(e).rgb:e,p=c(a.colors,f.color,b,!0)},u=function(a){o!==a&&(o=a,p=a.colors)};s.prototype.setColor=function(a,d,f){return u(this),a?c(this.colors,a,d,b,f):(f!==b&&(this.colors.alpha=k(f,0,1)),e(d))},s.prototype.setCustomBackground=function(a){return u(this),this.options.customBG="string"==typeof a?v.txt2color(a).rgb:a,c(this.colors,b,"rgb")},s.prototype.saveAsBackground=function(){return u(this),c(this.colors,b,"rgb",!0)},s.prototype.toString=function(a,b){return v.color2text((a||"rgb").toLowerCase(),this.colors,b)};var v={txt2color:function(a){var b={},c=a.replace(/(?:#|\)|%)/g,"").split("("),d=(c[1]||"").split(/,\s*/),e=c[1]?c[0].substr(0,3):"rgb",f="";if(b.type=e,b[e]={},c[1])for(var g=3;g--;)f=e[g]||e.charAt(g),b[e][f]=+d[g]/l[e][f][1];else b.rgb=v.HEX2rgb(c[0]);return b.alpha=d[3]?+d[3]:1,b},color2text:function(a,b,c){var d=c!==!1&&n(100*b.alpha)/100,e="number"==typeof d&&c!==!1&&(c||1!==d),f=b.RND.rgb,g=b.RND.hsl,h="hex"===a&&e,i="hex"===a&&!h,j="rgb"===a||h,k=j?f.r+", "+f.g+", "+f.b:i?"#"+b.HEX:g.h+", "+g.s+"%, "+g.l+"%";return i?k:(h?"rgb":a)+(e?"a":"")+"("+k+(e?", "+d:"")+")"},RGB2HEX:function(a){return((a.r<16?"0":"")+a.r.toString(16)+(a.g<16?"0":"")+a.g.toString(16)+(a.b<16?"0":"")+a.b.toString(16)).toUpperCase()},HEX2rgb:function(a){return a=a.split(""),{r:+("0x"+a[0]+a[a[3]?1:0])/255,g:+("0x"+a[a[3]?2:1]+(a[3]||a[1]))/255,b:+("0x"+(a[4]||a[2])+(a[5]||a[2]))/255}},hue2RGB:function(a){var b=6*a,c=~~b%6,d=6===b?0:b-c;return{r:n(255*[1,1-d,0,0,d,1][c]),g:n(255*[d,1,1,1-d,0,0][c]),b:n(255*[0,0,d,1,1,1-d][c])}},rgb2hsv:function(a){var b,c,d,e=a.r,f=a.g,g=a.b,h=0;return g>f&&(f=g+(g=f,0),h=-1),c=g,f>e&&(e=f+(f=e,0),h=-2/6-h,c=m.min(f,g)),b=e-c,d=e?b/e:0,{h:1e-15>d?p&&p.hsl&&p.hsl.h||0:b?m.abs(h+(f-g)/(6*b)):0,s:e?b/e:p&&p.hsv&&p.hsv.s||0,v:e}},hsv2rgb:function(a){var b=6*a.h,c=a.s,d=a.v,e=~~b,f=b-e,g=d*(1-c),h=d*(1-f*c),i=d*(1-(1-f)*c),j=e%6;return{r:[d,h,g,g,i,d][j],g:[i,d,d,h,g,g][j],b:[g,g,i,d,d,h][j]}},hsv2hsl:function(a){var b=(2-a.s)*a.v,c=a.s*a.v;return c=a.s?1>b?b?c/b:0:c/(2-b):0,{h:a.h,s:a.v||c?c:p&&p.hsl&&p.hsl.s||0,l:b/2}},rgb2hsl:function(a,b){var c=v.rgb2hsv(a);return v.hsv2hsl(b?c:p.hsv=c)},hsl2rgb:function(a){var b=6*a.h,c=a.s,d=a.l,e=.5>d?d*(1+c):d+c-c*d,f=d+d-e,g=e?(e-f)/e:0,h=~~b,i=b-h,j=e*g*i,k=f+j,l=e-j,m=h%6;return{r:[e,l,f,f,k,e][m],g:[k,e,e,l,f,f][m],b:[f,f,k,e,e,l][m]}}};return s}),function(a,b){"object"==typeof exports?module.exports=b(a,require("jquery"),require("colors")):"function"==typeof define&&define.amd?define(["jquery","colors"],function(c,d){return b(a,c,d)}):b(a,a.jQuery,a.Colors)}(this,function(a,b,c,d){"use strict";function e(a){return a.value||a.getAttribute("value")||b(a).css("background-color")||"#fff"}function f(a){return a=a.originalEvent&&a.originalEvent.touches?a.originalEvent.touches[0]:a,a.originalEvent?a.originalEvent:a}function g(a){return b(a.find(r.doRender)[0]||a[0])}function h(c){var d=b(this),f=d.offset(),h=b(a),j=r.gap;c?(s=g(d),s._colorMode=s.data("colorMode"),p.$trigger=d,(t||i()).css({left:(t[0]._left=f.left)-((t[0]._left=t[0]._left+t[0]._width-(h.scrollLeft()+h.width()))+j>0?t[0]._left+j:0),top:(t[0]._top=f.top+d.outerHeight())-((t[0]._top=t[0]._top+t[0]._height-(h.scrollTop()+h.height()))+j>0?t[0]._top+j:0)}).show(r.animationSpeed,function(){c!==!0&&(x._width=x.width(),u._width=u.width(),u._height=u.height(),q.setColor(e(s[0])),n(!0))})):p.$trigger&&b(t).hide(r.animationSpeed,function(){n(!1),p.$trigger=null})}function i(){return b("head").append('<style type="text/css" id="tinyColorPickerStyles">'+(r.css||H)+(r.cssAddon||"")+"</style>"),p.$UI=t=b(G).css({margin:r.margin}).appendTo("body").show(0,function(){var a=b(this);E=r.GPU&&a.css("perspective")!==d,u=b(".cp-xy-slider",this),v=b(".cp-xy-cursor",this),w=b(".cp-z-cursor",this),x=b(".cp-alpha",this).toggle(!!r.opacity),y=b(".cp-alpha-cursor",this),r.buildCallback.call(p,a),a.prepend("<div>").children().eq(0).css("width",a.children().eq(0).width()),this._width=this.offsetWidth,this._height=this.offsetHeight}).hide().on(C,".cp-xy-slider,.cp-z-slider,.cp-alpha",j)}function j(a){var c=this.className.replace(/cp-(.*?)(?:\s*|$)/,"$1").replace("-","_");(a.button||a.which)>1||(a.preventDefault&&a.preventDefault(),a.returnValue=!1,s._offset=b(this).offset(),(c="xy_slider"===c?k:"z_slider"===c?l:m)(a),n(),z.on(D,function(){z.off(".a")}).on(B,function(a){c(a),n()}))}function k(a){var b=f(a),c=b.pageX-s._offset.left,d=b.pageY-s._offset.top;q.setColor({s:c/u._width*100,v:100-d/u._height*100},"hsv")}function l(a){var b=f(a).pageY-s._offset.top;q.setColor({h:360-b/u._height*360},"hsv")}function m(a){var b=f(a).pageX-s._offset.left,c=b/x._width;q.setColor({},"rgb",c)}function n(a){var b=q.colors,c=b.hueRGB,e=(b.RND.rgb,b.RND.hsl,"#222"),f="#ddd",g=q.toString(s._colorMode,r.forceAlpha),h=b.HUELuminance>.22?e:f,i=b.rgbaMixBlack.luminance>.22?e:f,j=(1-b.hsv.h)*u._height,k=b.hsv.s*u._width,l=(1-b.hsv.v)*u._height,m=b.alpha*x._width,n=E?"translate3d":"",p=s[0].value,t=s[0].hasAttribute("value")&&""===p&&a!==d;u._css={backgroundColor:"rgb("+c.r+","+c.g+","+c.b+")"},v._css={transform:n+"("+k+"px, "+l+"px, 0)",left:E?"":k,top:E?"":l,borderColor:b.RGBLuminance>.22?e:f},w._css={transform:n+"(0, "+j+"px, 0)",top:E?"":j,borderColor:"transparent "+h},x._css={backgroundColor:"#"+b.HEX},y._css={transform:n+"("+m+"px, 0, 0)",left:E?"":m,borderColor:i+" transparent"},s._css={backgroundColor:t?"":g,color:t?"":b.rgbaMixBGMixCustom.luminance>.22?e:f},s.text=t?"":p!==g?g:"",a!==d?o(a):F(o)}function o(a){u.css(u._css),v.css(v._css),w.css(w._css),x.css(x._css),y.css(y._css),r.doRender&&s.css(s._css),s.text&&s.val(s.text),r.renderCallback.call(p,s,"boolean"==typeof a?a:d)}var p,q,r,s,t,u,v,w,x,y,z=b(document),A=b(),B="touchmove.a mousemove.a pointermove.a",C="touchstart.a mousedown.a pointerdown.a",D="touchend.a mouseup.a pointerup.a",E=!1,F=(Math.round,a.requestAnimationFrame||a.webkitRequestAnimationFrame||function(a){a()}),G='<div class="cp-color-picker"><div class="cp-z-slider"><div class="cp-z-cursor"></div></div><div class="cp-xy-slider"><div class="cp-white"></div><div class="cp-xy-cursor"></div></div><div class="cp-alpha"><div class="cp-alpha-cursor"></div></div></div>',H=".cp-color-picker{position:absolute;overflow:hidden;padding:6px 6px 0;background-color:#444;color:#bbb;font-family:Arial,Helvetica,sans-serif;font-size:12px;font-weight:400;cursor:default;border-radius:5px}.cp-color-picker>div{position:relative;overflow:hidden}.cp-xy-slider{float:left;height:128px;width:128px;margin-bottom:6px;background:linear-gradient(to right,#FFF,rgba(255,255,255,0))}.cp-white{height:100%;width:100%;background:linear-gradient(rgba(0,0,0,0),#000)}.cp-xy-cursor{position:absolute;top:0;width:10px;height:10px;margin:-5px;border:1px solid #fff;border-radius:100%;box-sizing:border-box}.cp-z-slider{float:right;margin-left:6px;height:128px;width:20px;background:linear-gradient(red 0,#f0f 17%,#00f 33%,#0ff 50%,#0f0 67%,#ff0 83%,red 100%)}.cp-z-cursor{position:absolute;margin-top:-4px;width:100%;border:4px solid #fff;border-color:transparent #fff;box-sizing:border-box}.cp-alpha{clear:both;width:100%;height:16px;margin:6px 0;background:linear-gradient(to right,#444,rgba(0,0,0,0))}.cp-alpha-cursor{position:absolute;margin-left:-4px;height:100%;border:4px solid #fff;border-color:#fff transparent;box-sizing:border-box}",I=function(a){q=this.color=new c(a),r=q.options,p=this};I.prototype={render:n,toggle:h},b.fn.colorPicker=function(c){var d=function(){};return c=b.extend({animationSpeed:150,GPU:!0,doRender:!0,customBG:"#FFF",opacity:!0,renderCallback:d,buildCallback:d,body:document.body,scrollResize:!0,gap:4},c),!p&&c.scrollResize&&b(a).on("resize.a scroll.a",function(){p.$trigger&&p.toggle.call(p.$trigger[0],!0)}),A=A.add(this),this.colorPicker=A.colorPicker=p||new I(c),b(c.body).off(".a").on(C,function(a){!A.add(t).find(a.target).add(A.filter(a.target))[0]&&h()}),this.on("focusin.a click.a",h).on("change.a",function(){q.setColor(this.value||"#FFF"),A.colorPicker.render(!0)}).each(function(){var a=e(this),d=a.split("("),f=g(b(this));f.data("colorMode",d[1]?d[0].substr(0,3):"HEX").attr("readonly",r.preventFocus),c.doRender&&f.css({"background-color":a,color:function(){return q.setColor(a).rgbaMixBGMixCustom.luminance>.22?"#222":"#ddd"}})})},b.fn.colorPicker.destroy=function(){A.add(r.body).off(".a"),p.toggle(!1),A=b()}});
|
4
|
-
//# sourceMappingURL=jqColorPicker.js.map
|
@@ -1,175 +1,191 @@
|
|
1
|
-
/**
|
2
|
-
* [kolor-picker]{@link https://github.com/emn178/kolor-picker}
|
3
|
-
*
|
4
|
-
* @version 0.
|
5
|
-
* @author Yi-Cyuan Chen [emn178@gmail.com]
|
6
|
-
* @copyright Yi-Cyuan Chen 2015-
|
7
|
-
* @license MIT
|
8
|
-
*/
|
9
|
-
(function ($) {
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var KEY = 'kolor-picker';
|
13
|
-
var wrapper;
|
14
|
-
|
15
|
-
function Wrapper(element, colorPicker) {
|
16
|
-
this.element = element;
|
17
|
-
this.colorPicker = colorPicker;
|
18
|
-
this.previewElement = $('<div class="kolor-picker"><div class="sampler"></div><div class="preview-block"><input type="text"/><div class="preview-wrapper"><div class="preview" /></div></div></div>');
|
19
|
-
this.element.append(this.previewElement);
|
20
|
-
|
21
|
-
var elements = {
|
22
|
-
preview: this.previewElement.find('.preview'),
|
23
|
-
input: this.previewElement.find('input'),
|
24
|
-
sampler: this.previewElement.find('.sampler'),
|
25
|
-
alpha: this.element.find('.cp-alpha')
|
26
|
-
};
|
27
|
-
this.elements = elements;
|
28
|
-
elements.sampler.click(this.enableSampler.bind(this));
|
29
|
-
|
30
|
-
|
31
|
-
this.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
this.
|
40
|
-
this.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
this.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
};
|
59
|
-
|
60
|
-
Wrapper.prototype.
|
61
|
-
var
|
62
|
-
this.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
this.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
};
|
123
|
-
|
124
|
-
KolorPicker.prototype.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
1
|
+
/**
|
2
|
+
* [kolor-picker]{@link https://github.com/emn178/kolor-picker}
|
3
|
+
*
|
4
|
+
* @version 0.3.0
|
5
|
+
* @author Yi-Cyuan Chen [emn178@gmail.com]
|
6
|
+
* @copyright Yi-Cyuan Chen 2015-2021
|
7
|
+
* @license MIT
|
8
|
+
*/
|
9
|
+
(function ($) {
|
10
|
+
'use strict';
|
11
|
+
|
12
|
+
var KEY = 'kolor-picker';
|
13
|
+
var wrapper;
|
14
|
+
|
15
|
+
function Wrapper(element, colorPicker) {
|
16
|
+
this.element = element;
|
17
|
+
this.colorPicker = colorPicker;
|
18
|
+
this.previewElement = $('<div class="kolor-picker"><div class="sampler"></div><div class="preview-block"><input type="text"/><div class="preview-wrapper"><div class="preview" /></div></div></div>');
|
19
|
+
this.element.append(this.previewElement);
|
20
|
+
|
21
|
+
var elements = {
|
22
|
+
preview: this.previewElement.find('.preview'),
|
23
|
+
input: this.previewElement.find('input'),
|
24
|
+
sampler: this.previewElement.find('.sampler'),
|
25
|
+
alpha: this.element.find('.cp-alpha')
|
26
|
+
};
|
27
|
+
this.elements = elements;
|
28
|
+
elements.sampler.click(this.enableSampler.bind(this));
|
29
|
+
elements.input.change(this.onInputChange.bind(this));
|
30
|
+
|
31
|
+
this.sampling = false;
|
32
|
+
this.lastToggled = false;
|
33
|
+
}
|
34
|
+
|
35
|
+
Wrapper.prototype.enableSampler = function () {
|
36
|
+
if (!this.kolorPicker.canvas) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
this.kolorPicker.canvas.colorSampler('enable');
|
40
|
+
this.sampling = true;
|
41
|
+
this.colorPicker.toggle(false);
|
42
|
+
};
|
43
|
+
|
44
|
+
Wrapper.prototype.onInputChange = function () {
|
45
|
+
this.kolorPicker.setColor(this.elements.input.val());
|
46
|
+
};
|
47
|
+
|
48
|
+
Wrapper.prototype.setKolorPicker = function (kolorPicker) {
|
49
|
+
this.kolorPicker = kolorPicker;
|
50
|
+
this.element.attr('data-theme', kolorPicker.theme);
|
51
|
+
this.elements.sampler.toggle(!!kolorPicker.canvas);
|
52
|
+
this.elements.alpha.toggle(kolorPicker.options.opacity !== false);
|
53
|
+
if (kolorPicker.options.doRender === undefined) {
|
54
|
+
this.colorPicker.color.options.doRender = true;
|
55
|
+
} else {
|
56
|
+
this.colorPicker.color.options.doRender = kolorPicker.options.doRender;
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
Wrapper.prototype.getColor = function () {
|
61
|
+
var rgb = this.colorPicker.color.colors.rgb;
|
62
|
+
return 'rgba(' + [parseInt(rgb.r * 255), parseInt(rgb.g * 255), parseInt(rgb.b * 255), this.colorPicker.color.colors.alpha.toFixed(2)].join(',') + ')';
|
63
|
+
};
|
64
|
+
|
65
|
+
Wrapper.prototype.updateColor = function () {
|
66
|
+
var color = this.getColor();
|
67
|
+
this.elements.preview.css('background-color', color);
|
68
|
+
this.elements.input.val(color);
|
69
|
+
this.kolorPicker.changeColor(color);
|
70
|
+
};
|
71
|
+
|
72
|
+
Wrapper.prototype.render = function (toggled) {
|
73
|
+
if (toggled === undefined) {
|
74
|
+
this.updateColor();
|
75
|
+
} else if (this.lastToggled === toggled) {
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
this.lastToggled = toggled;
|
79
|
+
if (toggled === false) {
|
80
|
+
if (!this.sampling) {
|
81
|
+
var color = this.getColor();
|
82
|
+
this.kolorPicker.selectColor(color);
|
83
|
+
}
|
84
|
+
} else {
|
85
|
+
this.updateColor();
|
86
|
+
}
|
87
|
+
};
|
88
|
+
|
89
|
+
function KolorPicker(element, options) {
|
90
|
+
this.element = element;
|
91
|
+
this.options = options || {};
|
92
|
+
this.canvas = this.options.canvas;
|
93
|
+
this.theme = this.options.theme || $.kolorPicker.theme;
|
94
|
+
this.color = this.element.css('background-color');
|
95
|
+
|
96
|
+
if (this.canvas) {
|
97
|
+
this.canvas = $(this.canvas);
|
98
|
+
this.canvas.colorSampler().colorSampler('disable')
|
99
|
+
.bind('sampler:preview', this.onSamplerPreview.bind(this))
|
100
|
+
.bind('sampler:select', this.onSamplerSelect.bind(this));
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
KolorPicker.prototype.onSamplerSelect = function (e, color) {
|
105
|
+
if (wrapper.kolorPicker != this) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
wrapper.sampling = false;
|
109
|
+
this.canvas.colorSampler('disable');
|
110
|
+
this.setColor(color);
|
111
|
+
color = wrapper.getColor();
|
112
|
+
this.selectColor(color);
|
113
|
+
};
|
114
|
+
|
115
|
+
KolorPicker.prototype.onSamplerPreview = function (e, color) {
|
116
|
+
if (wrapper.kolorPicker != this) {
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
this.element.css('background-color', color);
|
120
|
+
color = wrapper.getColor();
|
121
|
+
this.changeColor(color);
|
122
|
+
};
|
123
|
+
|
124
|
+
KolorPicker.prototype.selectColor = function (color) {
|
125
|
+
this.color = color;
|
126
|
+
if ($.isFunction(this.options.onSelect)) {
|
127
|
+
this.options.onSelect.call(this.element, color);
|
128
|
+
}
|
129
|
+
this.element.trigger('kolorPicker:select', color)
|
130
|
+
};
|
131
|
+
|
132
|
+
KolorPicker.prototype.changeColor = function (color) {
|
133
|
+
if ($.isFunction(this.options.onChange)) {
|
134
|
+
this.options.onChange.call(this.element, color);
|
135
|
+
}
|
136
|
+
this.element.trigger('kolorPicker:change', color)
|
137
|
+
};
|
138
|
+
|
139
|
+
KolorPicker.prototype.setColor = function (color) {
|
140
|
+
this.color = color;
|
141
|
+
this.element.css('background-color', color);
|
142
|
+
if (wrapper) {
|
143
|
+
wrapper.colorPicker.color.setColor(color);
|
144
|
+
wrapper.colorPicker.render();
|
145
|
+
}
|
146
|
+
};
|
147
|
+
|
148
|
+
KolorPicker.prototype.getColor = function () {
|
149
|
+
return this.color;
|
150
|
+
};
|
151
|
+
|
152
|
+
var KolorPickerOptions = {
|
153
|
+
buildCallback: function (element) {
|
154
|
+
wrapper = new Wrapper(element, this);
|
155
|
+
},
|
156
|
+
|
157
|
+
renderCallback: function (element, toggled) {
|
158
|
+
var kolorPicker = $(element).data(KEY);
|
159
|
+
if (kolorPicker) {
|
160
|
+
wrapper.setKolorPicker(kolorPicker);
|
161
|
+
wrapper.render(toggled);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
};
|
165
|
+
|
166
|
+
var PublicMethods = ['setColor', 'getColor'];
|
167
|
+
$.fn.kolorPicker = function (options) {
|
168
|
+
if (typeof (options) == 'string') {
|
169
|
+
if ($.inArray(options, PublicMethods) != -1) {
|
170
|
+
var args = Array.prototype.splice.call(arguments, 1);
|
171
|
+
var kolorPicker = $(this).data(KEY);
|
172
|
+
if (kolorPicker) {
|
173
|
+
return kolorPicker[options].apply(kolorPicker, args);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
} else {
|
177
|
+
this.each(function () {
|
178
|
+
var element = $(this);
|
179
|
+
if (!element.data(KEY)) {
|
180
|
+
return element.data(KEY, new KolorPicker(element, options))
|
181
|
+
.colorPicker($.extend({ cssAddon: $.kolorPicker.css }, options, KolorPickerOptions));
|
182
|
+
}
|
183
|
+
});
|
184
|
+
}
|
185
|
+
return this;
|
186
|
+
};
|
187
|
+
|
188
|
+
$.kolorPicker = {
|
189
|
+
theme: ''
|
190
|
+
};
|
191
|
+
})(jQuery);
|
@@ -1,16 +1,20 @@
|
|
1
1
|
/*
|
2
2
|
*= require kolor-picker/color-sampler
|
3
3
|
*/
|
4
|
-
.kolor-picker-
|
5
|
-
display: inline-block;
|
4
|
+
.kolor-picker-input {
|
6
5
|
width: 35px;
|
7
6
|
height: 30px;
|
8
7
|
border: 1px solid black;
|
9
|
-
|
10
|
-
|
11
|
-
background-image: url('data:image/gif;base64,R0lGODlhDAAMAIABAMzMzP///yH5BAEAAAEALAAAAAAMAAwAAAIWhB+ph5ps3IMyQFBvzVRq3zmfGC5QAQA7');
|
8
|
+
text-indent: -999px;
|
9
|
+
cursor: default;
|
12
10
|
}
|
13
11
|
|
14
|
-
.kolor-picker-
|
15
|
-
|
12
|
+
.kolor-picker-input:focus {
|
13
|
+
outline-offset: 0;
|
14
|
+
outline: 0;
|
15
|
+
}
|
16
|
+
|
17
|
+
.kolor-picker-wrapper {
|
18
|
+
display: inline-flex;
|
19
|
+
background-image: url('data:image/gif;base64,R0lGODlhDAAMAIABAMzMzP///yH5BAEAAAEALAAAAAAMAAwAAAIWhB+ph5ps3IMyQFBvzVRq3zmfGC5QAQA7');
|
16
20
|
}
|
@@ -1,54 +1,57 @@
|
|
1
|
-
/*!
|
2
|
-
* [color-sampler]{@link https://github.com/emn178/color-sampler}
|
3
|
-
*
|
4
|
-
* @version 0.1.5
|
5
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
6
|
-
* @copyright Chen, Yi-Cyuan 2015-2016
|
7
|
-
* @license MIT
|
8
|
-
*/
|
9
|
-
.color-sampler-preview {
|
10
|
-
position: absolute;
|
11
|
-
z-index: 100;
|
12
|
-
display: none;
|
13
|
-
width: 110px;
|
14
|
-
height: 110px;
|
15
|
-
border: 1px solid;
|
16
|
-
border-radius: 50%;
|
17
|
-
overflow: hidden;
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
/*!
|
2
|
+
* [color-sampler]{@link https://github.com/emn178/color-sampler}
|
3
|
+
*
|
4
|
+
* @version 0.1.5
|
5
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
6
|
+
* @copyright Chen, Yi-Cyuan 2015-2016
|
7
|
+
* @license MIT
|
8
|
+
*/
|
9
|
+
.color-sampler-preview {
|
10
|
+
position: absolute;
|
11
|
+
z-index: 100;
|
12
|
+
display: none;
|
13
|
+
width: 110px;
|
14
|
+
height: 110px;
|
15
|
+
border: 1px solid;
|
16
|
+
border-radius: 50%;
|
17
|
+
overflow: hidden;
|
18
|
+
background-color: white;
|
19
|
+
background-image: url('data:image/gif;base64,R0lGODlhDAAMAIABAMzMzP///yH5BAEAAAEALAAAAAAMAAwAAAIWhB+ph5ps3IMyQFBvzVRq3zmfGC5QAQA7');
|
20
|
+
background-size: 6px;
|
21
|
+
}
|
22
|
+
|
23
|
+
.color-sampler-preview.active {
|
24
|
+
display: block;
|
25
|
+
}
|
26
|
+
|
27
|
+
.color-sampler-preview table {
|
28
|
+
border-spacing: 0;
|
29
|
+
}
|
30
|
+
|
31
|
+
.color-sampler-preview td {
|
32
|
+
border: 1px solid gray;
|
33
|
+
height: 8px;
|
34
|
+
width: 8px;
|
35
|
+
background-color: #BBB4B4;
|
36
|
+
padding: 0;
|
37
|
+
}
|
38
|
+
|
39
|
+
.color-sampler-preview td[x="5"][y="5"] {
|
40
|
+
border-color: red;
|
41
|
+
}
|
42
|
+
|
43
|
+
.color-sampler-preview td[x="5"][y="4"] {
|
44
|
+
border-bottom-color: red;
|
45
|
+
}
|
46
|
+
|
47
|
+
.color-sampler-preview td[x="5"][y="6"] {
|
48
|
+
border-top-color: red;
|
49
|
+
}
|
50
|
+
|
51
|
+
.color-sampler-preview td[x="4"][y="5"] {
|
52
|
+
border-right-color: red;
|
53
|
+
}
|
54
|
+
|
55
|
+
.color-sampler-preview td[x="6"][y="5"] {
|
56
|
+
border-left-color: red;
|
57
|
+
}
|
data/lib/kolor-picker/builder.rb
CHANGED
@@ -4,7 +4,7 @@ module ActionView
|
|
4
4
|
module Helpers
|
5
5
|
class FormBuilder
|
6
6
|
def colorpicker(method, options = {}, html_options = {})
|
7
|
-
@template.
|
7
|
+
text_field(method, @template.colorpicker_options(options, html_options))
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/kolor-picker/engine.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
if defined?(::Rails::Engine)
|
2
|
-
module KolorPicker
|
3
|
-
class Engine < ::Rails::Engine
|
4
|
-
initializer "kolor-picker" do
|
5
|
-
ActiveSupport.on_load(:action_view) do
|
6
|
-
include KolorPicker::Helper
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
if defined?(::Rails::Engine)
|
2
|
+
module KolorPicker
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
initializer "kolor-picker" do
|
5
|
+
ActiveSupport.on_load(:action_view) do
|
6
|
+
include KolorPicker::Helper
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/kolor-picker/helper.rb
CHANGED
@@ -3,17 +3,13 @@ module KolorPicker
|
|
3
3
|
def colorpicker_options(options, html_options)
|
4
4
|
html_options.deep_merge({
|
5
5
|
:data => {
|
6
|
-
:"kolor-picker" => options.to_json
|
6
|
+
:"widget-kolor-picker" => options.to_json
|
7
7
|
}
|
8
8
|
})
|
9
9
|
end
|
10
10
|
|
11
11
|
def colorpicker_tag(name, value = nil, options = {}, html_options = {})
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def colorpicker(object_name, method, options = {}, html_options = {})
|
16
|
-
ActionView::Helpers::Tags::HiddenField.new(object_name, method, self, colorpicker_options(options, html_options)).render
|
12
|
+
text_field_tag(name, value, colorpicker_options(options, html_options))
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
data/lib/kolor-picker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kolor-picker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chen, Yi-Cyuan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -125,7 +125,7 @@ homepage: https://github.com/emn178/kolor-picker-rails
|
|
125
125
|
licenses:
|
126
126
|
- MIT
|
127
127
|
metadata: {}
|
128
|
-
post_install_message:
|
128
|
+
post_install_message:
|
129
129
|
rdoc_options: []
|
130
130
|
require_paths:
|
131
131
|
- lib
|
@@ -140,9 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
signing_key:
|
143
|
+
rubygems_version: 3.0.8
|
144
|
+
signing_key:
|
146
145
|
specification_version: 4
|
147
146
|
summary: Integrate with kolor-picker to provide color picker and form helper.
|
148
147
|
test_files: []
|