mahsumurebe / mx-hook

Hook Plugin for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MXHook

Hook Plugin for JavaScript

1. Installation MXHook

  1. Download files !

  2. Add the code inside the body tag.

    <script src="mx-hook.js"></script>
    
  3. Start coding freely :)

2. Examples

  1. Easily create hooks.

    var h = new Hook({
       func:function() {
           console.log('Hook Example 1');
       },
       args:[],
       name:'test_hook'
    });
    
    h.run();
    
  2. Define events within options.

    var h = new Hook({
       func:function() {
    		console.log('Hook Example 2');
       },
       args:[],
       name:'test_hook'
    });
    
    h.on('run', function() {
    	console.log('Run event.');
    });
    
    h.run();
    
  3. Run Hooks.

    var h1 = new Hook({
       func:function() {
    		console.log('Hook Example 1');
       },
       args:[],
       name:'test_hook'
    });
    var h2 = new Hook({
       func:function() {
    		console.log('Hook Example 2');
       },
       args:[],
       name:'test_hook'
    });
    MXHook.run('test_hook');
    
  4. Remove Hooks

    MXHook.remove('testing_hook');
    

3. Options

Option Name Type Details
func function Function to be called
name string Hook name
args array Constant arguments to be sent to the job to be called.
initialize(hook) function The function to be executed after adding the hook.

4. Methods

Method Name Return Type Details

Hook

Hook.getCount int The number of times the hook works
Hook.trigger Hook Trigger hook event.
Hook.on Hook Bind hook event.
Hook.unbind Hook Unbind hook event.
Hook.run(['argument1', 'argumentn']) Hook Run hook.

MXHook

MXHook.add({/* Options */}) Hook Adding hook.
MXHook.remove(_/** Optional */_'hook_name') MXHook Remove hook by name. Note: If no name is sent, removes all hooks.
MXHook.run(_/** Optional */_'hook_name') Hook Run hooks by name. Note: If no name is sent, stopped all hooks.
MXHook.get('hook_name') Hook Get hooks by name.

5. Events

Event Name Details
beforerun This function is executed every time before the hook runs.
run This function is executed every time after the hook runs.
callback[ret, hook] Callback event.

6. Errors

Error Class Details
Invalid argument was sent for adding hook. HookInvalidAddArgs If a value other than object type is entered while adding the hook, you will get this error message. You can get help from the examples above when adding hooks.
Hook function not defined correctly. HookIsNotFunction The hook has to be defined as a function. The reason for encountering this error is to define a real function.

About

Hook Plugin for JavaScript

License:GNU General Public License v3.0


Languages

Language:JavaScript 64.9%Language:HTML 35.1%