From 991e805c619514360f67e06ab3fffd1f9e4b4e6b Mon Sep 17 00:00:00 2001 From: peterd Date: Thu, 28 Aug 2014 18:50:01 +0200 Subject: [PATCH] small (V8) optimization --- README.md | 6 +++--- colorPicker.js | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 26c8256..b34710e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # colorPicker and colors -An advanced, fast but small **javaScript** (only, framework independent) **color picker** (or color chooser for desktop use) that uses only one javaScript (.js) file (no extra HTML, CSS, images, etc... on IE9+ and internet browsers).
ColorPicker works in all browsers incl. IE6+ (an extra CSS has to be made to make it work in IE6 though and some additional setTimeout tricks to make it work in IE5.5)
+An advanced, fast but small (46.9KB, 19.9KB gZip) **javaScript** (only, framework independent) **color picker** (or color chooser for desktop use) that uses only one javaScript (.js) file (no extra HTML, CSS, images, etc... on IE9+ and internet browsers).
ColorPicker works in all browsers incl. IE6+ (an extra CSS has to be made to make it work in IE6 though and some additional setTimeout tricks to make it work in IE5.5)
**colorPicker.js** uses **colors.js**, a small but comprehensive tool for color conversions / calculations (WCAG 2.0, contrast, color difference, layer mix, etc.)... With **colors.js** (~8.7k or way smaller if other color spaces and complex calculations are taken out...) you can also build your own simpler and / or smaller color pickers quite easy as demonstrated on the [demo page](http://dematte.at/cpn).
@@ -64,7 +64,7 @@ var myColorPicker = new ColorPicker({ grey: ..., // see Colors... luminance: ..., // see Colors... devPicker: false // uses existing HTML instead of internal template for developing - renderCallback: // function(colors, mode){}, // callback on after rendering (for further rendering outside colorPicker) + renderCallback: function(colors, mode){}, // callback on after rendering (for further rendering outside colorPicker) actionCallback: function(e, action){}, // callback on any action within colorPicker (buttons, sliders, ...) convertCallback: function(colors, type){}, // see Colors... }); @@ -76,7 +76,7 @@ After initializing Color or ColorPicker you'll get a clean but rhich model of th ```javascript myColors: { - colors: { all kinds of color values... see late}, + colors: { all kinds of color values... see later}, options: { all the options you set or that are set as default... }, __proto__: { // all methods Color uses setColor: function(newCol, type, alpha) {}, diff --git a/colorPicker.js b/colorPicker.js index dedbfc4..1151228 100644 --- a/colorPicker.js +++ b/colorPicker.js @@ -1142,18 +1142,30 @@ return newColor; } - function color2string(color, type) { - var out = [], - n = 0; - - type = type || 'rgb'; - while (type[n] || type.charAt(n)) { // IE7 - out.push(color[type[n] || type.charAt(n)]); - n++; + // function color2string(color, type) { + // var out = [], + // n = 0; + + // type = type || 'rgb'; + // while (type.charAt(n)) { // IE7 // V8 type[n] || + // out.push(color[type.charAt(n)]); + // n++; + // } + // return type + '(' + out.join(', ') + ')'; + // } + + function color2string(color, type) { // ~2 x faster on V8 + var out = '', + t = (type || 'rgb').split(''), + n = t.length; + + for ( ; n--; ) { + out = ', ' + color[t[n]] + out; } - return type + '(' + out.join(', ') + ')'; + return (type || 'rgb') + '(' + out.substr(2) + ')'; } + function limitValue(value, min, max) { // return Math.max(min, Math.min(max, value)); // faster?? return (value > max ? max : value < min ? min : value);