logo

/Code Snippet|v2.2.0

Class

new CustomEvents()customEvents.jsline 24

EXAMPLES
// node, commonjs
var CustomEvents = require('tui-code-snippet/customEvents/customEvents');

Static Methods

mixin(func)customEvents.jsline 54

Mixin custom events feature to specific constructor

PARAMETERS
NameTypeDescription

func

function

constructor

EXAMPLES
var CustomEvents = require('tui-code-snippet/customEvents/customEvents'); // node, commonjs

var model;
function Model() {
    this.name = '';
}
CustomEvents.mixin(Model);

model = new Model();
model.on('change', function() { this.name = 'model'; }, this);
model.fire('change');
alert(model.name); // 'model';

Instance Methods

fire(eventName)customEvents.jsline 492

Fire custom event

PARAMETERS
NameTypeDescription

eventName

string

name of custom event

getListenerLength(eventName)customEvents.jsline 563

Return a count of events registered.

PARAMETERS
NameTypeDescription

eventName

string

Custom event name

RETURNS:
{

number

} - number of event

hasListener(eventName)customEvents.jsline 554

Return whether at least one of the handlers is registered in the given
event name.

PARAMETERS
NameTypeDescription

eventName

string

Custom event name

RETURNS:
{

boolean

} - Is there at least one handler in event name?

invoke(eventName, data)customEvents.jsline 524

Fire a event and returns the result of operation 'boolean AND' with all
listener's results.

PARAMETERS
NameTypeDescription

eventName

string

Custom event name

data

*

Data for event

RETURNS:
{

boolean

} - The result of operation 'boolean AND'
EXAMPLES
var map = new Map();
map.on({
    'beforeZoom': function() {
        // It should cancel the 'zoom' event by some conditions.
        if (that.disabled && this.getState()) {
            return false;
        }
        return true;
    }
});

if (this.invoke('beforeZoom')) {    // check the result of 'beforeZoom'
    // if true,
    // doSomething
}

off(eventName, handler)customEvents.jsline 471

Unbind custom events

PARAMETERS
NameTypeDescription

eventName

stringobjectfunction

event name or context or
{name: handler} pair object or handler function

handler

function

handler function

EXAMPLES
//-- #1. Get Module --//
var CustomEvents = require('tui-code-snippet/customEvents/customEvents'); // node, commonjs

//-- #2. Use method --//
// # 2.1 off by event name
CustomEvents.off('onload');

// # 2.2 off by event name and handler
CustomEvents.off('play', handler);

// # 2.3 off by handler
CustomEvents.off(handler);

// # 2.4 off by context
CustomEvents.off(myObj);

// # 2.5 off by context and handler
CustomEvents.off(myObj, handler);

// # 2.6 off by context and event name
CustomEvents.off(myObj, 'onload');

// # 2.7 off by an Object.<string, function> that is {eventName: handler}
CustomEvents.off({
  'play': handler,
  'pause': handler2
});

// # 2.8 off the all events
CustomEvents.off();

on(eventName, handler, context)customEvents.jsline 228

Bind event handlers

PARAMETERS
NameTypeDescription

eventName

stringObject

custom
event name or an object {eventName: handler}

handler

[ functionobject ]

handler function or context

context

[ object ]

context for binding
//-- #1. Get Module --//
var CustomEvents = require('tui-code-snippet/customEvents/customEvents'); // node, commonjs

once(eventName, handler, context)customEvents.jsline 253

Bind one-shot event handlers

PARAMETERS
NameTypeDescription

eventName

stringObject

custom
event name or an object {eventName: handler}

handler

[ functionobject ]

handler function or context

context

[ object ]

context for binding

Resizable