Add origEvent Property to Expose Original DOM Events
#232
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
origEventProperty to Expose Original DOM Events🎯 Overview
This PR adds access to the original DOM events (MouseEvent, TouchEvent, PointerEvent) that trigger joystick interactions. Developers can now access native event properties like
button,buttons,clientX,clientY,pressure,force, and other event-specific data.🚀 Motivation
Many developers need access to the original DOM events to:
Previously, this information was lost during event processing, limiting the library's flexibility for advanced use cases.
📋 Changes Made
Core Implementation (
src/collection.js)nipple.origEvent = evtin all event processing functions:processOnStart()- Stores original event when joystick interaction beginsprocessOnMove()- Updates original event during movement (multiple locations for different code paths)processOnEnd()- Stores original event when interaction endsorigEvent: nipple.origEventto move event data object to maintain consistency with existing data structureTypeScript Definitions (
types/index.d.ts)origEvent: EventtoJoystickOutputDatainterfaceorigEvent: EventtoJoystickinterfaceJoystickOutputData | Joystickto reflect actual implementation where:JoystickOutputDataobjectsJoystickinstancesExample Updates
codepen-demo.htmlpressure event handler to work with new data structure🔧 Usage Examples
Accessing Original Events
TypeScript Usage
🧪 Testing
📊 Impact
🔍 Implementation Details
The implementation stores the original DOM event in the
nippleinstance and ensures it's available in all event callbacks:nippleinstance → access vianipple.origEventdata.origEvent(copied fromnipple.origEvent)This approach maintains consistency with the existing event system while providing access to the original event data.
Files Changed:
src/collection.js- Core implementation (+10 lines)types/index.d.ts- TypeScript definitions (+6 lines)example/*.html- Context menu prevention for better testing (+20 lines total)Total: +36 lines added, minimal changes for maximum functionality gain.