Add Layout Name as a Class to Keyboard Container
I am using your keyboard for a project and really loving the flexibly and options it has. I love how almost everything has its own class or wrapper class which make styling it much easier. The one thing that I have noticed that doesn't add a class to the container is what layout you are using. This would be very helpful since it is nice to be able to style different layouts uniquely. I realize that you can add a class by using the css: option but I would like to be able to do it more dynamically so that if I choose a specific layout the custom theme will be applied automatically since it using the layout name as the class to apply its styles to.
Wow I guess I should have taken a slightly harder look at the code. Around line 1202 I found this:
container = $('<div />')
.addClass( kbcss.keyboard + ' xrx-keyboard ' + o.layout + ' ' +o.css.container + (o.alwaysOpen ? ' ' + kbcss.alwaysOpen : '') )
.attr({ 'role': 'textbox' })
.hide();
which I added javascript o.layout to the .addClass section which nicely adds the name of the layout to the container for the keyboard.
Feel free to close this issue if you want unless you think there might be a better way of doing this.
Hi @dwhiting10!
I wouldn't recommend changing the internal code, it makes it difficult to update and replace all the modifications each time. Instead, use the visible callback function (demo):
$('.keyboard').keyboard({
layout: 'qwerty',
visible: function (e, keyboard, el) {
keyboard.$keyboard.addClass('layout-' + keyboard.options.layout);
}
});
The above code will add a class name of "layout-qwerty", or whatever value is within the layout option.
The only difficulty I foresee in styling would be with custom layouts. The layout name gets a hash of the layout added to the name (e.g. "custom1444999601") so it should consistently be the same hash value, but may be more difficult to determine.
As of version 1.22.2, if the input/textarea has an ID, the popup keyboard ID will now have the element ID plus the value from $.keyboard.css.idSuffix (default is _keyboard) added to the end.
So, for example, if the input has an ID of "dvorak", the keyboard associated with it will have an ID of "dvorak_keyboard".