Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tidy up event propagation

No need to use chg flags at extras anymore. They'll just work.
  • Loading branch information...
commit 1aefdec7f83042c42fe401d829ac7afec1b60ef9 1 parent 77ddd84
Juho Vepsäläinen authored
70 dist/colorjoe.js
@@ -1053,7 +1053,6 @@ function fields(p, joe, o) {
1053 1053 };
1054 1054 var inputLen = ('' + fac).length + fix;
1055 1055 inputLen = fix? inputLen + 1: inputLen;
1056   - var chg = false; // XXX
1057 1056
1058 1057 var initials = cs.split('').map(function(n) {return n.toUpperCase();});
1059 1058
@@ -1074,34 +1073,28 @@ function fields(p, joe, o) {
1074 1073 elems.forEach(function(o) {col.push(o.e.input.value / fac);});
1075 1074 col.push(1); // alpha
1076 1075
1077   - chg = true;
1078 1076 joe.set(onecolor(col));
1079 1077 }
1080 1078
1081 1079 return {
1082 1080 change: function(col) {
1083   - if(!chg)
1084   - elems.forEach(function(o) {
1085   - o.e.input.value = (col[methods[o.name]]() * fac).toFixed(fix);
1086   - });
1087   - chg = false;
  1081 + elems.forEach(function(o) {
  1082 + o.e.input.value = (col[methods[o.name]]() * fac).toFixed(fix);
  1083 + });
1088 1084 }
1089 1085 };
1090 1086 }
1091 1087
1092 1088 function hex(p, joe) {
1093 1089 var e = utils.labelInput('hex', '', p, 6);
1094   - var chg = false; // XXX
1095 1090
1096 1091 e.input.onkeyup = function(elem) {
1097   - chg = true;
1098 1092 joe.set('#' + pad(elem.target.value, 6, '0'));
1099 1093 };
1100 1094
1101 1095 return {
1102 1096 change: function(col) {
1103   - if(!chg) e.input.value = col.hex().slice(1);
1104   - chg = false;
  1097 + e.input.value = col.hex().slice(1);
1105 1098 }
1106 1099 };
1107 1100 }
@@ -1253,9 +1246,15 @@ function setup(o) {
1253 1246 var col = cbs.init(previous, xy, z);
1254 1247 var listeners = {change: [], done: []};
1255 1248
1256   - function changed() {
1257   - for(var i = 0, len = listeners.change.length; i < len; i++) {
1258   - listeners.change[i](col);
  1249 + function changed(skip) {
  1250 + skip = isArray(skip)? skip: [];
  1251 +
  1252 + var li = listeners.change;
  1253 + var v;
  1254 +
  1255 + for(var i = 0, len = li.length; i < len; i++) {
  1256 + v = li[i];
  1257 + if(skip.indexOf(v.name) == -1) v.fn(col);
1259 1258 }
1260 1259 }
1261 1260
@@ -1270,10 +1269,10 @@ function setup(o) {
1270 1269
1271 1270 var ob = {
1272 1271 e: e,
1273   - update: function() {
1274   - changed();
  1272 + update: function(skip) {
  1273 + changed(skip);
1275 1274
1276   - return ob;
  1275 + return this;
1277 1276 },
1278 1277 get: function() {
1279 1278 return col;
@@ -1282,17 +1281,17 @@ function setup(o) {
1282 1281 var oldCol = this.get();
1283 1282 col = cbs.init(getColor(c), xy, z);
1284 1283
1285   - if(oldCol.hex() != col.hex()) changed();
  1284 + if(oldCol.hex() != col.hex()) this.update();
1286 1285
1287   - return ob;
  1286 + return this;
1288 1287 },
1289   - on: function(evt, cb) {
  1288 + on: function(evt, cb, name) {
1290 1289 if(evt == 'change' || evt == 'done') {
1291   - listeners[evt].push(cb);
  1290 + listeners[evt].push({name: name, fn: cb});
1292 1291 }
1293 1292 else console.warn('Passed invalid evt name "' + evt + '" to colorjoe.on');
1294 1293
1295   - return ob;
  1294 + return this;
1296 1295 },
1297 1296 removeAllListeners: function(evt) {
1298 1297 if (evt) {
@@ -1303,6 +1302,8 @@ function setup(o) {
1303 1302 delete listeners[key];
1304 1303 }
1305 1304 }
  1305 +
  1306 + return this;
1306 1307 }
1307 1308 };
1308 1309
@@ -1345,12 +1346,33 @@ function setupExtras(p, joe, extras) {
1345 1346 extra = name in picker._extras? picker._extras[name]: null;
1346 1347
1347 1348 if(extra) {
1348   - cbs = extra(c, joe, params);
1349   - for(var k in cbs) joe.on(k, cbs[k]);
  1349 + cbs = extra(c, extraProxy(joe, name), params);
  1350 + for(var k in cbs) joe.on(k, cbs[k], name);
1350 1351 }
1351 1352 });
1352 1353 }
1353 1354
  1355 +function extraProxy(joe, name) {
  1356 + var ret = copy(joe);
  1357 +
  1358 + ret.update = function() {
  1359 + joe.update([name]);
  1360 + };
  1361 +
  1362 + return ret;
  1363 +}
  1364 +
  1365 +function copy(o) {
  1366 + // returns a shallow copy
  1367 + var ret = {};
  1368 +
  1369 + for(var k in o) {
  1370 + ret[k] = o[k];
  1371 + }
  1372 +
  1373 + return ret;
  1374 +}
  1375 +
1354 1376 function all(cb, a) {return a.map(cb).filter(id).length == a.length;}
1355 1377
1356 1378 function isArray(o) {
2  dist/colorjoe.min.js
... ... @@ -1,4 +1,4 @@
1 1 /*! colorjoe - v0.6.2-wip - 2012-07-11
2 2 * http://bebraw.github.com/colorjoe/
3 3 * Copyright (c) 2012 Juho Vepsäläinen; Licensed MIT */
4   -function ONECOLOR(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a.length===4?new ONECOLOR.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new ONECOLOR[a[0]](a.slice(1,a.length));if(typeof a=="string"){var b=a.toLowerCase();namedColors[b]&&(a="#"+namedColors[b]);var c=a.match(cssColorRegExp);if(c){var d=c[1].toUpperCase(),e=undef(c[8])?c[8]:parseFloat(c[8]),f=d[0]==="H",g=c[3]?100:f?360:255,h=c[5]||f?100:255,i=c[7]||f?100:255;if(undef(ONECOLOR[d]))throw new Error("one.color."+d+" is not installed.");return new ONECOLOR[d](parseFloat(c[2])/g,parseFloat(c[4])/h,parseFloat(c[6])/i,e)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var j=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(j)return new ONECOLOR.RGB(parseInt(j[1],16)/255,parseInt(j[2],16)/255,parseInt(j[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!isNaN(a))return new ONECOLOR.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1}function installColorSpace(a,b,c){function g(a,b){var c={};c[b.toLowerCase()]=new Function("return this.rgb()."+b.toLowerCase()+"();"),ONECOLOR[b].propertyNames.forEach(function(a,d){c[a]=new Function("value","isDelta","return this."+b.toLowerCase()+"()."+a+"(value, isDelta);")});for(var d in c)c.hasOwnProperty(d)&&ONECOLOR[a].prototype[d]===undefined&&(ONECOLOR[a].prototype[d]=c[d])}ONECOLOR[a]=new Function(b.join(","),"if (Object.prototype.toString.apply("+b[0]+") === '[object Array]') {"+b.map(function(a,c){return a+"="+b[0]+"["+c+"];"}).reverse().join("")+"}"+"if ("+b.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("['+a+']: Invalid color: ("+'+b.join('+","+')+'+")");}'+b.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),ONECOLOR[a].propertyNames=b;var d=ONECOLOR[a].prototype;["valueOf","hex","css","cssa"].forEach(function(b){d[b]=d[b]||(a==="RGB"?d.hex:new Function("return this.rgb()."+b+"();"))}),d.isColor=!0,d.equals=function(c,d){undef(d)&&(d=1e-10),c=c[a.toLowerCase()]();for(var e=0;e<b.length;e=e+1)if(Math.abs(this["_"+b[e]]-c["_"+b[e]])>d)return!1;return!0},d.toJSON=new Function("return ['"+a+"', "+b.map(function(a){return"this._"+a},this).join(", ")+"];");for(var e in c)if(c.hasOwnProperty(e)){var f=e.match(/^from(.*)$/);f?ONECOLOR[f[1].toUpperCase()].prototype[a.toLowerCase()]=c[e]:d[e]=c[e]}d[a.toLowerCase()]=function(){return this},d.toString=new Function('return "[one.color.'+a+':"+'+b.map(function(a,c){return'" '+b[c]+'="+this._'+a}).join("+")+'+"]";'),b.forEach(function(a,c){d[a]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+a+";"+"}"+"if (isDelta) {"+"return new this.constructor("+b.map(function(b,c){return"this._"+b+(a===b?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+b.map(function(b,c){return a===b?"value":"this._"+b}).join(", ")+");")}),installedColorSpaces.forEach(function(b){g(a,b),g(b,a)}),installedColorSpaces.push(a)}function gs(){var a=this.rgb(),b=a._red*.3+a._green*.59+a._blue*.11;return new ONECOLOR.RGB(b,b,b,this._alpha)}(function(a,b){typeof define=="function"&&define.amd?define(b):a.drag=b()})(this,function(){function a(a,b){if(!a){console.warn("drag is missing elem!");return}g()?h(a,b,"touchstart","touchmove","touchend"):h(a,b,"mousedown","mousemove","mouseup")}function b(b){var c=e(b["class"]||"",b.parent),f=e("pointer",c);return e("shape shape1",f),e("shape shape2",f),e("bg bg1",c),e("bg bg2",c),a(c,d(b.cbs,f)),{background:c,pointer:f}}function c(b){var c=e(b["class"],b.parent),f=e("pointer",c);return e("shape",f),e("bg",c),a(c,d(b.cbs,f)),{background:c,pointer:f}}function d(a,b){function e(a){return function(c){c.pointer=b,a(c)}}var c={};for(var d in a)c[d]=e(a[d]);return c}function e(a,b){return f("div",a,b)}function f(a,b,c){var d=document.createElement(a);return b&&(d.className=b),c.appendChild(d),d}function g(){return typeof window.ontouchstart!="undefined"}function h(a,b,c,d,e){var f=!1;b=k(b);var g=b.begin,h=b.change,l=b.end;i(a,c,function(b){function k(){f=!1,j(document,d,c),j(document,e,k),n(l,a,b)}f=!0;var c=o(n,h,a);i(document,d,c),i(document,e,k),n(g,a,b)})}function i(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)}function j(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)}function k(a){if(!a){var b,c;return{begin:function(a){b={x:a.elem.offsetLeft,y:a.elem.offsetTop},c=a.cursor},change:function(a){l(a.elem,"left",b.x+a.cursor.x-c.x+"px"),l(a.elem,"top",b.y+a.cursor.y-c.y+"px")},end:m}}return{begin:a.begin||m,change:a.change||m,end:a.end||m}}function l(a,b,c){a.style[b]=c}function m(){}function n(a,b,c){c.preventDefault();var d=p(b),e=b.clientWidth,f=b.clientHeight,g={x:q(b,c),y:r(b,c)},h=(g.x-d.x)/e,i=(g.y-d.y)/f;a({x:isNaN(h)?0:h,y:isNaN(i)?0:i,cursor:g,elem:b,e:c})}function o(a){var b=Array.prototype.slice,c=b.apply(arguments,[1]);return function(){return a.apply(null,c.concat(b.apply(arguments)))}}function p(a){var b=0,c=0;if(a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop;while(a=a.offsetParent);return{x:b,y:c}}function q(a,b){if(t(a)){var c=parseInt(u(document.body,"marginLeft"),10)-s(a,"scrollLeft")+window.pageXOffset+a.style.marginLeft;return b.clientX-c}if(b.pageX)return b.pageX;if(b.clientX)return b.clientX+document.body.scrollLeft}function r(a,b){if(t(a)){var c=parseInt(u(document.body,"marginTop"),10)-s(a,"scrollTop")+window.pageYOffset+a.style.marginTop;return b.clientY-c}if(b.pageY)return b.pageY;if(b.clientY)return b.clientY+document.body.scrollTop}function s(a,b){var c=0;while(a.nodeName!="HTML")c+=a[b],a=a.parentNode;return c}function t(a){while(a.nodeName!="HTML"&&v(a,"position")!="fixed")a=a.parentNode;return a.nodeName=="HTML"?!1:!0}function u(a,b){return a.currentStyle?a.currentStyle[b]:document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(a,"")[b]:a.style[b]}function v(a,b){var c;return window.getComputedStyle?c=window.getComputedStyle(a,null):c=a.currentStyle,c[b]}return a.xyslider=b,a.slider=c,a});var installedColorSpaces=[],namedColors={},undef=function(a){return typeof a=="undefined"},channelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,alphaChannelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,cssColorRegExp=new RegExp("^(rgb|hsl|hsv)a?\\("+channelRegExp.source+","+channelRegExp.source+","+channelRegExp.source+"(?:,"+alphaChannelRegExp.source+")?"+"\\)$","i");ONECOLOR.installMethod=function(a,b){installedColorSpaces.forEach(function(c){ONECOLOR[c].prototype[a]=b})},installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var a=(Math.round(255*this._red)*65536+Math.round(255*this._green)*256+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=ONECOLOR:typeof define=="function"&&!undef(define.amd)?define([],function(){return ONECOLOR}):(one=window.one||{},one.color=ONECOLOR),namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,d=Math.min(5,Math.floor(a*6)),e=a*6-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i,j,k;switch(d){case 0:i=c,j=h,k=f;break;case 1:i=g,j=c,k=f;break;case 2:i=f,j=c,k=h;break;case 3:i=f,j=g,k=c;break;case 4:i=h,j=f,k=c;break;case 5:i=c,j=f,k=g}return new ONECOLOR.RGB(i,j,k,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new ONECOLOR.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=Math.max(a,b,c),e=Math.min(a,b,c),f=d-e,g,h=d===0?0:f/d,i=d;if(f===0)g=0;else switch(d){case a:g=(b-c)/f/6+(b<c?1:0);break;case b:g=(c-a)/f/6+1/3;break;case c:g=(a-b)/f/6+2/3}return new ONECOLOR.HSV(g,h,i,this._alpha)}}),installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new ONECOLOR.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new ONECOLOR.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=1-a,e=1-b,f=1-c,g=1;return a||b||c?(g=Math.min(d,Math.min(e,f)),d=(d-g)/(1-g),e=(e-g)/(1-g),f=(f-g)/(1-g)):g=1,new ONECOLOR.CMYK(d,e,f,g,this._alpha)}}),ONECOLOR.installMethod("clearer",function(a){return this.alpha(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("darken",function(a){return this.lightness(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("saturate",function(a){return this.saturation(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("greyscale",gs),ONECOLOR.installMethod("grayscale",gs),ONECOLOR.installMethod("lighten",function(a){return this.lightness(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("mix",function(a,b){a=ONECOLOR(a).rgb(),b=1-(b||.5);var c=b*2-1,d=this._alpha-a._alpha,e=((c*d===-1?c:(c+d)/(1+c*d))+1)/2,f=1-e,g=this.rgb();return new ONECOLOR.RGB(this._red*e+a._red*f,this._green*e+a._green*f,this._blue*e+a._blue*f,this._alpha*b+a._alpha*(1-b))}),ONECOLOR.installMethod("negate",function(){var a=this.rgb();return new ONECOLOR.RGB(1-a._red,1-a._green,1-a._blue,this._alpha)}),ONECOLOR.installMethod("opaquer",function(a){return this.alpha(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("rotate",function(a){return this.hue((a||0)/360,!0)}),ONECOLOR.installMethod("saturate",function(a){return this.saturation(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("toAlpha",function(a){var b=this.rgb(),c=ONECOLOR(a).rgb(),d=1e-10,e=new ONECOLOR.RGB(0,0,0,b._alpha),f=["_red","_green","_blue"];return f.forEach(function(a){b[a]<d?e[a]=b[a]:b[a]>c[a]?e[a]=(b[a]-c[a])/(1-c[a]):b[a]>c[a]?e[a]=(c[a]-b[a])/c[a]:e[a]=0}),e._red>e._green?e._red>e._blue?b._alpha=e._red:b._alpha=e._blue:e._green>e._blue?b._alpha=e._green:b._alpha=e._blue,b._alpha<d?b:(f.forEach(function(a){b[a]=(b[a]-c[a])/b._alpha+c[a]}),b._alpha*=e._alpha,b)}),function(a,b){typeof exports=="object"?module.exports=b():typeof define=="function"&&define.amd?define(b):a.elemutils=b()}(this,function(){function b(a,b,c){var d=document.createElement(a);return d.className=b,c.appendChild(d),d}function c(a){var b=Array.prototype.slice,c=b.apply(arguments,[1]);return function(){return a.apply(null,c.concat(b.apply(arguments)))}}function d(b,c,d,g){var h=a(b,d),i=e(c,h),j=f("text",h,g);return{label:i,input:j}}function e(a,c){var d=b("label","",c);return d.innerHTML=a,d}function f(a,c,d){var e=b("input","",c);return e.type=a,d&&(e.maxLength=d),e}function g(a,b){a.style.left=j(b*100,0,100)+"%"}function h(a,b){a.style.top=j(b*100,0,100)+"%"}function i(a,b){a.style.background=b}function j(a,b,c){return Math.min(Math.max(a,b),c)}var a=c(b,"div");return{clamp:j,e:b,div:a,partial:c,labelInput:d,X:g,Y:h,BG:i}}),function(a,b){typeof define=="function"&&define.amd?define(["./onecolor","./elemutils"],b):a.colorjoeextras=b(a.ONECOLOR,a.elemutils)}(this,function(a,b){function c(a){var c=b.div("currentColor",a);return{change:function(a){b.BG(c,a.cssa())}}}function d(c,d,e){function o(){var b=[f];n.forEach(function(a){b.push(a.e.input.value/g)}),b.push(1),k=!0,d.set(a(b))}var f=e.space,g=e.limit||255,h=e.fix>=0?e.fix:2,i={R:"red",G:"green",B:"blue",H:"hue",S:"saturation",V:"value",L:"lightness",C:"cyan",M:"magenta",Y:"yellow",K:"black"},j=(""+g).length+h;j=h?j+1:j;var k=!1,l=f.split("").map(function(a){return a.toUpperCase()});if(["RGB","HSL","HSV","CMYK"].indexOf(f)<0)return console.warn("Invalid field names",f);var m=b.div("colorFields",c),n=l.map(function(a,c){var d=b.labelInput("color "+i[a],a,m,j);return d.input.onkeyup=o,{name:a,e:d}});return{change:function(a){k||n.forEach(function(b){b.e.input.value=(a[i[b.name]]()*g).toFixed(h)}),k=!1}}}function e(a,c){var d=b.labelInput("hex","",a,6),e=!1;return d.input.onkeyup=function(a){e=!0,c.set("#"+f(a.target.value,6,"0"))},{change:function(a){e||(d.input.value=a.hex().slice(1)),e=!1}}}function f(a,b,c){var d=a;for(var e=a.length,f=b;e<b;e++)d+=c;return d}return{currentColor:c,fields:d,hex:e}}),function(a,b){typeof define=="function"&&define.amd?define(["./onecolor","./drag","./elemutils","./extras"],b):a.colorjoe=b(a.ONECOLOR,a.drag,a.elemutils,a.colorjoeextras)}(this,function(a,b,c,d){function g(b,d){c.BG(b,(new a.HSV(d,1,1)).cssa())}function h(a){function g(a){n=e.xy(n,{x:c.clamp(a.x,0,1),y:c.clamp(a.y,0,1)},f,h),p()}function k(a){n=e.z(n,c.clamp(a.y,0,1),f,h),p()}function p(){for(var a=0,b=o.change.length;a<b;a++)o.change[a](n)}function q(){if(l.equals(n))return;for(var a=0,b=o.done.length;a<b;a++)o.done[a](n);l=n}if(!a.e)return console.warn("colorjoe: missing element");var d=m(a.e)?document.getElementById(a.e):a.e;d.className="colorPicker";var e=a.cbs,f=b.xyslider({parent:d,"class":"twod",cbs:{begin:g,change:g,end:q}}),h=b.slider({parent:d,"class":"oned",cbs:{begin:k,change:k,end:q}}),l=i(a.color),n=e.init(l,f,h),o={change:[],done:[]},r={e:d,update:function(){return p(),r},get:function(){return n},set:function(a){var b=this.get();return n=e.init(i(a),f,h),b.hex()!=n.hex()&&p(),r},on:function(a,b){return a=="change"||a=="done"?o[a].push(b):console.warn('Passed invalid evt name "'+a+'" to colorjoe.on'),r},removeAllListeners:function(a){if(a)delete o[a];else for(var b in o)delete o[b]}};return j(d,r,a.extras),p(),r}function i(b){if(!n(b))return a("black");if(b.isColor)return b;var c=a(b);return c?c:(n(b)&&console.warn("Passed invalid color to colorjoe, using black instead"),a("black"))}function j(a,b,d){if(!d)return;var f=c.div("extras",a),g,h,i;d.forEach(function(a){l(a)?(h=a[0],i=a.length>1?a[1]:{}):(h=a,i={}),extra=h in e._extras?e._extras[h]:null;if(extra){g=extra(f,b,i);for(var c in g)b.on(c,g[c])}})}function k(a,b){return b.map(a).filter(p).length==b.length}function l(a){return Object.prototype.toString.call(a)==="[object Array]"}function m(a){return typeof a=="string"}function n(a){return typeof a!="undefined"}function o(a){return typeof a=="function"}function p(a){return a}var e=function(a){return k(o,[a.init,a.xy,a.z])?function(b,c,d){return h({e:b,color:c,cbs:a,extras:d})}:console.warn("colorjoe: missing cb")};e.rgb=e({init:function(b,c,d){var e=a(b).hsl();return this.xy(e,{x:e.saturation(),y:1-e.value()},c,d),this.z(e,e.hue(),c,d),e},xy:function(a,b,d,e){return c.X(d.pointer,b.x),c.Y(d.pointer,b.y),a.saturation(b.x).value(1-b.y)},z:function(a,b,d,e){return c.Y(e.pointer,b),g(d.background,b),a.hue(b)}}),e.hsl=e({init:function(b,c,d){var e=a(b).hsl();return this.xy(e,{x:e.hue(),y:1-e.saturation()},c,d),this.z(e,1-e.lightness(),c,d),e},xy:function(a,b,d,e){return c.X(d.pointer,b.x),c.Y(d.pointer,b.y),g(e.background,b.x),a.hue(b.x).saturation(1-b.y)},z:function(a,b,d,e){return c.Y(e.pointer,b),a.lightness(1-b)}}),e._extras={},e.registerExtra=function(a,b){a in e._extras&&console.warn('Extra "'+a+'"has been registered already!'),e._extras[a]=b};for(var f in d)e.registerExtra(f,d[f]);return e});
  4 +function ONECOLOR(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a.length===4?new ONECOLOR.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new ONECOLOR[a[0]](a.slice(1,a.length));if(typeof a=="string"){var b=a.toLowerCase();namedColors[b]&&(a="#"+namedColors[b]);var c=a.match(cssColorRegExp);if(c){var d=c[1].toUpperCase(),e=undef(c[8])?c[8]:parseFloat(c[8]),f=d[0]==="H",g=c[3]?100:f?360:255,h=c[5]||f?100:255,i=c[7]||f?100:255;if(undef(ONECOLOR[d]))throw new Error("one.color."+d+" is not installed.");return new ONECOLOR[d](parseFloat(c[2])/g,parseFloat(c[4])/h,parseFloat(c[6])/i,e)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var j=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(j)return new ONECOLOR.RGB(parseInt(j[1],16)/255,parseInt(j[2],16)/255,parseInt(j[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!isNaN(a))return new ONECOLOR.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1}function installColorSpace(a,b,c){function g(a,b){var c={};c[b.toLowerCase()]=new Function("return this.rgb()."+b.toLowerCase()+"();"),ONECOLOR[b].propertyNames.forEach(function(a,d){c[a]=new Function("value","isDelta","return this."+b.toLowerCase()+"()."+a+"(value, isDelta);")});for(var d in c)c.hasOwnProperty(d)&&ONECOLOR[a].prototype[d]===undefined&&(ONECOLOR[a].prototype[d]=c[d])}ONECOLOR[a]=new Function(b.join(","),"if (Object.prototype.toString.apply("+b[0]+") === '[object Array]') {"+b.map(function(a,c){return a+"="+b[0]+"["+c+"];"}).reverse().join("")+"}"+"if ("+b.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("['+a+']: Invalid color: ("+'+b.join('+","+')+'+")");}'+b.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),ONECOLOR[a].propertyNames=b;var d=ONECOLOR[a].prototype;["valueOf","hex","css","cssa"].forEach(function(b){d[b]=d[b]||(a==="RGB"?d.hex:new Function("return this.rgb()."+b+"();"))}),d.isColor=!0,d.equals=function(c,d){undef(d)&&(d=1e-10),c=c[a.toLowerCase()]();for(var e=0;e<b.length;e=e+1)if(Math.abs(this["_"+b[e]]-c["_"+b[e]])>d)return!1;return!0},d.toJSON=new Function("return ['"+a+"', "+b.map(function(a){return"this._"+a},this).join(", ")+"];");for(var e in c)if(c.hasOwnProperty(e)){var f=e.match(/^from(.*)$/);f?ONECOLOR[f[1].toUpperCase()].prototype[a.toLowerCase()]=c[e]:d[e]=c[e]}d[a.toLowerCase()]=function(){return this},d.toString=new Function('return "[one.color.'+a+':"+'+b.map(function(a,c){return'" '+b[c]+'="+this._'+a}).join("+")+'+"]";'),b.forEach(function(a,c){d[a]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+a+";"+"}"+"if (isDelta) {"+"return new this.constructor("+b.map(function(b,c){return"this._"+b+(a===b?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+b.map(function(b,c){return a===b?"value":"this._"+b}).join(", ")+");")}),installedColorSpaces.forEach(function(b){g(a,b),g(b,a)}),installedColorSpaces.push(a)}function gs(){var a=this.rgb(),b=a._red*.3+a._green*.59+a._blue*.11;return new ONECOLOR.RGB(b,b,b,this._alpha)}(function(a,b){typeof define=="function"&&define.amd?define(b):a.drag=b()})(this,function(){function a(a,b){if(!a){console.warn("drag is missing elem!");return}g()?h(a,b,"touchstart","touchmove","touchend"):h(a,b,"mousedown","mousemove","mouseup")}function b(b){var c=e(b["class"]||"",b.parent),f=e("pointer",c);return e("shape shape1",f),e("shape shape2",f),e("bg bg1",c),e("bg bg2",c),a(c,d(b.cbs,f)),{background:c,pointer:f}}function c(b){var c=e(b["class"],b.parent),f=e("pointer",c);return e("shape",f),e("bg",c),a(c,d(b.cbs,f)),{background:c,pointer:f}}function d(a,b){function e(a){return function(c){c.pointer=b,a(c)}}var c={};for(var d in a)c[d]=e(a[d]);return c}function e(a,b){return f("div",a,b)}function f(a,b,c){var d=document.createElement(a);return b&&(d.className=b),c.appendChild(d),d}function g(){return typeof window.ontouchstart!="undefined"}function h(a,b,c,d,e){var f=!1;b=k(b);var g=b.begin,h=b.change,l=b.end;i(a,c,function(b){function k(){f=!1,j(document,d,c),j(document,e,k),n(l,a,b)}f=!0;var c=o(n,h,a);i(document,d,c),i(document,e,k),n(g,a,b)})}function i(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)}function j(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)}function k(a){if(!a){var b,c;return{begin:function(a){b={x:a.elem.offsetLeft,y:a.elem.offsetTop},c=a.cursor},change:function(a){l(a.elem,"left",b.x+a.cursor.x-c.x+"px"),l(a.elem,"top",b.y+a.cursor.y-c.y+"px")},end:m}}return{begin:a.begin||m,change:a.change||m,end:a.end||m}}function l(a,b,c){a.style[b]=c}function m(){}function n(a,b,c){c.preventDefault();var d=p(b),e=b.clientWidth,f=b.clientHeight,g={x:q(b,c),y:r(b,c)},h=(g.x-d.x)/e,i=(g.y-d.y)/f;a({x:isNaN(h)?0:h,y:isNaN(i)?0:i,cursor:g,elem:b,e:c})}function o(a){var b=Array.prototype.slice,c=b.apply(arguments,[1]);return function(){return a.apply(null,c.concat(b.apply(arguments)))}}function p(a){var b=0,c=0;if(a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop;while(a=a.offsetParent);return{x:b,y:c}}function q(a,b){if(t(a)){var c=parseInt(u(document.body,"marginLeft"),10)-s(a,"scrollLeft")+window.pageXOffset+a.style.marginLeft;return b.clientX-c}if(b.pageX)return b.pageX;if(b.clientX)return b.clientX+document.body.scrollLeft}function r(a,b){if(t(a)){var c=parseInt(u(document.body,"marginTop"),10)-s(a,"scrollTop")+window.pageYOffset+a.style.marginTop;return b.clientY-c}if(b.pageY)return b.pageY;if(b.clientY)return b.clientY+document.body.scrollTop}function s(a,b){var c=0;while(a.nodeName!="HTML")c+=a[b],a=a.parentNode;return c}function t(a){while(a.nodeName!="HTML"&&v(a,"position")!="fixed")a=a.parentNode;return a.nodeName=="HTML"?!1:!0}function u(a,b){return a.currentStyle?a.currentStyle[b]:document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(a,"")[b]:a.style[b]}function v(a,b){var c;return window.getComputedStyle?c=window.getComputedStyle(a,null):c=a.currentStyle,c[b]}return a.xyslider=b,a.slider=c,a});var installedColorSpaces=[],namedColors={},undef=function(a){return typeof a=="undefined"},channelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,alphaChannelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,cssColorRegExp=new RegExp("^(rgb|hsl|hsv)a?\\("+channelRegExp.source+","+channelRegExp.source+","+channelRegExp.source+"(?:,"+alphaChannelRegExp.source+")?"+"\\)$","i");ONECOLOR.installMethod=function(a,b){installedColorSpaces.forEach(function(c){ONECOLOR[c].prototype[a]=b})},installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var a=(Math.round(255*this._red)*65536+Math.round(255*this._green)*256+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=ONECOLOR:typeof define=="function"&&!undef(define.amd)?define([],function(){return ONECOLOR}):(one=window.one||{},one.color=ONECOLOR),namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,d=Math.min(5,Math.floor(a*6)),e=a*6-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i,j,k;switch(d){case 0:i=c,j=h,k=f;break;case 1:i=g,j=c,k=f;break;case 2:i=f,j=c,k=h;break;case 3:i=f,j=g,k=c;break;case 4:i=h,j=f,k=c;break;case 5:i=c,j=f,k=g}return new ONECOLOR.RGB(i,j,k,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new ONECOLOR.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=Math.max(a,b,c),e=Math.min(a,b,c),f=d-e,g,h=d===0?0:f/d,i=d;if(f===0)g=0;else switch(d){case a:g=(b-c)/f/6+(b<c?1:0);break;case b:g=(c-a)/f/6+1/3;break;case c:g=(a-b)/f/6+2/3}return new ONECOLOR.HSV(g,h,i,this._alpha)}}),installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new ONECOLOR.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new ONECOLOR.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=1-a,e=1-b,f=1-c,g=1;return a||b||c?(g=Math.min(d,Math.min(e,f)),d=(d-g)/(1-g),e=(e-g)/(1-g),f=(f-g)/(1-g)):g=1,new ONECOLOR.CMYK(d,e,f,g,this._alpha)}}),ONECOLOR.installMethod("clearer",function(a){return this.alpha(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("darken",function(a){return this.lightness(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("saturate",function(a){return this.saturation(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("greyscale",gs),ONECOLOR.installMethod("grayscale",gs),ONECOLOR.installMethod("lighten",function(a){return this.lightness(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("mix",function(a,b){a=ONECOLOR(a).rgb(),b=1-(b||.5);var c=b*2-1,d=this._alpha-a._alpha,e=((c*d===-1?c:(c+d)/(1+c*d))+1)/2,f=1-e,g=this.rgb();return new ONECOLOR.RGB(this._red*e+a._red*f,this._green*e+a._green*f,this._blue*e+a._blue*f,this._alpha*b+a._alpha*(1-b))}),ONECOLOR.installMethod("negate",function(){var a=this.rgb();return new ONECOLOR.RGB(1-a._red,1-a._green,1-a._blue,this._alpha)}),ONECOLOR.installMethod("opaquer",function(a){return this.alpha(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("rotate",function(a){return this.hue((a||0)/360,!0)}),ONECOLOR.installMethod("saturate",function(a){return this.saturation(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("toAlpha",function(a){var b=this.rgb(),c=ONECOLOR(a).rgb(),d=1e-10,e=new ONECOLOR.RGB(0,0,0,b._alpha),f=["_red","_green","_blue"];return f.forEach(function(a){b[a]<d?e[a]=b[a]:b[a]>c[a]?e[a]=(b[a]-c[a])/(1-c[a]):b[a]>c[a]?e[a]=(c[a]-b[a])/c[a]:e[a]=0}),e._red>e._green?e._red>e._blue?b._alpha=e._red:b._alpha=e._blue:e._green>e._blue?b._alpha=e._green:b._alpha=e._blue,b._alpha<d?b:(f.forEach(function(a){b[a]=(b[a]-c[a])/b._alpha+c[a]}),b._alpha*=e._alpha,b)}),function(a,b){typeof exports=="object"?module.exports=b():typeof define=="function"&&define.amd?define(b):a.elemutils=b()}(this,function(){function b(a,b,c){var d=document.createElement(a);return d.className=b,c.appendChild(d),d}function c(a){var b=Array.prototype.slice,c=b.apply(arguments,[1]);return function(){return a.apply(null,c.concat(b.apply(arguments)))}}function d(b,c,d,g){var h=a(b,d),i=e(c,h),j=f("text",h,g);return{label:i,input:j}}function e(a,c){var d=b("label","",c);return d.innerHTML=a,d}function f(a,c,d){var e=b("input","",c);return e.type=a,d&&(e.maxLength=d),e}function g(a,b){a.style.left=j(b*100,0,100)+"%"}function h(a,b){a.style.top=j(b*100,0,100)+"%"}function i(a,b){a.style.background=b}function j(a,b,c){return Math.min(Math.max(a,b),c)}var a=c(b,"div");return{clamp:j,e:b,div:a,partial:c,labelInput:d,X:g,Y:h,BG:i}}),function(a,b){typeof define=="function"&&define.amd?define(["./onecolor","./elemutils"],b):a.colorjoeextras=b(a.ONECOLOR,a.elemutils)}(this,function(a,b){function c(a){var c=b.div("currentColor",a);return{change:function(a){b.BG(c,a.cssa())}}}function d(c,d,e){function n(){var b=[f];m.forEach(function(a){b.push(a.e.input.value/g)}),b.push(1),d.set(a(b))}var f=e.space,g=e.limit||255,h=e.fix>=0?e.fix:2,i={R:"red",G:"green",B:"blue",H:"hue",S:"saturation",V:"value",L:"lightness",C:"cyan",M:"magenta",Y:"yellow",K:"black"},j=(""+g).length+h;j=h?j+1:j;var k=f.split("").map(function(a){return a.toUpperCase()});if(["RGB","HSL","HSV","CMYK"].indexOf(f)<0)return console.warn("Invalid field names",f);var l=b.div("colorFields",c),m=k.map(function(a,c){var d=b.labelInput("color "+i[a],a,l,j);return d.input.onkeyup=n,{name:a,e:d}});return{change:function(a){m.forEach(function(b){b.e.input.value=(a[i[b.name]]()*g).toFixed(h)})}}}function e(a,c){var d=b.labelInput("hex","",a,6);return d.input.onkeyup=function(a){c.set("#"+f(a.target.value,6,"0"))},{change:function(a){d.input.value=a.hex().slice(1)}}}function f(a,b,c){var d=a;for(var e=a.length,f=b;e<b;e++)d+=c;return d}return{currentColor:c,fields:d,hex:e}}),function(a,b){typeof define=="function"&&define.amd?define(["./onecolor","./drag","./elemutils","./extras"],b):a.colorjoe=b(a.ONECOLOR,a.drag,a.elemutils,a.colorjoeextras)}(this,function(a,b,c,d){function g(b,d){c.BG(b,(new a.HSV(d,1,1)).cssa())}function h(a){function g(a){m=e.xy(m,{x:c.clamp(a.x,0,1),y:c.clamp(a.y,0,1)},f,h),q()}function k(a){m=e.z(m,c.clamp(a.y,0,1),f,h),q()}function q(a){a=n(a)?a:[];var b=p.change,c;for(var d=0,e=b.length;d<e;d++)c=b[d],a.indexOf(c.name)==-1&&c.fn(m)}function r(){if(l.equals(m))return;for(var a=0,b=p.done.length;a<b;a++)p.done[a](m);l=m}if(!a.e)return console.warn("colorjoe: missing element");var d=o(a.e)?document.getElementById(a.e):a.e;d.className="colorPicker";var e=a.cbs,f=b.xyslider({parent:d,"class":"twod",cbs:{begin:g,change:g,end:r}}),h=b.slider({parent:d,"class":"oned",cbs:{begin:k,change:k,end:r}}),l=i(a.color),m=e.init(l,f,h),p={change:[],done:[]},s={e:d,update:function(a){return q(a),this},get:function(){return m},set:function(a){var b=this.get();return m=e.init(i(a),f,h),b.hex()!=m.hex()&&this.update(),this},on:function(a,b,c){return a=="change"||a=="done"?p[a].push({name:c,fn:b}):console.warn('Passed invalid evt name "'+a+'" to colorjoe.on'),this},removeAllListeners:function(a){if(a)delete p[a];else for(var b in p)delete p[b];return this}};return j(d,s,a.extras),q(),s}function i(b){if(!p(b))return a("black");if(b.isColor)return b;var c=a(b);return c?c:(p(b)&&console.warn("Passed invalid color to colorjoe, using black instead"),a("black"))}function j(a,b,d){if(!d)return;var f=c.div("extras",a),g,h,i;d.forEach(function(a){n(a)?(h=a[0],i=a.length>1?a[1]:{}):(h=a,i={}),extra=h in e._extras?e._extras[h]:null;if(extra){g=extra(f,k(b,h),i);for(var c in g)b.on(c,g[c],h)}})}function k(a,b){var c=l(a);return c.update=function(){a.update([b])},c}function l(a){var b={};for(var c in a)b[c]=a[c];return b}function m(a,b){return b.map(a).filter(r).length==b.length}function n(a){return Object.prototype.toString.call(a)==="[object Array]"}function o(a){return typeof a=="string"}function p(a){return typeof a!="undefined"}function q(a){return typeof a=="function"}function r(a){return a}var e=function(a){return m(q,[a.init,a.xy,a.z])?function(b,c,d){return h({e:b,color:c,cbs:a,extras:d})}:console.warn("colorjoe: missing cb")};e.rgb=e({init:function(b,c,d){var e=a(b).hsl();return this.xy(e,{x:e.saturation(),y:1-e.value()},c,d),this.z(e,e.hue(),c,d),e},xy:function(a,b,d,e){return c.X(d.pointer,b.x),c.Y(d.pointer,b.y),a.saturation(b.x).value(1-b.y)},z:function(a,b,d,e){return c.Y(e.pointer,b),g(d.background,b),a.hue(b)}}),e.hsl=e({init:function(b,c,d){var e=a(b).hsl();return this.xy(e,{x:e.hue(),y:1-e.saturation()},c,d),this.z(e,1-e.lightness(),c,d),e},xy:function(a,b,d,e){return c.X(d.pointer,b.x),c.Y(d.pointer,b.y),g(e.background,b.x),a.hue(b.x).saturation(1-b.y)},z:function(a,b,d,e){return c.Y(e.pointer,b),a.lightness(1-b)}}),e._extras={},e.registerExtra=function(a,b){a in e._extras&&console.warn('Extra "'+a+'"has been registered already!'),e._extras[a]=b};for(var f in d)e.registerExtra(f,d[f]);return e});
55 src/colorjoe.js
@@ -130,9 +130,15 @@ function setup(o) {
130 130 var col = cbs.init(previous, xy, z);
131 131 var listeners = {change: [], done: []};
132 132
133   - function changed() {
134   - for(var i = 0, len = listeners.change.length; i < len; i++) {
135   - listeners.change[i](col);
  133 + function changed(skip) {
  134 + skip = isArray(skip)? skip: [];
  135 +
  136 + var li = listeners.change;
  137 + var v;
  138 +
  139 + for(var i = 0, len = li.length; i < len; i++) {
  140 + v = li[i];
  141 + if(skip.indexOf(v.name) == -1) v.fn(col);
136 142 }
137 143 }
138 144
@@ -147,10 +153,10 @@ function setup(o) {
147 153
148 154 var ob = {
149 155 e: e,
150   - update: function() {
151   - changed();
  156 + update: function(skip) {
  157 + changed(skip);
152 158
153   - return ob;
  159 + return this;
154 160 },
155 161 get: function() {
156 162 return col;
@@ -159,17 +165,17 @@ function setup(o) {
159 165 var oldCol = this.get();
160 166 col = cbs.init(getColor(c), xy, z);
161 167
162   - if(oldCol.hex() != col.hex()) changed();
  168 + if(oldCol.hex() != col.hex()) this.update();
163 169
164   - return ob;
  170 + return this;
165 171 },
166   - on: function(evt, cb) {
  172 + on: function(evt, cb, name) {
167 173 if(evt == 'change' || evt == 'done') {
168   - listeners[evt].push(cb);
  174 + listeners[evt].push({name: name, fn: cb});
169 175 }
170 176 else console.warn('Passed invalid evt name "' + evt + '" to colorjoe.on');
171 177
172   - return ob;
  178 + return this;
173 179 },
174 180 removeAllListeners: function(evt) {
175 181 if (evt) {
@@ -180,6 +186,8 @@ function setup(o) {
180 186 delete listeners[key];
181 187 }
182 188 }
  189 +
  190 + return this;
183 191 }
184 192 };
185 193
@@ -222,12 +230,33 @@ function setupExtras(p, joe, extras) {
222 230 extra = name in picker._extras? picker._extras[name]: null;
223 231
224 232 if(extra) {
225   - cbs = extra(c, joe, params);
226   - for(var k in cbs) joe.on(k, cbs[k]);
  233 + cbs = extra(c, extraProxy(joe, name), params);
  234 + for(var k in cbs) joe.on(k, cbs[k], name);
227 235 }
228 236 });
229 237 }
230 238
  239 +function extraProxy(joe, name) {
  240 + var ret = copy(joe);
  241 +
  242 + ret.update = function() {
  243 + joe.update([name]);
  244 + };
  245 +
  246 + return ret;
  247 +}
  248 +
  249 +function copy(o) {
  250 + // returns a shallow copy
  251 + var ret = {};
  252 +
  253 + for(var k in o) {
  254 + ret[k] = o[k];
  255 + }
  256 +
  257 + return ret;
  258 +}
  259 +
231 260 function all(cb, a) {return a.map(cb).filter(id).length == a.length;}
232 261
233 262 function isArray(o) {
15 src/extras.js
@@ -32,7 +32,6 @@ function fields(p, joe, o) {
32 32 };
33 33 var inputLen = ('' + fac).length + fix;
34 34 inputLen = fix? inputLen + 1: inputLen;
35   - var chg = false; // XXX
36 35
37 36 var initials = cs.split('').map(function(n) {return n.toUpperCase();});
38 37
@@ -53,34 +52,28 @@ function fields(p, joe, o) {
53 52 elems.forEach(function(o) {col.push(o.e.input.value / fac);});
54 53 col.push(1); // alpha
55 54
56   - chg = true;
57 55 joe.set(onecolor(col));
58 56 }
59 57
60 58 return {
61 59 change: function(col) {
62   - if(!chg)
63   - elems.forEach(function(o) {
64   - o.e.input.value = (col[methods[o.name]]() * fac).toFixed(fix);
65   - });
66   - chg = false;
  60 + elems.forEach(function(o) {
  61 + o.e.input.value = (col[methods[o.name]]() * fac).toFixed(fix);
  62 + });
67 63 }
68 64 };
69 65 }
70 66
71 67 function hex(p, joe) {
72 68 var e = utils.labelInput('hex', '', p, 6);
73   - var chg = false; // XXX
74 69
75 70 e.input.onkeyup = function(elem) {
76   - chg = true;
77 71 joe.set('#' + pad(elem.target.value, 6, '0'));
78 72 };
79 73
80 74 return {
81 75 change: function(col) {
82   - if(!chg) e.input.value = col.hex().slice(1);
83   - chg = false;
  76 + e.input.value = col.hex().slice(1);
84 77 }
85 78 };
86 79 }

0 comments on commit 1aefdec

Please sign in to comment.
Something went wrong with that request. Please try again.