HEventResponder
Description
Automatic event responder. Defines what events
HControl listens to
and actions to be taken.
Event handler methods
Pre-defined event handler methods,
extend these in your subclass.
focus |
Called when the component gets focus |
blur |
Called when the component loses focus |
mouseDown |
Called when the mouse button is pushed down |
mouseUp |
Called when the mouse button is released |
mouseWheel |
Called when the mouse wheel is used |
startDrag |
Called when the mouse button is pressed (and item is draggable). |
endDrag |
Called when the mouse button is released (and item is draggable). |
drag |
Called when the mouse is moved and mouse button is down (and item is draggable). |
drop |
Called when a draggable item is released on the droppable. |
startHover |
Called when a draggable item is moved over the droppable. |
endHover |
Called when a draggable item is moved out of the droppable. |
keyDown |
Called when the user presses a key, and the control is active. |
keyUp |
Called when the user releases a key, and the control is active. |
textEnter |
Called when the user releases a key regardless if the control is active or not. |
gainedActiveStatus |
Called when the component gets activated. |
lostActiveStatus |
Called when the component gets deactivated. |
Inherits from:
Implemented by:
Constructor Method
The constructor is invoked, when a new instance of HEventResponder is created.
To create a new instance use HEventResponder.nu( ) or new HEventResponder( ).
constructor( )
Inherited from: HClass
Protected instance method, gets called when a new instance is created.
Class Methods
implement( interface )
Inherited from: HClass
Description
Copies the members of interface to
a
HClass or a class inherited from
HClass.
Usage:
Defines an interface:
// Create an interface class that calculates the area
var AreaInterface = HClass.extend({
constructor: null,
area: function() {
return this.getWidth() * this.getHeight();
}
});
// Create a class that contains the coordinates of a rectangle.
var Rectangle = HClass.extend({
constructor: function( x, y, width, height ) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
},
getWidth: function() {
return this.width;
},
getHeight: function() {
return this.height;
}
});
// Makes the Rectangle class implement the AreaInterface
Rectangle.implement( AreaInterface );
nu( )
Inherited from: HClass
Class members:
Description
nu is a protected class method.
It does the same thing as the new keyword, but it is a class method.
Parameters:
Any parameters are passed on to the
constructor method.
Usage:
Creates a class
MyClass, then creates two instances of it:
myClassInstance1 and
myClassInstance2. The end result is the same.
var MyClass = HClass.extend({
name: 'Foo',
constructor: function( param1, param2 ){
var logMsg = [ 'param1:', param1,
'param2:', param2,
'name:', this.name ];
console.log( logMsg.join(' ') );
}
});
// Construction using the new keyword:
var myClassInstance1 = new MyClass( 'one', 'two' );
// Construction using the nu method:
var myClassInstance2 = MyClass.nu( 'one', 'two' );
However, when extending in place, the benefits of the
nu method
become obvious.
// Extending in place with the new keyword:
var myExtendedClassInstance1 = new (
MyClass.extend({
name: 'Bar'
})
)( 'one', 'two' );
// The same as above, but using the nu method:
var myExtendedClassInstance2 = MyClass.extend({
name: 'Bar'
}).nu( 'one', 'two' );
extend( instance, static )
Inherited from: HClass
Description
The class method used to
extend a class.
If the member name constructor is defined as null instead of a function
block in the instance object block, the class is defined as a singleton
(single instance class).
Parameters:
instance |
The object that defines the class instance members. |
static |
The object that defines the static class members. |
Returns:
Returns the extended class object.
Usage:
var Point = HClass.extend({
constructor: function( x, y ) {
this.x = x;
this.y = y;
}
});
var Rectangle = Point.extend({
// Instance members:
constructor: function( x, y, width, height ) {
this.base( x, y );
this.width = width;
this.height = height;
},
getWidth: function() {
return this.width;
},
getHeight: function() {
return this.height;
}
},
// Class Members
{ description: "this is a Rectangle",
getClass: function() {
return this;
}
});
Instance Methods
setTextEnter( flag )
Description
Registers or releases event listening for
textEnter events
depending on the value of the flag argument.
Returns
self (HEventResponder#)
gainedActiveStatus( lastActiveControl )
Description
Default
gainedActiveStatus event responder method. Does nothing by default.
Called when the component gains active status; both focused and clicked.
Parameters
lastActiveControl |
A reference to the control that was active before this control became active. Can be null if there was no active control. |
mouseDown( x, y, isLeftButton )
Description
Default
mouseDown event responder method. Does nothing by default.
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
isLeftButton |
Boolean flag; false if the right(context) mouse button is pressed. |
startDrag( x, y )
Description
Default
startDrag event responder method. Sets internal flags by default.
This is the preferred method to
extend if you want to do something
when a
drag event starts. If you
extend, remember to call
this.base();
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
drag( x, y )
Description
Default
drag event responder method. Does nothing by default.
This is the preferred method to
extend while a
drag method is ongoing.
Called whenever the mouse cursor moves and a
drag event has been started.
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
setEnabled( flag )
Description
Enables the
HControl instance, if the enabled flag is true, and disables
it if enabled is false. A disabled
HControl won't respond events.
Component themes reflect the disabled state typically with
a dimmer appearance.
Parameters
flag |
Boolean; true enables, false disables. |
Returns
self (HEventResponder#)
setMouseMove( flag )
Description
Alternative flag setter for the
mouseMove event type. If set to true,
starts listening to
mouseDown events when the component has
focus.
Parameters
flag |
Set the mouseDown event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
setClickable( flag )
Description
Alternative flag setter for the
click event type. If set to true,
starts listening to
click events when the component has
focus.
Parameters
flag |
Set the click event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
setMouseWheel( flag )
Description
Alternative flag setter for the
mouseWheel event type. If set to true,
starts listening to
mouseWheel events when the component has
focus.
Parameters
flag |
Set the mouseWheel event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
setDraggable( flag )
Description
Registers or releases event listening for
startDrag,
drag and
endDrag -events depending on the value of the flag argument.
Parameters
flag |
Set the startDrag, drag and endDrag event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
mouseMove( x, y )
Description
Default
mouseMove event responder method. Does nothing by default.
Called whenever the mouse cursor is moved regardless if the
component is active or has
focus.
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
mouseWheel( delta )
Description
Default
mouseWheel event responder method. Does nothing by default.
Parameters
delta |
Scrolling delta, the wheel angle change. If delta is positive, wheel was scrolled up. Otherwise, it was scrolled down. |
setDoubleClick( flag )
Same as setDoubleClickable
doubleClick( x, y, isLeftButton )
Description
Default
click event responder method. Does nothing by default.
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
isLeftButton |
Boolean flag; false if the right(context) mouse button is pressed. |
endHover( obj )
Description
Default
endHover event responder method. Does nothing by default.
Extend the
endHover method, if you want to do something
when this instance is no longer the target of another instance's
drag event. Called when a dragged component instance is dragged
away from the target instance.
Parameters
obj |
The dragged component object. |
setKeyUp( flag )
Description
Registers or releases event listening for
keyUp events depending on
the value of the flag argument.
Parameters
flag |
Set the keyUp event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
focus( )
Description
Default
focus event responder method. Does nothing by default.
Called when the component gets
focus.
mouseUp( x, y, isLeftButton )
Description
Default
mouseDown event responder method. Does nothing by default.
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
isLeftButton |
Boolean flag; false if the right(context) mouse button is pressed. |
endDrag( x, y )
Description
Default
endDrag event responder method. Sets internal flags by default.
This is the preferred method to
extend if you want to do something
when a
drag event ends. If you
extend, remember to call
this.base();
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
startHover( obj )
Description
Default
startHover event responder method. Does nothing by default.
Extend the
startHover method, if you want to do something
when this instance is the target of another instance's
drag event.
Called when a dragged component instance is dragged over
the target instance.
Parameters
obj |
The dragged component object. |
textEnter( )
Description
Default
textEnter event responder method. Does nothing by default.
Extend the
textEnter method, if you want to do something
when a key is released regardless if the component is active,
has
focus or not.
Parameters
keycode |
The ascii key code of the key that was released. |
setEvents( events )
Description
The event responder interface for
HControl.
Registers the events defined by boolean properties of
the events object to the control instance. The event manager
handles the event mapping and abstraction itself.
NOTE
startDrag vs
mouseDown and
endDrag vs
mouseUp events
conflict, if both are set simultaneously.
Parameters
events |
A { event: state } Object structure, sets events based on the keys and the flag. All states are Booleans (true or false). A true state means the event listening for the event is enabled and a false state means the event listening is disabled. See the Event Types below: |
Event States
| Event State |
Description |
mouseMove |
The global mouseMove event state. The component receives this event regardless if it's focused or not. The event responder method for it is mouseMove and it receives the absolute x and y coordinates of the mouse pointer when the mouse cursor position changes. Can also be toggled separately by using the setMouseMove method. |
textEnter |
The global textEnter event state. The component receives this event regardless if it's focused or not. The event responder method for it is textEnter and it receives a every time a key on the keyboard is pressed. Can also be toggled separately by using the setTextEnter method. |
click |
The local click event state. The component receives this event only if it's focused. The event responder method for it is click and it receives the absolute x and y coordinates of the mouse pointer as well as which mouse button was used to trigger the event. Can also be toggled separately by using the setClickable method. |
mouseDown |
The local mouseDown event state. The component receives this event only if it's focused. The event responder method for it is mouseDown and it receives the absolute x and y coordinates of the mouse pointer as well as which mouse button was used to trigger the event. Can also be toggled separately by using the setMouseDown method. |
mouseUp |
The local mouseUp event state. The component receives this event only if it's focused. The event responder method for it is mouseUp and it receives the absolute x and y coordinates of the mouse pointer as well as which mouse button was used to trigger the event. Can also be toggled separately by using the setMouseUp method. |
mouseWheel |
The local mouseWheel event state. The component receives this event only if it's focused. The event responder method for it is mouseWheel and it receives the delta of the amount of the mouse scroll wheel was rolled: a floating point number, larger or smaller than 0, depending on the direction the scroll wheel was rolled. Can also be toggled separately by using the setMouseWheel method. |
draggable |
The local draggable event states. The component receives these events only if it's focused. The event responders methods are startDrag, drag and endDrag. The events receive the mouse cursor coordinates. Can also be toggled separately by using the setDraggable method. |
droppable |
The local droppable event states. The component receives this event only if another component is dragged (hovered) or dropped with the area of this component as the target. The event responders method for it are hoverStart, drop and hoverEnd. Can also be toggled separately by using the setDroppable method. |
keyDown |
The local keyDown event state. The component receives this event only if it's focused. The event responder method for it is keyDown and it receives the ascii key code whenever a keyboard key is pressed. Can also be toggled separately by using the setKeyDown method. |
keyUp |
The local keyUp event state. The component receives this event only if it's focused. The event responder method for it is keyUp and it receives the ascii key code whenever a keyboard key is released. Can also be toggled separately by using the setKeyUp method. |
Usage
HControl.new(
[0,0,100,20],
HApplication.nu()
).setEvents({
mouseUp: true,
mouseDown: true
});
Returns
self (HEventResponder#)
setMouseDown( flag )
Description
Registers or releases event listening for
mouseDown events depending on
the value of the flag argument.
Parameters
flag |
Set the mouseDown event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
keyDown( keycode )
Description
Default
keyDown event responder method. Does nothing by default.
Extend the
keyDown method, if you want to do something
when a key is pressed and the component is active.
Parameters
keycode |
The ascii key code of the key that was pressed. |
setDoubleClickable( flag )
Description
Registers or releases event listening for
doubleClick events depending on
the value of the flag argument.
Parameters
flag |
Set the doubleClick event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
drop( obj )
Description
Default
drop event responder method. Does nothing by default.
Extend the
drop method, if you want to do something
when this instance is the target of another instance's
endDrag event.
Called when a dragged component instance is dropped on the target instance.
Parameters
obj |
The dragged component object. |
blur( )
Description
Default
blur event responder method. Does nothing by default.
Called when the component loses
focus.
setMouseUp( flag )
Description
Registers or releases event listening for
mouseUp events depending on the
value of the flag argument.
Parameters
flag |
Set the mouseUp event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
setClick( flag )
Same as setClickable
lostActiveStatus( newActiveControl )
Description
Default
lostActiveStatus event responder method. Does nothing by default.
Called when the component loses active status; another component was
focused and clicked.
Parameters
newActiveControl |
A reference to the control that became the currently active control. Can be null if there is no active control. |
click( x, y, isLeftButton )
Description
Default
click event responder method. Does nothing by default.
Parameters
x |
The horizontal coordinate units (px) of the mouse cursor position. |
y |
The vertical coordinate units (px) of the mouse cursor position. |
isLeftButton |
Boolean flag; false if the right(context) mouse button is pressed. |
keyUp( keycode )
Description
Default
keyUp event responder method. Does nothing by default.
Extend the
keyUp method, if you want to do something
when a key is released and the component is active.
Parameters
keycode |
The ascii key code of the key that was released. |
invalidatePositionCache( )
Description
Forces retrieving this control's DOM element position directly rather than
using the cached version when the position is needed by
EVENT.
Child controls are invalidated recursively by
HView.
Returns
self (HEventResponder#)
setDroppable( flag )
Description
Registers or releases event listening for
startHover,
drop and
endHover -events depending on the value of the flag argument.
Parameters
Returns
self (HEventResponder#)
setKeyDown( flag )
Description
Registers or releases event listening for
keyDown events depending on the
value of the flag argument.
Parameters
flag |
Set the keyDown event listening on/off (true/false) for the component instance. |
Returns
self (HEventResponder#)
toString( )
Inherited from: HClass
Protected instance method, returns the instance represented as a String.
valueOf( )
Inherited from: HClass
Protected instance method, returns the value of an instance.
base( )
Inherited from: HClass
This method can be called from any other method to invoke that method's parent
Other Instance Members
defaultEvents = { }
Default event listeners.
prototype = { }
Inherited from: Object
Description
The
prototype member of
Object defines the instance members.
These are copied to the instance object when the
new keyword is called.