GithubHelp home page GithubHelp logo

natividadklein / caps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from avvertix/caps

0.0 1.0 0.0 136 KB

Why aren't you able to caps/uncap text by highlighting everything and hitting caps lock

JavaScript 95.54% HTML 4.46%

caps's Introduction

Caps

Make text uppercase or lower case with the caps lock key

Getting Started

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.

Current supported Browsers

Chrome (latest), Firefox (latest), Edge (on Win10 build 10240)

API

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.

Caps.attach(selector: string||DOMElement, options: Object)

Attaches a CapsLocker instance to a DOMElement.

parameters

  • {string||DOMElement} selector: the textarea or the input text field. You can use the selectors supported by document.querySelector;
  • {Object} options: The object options, default undefined;

return

{Object} the CapsLocker instance.

errors thrown

  • TypeError in case selector is undefined, null, and empty string or a boolean.
  • TypeError in case that the selected DOMElement is not an instance of HTMLTextAreaElement or HTMLInputElement

remarks

  • The document.querySelector is used in case of a string selector value.

Current supported options

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

Caps.capitalize(text: string, capsLockPressed: boolean)

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.

License

MIT © Alessio Vertemati

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.