mirror of
https://github.com/PitPik/tinyColorPicker
synced 2025-07-21 08:54:29 -06:00
some optimization
This commit is contained in:
parent
348b1068a2
commit
e2b8e93994
@ -51,7 +51,7 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.cp-alpha {
|
.cp-alpha {
|
||||||
clear: left;
|
clear: both;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
margin: 6px 0;
|
margin: 6px 0;
|
||||||
|
43
index.html
43
index.html
@ -66,15 +66,15 @@ window.myColorPicker = $('input.color').colorPicker({
|
|||||||
<p>Will follow... See <a href="https://github.com/PitPik/tinyColorPicker">tinyColorPicke on GitHub</a> for now.</p>
|
<p>Will follow... See <a href="https://github.com/PitPik/tinyColorPicker">tinyColorPicke on GitHub</a> for now.</p>
|
||||||
<!-- <script type="text/javascript" src="jquery-1.11.2.js"></script> -->
|
<!-- <script type="text/javascript" src="jquery-1.11.2.js"></script> -->
|
||||||
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
|
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
|
||||||
<!-- <script type="text/javascript" src="colors.js"></script> -->
|
<script type="text/javascript" src="colors.js"></script>
|
||||||
<!-- <script type="text/javascript" src="jqColorPicker.js"></script> -->
|
<script type="text/javascript" src="jqColorPicker.js"></script>
|
||||||
<script type="text/javascript" src="jqColorPicker.min.js"></script>
|
<!-- <script type="text/javascript" src="jqColorPicker.min.js"></script> -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
(function(window, undefined){
|
(function(window, undefined){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var plugin = {},
|
var plugin = {},
|
||||||
pluginSelect = document.getElementById('pluginSelect'),
|
$pluginSelect = $('#pluginSelect'),
|
||||||
getQueryVariable = function(variable) {
|
getQueryVariable = function(variable) {
|
||||||
var query = window.location.search.substring(1),
|
var query = window.location.search.substring(1),
|
||||||
vars = query.split('&'),
|
vars = query.split('&'),
|
||||||
@ -88,8 +88,7 @@ window.myColorPicker = $('input.color').colorPicker({
|
|||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
},
|
},
|
||||||
type = getQueryVariable('type'),
|
type = getQueryVariable('type');
|
||||||
selector = document.getElementById('pluginSelect');
|
|
||||||
|
|
||||||
// plugin for mobile use (bigger and value/color display on top)
|
// plugin for mobile use (bigger and value/color display on top)
|
||||||
plugin.mobile = {
|
plugin.mobile = {
|
||||||
@ -161,17 +160,15 @@ window.myColorPicker = $('input.color').colorPicker({
|
|||||||
'background:#666; border-top:1px solid #222;}',
|
'background:#666; border-top:1px solid #222;}',
|
||||||
|
|
||||||
renderCallback: function($elm, toggled) {
|
renderCallback: function($elm, toggled) {
|
||||||
var $panel = $('.cp-panel'),
|
var colors = this.color.colors,
|
||||||
colors = this.color.colors,
|
|
||||||
rgb = colors.RND.rgb,
|
rgb = colors.RND.rgb,
|
||||||
hsv = colors.RND.hsv;
|
hsv = colors.RND.hsv,
|
||||||
|
modes = { r: rgb.r, g: rgb.g, b: rgb.b,
|
||||||
|
h: hsv.h, s: hsv.s, v: hsv.v };
|
||||||
|
|
||||||
$('.cp-r', $panel).val(rgb.r);
|
$('input', '.cp-panel').each(function() {
|
||||||
$('.cp-g', $panel).val(rgb.g);
|
this.value = modes[this.className.substr(3, 1)];
|
||||||
$('.cp-b', $panel).val(rgb.b);
|
});
|
||||||
$('.cp-h', $panel).val(hsv.h);
|
|
||||||
$('.cp-s', $panel).val(hsv.s);
|
|
||||||
$('.cp-v', $panel).val(hsv.v);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -189,11 +186,13 @@ window.myColorPicker = $('input.color').colorPicker({
|
|||||||
'<div></div><div></div><div></div><div></div>' +
|
'<div></div><div></div><div></div><div></div>' +
|
||||||
'<div></div><div></div><div></div><div class="cp-store"><</div>').
|
'<div></div><div></div><div></div><div class="cp-store"><</div>').
|
||||||
on('click', '.cp-memory div', function(e) {
|
on('click', '.cp-memory div', function(e) {
|
||||||
|
var $this = $(this);
|
||||||
|
|
||||||
if (this.className) {
|
if (this.className) {
|
||||||
$(this).parent().prepend($(this).prev()).children().eq(0).
|
$this.parent().prepend($this.prev()).children().eq(0).
|
||||||
css('background-color', '#' + colorInstance.colors.HEX);
|
css('background-color', '#' + colorInstance.colors.HEX);
|
||||||
} else {
|
} else {
|
||||||
colorInstance.setColor($(this).css('background-color'));
|
colorInstance.setColor($this.css('background-color'));
|
||||||
colorPicker.render();
|
colorPicker.render();
|
||||||
}
|
}
|
||||||
}).find('.cp-memory div').each(function() {
|
}).find('.cp-memory div').each(function() {
|
||||||
@ -238,13 +237,13 @@ window.myColorPicker = $('input.color').colorPicker({
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
pluginSelect.value = type || 'desktop';
|
$pluginSelect.val(type || 'desktop').
|
||||||
pluginSelect.onchange = function(e) {
|
on('change', function(e) {
|
||||||
location = window.location;
|
location = window.location;
|
||||||
|
|
||||||
window.location = location.origin + location.pathname +
|
window.location =
|
||||||
'?type=' + this.value + '#demo';
|
location.origin + location.pathname + '?type=' + this.value + '#demo';
|
||||||
}
|
});
|
||||||
|
|
||||||
window.myColorPicker = $('input.color').colorPicker(
|
window.myColorPicker = $('input.color').colorPicker(
|
||||||
plugin[type] || plugin.desktop
|
plugin[type] || plugin.desktop
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
_color,
|
_color,
|
||||||
_options,
|
_options,
|
||||||
_cache = {},
|
_cache = {},
|
||||||
_$UI,
|
_$UI, _$xy_slider, _$xy_cursor, _$z_cursor , _$alpha , _$alpha_cursor,
|
||||||
_pointermove = 'touchmove mousemove pointermove',
|
_pointermove = 'touchmove mousemove pointermove',
|
||||||
_pointerup = 'touchend mouseup pointerup',
|
_pointerup = 'touchend mouseup pointerup',
|
||||||
_GPU = false,
|
_GPU = false,
|
||||||
@ -89,6 +89,11 @@
|
|||||||
show(0, function() {
|
show(0, function() {
|
||||||
_GPU = _options.GPU && $(this).css('transform') === '';
|
_GPU = _options.GPU && $(this).css('transform') === '';
|
||||||
_options.buidCallback.call(_colorPicker, $(this));
|
_options.buidCallback.call(_colorPicker, $(this));
|
||||||
|
_$xy_slider = $('.cp-xy-slider', this);
|
||||||
|
_$xy_cursor = $('.cp-xy-cursor', this);
|
||||||
|
_$z_cursor = $('.cp-z-cursor', this);
|
||||||
|
_$alpha = $('.cp-alpha', this);
|
||||||
|
_$alpha_cursor = $('.cp-alpha-cursor', this);
|
||||||
}).hide().
|
}).hide().
|
||||||
on('touchstart mousedown pointerdown',
|
on('touchstart mousedown pointerdown',
|
||||||
'.cp-xy-slider,.cp-z-slider,.cp-alpha', pointerdown).
|
'.cp-xy-slider,.cp-z-slider,.cp-alpha', pointerdown).
|
||||||
@ -164,23 +169,23 @@
|
|||||||
a = alpha * _cache.alphaWidth,
|
a = alpha * _cache.alphaWidth,
|
||||||
t3d = _GPU ? 'translate3d' : '';
|
t3d = _GPU ? 'translate3d' : '';
|
||||||
|
|
||||||
$('.cp-xy-slider').css({
|
_$xy_slider.css({
|
||||||
backgroundColor: 'rgb(' +
|
backgroundColor: 'rgb(' +
|
||||||
hueRGB.r + ',' + hueRGB.g + ',' + hueRGB.b + ')'});
|
hueRGB.r + ',' + hueRGB.g + ',' + hueRGB.b + ')'});
|
||||||
$('.cp-xy-cursor').css({
|
_$xy_cursor.css({
|
||||||
transform: t3d + '(' + s + 'px, ' + v + 'px, 0)',
|
transform: t3d + '(' + s + 'px, ' + v + 'px, 0)',
|
||||||
left: !_GPU ? s : '',
|
left: !_GPU ? s : '',
|
||||||
top: !_GPU ? v : '',
|
top: !_GPU ? v : '',
|
||||||
borderColor : colors.RGBLuminance > 0.22 ? dark : light
|
borderColor : colors.RGBLuminance > 0.22 ? dark : light
|
||||||
});
|
});
|
||||||
$('.cp-z-cursor').css({
|
_$z_cursor.css({
|
||||||
transform: t3d + '(0, ' + h + 'px, 0)',
|
transform: t3d + '(0, ' + h + 'px, 0)',
|
||||||
top: !_GPU ? h : '',
|
top: !_GPU ? h : '',
|
||||||
borderLeftColor : HUEContrast,
|
borderLeftColor : HUEContrast,
|
||||||
borderRightColor : HUEContrast
|
borderRightColor : HUEContrast
|
||||||
});
|
});
|
||||||
$('.cp-alpha').css({backgroundColor: 'rgb(' + RGBInnerText + ')'});
|
_$alpha.css({backgroundColor: 'rgb(' + RGBInnerText + ')'});
|
||||||
$('.cp-alpha-cursor').css({
|
_$alpha_cursor.css({
|
||||||
transform: t3d + '(' + a + 'px, 0, 0)',
|
transform: t3d + '(' + a + 'px, 0, 0)',
|
||||||
left: !_GPU ? a : '',
|
left: !_GPU ? a : '',
|
||||||
borderTopColor : alphaContrast,
|
borderTopColor : alphaContrast,
|
||||||
|
File diff suppressed because one or more lines are too long
2
jqColorPicker.min.js
vendored
2
jqColorPicker.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user