Sha256: f25f1e54dc8ca1870b1db3cec5f0c643c467cec8c4b0b8c1607f98202e2d696d

Contents?: true

Size: 1.38 KB

Versions: 117

Compression:

Stored size: 1.38 KB

Contents

// Custom JS to give functionality to the "Refresh the alert" button
// Button HTML is build into DOM by ./alert.js
// Styling is located in /assets/scss/{ _buttons, _loader, _svg}.scss
const BUTTON = document.getElementById('syncAlert');

function syncHandler(e) {
  const SVG = BUTTON.querySelector('.svg__sync');

  Promise.resolve()
    .then(() => {
      BUTTON.classList.add('buttons--sync--visible');
      SVG.classList.add('loader__sync--animate');
    }).then(() => {
      // Add a short delay before fetching the new alert
      window.setTimeout(() => { // (alert fetches too fast for the loading animation without this delay)
        import('./fetchNewAlert').then(({default: fetchNewAlert}) => {
          gapi.load('client', fetchNewAlert); // Runs a new call to gapi and repaints the alert HTML
        });
      }, 1000);
    })
}

function showButtonOnInitialLoad(button) {
  button.classList.add('buttons--sync--preview'); // This class has an animation that shows the button for 3-sec.
  window.setTimeout(() => {
    button.classList.remove('buttons--sync--preview'); // Remove the class after enough time for animations has elapsed
  }, 3000);
}

function refreshAlertButton() {
  window.setTimeout(() => { // Short delay before showing the refresh button
    showButtonOnInitialLoad(BUTTON);
  }, 500);
  BUTTON.addEventListener('click', syncHandler);
}

export default refreshAlertButton;

Version data entries

117 entries across 117 versions & 2 rubygems

Version Path
kcc-gem-theme-3.11.4 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.11.3 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.11.1 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.11.0 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.7 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.6 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.5 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.4 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.3 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.2 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.1 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.10.0 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.9.4 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.9.3 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.9.2 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.9.1 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.9.0 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.8.0 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.7.10 assets/js/alerts/refreshAlertButton.js
kcc-gem-theme-3.7.9 assets/js/alerts/refreshAlertButton.js