Browse Source

better GPU render detection and render enhancement

pull/25/head
peterd 7 years ago
parent
commit
ce643f09d6
  1. 10
      index.html
  2. 104
      jqColorPicker.js
  3. 2
      jqColorPicker.js.map
  4. 2
      jqColorPicker.min.js

10
index.html

@ -11,7 +11,7 @@
<body>
<h1>Tiny jQuery colorPicker</h1>
<p>Looking for mobile first, tiny foot print, fast, scaleable, flexible and pluggable...<br>
This <strong>4.4KB</strong> small HSB color picker is based on a subset of <a href="https://github.com/PitPik/colorPicker/blob/master/colors.js">colors.js</a> from it's big brother <a href="http://dematte.at/colorPicker/">colorPicker</a>, supports all modern features like touch and MS pointer, GPU accelerated rendering, battery friendly requestAnimationFrame and provides a lot of hooks for developers to write plugins (See demo plugins below in <a href="#demo">Demo</a>).</p>
This <strong>4.5KB</strong> small HSB color picker is based on a subset of <a href="https://github.com/PitPik/colorPicker/blob/master/colors.js">colors.js</a> from it's big brother <a href="http://dematte.at/colorPicker/">colorPicker</a>, supports all modern features like touch and MS pointer, GPU accelerated rendering, battery friendly requestAnimationFrame and provides a lot of hooks for developers to write plugins (See demo plugins below in <a href="#demo">Demo</a>).</p>
<a name="demo" id="demo"></a>
<h2>Demo</h2>
On all elements with className 'color': <pre>$('.color').colorPicker();</pre>
@ -73,9 +73,9 @@ window.myColorPicker = $('input.color').colorPicker({
<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 src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<!-- <script type="text/javascript" src="colors.js"></script> -->
<!-- <script type="text/javascript" src="jqColorPicker.js"></script> -->
<script type="text/javascript" src="jqColorPicker.min.js"></script>
<script type="text/javascript" src="colors.js"></script>
<script type="text/javascript" src="jqColorPicker.js"></script>
<!-- <script type="text/javascript" src="jqColorPicker.min.js"></script> -->
<script type="text/javascript">
(function(window, undefined){
'use strict';
@ -477,7 +477,7 @@ window.myColorPicker = $('input.color').colorPicker({
var colors = this.color.colors,
rgb = colors.RND.rgb;
$('.cp-patch div').css({'background-color': $elm.css('background-color')});
$('.cp-patch div').css({'background-color': $elm[0].style.backgroundColor});
$('.cp-disp').text(this.color.options.colorNames[colors.HEX] || $elm.val());
if (toggled === true) {
// here you can recalculate position after showing the color picker

104
jqColorPicker.js

@ -94,7 +94,9 @@
find('.cp-alpha').toggle(!!_options.opacity).
parent(). // back to $(_html)
show(0, function() {
_GPU = _options.GPU && $(this).css('perspective') === '';
_GPU = _options.GPU &&
$('<div>').css('transform', 'matrix(1,0,0,2,0,0)')[0].
style.cssText.replace(/2.*$/, '1,');
_options.buidCallback.call(_colorPicker, $(this));
_$xy_slider = $('.cp-xy-slider', this);
_$xy_cursor = $('.cp-xy-cursor', this);
@ -173,58 +175,58 @@
h = (1 - colors.hsv.h) * _cache.sliderWidth,
s = colors.hsv.s * _cache.sliderWidth,
v = (1 - colors.hsv.v) * _cache.sliderWidth,
a = alpha * _cache.alphaWidth,
t3d = _GPU ? 'translate3d' : '';
_$xy_slider.css({
backgroundColor: 'rgb(' +
hueRGB.r + ',' + hueRGB.g + ',' + hueRGB.b + ')'});
_$xy_cursor.css({
transform: t3d + '(' + s + 'px, ' + v + 'px, 0)',
left: !_GPU ? s : '',
top: !_GPU ? v : '',
borderColor : colors.RGBLuminance > 0.22 ? dark : light
});
_$z_cursor.css({
transform: t3d + '(0, ' + h + 'px, 0)',
top: !_GPU ? h : '',
borderColor : 'transparent ' + HUEContrast,
});
_$alpha.css({backgroundColor: 'rgb(' + RGBInnerText + ')'});
_$alpha_cursor.css({
transform: t3d + '(' + a + 'px, 0, 0)',
left: !_GPU ? a : '',
borderColor : alphaContrast + ' transparent'
});
_options.doRender && _cache.$element.css({
backgroundColor : RGBAText,
color: colors.rgbaMixBGMixCustom.luminance > 0.22 ? dark : light
});
_cache.$element.val(text);
a = alpha * _cache.alphaWidth; //,
// t3d = _GPU ? 'translate3d' : '';
// _$xy_slider.css({
// backgroundColor: 'rgb(' +
// hueRGB.r + ',' + hueRGB.g + ',' + hueRGB.b + ')'});
// _$xy_cursor.css({
// transform: t3d + '(' + s + 'px, ' + v + 'px, 0)',
// left: !_GPU ? s : '',
// top: !_GPU ? v : '',
// borderColor : colors.RGBLuminance > 0.22 ? dark : light
// });
// _$z_cursor.css({
// transform: t3d + '(0, ' + h + 'px, 0)',
// top: !_GPU ? h : '',
// borderColor : 'transparent ' + HUEContrast,
// });
// _$alpha.css({backgroundColor: 'rgb(' + RGBInnerText + ')'});
// _$alpha_cursor.css({
// transform: t3d + '(' + a + 'px, 0, 0)',
// left: !_GPU ? a : '',
// borderColor : alphaContrast + ' transparent'
// });
// _options.doRender && _cache.$element.css({
// backgroundColor : RGBAText,
// color: colors.rgbaMixBGMixCustom.luminance > 0.22 ? dark : light
// });
// _cache.$element.val(text);
// faster version (more than 2.5x)... though, no jQuery (colors, ...)
//
// _$xy_slider[0].style.cssText =
// 'background-color:' + 'rgb(' +
// hueRGB.r + ',' + hueRGB.g + ',' + hueRGB.b + ');';
// _$xy_cursor[0].style.cssText =
// (_GPU ? 'transform:' + t3d + '(' + s + 'px, ' + v + 'px, 0);' :
// 'left:' + s + 'px;' + 'top:' + v + 'px;') +
// 'border-color:' + (colors.RGBLuminance > 0.22 ? dark : light);
// _$z_cursor[0].style.cssText =
// (_GPU ? 'transform:' + t3d + '(0, ' + h + 'px, 0);' :
// 'top:' + h + 'px;') +
// 'border-color:' + 'transparent ' + HUEContrast;
// _$alpha[0].style.cssText = 'background-color:' + 'rgb(' + RGBInnerText + ')';
// _$alpha_cursor[0].style.cssText =
// (_GPU ? 'transform:' + t3d + '(' + a + 'px, 0, 0);' :
// 'left:' + a + 'px;') +
// 'border-color:' + alphaContrast + ' transparent';
// _options.doRender && (_cache.$element[0].style.cssText =
// 'background-color:' + RGBAText +
// ';color:' + (colors.rgbaMixBGMixCustom.luminance > 0.22 ? dark : light));
// _cache.$element[0].value = text;
_$xy_slider[0].style.cssText =
'background-color:' + 'rgb(' +
hueRGB.r + ',' + hueRGB.g + ',' + hueRGB.b + ');';
_$xy_cursor[0].style.cssText =
(_GPU ? _GPU + s + ',' + v + ');' :
'left:' + s + 'px;' + 'top:' + v + 'px;') +
'border-color:' + (colors.RGBLuminance > 0.22 ? dark : light);
_$z_cursor[0].style.cssText =
(_GPU ? _GPU + '0,' + h + ');' :
'top:' + h + 'px;') +
'border-color:' + 'transparent ' + HUEContrast;
_$alpha[0].style.cssText = 'background-color:' + 'rgb(' + RGBInnerText + ')';
_$alpha_cursor[0].style.cssText =
(_GPU ? _GPU + a + ', 0);' :
'left:' + a + 'px;') +
'border-color:' + alphaContrast + ' transparent';
_options.doRender && (_cache.$element[0].style.cssText =
'background-color:' + RGBAText +
';color:' + (colors.rgbaMixBGMixCustom.luminance > 0.22 ? dark : light));
_cache.$element[0].value = text;
_options.renderCallback.call(
_colorPicker,

2
jqColorPicker.js.map
File diff suppressed because it is too large
View File

2
jqColorPicker.min.js
File diff suppressed because it is too large
View File

Loading…
Cancel
Save