You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nathan boileau c0e9777968
push node_module
3 years ago
..
activeElement push node_module 3 years ago
addClass push node_module 3 years ago
addEventListener push node_module 3 years ago
animate push node_module 3 years ago
animationFrame push node_module 3 years ago
attribute push node_module 3 years ago
camelize push node_module 3 years ago
camelizeStyle push node_module 3 years ago
canUseDOM push node_module 3 years ago
childElements push node_module 3 years ago
childNodes push node_module 3 years ago
cjs push node_module 3 years ago
clear push node_module 3 years ago
closest push node_module 3 years ago
collectElements push node_module 3 years ago
collectSiblings push node_module 3 years ago
contains push node_module 3 years ago
css push node_module 3 years ago
esm push node_module 3 years ago
filterEventHandler push node_module 3 years ago
getComputedStyle push node_module 3 years ago
getScrollAccessor push node_module 3 years ago
hasClass push node_module 3 years ago
height push node_module 3 years ago
hyphenate push node_module 3 years ago
hyphenateStyle push node_module 3 years ago
insertAfter push node_module 3 years ago
isDocument push node_module 3 years ago
isInput push node_module 3 years ago
isTransform push node_module 3 years ago
isVisible push node_module 3 years ago
isWindow push node_module 3 years ago
listen push node_module 3 years ago
matches push node_module 3 years ago
nextUntil push node_module 3 years ago
offset push node_module 3 years ago
offsetParent push node_module 3 years ago
ownerDocument push node_module 3 years ago
ownerWindow push node_module 3 years ago
parents push node_module 3 years ago
position push node_module 3 years ago
prepend push node_module 3 years ago
querySelectorAll push node_module 3 years ago
remove push node_module 3 years ago
removeClass push node_module 3 years ago
removeEventListener push node_module 3 years ago
scrollLeft push node_module 3 years ago
scrollParent push node_module 3 years ago
scrollTo push node_module 3 years ago
scrollTop push node_module 3 years ago
scrollbarSize push node_module 3 years ago
siblings push node_module 3 years ago
text push node_module 3 years ago
toggleClass push node_module 3 years ago
transitionEnd push node_module 3 years ago
triggerEvent push node_module 3 years ago
width push node_module 3 years ago
LICENSE push node_module 3 years ago
README.md push node_module 3 years ago
package.json push node_module 3 years ago

README.md

dom-helpers

tiny modular DOM lib for ie9+

Install

npm i -S dom-helpers

Mostly just naive wrappers around common DOM API inconsistencies, Cross browser work is minimal and mostly taken from jQuery. This library doesn't do a lot to normalize behavior across browsers, it mostly seeks to provide a common interface, and eliminate the need to write the same damn if (ie9) statements in every project.

For example on() works in all browsers ie9+ but it uses the native event system so actual event oddities will continue to exist. If you need robust cross-browser support, use jQuery. If you are just tired of rewriting:

if (document.addEventListener)
  return (node, eventName, handler, capture) =>
    node.addEventListener(eventName, handler, capture || false)
else if (document.attachEvent)
  return (node, eventName, handler) =>
    node.attachEvent('on' + eventName, handler)

over and over again, or you need a ok getComputedStyle polyfill but don't want to include all of jQuery, use this.

dom-helpers does expect certain, polyfillable, es5 features to be present for which you can use es5-shim where needed

The real advantage to this collection is that any method can be required individually, meaning bundlers like webpack will only include the exact methods you use. This is great for environments where jQuery doesn't make sense, such as React where you only occasionally need to do direct DOM manipulation.

All methods are exported as a flat namesapce

var helpers = require('dom-helpers')
var offset = require('dom-helpers/offset')

// style is a function
require('dom-helpers/css')(node, { width: '40px' })
  • dom-helpers
    • ownerDocument(element): returns the element's document owner
    • ownerWindow(element): returns the element's document window
    • activeElement: return focused element safely
    • querySelectorAll(element, selector): optimized qsa, uses getElementBy{Id|TagName|ClassName} if it can.
    • contains(container, element)
    • height(element, useClientHeight)
    • width(element, useClientWidth)
    • matches(element, selector)
    • offset(element) -> { top: Number, left: Number, height: Number, width: Number}
    • offsetParent(element): return the parent node that the element is offset from
    • position(element, [offsetParent]: return "offset" of the node to its offsetParent, optionally you can specify the offset parent if different than the "real" one
    • scrollTop(element, [value])
    • scrollLeft(element, [value])
    • scrollParent(element)
    • addClass(element, className)
    • removeClass(element, className)
    • hasClass(element, className)
    • toggleClass(element, className)
    • style(element, propName) or style(element, objectOfPropValues)
    • getComputedStyle(element) -> getPropertyValue(name)
    • animate(node, properties, duration, easing, callback) programmatically start css transitions
    • transitionEnd(node, handler, [duration], [padding]) listens for transition end, and ensures that the handler if called even if the transition fails to fire its end event. Will attempt to read duration from the element, otherwise one can be provided
    • addEventListener(node, eventName, handler, [options]):
    • removeEventListener(node, eventName, handler, [options]):
    • listen(node, eventName, handler, [options]): wraps addEventlistener and returns a function that calls removeEventListener for you
    • filter(selector, fn): returns a function handler that only fires when the target matches or is contained in the selector ex: on(list, 'click', filter('li > a', handler))
    • requestAnimationFrame(cb) returns an ID for canceling
    • cancelAnimationFrame(id)
    • scrollbarSize([recalc]) returns the scrollbar's width size in pixels
    • scrollTo(element, [scrollParent])