EventsManager.js
JavaScript class inherit to add an events management
Follow the project
Contribute
To contribute to the project, read the Contribution guidelines. After that, you can create your own Pull Requests (PR) and submit them here.
Installation
Copy the events-manager.js file into your project and include it in your HTML page. You can use it at anytime on your web page.
Manage your objects events
In your object declaration, call EventsManager to get access of the features:
{ // inherit EventsManager features EventsManager; } var myClass = ; // Register an event with a name and a function// the function always gives the args variable object// you can add a priority (optional) in the third argument like:// 'low', 'normal' (default), 'high' or and integer valuemyClass; // If your stack of events needs to wait until your event have// completed its async execution, use "onAsync"// This method provide a "callback" functionmyClass; // For more safety the method "onSafe" deletes// automatically the same event if it is already registeredforvar i = 0; i < 10; i++ myClass; // The same way for "onAsync" myClass; // You can register a special event to be fired on every .fire()// You have to use a namespace before for safety// .onAnythingSafe() is also accessiblemyClass; // Fire an event trigger all of the registered events// The second (optionnal) argument is the args variable// The third (optionnal) argument is the callback methodmyClass; // To remove an event from the stack, use .off() with the exact// same function on itmyClass; // To remove an onAnything() eventmyClass; // To remove all registered eventsmyClass; // Events can use a namespace to be registered by feature// They works in the same way as traditionnal eventmyClass; // you can remove all events from namespace registeredmyClass; // many events can be used in the same call with a space separationmyClass;