Added internal getButtonTheme

This commit is contained in:
Francisco Hodge 2019-03-06 19:29:29 -05:00
parent c4005e7409
commit 93a45a7c26

View File

@ -620,6 +620,52 @@ class SimpleKeyboard {
}); });
} }
/**
* Process buttonTheme option
*/
getButtonTheme(){
let buttonThemesParsed = {};
this.options.buttonTheme.forEach(themeObj => {
if (themeObj.buttons && themeObj.class) {
let themeButtons;
if (typeof themeObj.buttons === "string") {
themeButtons = themeObj.buttons.split(" ");
}
if (themeButtons) {
themeButtons.forEach(themeButton => {
let themeParsed = buttonThemesParsed[themeButton];
// If the button has already been added
if (themeParsed) {
// Making sure we don't add duplicate classes, even when buttonTheme has duplicates
if (
!this.utilities.countInArray(
themeParsed.split(" "),
themeObj.class
)
) {
buttonThemesParsed[themeButton] = `${themeParsed} ${
themeObj.class
}`;
}
} else {
buttonThemesParsed[themeButton] = themeObj.class;
}
});
}
} else {
console.warn(
`buttonTheme row is missing the "buttons" or the "class". Please check the documentation.`
);
}
});
return buttonThemesParsed;
}
/** /**
* Process autoTouchEvents option * Process autoTouchEvents option
@ -734,45 +780,7 @@ class SimpleKeyboard {
/** /**
* Account for buttonTheme, if set * Account for buttonTheme, if set
*/ */
let buttonThemesParsed = {}; let buttonThemesParsed = Array.isArray(this.options.buttonTheme) ? this.getButtonTheme() : {};
if (Array.isArray(this.options.buttonTheme)) {
this.options.buttonTheme.forEach(themeObj => {
if (themeObj.buttons && themeObj.class) {
let themeButtons;
if (typeof themeObj.buttons === "string") {
themeButtons = themeObj.buttons.split(" ");
}
if (themeButtons) {
themeButtons.forEach(themeButton => {
let themeParsed = buttonThemesParsed[themeButton];
// If the button has already been added
if (themeParsed) {
// Making sure we don't add duplicate classes, even when buttonTheme has duplicates
if (
!this.utilities.countInArray(
themeParsed.split(" "),
themeObj.class
)
) {
buttonThemesParsed[themeButton] = `${themeParsed} ${
themeObj.class
}`;
}
} else {
buttonThemesParsed[themeButton] = themeObj.class;
}
});
}
} else {
console.warn(
`buttonTheme row is missing the "buttons" or the "class". Please check the documentation.`
);
}
});
}
/** /**
* Adding themeClass, layoutClass to keyboardDOM * Adding themeClass, layoutClass to keyboardDOM