/phrases

A way to type defined phrases anywhere to fire off callback functions.

Primary LanguageJavaScript

phrases

A way to type defined phrases anywhere to fire off callback functions. Type anywhere except input fields to fire off a function!

Using

Requre the source script in your HTML file.

<script src="js/phrases.js"></script>

Then create a new Phrases object

phrase = new Phrases();

You can add phrases one by one with an array containing the string and the function to execute...

phrase.addPhrase(['lala', function(){console.log('la-la-la')}]);

or as an array containing arrays of strings and functions to execute...

phrase.addPhrases([
  ['login', function(){openModalForLogin()}], 
  ['bottom', function(){window.scrollTo(0, document.body.scrollHeight)}],
  ['alert', function(){window.alert('Hi!')}],
  ]);

and then start watching on keypress!

phrase.checkAllPhrases();

Oh, and these methods are chainable!

  phrase = new Phrases().addPhrases([
  ['login', function(){openModalForLogin()}], 
  ['bottom', function(){window.scrollTo(0, document.body.scrollHeight)}],
  ['alert', function(){window.alert('Hi!')}],
  ]).checkAllPhrases();

#API

.addPhrase([name, function])

Add phrase to the list to be checked.

name

String containing what you would like to be typed.

function

A function containing the code you would like executed once run.

.addPhrases(array)

Add multiple phrases to the list to be checked.

array

An array containing arrays of names and functions.

.checkAllPhrases()

Start listening for typing.