added demo
parent
6843c23590
commit
3e55b26d50
@ -0,0 +1,37 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta name="Description" content="tiny ColorPicker is a small (10.0KB, 4.5KB gZip) but very advanced jQuery color picker and color conversion / calculation tool that supports the following color spaces: rgb, hsv, hsl, hex, but also alpha, WCAG 2.0 readability standards (based on opacity levels of all layers), contrast, color similarity, grayscale, 2-layer or 3-layer overlap mix, etc..." />
|
||||||
|
<meta name="author" content="Peter Dematté" />
|
||||||
|
<meta http-equiv="language" content="en" />
|
||||||
|
<link rel="shortcut icon" type="image/x-icon" href="../development/favicon.ico">
|
||||||
|
<link rel="icon" type="image/x-icon" href="../development/favicon.ico">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="../index.css">
|
||||||
|
<link id="colorPickerMod" rel="stylesheet" type="text/css" href="mod.css">
|
||||||
|
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../jqColorPicker.min.js"></script>
|
||||||
|
<script type="text/javascript" src="index.js"></script>
|
||||||
|
|
||||||
|
<title>tiny jQuery color picker demo</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="content-wrapper">
|
||||||
|
<h1>Tiny jQuery colorPicker</h1>
|
||||||
|
<p>This a demo that describes tinyColorPicker custumization 'Skinned dev-tools like with RGB sliders' in a more understandable way.</p>
|
||||||
|
<a name="demo" id="demo" class="a-inline"></a>
|
||||||
|
<h2>Skinned dev-tools like, with RGB sliders</h2>
|
||||||
|
<div class="input-toggles">
|
||||||
|
<input class="color no-alpha" value="#B6BD79" />
|
||||||
|
<input class="color no-alpha" value="rgb(162, 63, 3)" />
|
||||||
|
<input class="color no-alpha" value="hsl(32, 95%, 23%)" />
|
||||||
|
</div>
|
||||||
|
<div class="div-toggles">
|
||||||
|
<div class="trigger" value="#556B2F"><div><div></div></div></div>
|
||||||
|
<div class="trigger" value="rgb(100, 86, 70)"><div><div></div></div></div>
|
||||||
|
<div class="trigger" value="hsla(167, 29%, 68%, 0.8)"><div><div></div></div></div>
|
||||||
|
|
||||||
|
<a class="a-inline" href="https://github.com/PitPik/tinyColorPicker"><img style="position: absolute; top: 0; right: 0; border: 0;" src="../development/fmog.png" alt="Fork me on GitHub"></a>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,90 @@
|
|||||||
|
$(function(){
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
customBG: '#222', // bg of page is dark, so if opcity close to 0 -> dark shines through
|
||||||
|
doRender: 'div div', // tell it where to render bg-color if no input
|
||||||
|
colorNames: { // get more colors in the other demo... will be displayed next to color patch
|
||||||
|
'808080': 'grey',
|
||||||
|
'00FFFF': 'cyan',
|
||||||
|
'000000': 'black',
|
||||||
|
'0000FF': 'blue',
|
||||||
|
'FF00FF': 'magenta',
|
||||||
|
'008000': 'green',
|
||||||
|
'FF0000': 'red',
|
||||||
|
'C0C0C0': 'silver',
|
||||||
|
'FFFFFF': 'white',
|
||||||
|
'FFFF00': 'yellow'
|
||||||
|
},
|
||||||
|
buildCallback: function($elm) { // called the first time colorPicker gets triggered
|
||||||
|
var that = this; // for callback function
|
||||||
|
var currentRGB = ''; // either r, g or b
|
||||||
|
var $currentSlider = $(); // the clicked rgb slider
|
||||||
|
var currentOffset = {}; // of slider
|
||||||
|
var $window = $(window);
|
||||||
|
var mouseMove = function(e) { // don't render sliders here. Just setColor;
|
||||||
|
var color = {}; // new calculated color
|
||||||
|
|
||||||
|
color[currentRGB] = (e.pageX - currentOffset.left) / that.currentWidth * 255;
|
||||||
|
that.color.setColor(color, 'rgb'); // set calculated value
|
||||||
|
that.render(); // tell colorPicker to render
|
||||||
|
};
|
||||||
|
|
||||||
|
$elm.append( // render extra sliders and patch
|
||||||
|
'<div class="cp-rgb-r"><div class="cp-rgb-r-cursor"></div></div>' +
|
||||||
|
'<div class="cp-rgb-g"><div class="cp-rgb-g-cursor"></div></div>' +
|
||||||
|
'<div class="cp-rgb-b"><div class="cp-rgb-b-cursor"></div></div>' +
|
||||||
|
'<div class="cp-patch"><div></div></div><div class="cp-disp"></div>');
|
||||||
|
|
||||||
|
this.cursorRStyle = $elm.find('.cp-rgb-r-cursor')[0].style; // caching for faster render renderCallback
|
||||||
|
this.cursorGStyle = $elm.find('.cp-rgb-g-cursor')[0].style;
|
||||||
|
this.cursorBStyle = $elm.find('.cp-rgb-b-cursor')[0].style;
|
||||||
|
|
||||||
|
this.patchStyle = $('.cp-patch div')[0].style;
|
||||||
|
this.$display = $('.cp-disp');
|
||||||
|
|
||||||
|
$elm.on('mousedown', '.cp-rgb-r, .cp-rgb-g, .cp-rgb-b', function(e) { // event delegation
|
||||||
|
$currentSlider = $(this); // well ;o)
|
||||||
|
currentRGB = this.className.replace(/cp-rgb-(\D){1}/, "$1"); // cp-rgb-r -> r
|
||||||
|
currentOffset = $currentSlider.offset(); // for later calculations
|
||||||
|
that.currentWidth = $currentSlider.width(); // ... also here
|
||||||
|
$window.on('mousemove.rgb', mouseMove); // install mousemove listener
|
||||||
|
e.preventDefault && e.preventDefault(); // prevent selecting text
|
||||||
|
mouseMove(e); // render color picker the first time
|
||||||
|
return false; // for IE
|
||||||
|
});
|
||||||
|
|
||||||
|
$window.on('mouseup', function(e) {
|
||||||
|
$window.off('mousemove.rgb'); // turn off mousemove event handler
|
||||||
|
});
|
||||||
|
|
||||||
|
// append css after just generated / use cssAddon instead if you want
|
||||||
|
$('#colorPickerMod').appendTo('head');
|
||||||
|
},
|
||||||
|
renderCallback: function($elm, toggled) {
|
||||||
|
var colors = this.color.colors; // the whole color object
|
||||||
|
var rgb = colors.RND.rgb; // the RGB color in 0-255
|
||||||
|
|
||||||
|
// the following 6 lines are not necessary if you don't have the trigger icons with the arrows...
|
||||||
|
// if (toggled === true) { // just showing (only on show)
|
||||||
|
// $('.trigger').removeClass('active'); // turns arrow of color triggers
|
||||||
|
// $elm.closest('.trigger').addClass('active');
|
||||||
|
// } else if (toggled === false) { // just hiding (only on hide)
|
||||||
|
// $elm.closest('.trigger').removeClass('active');
|
||||||
|
// }
|
||||||
|
|
||||||
|
this.patchStyle.backgroundColor = $elm[0].style.backgroundColor; // set patch color...
|
||||||
|
this.$display.text(this.color.options.colorNames[colors.HEX] || $elm.val()); // ...and text aside
|
||||||
|
|
||||||
|
this.currentWidth = this.currentWidth || this.$UI.find('.cp-rgb-r')[0].clientWidth; // first time
|
||||||
|
this.cursorRStyle.left = (rgb.r / 255 * this.currentWidth) + 'px'; // render sliders
|
||||||
|
this.cursorGStyle.left = (rgb.g / 255 * this.currentWidth) + 'px'; // faster than with $().css
|
||||||
|
this.cursorBStyle.left = (rgb.b / 255 * this.currentWidth) + 'px';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
window.myColorPicker =
|
||||||
|
$('.color').colorPicker(options);
|
||||||
|
$('.trigger').colorPicker();
|
||||||
|
});
|
Loading…
Reference in New Issue