• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Non-dom-event way to catch nodes showing up. And it uses selectors.

insertionQuery

Non-dom-event way to catch nodes showing up. And it uses selectors.

It's not just for wider browser support, It can be better than DOMMutationObserver for certain things.

Why?

  • Because DOM Events slow down the browser and insertionQuery doesn't
  • Because DOM Mutation Observer has less browser support than insertionQuery
  • Because with insertionQuery you can filter DOM changes using selectors without performance overhead!

Widespread support!

IE10+ and mostly anything else (including mobile)

Details: http://caniuse.com/#feat=css-animation

Installation

npm install insertion-query

or just download the insQ.min.js file.

Basic usage

insertionQ('selector').every(function(element){
	//callback
});

Runs the callback whenever an element matching the selector is created in the document. This means it handles DOM insertions of new nodes.

Changing an existing element to match the selector won't run the callback. Showing an element that was not displayed before won't run the callback. You can disable preventing those situations with configuration option insertionQ.config({ strictlyNew:false }), but it's not recommended.

Insertion summary

insertionQ('selector').summary(function(arrayOfInsertedNodes){
	//callback
});

Runs the callback with an array of newly inserted nodes that contain element(s) matching the selector. For multiple nodes matching the selector, if they were inserted in a wrapper, the wrapper will be returned in the array. The array will contain the smallest set of nodes containing all the changes that happened to document's body.

Config options

You can change insertionQuery options by calling the config method:

insertionQ.config({
    strictlyNew : true,
    timeout : 20,
    addImportant: false
});
  • strictlyNew Keep track of nodes that existed at the moment of defining a new insertionQuery. Defaults to true.
  • timeout Time in miliseconds to wait before insertionQuery starts listening to events. If DOM already contained elements matching the selector, animation events will be triggered and there's some latency. Defaults to 20. 20ms was safe in testing, you can change it to 0 if you know what you're doing. (or if you don't mind getting events from existing nodes matching the selector)
  • addImportant - Specifies whether to add !important to animation declarations. Defaults to false.

Technical notes:

  • run after DOM is ready or you'll get all the callbacks from HTML elements there. (thank you capt. Obvious)
  • the implementation is based on CSS animations NOT DOM events. So no consequences for performance.
  • because it's done with CSS you get the selectors for free, no javascript work is done matching that, not even a querySelector call
  • to make sure you won't get calls from elements that are there, the callbacks start working some miliseconds after you call insertionQ, so if you add elements in the same function call that you initiated insertionQuery, you won't get callbacks. This can be changed in config.
  • it actually takes a few miliseconds before the callback runs after element is added (I measured upto 30ms in Firefox)

More Repositories

1

xhr

A small xhr wrapper
JavaScript
804
star
2

blocked-at

Detects node eventloop block and reports where it started
JavaScript
319
star
3

npm-audit-resolver

JavaScript
121
star
4

node-example-flamegraph

Shell
66
star
5

can-i-ignore-scripts

JavaScript
56
star
6

debugging-aid

Experimental tools for debugging Node.js apps without pausing
JavaScript
54
star
7

builder4impress

A tool to build slides in impress.js in a WYSIWYG manner
JavaScript
36
star
8

node-diagnostics-howtos

23
star
9

handsfreeyoutube

no hands and no eyes youtube experience
JavaScript
23
star
10

backbone-redux-migrator

Lets Backbone and Redux apps coexist, so you don't have to rewrite everything at once
JavaScript
23
star
11

https-proxy-cli

One command to run a local https server proxying to local http
JavaScript
20
star
12

naughty-images

SVG Images with XSS in them
C
17
star
13

safe-memory-cache

Secure and size-limited in-memory cache for node.js
JavaScript
14
star
14

node-example-heapdump

JavaScript
14
star
15

js-training-examples

Examples for JS trainings
JavaScript
13
star
16

CSP-exercise

JavaScript
12
star
17

strongly-typed

Strongly typed javascript objects, self-validating, detailed error reports
JavaScript
11
star
18

aframe-point-component

implements a-point based on THREE.js point object
JavaScript
11
star
19

naugtur.github.com

HTML
9
star
20

overlord.js

Mediator pattern taken to the limits. Can do more than just PubSub
JavaScript
9
star
21

secure-dependencies

Creates a tarball of your app dependencies checked with node security platform
JavaScript
8
star
22

lavalab

JavaScript
8
star
23

google-pubsub-mock

Transparently overrides @googlecloud/pub-sub for local testing
JavaScript
8
star
24

ripper

Ripper.js - copy fragments of DOM and insert to another document preserving the CSS styles of elements
JavaScript
8
star
25

jQuery-Mobile-dictionary

Community jquerymobile documentation in a handy form
JavaScript
8
star
26

meetjs.pl

Official meet.js website
TypeScript
5
star
27

node-examples

examples for node trainings
HTML
4
star
28

axons.js

A communication channel you always wanted instead of pub-sub
JavaScript
4
star
29

extendable-module

Extendable Revealing Module - lets you extend the private parts [ seriously ;) ]
JavaScript
4
star
30

research

Rabbit-holes and wild-goose chases.
JavaScript
3
star
31

git-livecoding

a tool to show commits from history as if they were about to be made
Shell
3
star
32

promise-blocked

Detect which function blocks your eventloop
JavaScript
3
star
33

human-redux-reactor

JavaScript
3
star
34

transitionrunner

tiny bit of javascript enabling CSS-defined animations with fallback for older browsers
JavaScript
3
star
35

csp-report-lite

JavaScript
3
star
36

selfexplanatory.js

Make your functions and methods self-explanatory with this simple wrapper
JavaScript
3
star
37

request-dependency

Requesting dependencies instead of DI
JavaScript
2
star
38

selfaware

A bind function for all the methods at once
JavaScript
2
star
39

package-firewall

An experimental package network access control tool
JavaScript
2
star
40

audit-resolve-core

Core modules for audit-resolve.json file and logic of its processing
JavaScript
1
star
41

js-memory-demo

Simple tests demonstrating memory impact of certain bits of code
JavaScript
1
star
42

alphabet-game

HTML
1
star
43

training-notes

HTML
1
star
44

podcastmaker-cli

a pile of bash tricks for unattended audio editing
Shell
1
star
45

node-example-websec

Example app for learning websecurity fundamentals
HTML
1
star
46

redux-request-generator

no-boilerplate http requests from redux apps
JavaScript
1
star
47

i-run-code-from-the-internet

1
star
48

debugging-tools-livecoding

1
star
49

bootstrap-prototyping

tiny introduction to prototyping with bootstrap - for UX designers
CSS
1
star
50

aframe-livereload-image

JavaScript
1
star