Make text uppercase or lower case with the caps lock key
Download the production version or the development version.
In your web page:
<p>
<textarea name="textarea" id="textarea" cols="30" rows="10">example text</textarea>
</p>
<script src="dist/caps-locker.min.js"></script>
<script>
window.Caps.attach("#textarea");
</script>
At now only supports textarea
and input[type=text]
elements
Now when you select the text in that #textarea
you can press the Shift key to capitilize or make upper case your selected text. You can also use the CapsLock key for the same behavior.
Chrome (latest), Firefox (latest), Edge (on Win10 build 10240)
The CapsLocker API is pretty simple. You can attach
the capitalization behavior to a textarea or an input text. You can also use tha capitalize
function independently from a DOM Element.
Attaches a CapsLocker instance to a DOMElement.
parameters
{string||DOMElement} selector
: the textarea or the input text field. You can use the selectors supported bydocument.querySelector
;{Object} options
: The object options, default undefined;
return
{Object}
the CapsLocker instance.
errors thrown
TypeError
in caseselector
is undefined, null, and empty string or a boolean.TypeError
in case that the selected DOMElement is not an instance ofHTMLTextAreaElement
orHTMLInputElement
remarks
- The
document.querySelector
is used in case of a string selector value.
The supported options are:
property | type | default value | description |
---|---|---|---|
keypress | boolean | false |
Listen for keypress events instead of keyup. Set to true to listen for keypress events instead of keyup events. |
capslock | boolean | true |
Listen for CapLock key. Set to true to listen for accepting the capslock key usage |
Capitalize a text. Transform the text from lower case to upper case, while stepping through the first letter capitalization.
Capitalization cycle:
lower case => first letter uppercase => all upper case => lower case
if capsLockPressed is true the capitalization cycle is the following:
lower case => upper case => lower case
parameters
{string} text
: the text string to capitalize;{boolean} capsLockPressed
:true
if the behaviour to apply is governed by the CapsLock key,false
otherwise;
return
{string}
the uppercase/capitalized version of the text
parameter
errors thrown
TypeError
in case text
is undefined or null
edge cases
- The capitalization of an empty string is an empty string.
MIT © Alessio Vertemati