Helpers
The components are built from small functions: finding elements, classes, events, styles, and reading options. They are exported too, so your own code can use the same ones.
They are in the module build only. The <script> build defines the components, as ML.Modal and the others, and
nothing else.
import { $q, addClass, evt } from '@mikewgd/myjs';
// Or only the helpers, from the folder that has nothing else in it:import { ready } from '@mikewgd/myjs/core';
ready(() => { evt($q('#open'), 'click', () => addClass($q('#panel'), 'open'));});Importing the helpers does nothing by itself: they never touch window or document until you call them. Each one
is documented, with examples, in the API reference under Functions.
| Group | Functions |
|---|---|
| Finding | $q, $qAll, findParent |
| Classes | hasClass, addClass, removeClass, toggleClass |
| Events | evt, removeEvt, isBound, clicked, customEventTrigger, triggerEvent, ready, Events |
| Elements | create, clean, assertElement |
| Attributes | data, getAttr |
| Size | windowDimen, position, dimens, collides |
| Styles | getStyle, setStyles, cssTransition, cssTransform |
Values
Section titled “Values”| Group | Functions |
|---|---|
| Types | isUndef, isString, isBool, isNum |
| Converting | bool, nodeArr |
| Options | toInt, toBool, clamp, extend, parObj (data-* attributes like width:700:align:top) |
| URLs | urlParams |
- Everything here works in IE10. Where a browser function is missing there, the helper does the work:
createanddatainstead ofdataset,nodeArrinstead ofArray.from,triggerEventinstead ofnew Event(). evtandremoveEvtkeep a list of the listeners they add, which is whatisBoundandEventsread. A listener added withaddEventListeneris not in it.isUndef,isNumandisBoolare lenient on purpose: options that come from adata-*attribute are strings. They are not type guards for that reason.
Enhancements
Section titled “Enhancements”A checklist. An unticked item is not built, and not promised: it says what is missing today. A ticked item has been built.
- All the
data-*attributes.data(element)with no name could give them all, as an object. Today a name is required. -
debounceandthrottle. Breakpoints has its own debounce of the resize event. -
uid(prefix). Tooltip counts its own ids, and the accessibility work will need more of them. -
closestandmatches. IE10 has neither, andfindParentonly takes one tag name and one class. - Delegated events.
delegate(root, selector, type, callback). - Focus helpers. Keeping the focus in an element, and giving it back. Modal and Dropdown need both.
-
lockScroll. Modal stops the page from scrolling with a class on<html>. -
prefersReducedMotion(). For Animate and Carousel. - Both spellings.
getStyletakesmargin-rightandsetStylestakesmarginLeft. Accepting both in both would remove a trap. -
isNumthat is strict.isNum(''),isNum(null)andisNum([])aretrue.