Helpers - dennisvintherjensen/OpenClassrooms-FED-Enhance-an-existing-project GitHub Wiki
Description
Misc helper functions. Also adds a forEach prototype function to NodeList (copied from Array prototype) to allow for looping node lists.
Functions
window.qs(selector, scope)
: Wrapper for querySelector
Arguments
{string} selector
: CSS selector to locate{element} [scope]
: Element to scope search to - if left out the global DOM will be used
qsa(selector, scope)
: Wrapper for querySelectorAll
Arguments
{string} selector
: CSS selector to locate{element} [scope]
: Element to scope search to - if left out the global DOM will be used
window.$on(target, type, callback, useCapture)
: Wrapper for addEventListener
Arguments
{element} target
: The element to which the event listener should be assigned to{string} type
: The event to listen for{function} callback
: The function to run when the event occurs{boolean} useCapture
: Whether or not to capture the event (not allowing it to bubble upwards).
window.$delegate(target, selector, type, handler)
: Attach a handler to event for all elements that match the selector, now or in the future, based on a root element
Arguments
{element} target
: The root element in which to scope the matching{string} selector
: CSS selector{string} type
: The type of event to listen for{function} handler
: The function to run when the event occurs
window.$parent(element, tagName)
: Find the element's parent with the given tag name
Arguments
{element} element
: The root element from which to start looking{string} tagName
: The tag name to look for
Returns
{element|null}
: The first parent element that matches the tag name