new Normalizer()
A class which normalizes DOM event object to caph.event.Message object.
- Since:
-
- 2.0.0
Example
window.addEventListener('click', function(event) { var message = caph.event.Normalizer.getInstance().toMessage(event); if (message.mouse().right) { message.stopPropagation(); } });
Methods
-
<static> getInstance() → {caph.event.Normalizer}
-
Gets the singleton instance.
- Since:
-
- 2.0.0
Returns:
Example
var normalizer = caph.event.Normalizer.getInstance();
-
createFrom(message, replacement) → {caph.event.Message}
-
Creates a new message based on the given caph.event.Message object properties such as "type", "source", "related", "bubbles", "timeStamp" and "detail". If you want to replace property values, pass a key/value pair object to configure the message properties. Refer to the details in caph.event.Message constructor.
Parameters:
Name Type Argument Description message
caph.event.Message A caph.event.Message object to be based.
replacement
Object <optional>
A key/value pair object to configure the new message properties. Refer to the details in caph.event.Message constructor.
- Since:
-
- 2.0.0
Returns:
A cloned caph.event.Message object.
- Type
- caph.event.Message
Example
var message = new caph.event.Message({ type: 'test' }); message.stopPropagation(); var newMessage = caph.event.Normalizer.getInstance().createFrom(message, { detail: { message: 'The newMessage is not stop propagation.' } });
-
toMessage(event) → {caph.event.Message}
-
Converts DOM event object to caph.event.Message object.
Parameters:
Name Type Description event
Event DOM event.
- Since:
-
- 2.0.0
Returns:
- Type
- caph.event.Message
Example
caph.dom.event.add(window, 'click', function(event) { var message = caph.event.Normalizer.getInstance().toMessage(event); });