From c98b0aac906e6176808d991eda83dffbd6e04124 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sun, 7 May 2017 11:54:15 +0200 Subject: [PATCH] Added bootstrap-colorpicker --- .gitattributes | 1 + src/pretix/control/forms/event.py | 3 +- .../control/templates/pretixcontrol/base.html | 1 + .../static/colorpicker/alpha-horizontal.png | Bin 0 -> 557 bytes src/pretix/static/colorpicker/alpha.png | Bin 0 -> 488 bytes .../colorpicker/bootstrap-colorpicker.js | 1319 +++++++++++++++++ .../colorpicker/bootstrap-colorpicker.scss | 230 +++ .../static/colorpicker/hue-horizontal.png | Bin 0 -> 478 bytes src/pretix/static/colorpicker/hue.png | Bin 0 -> 504 bytes src/pretix/static/colorpicker/saturation.png | Bin 0 -> 4143 bytes src/pretix/static/pretixcontrol/js/ui/main.js | 6 + .../static/pretixcontrol/scss/main.scss | 18 +- 12 files changed, 1576 insertions(+), 2 deletions(-) create mode 100644 src/pretix/static/colorpicker/alpha-horizontal.png create mode 100644 src/pretix/static/colorpicker/alpha.png create mode 100644 src/pretix/static/colorpicker/bootstrap-colorpicker.js create mode 100644 src/pretix/static/colorpicker/bootstrap-colorpicker.scss create mode 100644 src/pretix/static/colorpicker/hue-horizontal.png create mode 100644 src/pretix/static/colorpicker/hue.png create mode 100644 src/pretix/static/colorpicker/saturation.png diff --git a/.gitattributes b/.gitattributes index 545288622..ae2fa07cf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,7 @@ src/static/lightbox/* linguist-vendored src/static/typeahead/* linguist-vendored src/static/moment/* linguist-vendored src/static/datetimepicker/* linguist-vendored +src/static/colorpicker/* linguist-vendored src/static/charts/* linguist-vendored # Denote all files that are truly binary and should not be modified. diff --git a/src/pretix/control/forms/event.py b/src/pretix/control/forms/event.py index 962693c08..808e4604c 100644 --- a/src/pretix/control/forms/event.py +++ b/src/pretix/control/forms/event.py @@ -602,7 +602,8 @@ class DisplaySettingsForm(SettingsForm): validators=[ RegexValidator(regex='^#[0-9a-fA-F]{6}$', message=_('Please enter the hexadecimal code of a color, e.g. #990000.')) - ] + ], + widget=forms.TextInput(attrs={'class': 'colorpickerfield'}) ) logo_image = ExtFileField( label=_('Logo image'), diff --git a/src/pretix/control/templates/pretixcontrol/base.html b/src/pretix/control/templates/pretixcontrol/base.html index d402d43ab..73dddb072 100644 --- a/src/pretix/control/templates/pretixcontrol/base.html +++ b/src/pretix/control/templates/pretixcontrol/base.html @@ -35,6 +35,7 @@ + {% endcompress %} {{ html_head|safe }} diff --git a/src/pretix/static/colorpicker/alpha-horizontal.png b/src/pretix/static/colorpicker/alpha-horizontal.png new file mode 100644 index 0000000000000000000000000000000000000000..f83188951a8e4fab4ba847c8c89f3105354a9816 GIT binary patch literal 557 zcmV+|0@D47P)Nkl5JbD$mJ%t8>^MX+pA8q_5}cAta0DO|R@{IU5|M(GxNxgy+GBd8l;w&2Ec?5< zVo(HvFZxdJAnNTau8ZPXtKOAPtn2rp+IrX0nbY#4bkaNYzIIZLJrooctxYd|?rp8? z)cO+ap+cSA7pbEAUi(YitNzQ6mD^}>0x7Ez^ll73R_Xc-*~Q+Zpz#R`Ko|>@qj2QF zAcKncK;vstA0eL^`!E>xIk#_;8u-NduvaQXn$g$>7z4ttYmjqc8pS->gW&WGdI5U9QmYbj;6~_suM0VjVBk)9?FjGKLNzR9mK$u}% zJ?3)?fRmicTx%xVMC69^f7R;rWA8uZm)yve{K1EP8^1~E?L`XT8&R{cit@G7SGmNI zD-;bNVa)Z2Mil~Fb~9WBo8Kj@u3_#HiLFA<1-{qWmO2-=?0YdKVz6%S z2*9Wz8-&7K@4=W?VKkD82M*@cB4wmZ=tias{62*I43WQYJZEcwS<&N#Nal+GF`i11 zY=e+9d7#-KG!R}kc+3AQ$^6t@932p}V@@!QyyuhBvt_KD{nGq0=-+8wbOe^=^onsM vr1hwgCt@ro;xv+DFr+*}$b1+=kSNMOdLipIvOQ8u00000NkvXXu0mjf9#jU9 literal 0 HcmV?d00001 diff --git a/src/pretix/static/colorpicker/alpha.png b/src/pretix/static/colorpicker/alpha.png new file mode 100644 index 0000000000000000000000000000000000000000..2e53a30e73175009326fc030f00862d682ddfc45 GIT binary patch literal 488 zcmVP)B00056Nkl} zZ#=A8HwTy*Ji~Hui*DN)Xc=D2SbWU)JF^vFq?ipSE1)dQB?%2~zL;*2(|O#(oBR;O z#J!!4+zDc0I&77>T+tDIE@oI;6%kXWiptfQV#*c>2foJxnWs^#66pqri5SJi0v*Xc z_vjIT9?6}|hzFF05)=1g9#80;7y9mior*2jP95+vQ|{sWGtx)s=39zr^u6;HX^F`p zkx2{{y^wicti6Khm3Wyed%Eg2H=fbPc7D3VBcDWdj{r#qvrgUX$)#2lTEc%5bs}9E zZ`+UiVVyX}VI5jr+$k@C{pP8ABQF)*q|@k8ll1fgWY+Q?y|Zg0V9OmodqfH%3xo%V zF_0b~gfCME=jtfJ($v-Y^!<}BBQx2`+78RhRbxt$n5&{MunD^|({9#^#Hp{!+@o)R z!Ci&=u08T*r)OJ-Py8D;`eSXCiKA=ket6eR*LHXng}b_5r%ttFu8MwPi~vTbhPJwk eS?^O73H$>F-M_zn@}r;t0000 0 && L <= 1) { + S /= L; + } else { + S /= 2 - L; + } + L /= 2; + if (S > 1) { + S = 1; + } + return { + h: isNaN(H) ? 0 : H, + s: isNaN(S) ? 0 : S, + l: isNaN(L) ? 0 : L, + a: isNaN(a) ? 0 : a + }; + }, + toAlias: function(r, g, b, a) { + var c, rgb = (arguments.length === 0) ? this.toHex() : this.toHex(r, g, b, a); + + // support predef. colors in non-hex format too, as defined in the alias itself + var original = this.origFormat === 'alias' ? rgb : this.toString(this.origFormat, false); + + for (var alias in this.colors) { + c = this.colors[alias].toLowerCase().trim(); + if ((c === rgb) || (c === original)) { + return alias; + } + } + return false; + }, + RGBtoHSB: function(r, g, b, a) { + r /= 255; + g /= 255; + b /= 255; + + var H, S, V, C; + V = Math.max(r, g, b); + C = V - Math.min(r, g, b); + H = (C === 0 ? null : + V === r ? (g - b) / C : + V === g ? (b - r) / C + 2 : + (r - g) / C + 4 + ); + H = ((H + 360) % 6) * 60 / 360; + S = C === 0 ? 0 : C / V; + return { + h: this._sanitizeNumber(H), + s: S, + b: V, + a: this._sanitizeNumber(a) + }; + }, + HueToRGB: function(p, q, h) { + if (h < 0) { + h += 1; + } else if (h > 1) { + h -= 1; + } + if ((h * 6) < 1) { + return p + (q - p) * h * 6; + } else if ((h * 2) < 1) { + return q; + } else if ((h * 3) < 2) { + return p + (q - p) * ((2 / 3) - h) * 6; + } else { + return p; + } + }, + HSLtoRGB: function(h, s, l, a) { + if (s < 0) { + s = 0; + } + var q; + if (l <= 0.5) { + q = l * (1 + s); + } else { + q = l + s - (l * s); + } + + var p = 2 * l - q; + + var tr = h + (1 / 3); + var tg = h; + var tb = h - (1 / 3); + + var r = Math.round(this.HueToRGB(p, q, tr) * 255); + var g = Math.round(this.HueToRGB(p, q, tg) * 255); + var b = Math.round(this.HueToRGB(p, q, tb) * 255); + return [r, g, b, this._sanitizeNumber(a)]; + }, + /** + * @param {String} strVal + * @returns {Object} Object containing h,s,b,a,format properties or FALSE if failed to parse + */ + parse: function(strVal) { + if (arguments.length === 0) { + return false; + } + + var that = this, + result = false, + isAlias = (typeof this.colors[strVal] !== 'undefined'), + values, format; + + if (isAlias) { + strVal = this.colors[strVal].toLowerCase().trim(); + } + + $.each(this.stringParsers, function(i, parser) { + var match = parser.re.exec(strVal); + values = match && parser.parse.apply(that, [match]); + if (values) { + result = {}; + format = (isAlias ? 'alias' : (parser.format ? parser.format : that.getValidFallbackFormat())); + if (format.match(/hsla?/)) { + result = that.RGBtoHSB.apply(that, that.HSLtoRGB.apply(that, values)); + } else { + result = that.RGBtoHSB.apply(that, values); + } + if (result instanceof Object) { + result.format = format; + } + return false; // stop iterating + } + return true; + }); + return result; + }, + getValidFallbackFormat: function() { + var formats = [ + 'rgba', 'rgb', 'hex', 'hsla', 'hsl' + ]; + if (this.origFormat && (formats.indexOf(this.origFormat) !== -1)) { + return this.origFormat; + } + if (this.fallbackFormat && (formats.indexOf(this.fallbackFormat) !== -1)) { + return this.fallbackFormat; + } + + return 'rgba'; // By default, return a format that will not lose the alpha info + }, + /** + * + * @param {string} [format] (default: rgba) + * @param {boolean} [translateAlias] Return real color for pre-defined (non-standard) aliases (default: false) + * @returns {String} + */ + toString: function(format, translateAlias) { + format = format || this.origFormat || this.fallbackFormat; + translateAlias = translateAlias || false; + + var c = false; + + switch (format) { + case 'rgb': + { + c = this.toRGB(); + if (this.rgbaIsTransparent(c)) { + return 'transparent'; + } + return 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')'; + } + break; + case 'rgba': + { + c = this.toRGB(); + return 'rgba(' + c.r + ',' + c.g + ',' + c.b + ',' + c.a + ')'; + } + break; + case 'hsl': + { + c = this.toHSL(); + return 'hsl(' + Math.round(c.h * 360) + ',' + Math.round(c.s * 100) + '%,' + Math.round(c.l * 100) + '%)'; + } + break; + case 'hsla': + { + c = this.toHSL(); + return 'hsla(' + Math.round(c.h * 360) + ',' + Math.round(c.s * 100) + '%,' + Math.round(c.l * 100) + '%,' + c.a + ')'; + } + break; + case 'hex': + { + return this.toHex(); + } + break; + case 'alias': + { + c = this.toAlias(); + + if (c === false) { + return this.toString(this.getValidFallbackFormat()); + } + + if (translateAlias && !(c in Color.webColors) && (c in this.predefinedColors)) { + return this.predefinedColors[c]; + } + + return c; + } + default: + { + return c; + } + break; + } + }, + // a set of RE's that can match strings and generate color tuples. + // from John Resig color plugin + // https://github.com/jquery/jquery-color/ + stringParsers: [{ + re: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*?\)/, + format: 'rgb', + parse: function(execResult) { + return [ + execResult[1], + execResult[2], + execResult[3], + 1 + ]; + } + }, { + re: /rgb\(\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*?\)/, + format: 'rgb', + parse: function(execResult) { + return [ + 2.55 * execResult[1], + 2.55 * execResult[2], + 2.55 * execResult[3], + 1 + ]; + } + }, { + re: /rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)/, + format: 'rgba', + parse: function(execResult) { + return [ + execResult[1], + execResult[2], + execResult[3], + execResult[4] + ]; + } + }, { + re: /rgba\(\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)/, + format: 'rgba', + parse: function(execResult) { + return [ + 2.55 * execResult[1], + 2.55 * execResult[2], + 2.55 * execResult[3], + execResult[4] + ]; + } + }, { + re: /hsl\(\s*(\d*(?:\.\d+)?)\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*?\)/, + format: 'hsl', + parse: function(execResult) { + return [ + execResult[1] / 360, + execResult[2] / 100, + execResult[3] / 100, + execResult[4] + ]; + } + }, { + re: /hsla\(\s*(\d*(?:\.\d+)?)\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)/, + format: 'hsla', + parse: function(execResult) { + return [ + execResult[1] / 360, + execResult[2] / 100, + execResult[3] / 100, + execResult[4] + ]; + } + }, { + re: /#?([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/, + format: 'hex', + parse: function(execResult) { + return [ + parseInt(execResult[1], 16), + parseInt(execResult[2], 16), + parseInt(execResult[3], 16), + 1 + ]; + } + }, { + re: /#?([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/, + format: 'hex', + parse: function(execResult) { + return [ + parseInt(execResult[1] + execResult[1], 16), + parseInt(execResult[2] + execResult[2], 16), + parseInt(execResult[3] + execResult[3], 16), + 1 + ]; + } + }], + colorNameToHex: function(name) { + if (typeof this.colors[name.toLowerCase()] !== 'undefined') { + return this.colors[name.toLowerCase()]; + } + return false; + } + }; + + /* + * Default plugin options + */ + var defaults = { + horizontal: false, // horizontal mode layout ? + inline: false, //forces to show the colorpicker as an inline element + color: false, //forces a color + format: false, //forces a format + input: 'input', // children input selector + container: false, // container selector + component: '.add-on, .input-group-addon', // children component selector + fallbackColor: false, // fallback color value. null = keeps current color. + fallbackFormat: 'hex', // fallback color format + hexNumberSignPrefix: true, // put a '#' (number sign) before hex strings + sliders: { + saturation: { + maxLeft: 100, + maxTop: 100, + callLeft: 'setSaturation', + callTop: 'setBrightness' + }, + hue: { + maxLeft: 0, + maxTop: 100, + callLeft: false, + callTop: 'setHue' + }, + alpha: { + maxLeft: 0, + maxTop: 100, + callLeft: false, + callTop: 'setAlpha' + } + }, + slidersHorz: { + saturation: { + maxLeft: 100, + maxTop: 100, + callLeft: 'setSaturation', + callTop: 'setBrightness' + }, + hue: { + maxLeft: 100, + maxTop: 0, + callLeft: 'setHue', + callTop: false + }, + alpha: { + maxLeft: 100, + maxTop: 0, + callLeft: 'setAlpha', + callTop: false + } + }, + template: '