Class: H_event

H_event

Manages all DOM and custom events for the application.
Provides static methods for adding, removing, dispatching, and handling events.
Handles mouse, keyboard, touch, pen tablet, drag, drop, resize, and custom events.

Its main purpose is to permit to add multiple callbacks on one event.
To do that, inline event attributes like onclick, are transformed (except on A tag) by h.php class, as js events stored in h.e.events_listeners.

Secondary, this class unify them , to manage a simple "click", with a mouse, a pen, a touch handler etc... scripts become often so big !
What about drag&drop on a touch system and a mouse or a touch pad ? This class unify them all, for all kind of deviceS.
to switch event activation on dom element without removing it look at H_dom.disable_mouse_events and H_dom.enable_mouse_events in dom.js

take a look too to shortcut functions at the end of the class.
Used as h.libs.event or h.e.

new H_event()

events.js, line 28

Methods

staticH_event.add_event(dom_element, event_name, callback, use_capture){boolean|undefined}

events.js, line 658
Adds an event listener to a DOM element.
Handles duplicate prevention and delayed registration.
Name Type Description
dom_element HTMLElement Target element.
event_name string Event type.
callback function | string Callback function.
use_capture boolean optional Use capture phase.
Returns:
Type Description
boolean | undefined True if added, false if duplicate.

staticH_event.add_event_click(dom_element, callback, use_capture)

events.js, line 1965
Adds a click event listener to a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.
use_capture boolean optional Use capture phase.

staticH_event.add_event_click_outside(dom_element, callback, use_capture)

events.js, line 1995
Add a click outside event listener to a DOM element.
H_event.other_inside_elements is an array to save other HTMLElement to handle the click like it was inside.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.
use_capture boolean | null Use capture phase.

staticH_event.add_event_dbl_click(dom_element, callback, use_capture)

events.js, line 1975
Adds a double-click event listener to a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.
use_capture boolean optional Use capture phase.

staticH_event.add_event_delayed(dom_element, event_name, callback, use_capture, delay)

events.js, line 732
Adds an event listener with a delay.
Why a delay ? to avoid accident trigerring, if we add event on same dom_element that trigger the add_event.
Name Type Description
dom_element HTMLElement Target element.
event_name string Event type.
callback function Callback function.
use_capture boolean Use capture phase.
delay number Delay in ms.

staticH_event.add_event_key(dom_element, callback, use_capture)

events.js, line 1985
Adds a keyup event listener to a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.
use_capture boolean optional Use capture phase.

staticH_event.add_handler(list, handler)

events.js, line 218
Adds a handler to one of the global handler lists.
The list is a property of H_event holding the registered callbacks: window_on_load_handlers or window_on_resize_handlers. A handler already present is refused; a load handler registered once the window is loaded runs immediately instead of being stored.
Name Type Description
list string Name of the handler list.
handler function | string Handler function, or the name of a global function to register once it exists (a module may not be loaded yet when the name is given).

staticH_event.add_load_handler(handler)

events.js, line 272
Adds a handler to be called on window load.
If the window is already loaded, executes immediately.
Name Type Description
handler function | string Handler function.

staticH_event.add_resize_handler(handler)

events.js, line 306
Adds a handler to be called on window resize.
Name Type Description
handler function | string Handler function

staticH_event.apply_event(event_name, event, other_event)

events.js, line 746
Applies an event to all registered handlers for the event name.
Handles outside events, bubbling, and nested listeners.
Name Type Description
event_name string Event type.
event Event The event.
other_event Event optional Optional related event.

staticH_event.broadcast_event(event_name, data, from)

events.js, line 553
Broadcasts an event to all listeners.
Optionally restricts to listeners from a specific sender. if from is not specified, all elements listening to an event with the name specified in event_name will be invoked!
Name Type Description
event_name string Name of the event.
data * Data to send.
from Object optional Sender object (optional).

staticH_event.check_resize(event){boolean}

events.js, line 1370
Checks if the mouse is near a resizable border. Updates resize_data and cursor.
Name Type Description
event Event The event.
Returns:
Type Description
boolean True if resize should start.

staticH_event.confirm_gate(event_name, event){boolean}

events.js, line 923
Holds back an event that carries a data-confirm question.
A click or a change on an element owning a data-confirm attribute is stopped here, the question is asked once, and the callbacks of the event are applied only when the user agrees. Any element works this way: a plain button, a div whose click is bound in JavaScript, a select, a checkbox.
A form submit is not concerned: H_validator asks its question once the form is known to be valid, because a confirmation asked here would come before the fields are checked, and a submit sent with the Enter key produces no click at all.
The element must have a listener for the event, so a submit button that carries only data-confirm is left untouched and keeps its confirmation in H_validator.
Name Type Description
event_name string Event type.
event Event The event.
Returns:
Type Description
boolean True when the event is held back and must not be applied now.

