Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/apps/system/js/system_banner.js
blob: 89028e26572c17efeb003f1cff5e180e1899f704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';

var SystemBanner = {
  banner: document.getElementById('system-banner'),

  // Shows a banner with a given message.
  // Optionally shows a button with a given label/callback.
  // buttonParams = { label: ..., callback: ... }
  show: function sb_show(message, buttonParams) {
    var banner = this.banner;
    banner.firstElementChild.textContent = message;

    var button = banner.querySelector('button');
    if (buttonParams) {
      banner.dataset.button = true;
      button.textContent = buttonParams.label;
      button.addEventListener('click', buttonParams.callback);
    }

    banner.addEventListener('animationend', function animationend() {
      banner.removeEventListener('animationend', animationend);
      banner.classList.remove('visible');

      if (buttonParams) {
        banner.dataset.button = false;
        button.removeEventListener('click', buttonParams.callback);
        button.classList.remove('visible');
      }
    });

    banner.classList.add('visible');
  }
};