Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit f605b47

Browse files
committed
Merge pull request #2212 from DennisKehrig/dk/issue-2050
Add support for percentage based RGB colors to the inline color editor
2 parents 6eca8f7 + 34bd5cc commit f605b47

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/extensions/default/InlineColorEditor/ColorEditor.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ define(function (require, exports, module) {
218218
_this = this;
219219
handler = function (event) {
220220
var colorObject, newColor, newFormat;
221-
newFormat = $(event.currentTarget).html().toLowerCase();
221+
newFormat = $(event.currentTarget).html().toLowerCase().replace("%", "p");
222222
newColor = _this.getColor();
223223
colorObject = tinycolor(newColor);
224224
switch (newFormat) {
@@ -228,6 +228,9 @@ define(function (require, exports, module) {
228228
case "rgba":
229229
newColor = colorObject.toRgbString();
230230
break;
231+
case "prgba":
232+
newColor = colorObject.toPercentageRgbString();
233+
break;
231234
case "hex":
232235
newColor = colorObject.toHexString();
233236
_this._hsv.a = 1;
@@ -266,10 +269,10 @@ define(function (require, exports, module) {
266269
}
267270
return color;
268271
};
269-
272+
270273
/**
271274
* Normalize the given color string into the format used by tinycolor, by adding a space
272-
* after commas and converting RGB colors from percentages to integers.
275+
* after commas.
273276
* @param {string} color The color to be corrected if it looks like an RGB or HSL color.
274277
* @return {string} a normalized color string.
275278
*/
@@ -285,7 +288,7 @@ define(function (require, exports, module) {
285288
normalizedColor = normalizedColor.replace(/\(\s+/, "(");
286289
normalizedColor = normalizedColor.replace(/\s+\)/, ")");
287290
}
288-
return this._convertToNormalRGB(normalizedColor.toLowerCase());
291+
return normalizedColor.toLowerCase();
289292
};
290293

291294
/** Handle changes in text field */
@@ -385,6 +388,9 @@ define(function (require, exports, module) {
385388
case "rgb":
386389
colorVal = newColor.toRgbString();
387390
break;
391+
case "prgb":
392+
colorVal = newColor.toPercentageRgbString();
393+
break;
388394
case "hex":
389395
case "name":
390396
colorVal = this._hsv.a < 1 ? newColor.toRgbString() : newColor.toHexString();

0 commit comments

Comments
 (0)