staticH_event.confirm_revert(dom_element, event_name)

events.js, line 1004
Puts a control back on the value it was rendered with, when the user refuses the data-confirm question of a change.
The browser moves a select, a checkbox or a text field before sending the change event, so a refusal has to undo that move by hand. A file field cannot be put back: its choice is lost.
Name Type Description
dom_element HTMLElement The control carrying the question.
event_name string Event type: only a change moves a control.

staticH_event.detect_mouse_buttons(event)

events.js, line 425
Detects which mouse buttons are pressed. Updates H_event.mouse state.
Name Type Description
event MouseEvent | PointerEvent The event.

staticH_event.disable_drag(dom_element)

events.js, line 1596
Disables dragging for a DOM element.
Name Type Description
dom_element HTMLElement The element.

staticH_event.disable_drop(dom_element)

events.js, line 1876
Disables drop events on a DOM element.
Name Type Description
dom_element HTMLElement | Document The element or document.

staticH_event.disable_event_callback(event){boolean}

events.js, line 459
Prevents default event behavior.
Name Type Description
event Event The event.
Returns:
Type Description
boolean Always false to block callbacks...

staticH_event.disable_resize(dom_element)

events.js, line 1319
Disables resizing for a DOM element.
Name Type Description
dom_element HTMLElement The element.

staticH_event.disable_scroll_on_touch(event){boolean}

events.js, line 1810
Prevents scrolling on touch devices during drag/resize.
actually similar to H_event.prevent_default(), but it was not the case in the past.
so perhaps it will change again in the future...
so keeped for compatibility reason.
Name Type Description
event TouchEvent The event.
Returns:
Type Description
boolean Always false.

staticH_event.drag(event, b)

events.js, line 1660
Handles dragging of a DOM element during mouse move.
Name Type Description
event Event The event.
b boolean Unused.

staticH_event.drag_end(event)

events.js, line 1766
Ends drag operation.
Name Type Description
event Event The event.

staticH_event.drag_target(dom_element){HTMLElement|null}

events.js, line 1577
Resolves the element a mousedown has to drag.
An element carrying data-draggable is dragged when it is grabbed itself. An element carrying data-drag_anywhere (a window: H_ui_window) is dragged when a non interactive part of it is grabbed - a modal of module has no title bar, and its content covers the whole window. A form control keeps its own behaviour: a drag started on a field must not move the window.
Name Type Description
dom_element HTMLElement The mousedown target.
Returns:
Type Description
HTMLElement | null The element to drag, null if none.

staticH_event.enable_drag(dom_element, start_handler, move_handler, end_handler, avatar_handler){boolean}

events.js, line 1526
Enables dragging for a DOM element.
Sets up handlers and optional avatar to represent the moving element.
all handlers are callbacks to call at each moment of the drag& drop : start, move, end, and can be replaced by null.
the end_handler can used to replace the drop event on the target.
Name Type Description
dom_element HTMLElement The element.
start_handler function | Object Start handler or settings object.
move_handler function Move handler.
end_handler function End handler.
avatar_handler function | string Avatar handler or string.
Returns:
Type Description
boolean True if enabled.

staticH_event.enable_drop(dom_element, callback){boolean}

events.js, line 1844
Enables drop events on a DOM element.
Name Type Description
dom_element HTMLElement | Document The element or document.
callback function Drop callback.
Returns:
Type Description
boolean True if enabled.

staticH_event.enable_resize(dom_element, start_resize_handler, resize_handler, end_resize_handler, border_detection_size)

events.js, line 1300
Enables resizing for a DOM element.
By default, the border detection size is 10 px, and you can use the right and bottom border to resize.
It's better practice to display this border, and set the overflow style property of the dom element to hidden
Sets up handlers and border detection.
Name Type Default Description
dom_element HTMLElement The element.
start_resize_handler function null Start handler.
resize_handler function null Resize handler.
end_resize_handler function null End handler.
border_detection_size number 10 optional Border size in px.

staticH_event.end_global_move(event)

events.js, line 1246
Ends global move tracking for drag/resize.
Name Type Description
event Event The event.

staticH_event.end_resize(event)

events.js, line 1458
Ends resize operation.
Name Type Description
event Event The event.

staticH_event.extract_data_from_drop_event(event, filter){Object}

events.js, line 1911
Extracts data from a drop event.
Supports files, HTML, and text.
Name Type Description
event DragEvent | CustomEvent The event.
filter Array optional Types to filter.
Returns:
Type Description
Object Extracted data.

