A small script / plugin to fire a callback after a sequence of characters is typed.
License is MIT, do with it what you want. (See the file LICENSE.)
- jQuery
- Vanilla / plain old JavaScript (no external dependencies)
Accepts three options:
sequence
[ARRAY] an array with either key codes or a string with special keys such as ENTER;enter
[BOOL] if the enter key needs to be pressed at the end. Default: false;callback
[FUNCTION] the JS function that needs to be called when the sequence is completed.once
[BOOL OR STRING]true
if only one time the sequence can be typed;false
for multiple times (default);'depends'
looks at the return of the callback function: if true, the sequence can't be typed again.
$(window).typesequence({
sequence: ['p', 'a', 's', 's', 'w', 'o', 'r', 'd'],
enter: true,
callback: function(){
alert('Foo');
}
});
See also the source of demo-jquery.html
.
Accepts three options:
elm
[HTML Element Object] the element for binding the event to. Defaults towindow
;sequence
[ARRAY] an array with either key codes or a string with special keys such as ENTER;enter
[BOOL] if the enter key needs to be pressed at the end. Default: false;callback
[FUNCTION] the JS function that needs to be called when the sequence is completed.once
[BOOL OR STRING]true
if only one time the sequence can be typed;false
for multiple times (default);'depends'
looks at the return of the callback function: if true, the sequence can't be typed again.
typesequence({
sequence: ['p', 'a', 's', 's', 'w', 'o', 'r', 'd'],
enter: true,
callback: function(){
alert('Foo');
}
});
See also the source of demo-vanilla.html
.