-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for #AARRGGBB vs #RRGGBBAA #33
Comments
Wow, why did Google decide on that format..? And also, did it change with Android P? Anyway, unless a lot of people start requesting this, I'm not going to change the supported formats. It should be easy enough to change the hex order before and after. |
@Sphinxxxx is there a way of just overriding the relevant function (without creating a modified version of the whole thing) so that it treats all hex codes as |
In your case, you'll probably have to override json-editor. It's not pretty, but looking at their code, you may be able to do something like this: var editor = new JSONEditor(document.getElementById('editor_holder'), { ... });
//Do this for all your schema properties that are colors:
useARGB(editor.getEditor('root.hexa'));
useARGB(editor.getEditor( ... ));
function useARGB(colorEditor) {
colorEditor._setValue = colorEditor.setValue;
colorEditor.setValue = function(RGBA, initial, fromTemplate) {
var ARGB = '#' + RGBA.slice(-2) + RGBA.slice(1, 7);
var res = this._setValue(ARGB, initial, fromTemplate);
if (this.picker_instance) {
this.picker_instance.setColor(RGBA, true);
}
return res;
}
//Sync initial color:
colorEditor._createPicker = colorEditor.createPicker;
colorEditor.createPicker = function(create) {
this._createPicker(create);
if(create) {
var originalARGB = this.value,
originalRGBA = '#' + originalARGB.slice(-6) + originalARGB.slice(1, 3);
this.setValue(originalRGBA);
}
}
} |
@Sphinxxxx absolutely spot on first time, thanks. For reference, to apply the
I had previously implemented a version which converted hex values before exposing them to vanilla, then converted them back after, but my page shows both raw values and converted values so it just got confusing to have both formats on the same page. Just overriding the picker and leaving the hex values alone is a lot easier. |
@Sphinxxxx several years later, something has broken and I can't figure out what. On this page I am following the solution suggested in your post above, to alter the behaviour of the EDIT: think I sorted it! Problem was that I was doing the customisation in |
@drmrbrewer Thanks for the update, glad you fixed it! |
It would be great if there could be support for
#AARRGGBB
format (i.e. with alphaAA
at the start not at the end). I am coming to this from an Android environment, where all my colours are represented in this format (see here) and whilst it would be possible to create a bolt-on to translate from#AARRGGBB
to#RRGGBBAA
before vanilla sees it, and then translate back at the other end to#AARRGGBB
, it would be really nice if this could be supported natively.The text was updated successfully, but these errors were encountered: