Skip to content

A bundle of different js tools that attach themselves to other libraries.

License

Notifications You must be signed in to change notification settings

tkellehe/utils.js

Repository files navigation

utils.js

A bundle of different js tools that attach themselves to other libraries.

Each tool is created with three different files.

\<tool\>.js => Contains comments describing the design that went into creating the tool's code implementation.

````<tool>.min.js``` => A minified version of the tool, but still keeps all object names such that when debugging can view exactly what is breaking.

\<tool\>.compressed.js => Using JScompress to compress the tool down even more by removing all variable names down to a single character.

Note: No variable names does not mean that the tool's name is removed, just the underlying object and functions used to create those objects' names were changed.



Current Tools

The current tools being worked on are:


###onlistener.js

onlistener.js

onlistener.js provides a simple way to make objects have event listener capabilities. This allows for generating more complex events for components.

// The object to attach to.
var eventHandler = {};
// Adds the functions addEventListener, removeEventListener, and onevent to the object (if provided).
var eventInfo = onlistener(eventHandler);
// To add events, by not providing an eventType it will create its own with the name of the event.
eventInfo = onlistener(eventHandler, "event");
console.log(eventInfo.eventType); // => function eventEvent() { ... }
// Now can add an event and trigger it!
function foo(event) { console.log(event) }
eventHandler.addEventListener("event", foo);
eventHandler.onevent(); // => displays and eventEvent object.
// Then can remove the function.
eventHandler.removeEventListener("event", foo);
eventHandler.onevent(); // => No events are invoked.

* dependencies *

onlistener.js relies on simplearray.js which is a basic array class used internally.

simplearray.js [2.54 KB]

simplearray.compressed.js [1.02 KB]


###keys.js

keys.js

keys.js provides a simple low-level interface for keyboard events. The concept is to create objects that manage an individual connection to a particular key.

// Get the object to listen to.
var element = document.getElementById("element");
// Creates the object that listens to the "any" key.
var any = keys("any", element);
// Attaches the Key instance to the object then adds an onkeydown event.
any.attach().on("keydown",function(){ console.log("down") });
// When done, just detach!
any.detach();

The onkeydown event is different than the usual style where it is called repeatedly. This event is only called when the state of the key transitions from up to down (which makes more sense to me). Once that state is called, the normal onkeydown kicks in with the onkeypressed event.

* dependencies *

keys.js relies on simplearray.js which is a basic array class used internally.

simplearray.js [2.54 KB]

simplearray.compressed.js [1.02 KB]

keys.js also relies on onlistener.js for making objects have event listeners.

onlistener.js

About

A bundle of different js tools that attach themselves to other libraries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published