staticH_event.global_drop(event)

events.js, line 1828
Handles global drop events.
Calls the default drop callback if set.
Name Type Description
event DragEvent | CustomEvent The event.

staticH_event.global_key_down(event)

events.js, line 337
Handles global keydown events.
Updates key state and applies EVENT_KEYDOWN.
Name Type Description
event KeyboardEvent The keydown event.

staticH_event.global_key_up(event)

events.js, line 355
Handles global keyup events.
Updates key state and applies EVENT_KEYUP.
Name Type Description
event KeyboardEvent The keyup event.

staticH_event.global_mouse_down(event)

events.js, line 373
Handles global mousedown or pointerdown events.
Detects mouse buttons, initializes drag/resize, and applies EVENT_MOUSEDOWN.
Name Type Description
event MouseEvent | PointerEvent The event.

staticH_event.global_mouse_move(event)

events.js, line 1149
Handles global mouse or pointer move events.
Updates drag/resize state and triggers mouse enter/leave.
Name Type Description
event MouseEvent | PointerEvent The event.

staticH_event.global_mouse_up(event)

events.js, line 469
Handles global mouseup or pointerup events.
Detects clicks end, double clicks end, and applies EVENT_MOUSEUP.
Name Type Description
event MouseEvent | PointerEvent The event.

staticH_event.handler_event(event)

events.js, line 720
Internal event handler that applies the event to registered callbacks.
Name Type Description
event Event The event.

staticH_event.has_drag(dom_element){boolean}

events.js, line 1561
Checks if a DOM element has drag enabled.
Name Type Description
dom_element HTMLElement The element.
Returns:
Type Description
boolean True if draggable.

staticH_event.has_drop(dom_element){boolean|number}

events.js, line 1894
Checks if a DOM element has drop enabled.
Name Type Description
dom_element HTMLElement | Document The element or document.
Returns:
Type Description
boolean | number True/1 if enabled, 0 if not.

staticH_event.has_event(dom_element, event_name){boolean}

events.js, line 873
Checks if a DOM element has a listener for a specific event.
Name Type Description
dom_element HTMLElement The element.
event_name string Event type.
Returns:
Type Description
boolean True if found.

staticH_event.has_event_callback(dom_element, event_name, callback){boolean}

events.js, line 894
Checks if a DOM element has a specific callback for an event.
Name Type Description
dom_element HTMLElement The element.
event_name string Event type.
callback function Callback function.
Returns:
Type Description
boolean True if found.

staticH_event.init()

events.js, line 176
Initializes global event listeners for mouse, touch, keyboard, resize, and load events.
Detects platform and sets up appropriate handlers.

staticH_event.init_drag(dom_element)

events.js, line 1629
Initializes drag operation for a DOM element.
launched by global_mouse_down
Name Type Description
dom_element HTMLElement The element.

staticH_event.init_mouse_down_event(event)

events.js, line 435
Initializes the current mousedown event and computes offsets.
Name Type Description
event MouseEvent | PointerEvent The event.

staticH_event.init_resize(mouse_down_event){boolean}

events.js, line 1339
Initializes resize operation.
launched by global_mouse_down
Name Type Description
mouse_down_event Event The mousedown event.
Returns:
Type Description
boolean True if resize started.

staticH_event.is_resizable(dom_element){boolean}

events.js, line 1329
Checks if a DOM element is resizable.
Name Type Description
dom_element HTMLElement The element.
Returns:
Type Description
boolean True if resizable.

staticH_event.is_submit_control(dom_element){boolean}

