flash-document-title

flash a notification message in the tab title area

OTHER License

Downloads
1.1K
Stars
3
Committers
2

flash-document-title

Flash a notification message in the tab title area.

If the tab is hidden, this module prepends the given argument before the current document title. Each second, it animates by prepending and removing a ! character. Once the tab is no longer hidden, the document title is reset.

Install

npm install flash-document-title

Usage

var flashDocumentTitle = require('flash-document-title')

flashDocumentTitle('💬 someone said something!')

Easily use it in choo views by creating a store that adds an event listener:

var app = choo()
app.use(flashStore)
function flashStore (state, emitter) {
  emitter.on('notify', flashDocumentTitle)
}

app.route('/', function (state, emit) {
  return html`
    <body>
      <button onclick=${onclick}>Notify me soon</button>
    </body>
  `
  function onclick () {
    setTimeout(function () { emit('notify', 'NOTIFICATION TIME!') }, 5000)
  }
})
app.mount('body')

License

Apache-2.0