A way to type defined phrases anywhere to fire off callback functions. Type anywhere except input fields to fire off a function!
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
Add phrase to the list to be checked. String containing what you would like to be typed. A function containing the code you would like executed once run. Add multiple phrases to the list to be checked. An array containing arrays of names and functions. Start listening for typing.