Skip to content

tormjens/dumdum-js

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Dumdum Js

DumDum is a condtional JavaScript executor, or a router if you will. Routes are executed based on class names on the body element. DumDum has no package dependencies, but relies on MutationObservers. Although it provides a light replacement for cases where MutationObservers are not availiable.

NPM version NPM downloads Build status Test coverage

Installation

npm install dumdum-js --save

Usage

CommonJs:

var DumDum = require('dumdum-js')

ES6:

import DumDum from 'dumdum-js'

Using it in your javascript:

new DumDum({
  common: function() {
    // Generic JS here.
  },
  home: function() {
    // JS for pages containing the 'home' class
  },
  nav_ready: function() {
    // Will be executed as soon as the 'nav-ready' class is added to the body.
  }
})

This will enable DumDum to watch for changes to your body element.

If you need to watch for changes on different element you can pass it as the second argument:

new DumDum({
  ...
}, document.querySelector('#awesome-div'))

License

MIT license

About

Execute javascript based on classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published