Clones events from one object to another bean.clone() is a method for cloning events from one DOM element or object to another. https://github.com/fat/bean#clone
Accepts
destElement
An HTML DOM element or any JavaScript Object to copy events to
srcElement
An HTML DOM element or any JavaScript Object to copy events from
eventType
An Event (or multiple events, space separated) to clone
Clone events from an element to other
Code
.element(ev)
method
Gets the event's target element.
Accepts
ev
Event object
Gets the event's element target (Find the element clicked)
Code
.findElement(ev, elmTagName, [force])
method
Find closest ancestor element by tag name related to the event target. Navigate up the DOM tree, looking for a tag with the name elmTagName.
If such tag is not found, document is returned.
Accepts
ev
Event object
elmTagName
Tag name to find
force
falseFlag to skip returning `document` and to return `false` instead.
Finds closest ancestor element by tag where the event occurs
Receives the event object as a parameter. If you're manually firing custom events, check it's eventName property to make sure you're handling the right event.
useCapture
Flag to change event listening from bubbling to capture.
Attaches an event to a selector or array of elements.
Accepts
elements
Array of elements which are going to be observed. A selector is acceptable too.
eventName
Event name
callBack
Receives the event object as a parameter. If you're manually firing custom events, check it's eventName property to make sure you're handling the right event.
useCapture
Flag change event listening from bubbling to capture.
Receives the event object as a parameter. If you're manually firing custom events, check it's eventName property to make sure you're handling the right event.
useCapture
Flag to change event listening from bubbling to capture.
Code
.off(element, eventType, [handler])
method
Removes event handlers. bean.off() is how you get rid of handlers once you no longer want them active. It's also a good idea to call off on elements before you remove them from your DOM; this gives Bean a chance to clean up some things and prevents memory leaks. https://github.com/fat/bean#off
Accepts
element
An HTML DOM element or any JavaScript Object
eventType
An Event (or multiple events, space separated) to remove
handler
The specific callback function to remove
Works like .observe() but can be used to add more event types
Alias for on but will only be executed once. bean.one() is an alias for bean.on() except that the handler will only be executed once and then removed for the event type(s). https://github.com/fat/bean#one
Accepts
element
An HTML DOM element or any JavaScript Object
eventType
An Event (or multiple events, space separated) to listen to
selector
A CSS DOM Element selector string to bind the listener to child elements matching the selector
handler
The callback function
args...
Additional arguments to pass to the callback function when triggered
Code
.pointer(ev)
method
Gets the pointer's coordinates from the event object.
Accepts
ev
Event object
Code
.pointerX(ev)
method
Gets the pointer's X coordinate.
Accepts
ev
Event object
.pointerY(ev)
method
Gets the pointer's Y coordinate.
Accepts
ev
Event object
.relatedTarget(ev)
method
Gets the event's related target element.
Accepts
ev
event object
Gets the event's related target (Find the element leaved before enter in an element)
Set to true if the event was being observed with useCapture set to true as well.
Works like .observe() but can be used to add more event types
Code
.stopPropagation(event)
method
Stops event propagation.
Accepts
event
Event handle
Code
.throttle(func, [wait], [options])
method
Creates a throttled version of a function. Returns a function which calls func, waiting at least wait milliseconds between calls. This is useful for events such as scroll or resize, which can be triggered too many times per second, slowing down the browser with needless function calls.
note: This does not delay the first function call to the function.
Accepts
func
Function to call. Arguments and context are both passed.
wait
0Milliseconds to wait between calls.
options
{}Options object, containing:
options.preventDefault
falseWhether to call preventDefault() on events received here. Use this to throttle mousemove events which you also want to preventDefault() because throttle will not call your function all the time so you don't get a chance to preventDefault() all the events, altough you might need to.
options.bind
The throttled function is bound to this context. Otherwise, it will use whatever `this` it gets. Just a shorthand of also calling Ink.bind(context, func) on the function after throttling it.