author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-03-17 21:08:23 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-03-17 21:08:23 (UTC) |
commit | 928f3f3ed3981f7f81b69ed94f2a315205db39fa (patch) (side-by-side diff) | |
tree | 8a47229b56e4c906de8512baf0c5ca100bc03dfb /frontend/gamma/js/MochiKit/Color.js | |
parent | bf7d8191a3a6dbd092a88911098a3e7f6cf30cf7 (diff) | |
download | clipperz-928f3f3ed3981f7f81b69ed94f2a315205db39fa.zip clipperz-928f3f3ed3981f7f81b69ed94f2a315205db39fa.tar.gz clipperz-928f3f3ed3981f7f81b69ed94f2a315205db39fa.tar.bz2 |
Fixed frontend properties and updated MochiKit version
Diffstat (limited to 'frontend/gamma/js/MochiKit/Color.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/MochiKit/Color.js | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/frontend/gamma/js/MochiKit/Color.js b/frontend/gamma/js/MochiKit/Color.js index 27dc2d0..f2a0f67 100644 --- a/frontend/gamma/js/MochiKit/Color.js +++ b/frontend/gamma/js/MochiKit/Color.js @@ -1,211 +1,211 @@ /*** MochiKit.Color 1.5 See <http://mochikit.com/> for documentation, downloads, license, etc. (c) 2005 Bob Ippolito and others. All rights Reserved. ***/ -MochiKit.Base._module('Color', '1.5', ['Base', 'DOM', 'Style']); +MochiKit.Base.module(MochiKit, 'Color', '1.5', ['Base', 'DOM', 'Style']); /** @id MochiKit.Color.Color */ MochiKit.Color.Color = function (red, green, blue, alpha) { if (typeof(alpha) == 'undefined' || alpha === null) { alpha = 1.0; } this.rgb = { r: red, g: green, b: blue, a: alpha }; }; // Prototype methods MochiKit.Color.Color.prototype = { __class__: MochiKit.Color.Color, /** @id MochiKit.Color.Color.prototype.colorWithAlpha */ colorWithAlpha: function (alpha) { var rgb = this.rgb; var m = MochiKit.Color; return m.Color.fromRGB(rgb.r, rgb.g, rgb.b, alpha); }, /** @id MochiKit.Color.Color.prototype.colorWithHue */ colorWithHue: function (hue) { // get an HSL model, and set the new hue... var hsl = this.asHSL(); hsl.h = hue; var m = MochiKit.Color; // convert back to RGB... return m.Color.fromHSL(hsl); }, /** @id MochiKit.Color.Color.prototype.colorWithSaturation */ colorWithSaturation: function (saturation) { // get an HSL model, and set the new hue... var hsl = this.asHSL(); hsl.s = saturation; var m = MochiKit.Color; // convert back to RGB... return m.Color.fromHSL(hsl); }, /** @id MochiKit.Color.Color.prototype.colorWithLightness */ colorWithLightness: function (lightness) { // get an HSL model, and set the new hue... var hsl = this.asHSL(); hsl.l = lightness; var m = MochiKit.Color; // convert back to RGB... return m.Color.fromHSL(hsl); }, /** @id MochiKit.Color.Color.prototype.darkerColorWithLevel */ darkerColorWithLevel: function (level) { var hsl = this.asHSL(); hsl.l = Math.max(hsl.l - level, 0); var m = MochiKit.Color; return m.Color.fromHSL(hsl); }, /** @id MochiKit.Color.Color.prototype.lighterColorWithLevel */ lighterColorWithLevel: function (level) { var hsl = this.asHSL(); hsl.l = Math.min(hsl.l + level, 1); var m = MochiKit.Color; return m.Color.fromHSL(hsl); }, /** @id MochiKit.Color.Color.prototype.blendedColor */ blendedColor: function (other, /* optional */ fraction) { if (typeof(fraction) == 'undefined' || fraction === null) { fraction = 0.5; } var sf = 1.0 - fraction; var s = this.rgb; var d = other.rgb; var df = fraction; return MochiKit.Color.Color.fromRGB( (s.r * sf) + (d.r * df), (s.g * sf) + (d.g * df), (s.b * sf) + (d.b * df), (s.a * sf) + (d.a * df) ); }, /** @id MochiKit.Color.Color.prototype.compareRGB */ compareRGB: function (other) { var a = this.asRGB(); var b = other.asRGB(); return MochiKit.Base.compare( [a.r, a.g, a.b, a.a], [b.r, b.g, b.b, b.a] ); }, /** @id MochiKit.Color.Color.prototype.isLight */ isLight: function () { - return this.asHSL().b > 0.5; + return this.asHSL().l > 0.5; }, /** @id MochiKit.Color.Color.prototype.isDark */ isDark: function () { return (!this.isLight()); }, /** @id MochiKit.Color.Color.prototype.toHSLString */ toHSLString: function () { var c = this.asHSL(); var ccc = MochiKit.Color.clampColorComponent; var rval = this._hslString; if (!rval) { var mid = ( ccc(c.h, 360).toFixed(0) + "," + ccc(c.s, 100).toPrecision(4) + "%" + "," + ccc(c.l, 100).toPrecision(4) + "%" ); var a = c.a; if (a >= 1) { a = 1; rval = "hsl(" + mid + ")"; } else { if (a <= 0) { a = 0; } rval = "hsla(" + mid + "," + a + ")"; } this._hslString = rval; } return rval; }, /** @id MochiKit.Color.Color.prototype.toRGBString */ toRGBString: function () { var c = this.rgb; var ccc = MochiKit.Color.clampColorComponent; var rval = this._rgbString; if (!rval) { var mid = ( ccc(c.r, 255).toFixed(0) + "," + ccc(c.g, 255).toFixed(0) + "," + ccc(c.b, 255).toFixed(0) ); if (c.a != 1) { rval = "rgba(" + mid + "," + c.a + ")"; } else { rval = "rgb(" + mid + ")"; } this._rgbString = rval; } return rval; }, /** @id MochiKit.Color.Color.prototype.asRGB */ asRGB: function () { return MochiKit.Base.clone(this.rgb); }, /** @id MochiKit.Color.Color.prototype.toHexString */ toHexString: function () { var m = MochiKit.Color; var c = this.rgb; var ccc = MochiKit.Color.clampColorComponent; var rval = this._hexString; if (!rval) { rval = ("#" + m.toColorPart(ccc(c.r, 255)) + m.toColorPart(ccc(c.g, 255)) + m.toColorPart(ccc(c.b, 255)) ); this._hexString = rval; } return rval; }, /** @id MochiKit.Color.Color.prototype.asHSV */ asHSV: function () { var hsv = this.hsv; var c = this.rgb; if (typeof(hsv) == 'undefined' || hsv === null) { hsv = MochiKit.Color.rgbToHSV(this.rgb); this.hsv = hsv; } return MochiKit.Base.clone(hsv); }, /** @id MochiKit.Color.Color.prototype.asHSL */ asHSL: function () { var hsl = this.hsl; var c = this.rgb; if (typeof(hsl) == 'undefined' || hsl === null) { hsl = MochiKit.Color.rgbToHSL(this.rgb); this.hsl = hsl; } return MochiKit.Base.clone(hsl); @@ -548,205 +548,196 @@ MochiKit.Base.update(MochiKit.Color, { var hue; var saturation; var lightness = (max + min) / 2.0; var delta = max - min; if (delta === 0) { hue = 0; saturation = 0; } else { if (lightness <= 0.5) { saturation = delta / (max + min); } else { saturation = delta / (2 - max - min); } if (red == max) { hue = (green - blue) / delta; } else if (green == max) { hue = 2 + ((blue - red) / delta); } else { hue = 4 + ((red - green) / delta); } hue /= 6; if (hue < 0) { hue += 1; } if (hue > 1) { hue -= 1; } } return { h: hue, s: saturation, l: lightness, a: alpha }; }, /** @id MochiKit.Color.toColorPart */ toColorPart: function (num) { num = Math.round(num); var digits = num.toString(16); if (num < 16) { return '0' + digits; } return digits; }, __new__: function () { var m = MochiKit.Base; /** @id MochiKit.Color.Color.fromRGBString */ this.Color.fromRGBString = m.bind( this.Color._fromColorString, this.Color, "rgb", "fromRGB", [1.0/255.0, 1.0/255.0, 1.0/255.0, 1] ); /** @id MochiKit.Color.Color.fromHSLString */ this.Color.fromHSLString = m.bind( this.Color._fromColorString, this.Color, "hsl", "fromHSL", [1.0/360.0, 0.01, 0.01, 1] ); var third = 1.0 / 3.0; /** @id MochiKit.Color.colors */ var colors = { // NSColor colors plus transparent /** @id MochiKit.Color.blackColor */ black: [0, 0, 0], /** @id MochiKit.Color.blueColor */ blue: [0, 0, 1], /** @id MochiKit.Color.brownColor */ brown: [0.6, 0.4, 0.2], /** @id MochiKit.Color.cyanColor */ cyan: [0, 1, 1], /** @id MochiKit.Color.darkGrayColor */ darkGray: [third, third, third], /** @id MochiKit.Color.grayColor */ gray: [0.5, 0.5, 0.5], /** @id MochiKit.Color.greenColor */ green: [0, 1, 0], /** @id MochiKit.Color.lightGrayColor */ lightGray: [2 * third, 2 * third, 2 * third], /** @id MochiKit.Color.magentaColor */ magenta: [1, 0, 1], /** @id MochiKit.Color.orangeColor */ orange: [1, 0.5, 0], /** @id MochiKit.Color.purpleColor */ purple: [0.5, 0, 0.5], /** @id MochiKit.Color.redColor */ red: [1, 0, 0], /** @id MochiKit.Color.transparentColor */ transparent: [0, 0, 0, 0], /** @id MochiKit.Color.whiteColor */ white: [1, 1, 1], /** @id MochiKit.Color.yellowColor */ yellow: [1, 1, 0] }; - var makeColor = function (name, r, g, b, a) { - var rval = this.fromRGB(r, g, b, a); - this[name] = function () { return rval; }; - return rval; - }; - for (var k in colors) { var name = k + "Color"; - var bindArgs = m.concat( - [makeColor, this.Color, name], - colors[k] - ); - this.Color[name] = m.bind.apply(null, bindArgs); + var value = this.Color.fromRGB.apply(this.Color, colors[k]); + this.Color[name] = m.partial(m.operator.identity, value); } var isColor = function () { for (var i = 0; i < arguments.length; i++) { if (!(arguments[i] instanceof MochiKit.Color.Color)) { return false; } } return true; }; var compareColor = function (a, b) { return a.compareRGB(b); }; m.nameFunctions(this); m.registerComparator(this.Color.NAME, isColor, compareColor); } }); MochiKit.Color.__new__(); // Full table of css3 X11 colors <http://www.w3.org/TR/css3-color/#X11COLORS> MochiKit.Color.Color._namedColors = { aliceblue: "#f0f8ff", antiquewhite: "#faebd7", aqua: "#00ffff", aquamarine: "#7fffd4", azure: "#f0ffff", beige: "#f5f5dc", bisque: "#ffe4c4", black: "#000000", blanchedalmond: "#ffebcd", blue: "#0000ff", blueviolet: "#8a2be2", brown: "#a52a2a", burlywood: "#deb887", cadetblue: "#5f9ea0", chartreuse: "#7fff00", chocolate: "#d2691e", coral: "#ff7f50", cornflowerblue: "#6495ed", cornsilk: "#fff8dc", crimson: "#dc143c", cyan: "#00ffff", darkblue: "#00008b", darkcyan: "#008b8b", darkgoldenrod: "#b8860b", darkgray: "#a9a9a9", darkgreen: "#006400", darkgrey: "#a9a9a9", 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: "#ff00ff", gainsboro: "#dcdcdc", ghostwhite: "#f8f8ff", gold: "#ffd700", goldenrod: "#daa520", gray: "#808080", green: "#008000", greenyellow: "#adff2f", grey: "#808080", 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", |