Event

Event is the standard dom-events wrapper in RightJS. It provides a cross-browser interface to deal with common dom-events related operations, plus it has several w3c style properties

  • which - which mouse button was pressed (1, 2, 3)
  • target - target element reference
  • currentTarget - the bounding (listener) element reference
  • relatedTarget - the related element for the over and out mouse events

Methods

include, find, offset, position, preventDefault, stop, stopPropagation

top ↑include

Event.include(Object methods[, boolean dont_rewrite])

Description

Registers additional methods for the DOM events.

Example

Event.include({
myMethod: function() {....}
});

$('my_element').onClick(function(event) {
event.myMethod()
});

top ↑find

find(String css_rule) -> Element

Description

This method finds the first matching element between the element that triggered the event and the one where the event listener was attached.

Example

/*
<div id="first">
<div id="second">
<div id="third"></div>
</div>
</div>
*/


$('first').onClick(function(event) {
event.find('div#second');
});

$('third').fire('click');

top ↑offset

offset() -> {x: NNN, y: NNN}

Description

Returns the current cursor position relatively to the target element (useful for handling relatively positioned elements within the target element)

Example

$('element').onMousemove(function(event) {
$('relative-element').moveTo(event.offset());
});

top ↑position

position() -> {x: NNN, y: NNN}

Description

Returns the current event position.

Example

$('element').onMouseover(function(event) {
$('nice-looking-title').show().moveTo(event.position());
});

top ↑preventDefault

preventDefault() -> Event self

Description

Prevents the event defaults.

top ↑stop

stop() -> Event self

Description

Stops the event from further bubbling and cancels default handling.

Example

$('element').onContextmenu(function(e) {
e.stop();
$('context-menu').moveTo(e.position()).show();
});

top ↑stopPropagation

stopPropagation() -> Event self

Description

Stops the event propagation.