Skip to content

Notification

fapnip edited this page Jan 1, 2021 · 12 revisions

Create and display a Notification

Example:

// Create and display new Notification instance
var myNotification = new Notification({
  title: "Title",
  id: "myNotification",
  timerDuration: "10s",
  buttonLabel: "The Best Button",
  onClick: function () {
    pages.goto('the-best-page')
  },
  onTimeout: function () {
    new Say({label: "You ran out of time."})
  }
})
// Change notification title in 1.5 seconds.
setTimeout(function() {myNotification.setTitle('A better Title')}, 1500)

Notification

Constructor Options

id

Optional String. Id to use with Notification.get(id)

title

Optional String. HTML (xss filtered) to display in the bubble. No title if falsy.

timerDuration

Optional String or Number. (Required for onTimeout) If number, number of ms for timer to run. If string, '1s' = 1 second, '1m' one minute, etc.

onTimeout

Optional Function. Called when timer is complete. Notification is removed.

buttonLabel

Optional String. HTML (xss filtered) to display in the button. No button if falsy.

onClick

Optional Function. Called when button is clicked. Notification is removed.

ready

Optional Function. Called when notification has been rendered and is ready. Passes notification's abstracted HTMLElement to function.

Example

var myNotification = new Notification({
  title: 'A title',
  ready: function(e) {
    e.innerHTML = '<div>I will replace everything in this notification.</div>'
  }
})

Constructor Methods

Notification.getAll()

Return array of all active notification ids

Notification.get(string)

Return notification instance for given id

Instance Methods

remove()

Remove notification. Do not run onTimeout or onClick.

getId()

Return id for given notification instance

setButtonLabel(string)

Update the button label for the notification

setTitle()

Update the title for the notification

getElement()

Get notification's abstracted HTMLElement. (Note: Not all standard HTMLElement methods and properties are available, but many are.)