events.js, line 980
Tells whether a click on an element submits a form, i.e. whether its question belongs to H_validator rather than to the gate.
A `
Name Type Description
dom_element HTMLElement The element.
Returns:
Type Description
boolean True when a click on it leads to the submit of a form.

staticH_event.listen_to_event(to, event_name, callback, from)

events.js, line 585
Registers a listener for an event.
Optionally restricts to events from a specific sender.
if from is not specified, all elements listening to an event with the name specified in event_name will be invoked.
Name Type Description
to Object Target object.
event_name string Name of the event.
callback function Callback function.
from Object optional Sender object (optional).

staticH_event.mouse_interacting(){boolean}

events.js, line 297
Returns true if mouse is interacting (dragging, resizing, etc).
Returns:
Type Description
boolean True if interacting.

staticH_event.prevent_default(event)

events.js, line 1283
Prevents default event behavior only.
Name Type Description
event Event The event.

staticH_event.remove_all_events(dom_element){boolean}

events.js, line 1090
Removes all event listeners from a DOM element.
Name Type Description
dom_element HTMLElement The element.
Returns:
Type Description
boolean True if removed.

staticH_event.remove_event(dom_element, event_name, callback){boolean}

events.js, line 1042
Removes a specific event listener from a DOM element.
Name Type Description
dom_element HTMLElement The element.
event_name string Event type.
callback function Callback function.
Returns:
Type Description
boolean True if removed.

staticH_event.remove_event_click(dom_element, callback)

events.js, line 2006
Removes a click event listener from a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.

staticH_event.remove_event_click_outside(dom_element, callback)

events.js, line 2033
Removes a click outside event listener from a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.

staticH_event.remove_event_dbl_click(dom_element, callback)

events.js, line 2015
Removes a double-click event listener from a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.

staticH_event.remove_event_key(dom_element, callback)

events.js, line 2024
Removes a keyup event listener from a DOM element.
Name Type Description
dom_element HTMLElement The element.
callback function Callback function.

staticH_event.remove_handler(list, handler)

events.js, line 243
Removes a handler from one of the global handler lists.
Name Type Description
list string Name of the handler list.
handler function Handler to remove.

staticH_event.remove_load_handler(handler)

events.js, line 280
Removes a handler from the window load handlers list.
Name Type Description
handler function Handler to remove.

staticH_event.remove_resize_handler(handler)

events.js, line 315
Removes a handler from the window resize handlers list.
Name Type Description
handler function Handler to remove.

staticH_event.resize(event)

events.js, line 1470
Handles resizing of a DOM element during mouse move.
Name Type Description
event Event The event.

staticH_event.run_handlers(list)

events.js, line 256
Executes every handler of one of the global handler lists.
Name Type Description
list string Name of the handler list.

staticH_event.send_event(dom_element, type, data, bubbles, cancelable)

events.js, line 617
Dispatches a DOM or custom event on an element.
Name Type Default Description
dom_element HTMLElement Target element.
type string Event type.
data * optional Event detail data.
bubbles boolean true optional Whether the event bubbles.
cancelable boolean true optional Whether the event is cancelable.

staticH_event.send_event_click(dom_element, data, bubbles, cancelable)

events.js, line 2047
Dispatches a click event on a DOM element.
Name Type Description
dom_element HTMLElement The element.
data * optional Event detail data.
bubbles boolean optional Whether the event bubbles.
cancelable boolean optional Whether the event is cancelable.

staticH_event.send_event_click_outside(dom_element, data, bubbles, cancelable)

events.js, line 2080
Dispatches a click outside event on a DOM element.
Name Type Description
dom_element HTMLElement The element.
data * optional Event detail data.
bubbles boolean optional Whether the event bubbles.
cancelable boolean optional Whether the event is cancelable.

staticH_event.send_event_dbl_click(dom_element, data, bubbles, cancelable)

events.js, line 2058
Dispatches a double-click event on a DOM element.
Name Type Description
dom_element HTMLElement The element.
data * optional Event detail data.
bubbles boolean optional Whether the event bubbles.
cancelable boolean optional Whether the event is cancelable.

staticH_event.send_event_key(dom_element, data, bubbles, cancelable)

events.js, line 2069
Dispatches a keyup event on a DOM element.
Name Type Description
dom_element HTMLElement The element.
data * optional Event detail data.
bubbles boolean optional Whether the event bubbles.
cancelable boolean optional Whether the event is cancelable.

staticH_event.set_default_drop_callback(callback)

events.js, line 1820
Sets the default drop callback for drag-and-drop.
Name Type Description
callback function Callback function.

staticH_event.set_drag_area(dom_element, area_dom_element, padding)

events.js, line 1606
Sets a drag area dom element for a DOM element.
Name Type Default Description
dom_element HTMLElement The element.
area_dom_element HTMLElement Area element.
padding number 0 optional Padding in px.

staticH_event.start_global_move(dom_element, move_handler, end_move_handler)

events.js, line 1129
Starts tracking global mouse/touch movement for drag/resize.
Name Type Description
dom_element HTMLElement Target element.
move_handler function Move handler.
end_move_handler function End handler.

staticH_event.stop_event(event){boolean}

events.js, line 1262
Stops event propagation and default behavior.
Name Type Description
event Event The event.
Returns:
Type Description
boolean Always false.

staticH_event.unset_drag_area(dom_element)

events.js, line 1618
Unsets the drag area for a DOM element.
Name Type Description
dom_element HTMLElement The element.

staticH_event.window_load(event)

events.js, line 289
Executes all registered window load handlers.
Sets window_loaded to true.
Name Type Description
event Event The load event.

staticH_event.window_resize(event)

events.js, line 324
Executes all registered window resize handlers.
Also marks the body rect as dirty.
Name Type Description
event Event The resize event.