-
-
Notifications
You must be signed in to change notification settings - Fork 920
feat: Add button for exporting a theme from the demo site #176
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
Changes from 1 commit
61bf22b
f184892
2b1f03b
fd1c7b6
337294e
f225940
11eed5d
cd7440d
2b448ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ let preview = { | |
let obj = { ...acc }; | ||
let value = next.value; | ||
|
||
if (value.indexOf('#') >= 0) { | ||
if (value.indexOf("#") >= 0) { | ||
// if the value is colour, remove the hash sign | ||
value = value.replace(/#/g, ""); | ||
if (value.length > 6) { | ||
|
@@ -72,9 +72,9 @@ let preview = { | |
label.setAttribute("data-property", property); | ||
// color picker | ||
const jscolorConfig = { | ||
format: 'hexa', | ||
onChange: 'pickerChange(this, "'+property+'")', | ||
onInput: 'pickerChange(this, "'+property+'")' | ||
format: "hexa", | ||
onChange: 'pickerChange(this, "' + property + '")', | ||
onInput: 'pickerChange(this, "' + property + '")', | ||
}; | ||
const input = document.createElement("input"); | ||
input.className = "param jscolor"; | ||
|
@@ -179,8 +179,55 @@ window.addEventListener( | |
}, | ||
false | ||
); | ||
function exportPhp() { | ||
let properties = [ | ||
"border", | ||
"stroke", | ||
"ring", | ||
"fire", | ||
"currStreakNum", | ||
"sideNums", | ||
"currStreakLabel", | ||
"sideLabels", | ||
"dates", | ||
"background", | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of listing them here, can just use a more specific query when creating the mapping below Eg. document.querySelectorAll(".advanced .param.jscolor") instead of document.querySelectorAll(".param") |
||
let array = Array.from(document.querySelectorAll(".param")).reduce( | ||
(acc, next) => { | ||
let obj = { ...acc }; | ||
let value = next.value; | ||
if (value.indexOf("#") >= 0) { | ||
// if the value is colour, remove the hash sign | ||
value = value.replace(/#/g, ""); | ||
if (value.length > 6) { | ||
// if the value is in hexa and opacity is 1, remove FF | ||
value = value.replace(/(F|f){2}$/, ""); | ||
} | ||
} | ||
obj[next.id] = value; | ||
return obj; | ||
}, | ||
{} | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is same code from line 10, if it's used twice, it should be extracted to a function to use in both places. Eg. function objectFromElements(elements) {
// create a key value mapping of parameter values from all elements in a Node list
return Array.from(elements).reduce((acc, next) => {
let obj = { ...acc };
let value = next.value;
if (value.indexOf("#") >= 0) {
// if the value is colour, remove the hash sign
value = value.replace(/#/g, "");
if (value.length > 6) {
// if the value is in hexa and opacity is 1, remove FF
value = value.replace(/(F|f){2}$/, "");
}
}
obj[next.id] = value;
return obj;
}, {});
} // line 10
const params = objectFromElements(document.querySelectorAll(".param"));
// here
const params = objectFromElements(document.querySelectorAll(".advanced .param.jscolor")); |
||
var exportPhp = {}; | ||
|
||
for (const [key, val] of Object.entries(array)) { | ||
if (properties.includes(key) > 0) { | ||
exportPhp[key] = val; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the above changes, this is unnecessary |
||
|
||
const output = | ||
"[\n" + | ||
Object.keys(exportPhp) | ||
.map((key) => `\t"${key}" => "#${exportPhp[key]}",\n`) | ||
.join("") + | ||
"]"; | ||
komen205 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
document.getElementById('test').value = output; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the "test" and "button" text are temporary, but I'll mention anyway, they should be made more descriptive. |
||
console.log(output); | ||
} | ||
|
||
function checkColor(color, input){ | ||
function checkColor(color, input) { | ||
if (color.length == 9 && color.slice(-2) == "FF") { | ||
// if color has hex alpha value -> remove it | ||
document.getElementById(input).value = color.slice(0, -2); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can go inside the advanced panel and you can make the textarea hidden until the export button is actually clicked.