Keasy
Method Summary
Public Methods | ||
public |
Sets the amount of time and the unit of time this Keasy instance should wait until triggering the callback set in Keasy.then |
|
public |
Binds a String representing a set of keys to this Keasy instance limiting when the callback Function passed to Keasy.then gets called. |
|
public |
off() Removes the current listener from the EventTarget passed to Keasy.on. |
|
public |
on(eventTarget: EventTarget): Keasy Binds an EventTarget to this Keasy instance. |
|
public |
Binds a callback Function to this Keasy intsance. |
|
public |
Public Methods
public after(amount: Number, unit: String): Keasy source
Sets the amount of time and the unit of time this Keasy instance should wait until triggering the callback set in Keasy.then
Params:
Name | Type | Attribute | Description |
amount | Number | The amount of time Keasy waits until the EventTarget passed to Keasy.on stops firing KeyBoardEvents. |
|
unit | String |
|
This parameter is optional. If Keasy.after(amount,unit) is not passed a unit it defaults to milliseconds. |
Throw:
Example:
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(600);
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(60000, Keasy.milliseconds);
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(60, Keasy.seconds);
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(1, Keasy.minutes);
public is(keyString: String): Keasy source
Binds a String representing a set of keys to this Keasy instance limiting when the callback Function passed to Keasy.then gets called. The keys in the {String} that is passed should be divided by a "+" character.
Params:
Name | Type | Attribute | Description |
keyString | String |
Example:
Keasy.when(Keasy.eventType).on(target).is(Keasy.ctrl+"+k").then(function(){console.warn("Event was CTRL+K")})
public on(eventTarget: EventTarget): Keasy source
Binds an EventTarget to this Keasy instance.
Params:
Name | Type | Attribute | Description |
eventTarget | EventTarget | The targeted EventTarget Keasy should target for KeyBoardEvent. |
Throw:
If Keasy.on is not passed a valid EventTarget it will throw a TypeError. |
Example:
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn("Keasy-peasy!")});
Keasy.when(Keasy.down).on($('#fancyId')[0]).then(function(){console.warn("Keasy-peasy!")});
public then(callback: Function): Keasy source
Binds a callback Function to this Keasy intsance. Not calling Keasy.then means Keasy produces no output. Keasy still catches events of the type passed to Keasy.when. Meaning you can call Keasy.then at another point in your code. See Example 3 for details.
Params:
Name | Type | Attribute | Description |
callback | Function | The Function Keasy will call after it has caught a KeyBoardEvent. |
Example:
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')});
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){document.getElementById('pretty').innterText = "Thank you!!"});
var keasy = Keasy.when(Keasy.down).on(document.getElementById('fancyId'));
document.getElementById('pretty').innerText = "Waiting is so boring..";
function delayedThen(){
document.getElementById('pretty').innerText = "Ok I'm fed up with waiting.. For the love of God please type something!";
keasy.then(function(){
document.getElementById('pretty').innerText = "Thank you!!";
});
};
window.setTimeout(delayedThen, 5000);
public when(eventType: String): Keasy source
Params:
Name | Type | Attribute | Description |
eventType | String |
|
This parameter is optional. If Keasy.when(eventType) is not passed an eventType it defaults to 'keydown'. Passing an eventType is advisable for readability purposes. |
Example:
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn("Keasy-peasy!")});
Keasy.when('keydown').on(document.getElementById('fancyId')).then(function(){console.warn("Keasy-peasy!")});