Execute javascript based on classes
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
examples
lib
test
.babelrc
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
bower.json
package-lock.json
package.json

README.md

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