Skip to content
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

[WIP] Add support for caps lock auto uppercase first character #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ declare namespace KioskBoard {
*/
capsLockActive?: boolean;

/**
* @property {boolean} - Optional, Uppercase or lowercase first character only. Uppercased when `true`.
* @defaultValue `true`
*/
capsLockAuto?: boolean;

/**
* @property {boolean} - Optional, Allow or prevent real/physical keyboard usage. Prevented when `false`.
* @defaultValue `false`
Expand Down
12 changes: 12 additions & 0 deletions src/kioskboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
background: #5decaa;
}

#KioskBoard-VirtualKeyboard .kioskboard-row-bottom span.kioskboard-key-capslock.capslock-auto::before {
background: #2329f6;
}

#KioskBoard-VirtualKeyboard .kioskboard-row-bottom span.kioskboard-key-enter,
#KioskBoard-VirtualKeyboard .kioskboard-row-bottom span.kioskboard-key-backspace {
position: relative;
Expand Down Expand Up @@ -513,6 +517,14 @@
background: #5decaa;
}

#KioskBoard-VirtualKeyboard.kioskboard-theme-oldschool span.kioskboard-key-capslock.capslock-auto::before,
#KioskBoard-VirtualKeyboard.kioskboard-theme-flat span.kioskboard-key-capslock.capslock-auto::before,
#KioskBoard-VirtualKeyboard.kioskboard-theme-light span.kioskboard-key-capslock.capslock-auto::before,
#KioskBoard-VirtualKeyboard.kioskboard-theme-dark span.kioskboard-key-capslock.capslock-auto::before,
#KioskBoard-VirtualKeyboard.kioskboard-theme-material span.kioskboard-key-capslock.capslock-auto::before {
background: #2329f6;
}

#KioskBoard-VirtualKeyboard.kioskboard-theme-flat .kioskboard-row span[class^="kioskboard-key"] svg,
#KioskBoard-VirtualKeyboard.kioskboard-theme-light .kioskboard-row span[class^="kioskboard-key"] svg {
fill: #707070 !important;
Expand Down
36 changes: 31 additions & 5 deletions src/kioskboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
theme: 'light', // "light" || "dark" || "flat" || "material" || "oldschool"
autoScroll: true,
capsLockActive: true,
capsLockAuto: false,
allowRealKeyboard: false,
allowMobileKeyboard: false,
cssAnimations: true,
Expand Down Expand Up @@ -394,7 +395,8 @@
var fontWeight = typeof opt.keysFontWeight === 'string' && opt.keysFontWeight.length > 0 ? opt.keysFontWeight : 'normal';

// static keys: begin
var isCapsLockActive = opt.capsLockActive === true;
var isCapsLockAuto = opt.capsLockAuto === true;
var isCapsLockActive = opt.capsLockActive === true || isCapsLockAuto;
var keysIconWidth = typeof opt.keysIconSize === 'string' && opt.keysIconSize.length > 0 ? opt.keysIconSize : '25px';
var keysIconColor = '#707070';
var keysAllowSpacebar = opt.keysAllowSpacebar === true;
Expand All @@ -403,7 +405,7 @@
var keysEnterText = typeof opt.keysEnterText === 'string' && opt.keysEnterText.length > 0 ? opt.keysEnterText : 'Enter';

var spaceKey = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key kioskboard-key-space ' + (keysAllowSpacebar ? 'spacebar-allowed' : 'spacebar-denied') + '" data-value="' + spaceKeyValue + '">' + keysSpacebarText + '</span>';
var capsLockKey = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key-capslock ' + (isCapsLockActive ? 'capslock-active' : '') + '">' + kioskBoardIconCapslock(keysIconWidth, keysIconColor) + '</span>';
var capsLockKey = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key-capslock ' + (isCapsLockAuto ? 'capslock-auto' : (isCapsLockActive ? 'capslock-active' : '')) + '">' + kioskBoardIconCapslock(keysIconWidth, keysIconColor) + '</span>';
var backspaceKey = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key-backspace">' + kioskBoardIconBackspace(keysIconWidth, keysIconColor) + '</span>';
var enterKey = '<span style="font-family:' + fontFamily + ',sans-serif;font-weight:' + fontWeight + ';font-size:' + fontSize + ';" class="kioskboard-key-enter">' + keysEnterText + '</span>';
// static keys: end
Expand Down Expand Up @@ -643,6 +645,17 @@
keyValue = keyValue.toLocaleLowerCase(keyboardLanguage);
}

if (isCapsLockAuto) {
isCapsLockActive = false;
isCapsLockAuto = false;
kioskBoardVirtualKeyboard.classList.add('kioskboard-tolowercase');
kioskBoardVirtualKeyboard.classList.remove('kioskboard-touppercase');
var capsLockKeyElm = window.document.querySelector('.kioskboard-key-capslock');
if (capsLockKeyElm) {
capsLockKeyElm.classList.remove('capslock-auto');
}
}

var keyValArr = keyValue.split('');
for (var keyValIndex = 0; keyValIndex < keyValArr.length; keyValIndex++) {
// update the selectionStart
Expand Down Expand Up @@ -675,16 +688,24 @@
// focus the input
input.focus();

if (e.currentTarget.classList.contains('capslock-active')) {
if (e.currentTarget.classList.contains('capslock-auto')) {
e.currentTarget.classList.remove('capslock-auto');
kioskBoardVirtualKeyboard.classList.add('kioskboard-tolowercase');
kioskBoardVirtualKeyboard.classList.remove('kioskboard-touppercase');
isCapsLockActive = false;
isCapsLockAuto = false;
} else if (e.currentTarget.classList.contains('capslock-active')) {
e.currentTarget.classList.remove('capslock-active');
kioskBoardVirtualKeyboard.classList.add('kioskboard-tolowercase');
kioskBoardVirtualKeyboard.classList.remove('kioskboard-touppercase');
isCapsLockActive = false;
isCapsLockAuto = false;
} else {
e.currentTarget.classList.add('capslock-active');
kioskBoardVirtualKeyboard.classList.remove('kioskboard-tolowercase');
kioskBoardVirtualKeyboard.classList.add('kioskboard-touppercase');
isCapsLockActive = true;
isCapsLockAuto = false;
}
});
}
Expand Down Expand Up @@ -727,11 +748,15 @@
keysEventListeners(specialCharacterKeyElm, function (e) {
e.preventDefault();
input.focus(); // focus the input
if (e.currentTarget.classList.contains('specialcharacter-active')) {
if (e.currentTarget.classList.contains('specialcharacter-auto')) {
e.currentTarget.classList.remove('specialcharacter-auto');
e.currentTarget.classList.add('specialcharacter-active');
specialCharactersRowElm.classList.add('kioskboard-specialcharacter-show');
} else if (e.currentTarget.classList.contains('specialcharacter-active')) {
e.currentTarget.classList.remove('specialcharacter-active');
specialCharactersRowElm.classList.remove('kioskboard-specialcharacter-show');
} else {
e.currentTarget.classList.add('specialcharacter-active');
e.currentTarget.classList.add('specialcharacter-auto');
specialCharactersRowElm.classList.add('kioskboard-specialcharacter-show');
}
});
Expand All @@ -743,6 +768,7 @@
e.preventDefault();
input.focus(); // focus the input
specialCharacterKeyElm.classList.remove('specialcharacter-active');
specialCharacterKeyElm.classList.remove('specialcharacter-auto');
specialCharactersRowElm.classList.remove('kioskboard-specialcharacter-show');
});
}
Expand Down