Sha256: 3df196e244287386565925f12912ff33a24c7971852343ed68e8e6186909cb53

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

(function () {
  'use strict';

  document.addEventListener('DOMContentLoaded', function() {
    var messagesContainer = document.querySelector('#alert-messages'),
        alertItems = messagesContainer.querySelectorAll('.alert'),
        alertItemCount = alertItems.length;

    function setOpacity(element, opacity, filterOpacity) {
      element.style.opacity = opacity;
      element.style.filter = 'alpha(opacity = ' + filterOpacity + ')';
    }

    function fadeOutFlash(element, startLevel, endLevel, duration, callback) {
      var fadeInternal,
          level = startLevel;

      fadeInternal = setInterval(function() {
        if (level <= endLevel) {
          setOpacity(element, endLevel, endLevel);

          clearInterval(fadeInternal);

          if (typeof callback == 'function') callback(true);
        }

        else {
          level -= 0.1;

          setOpacity(element, level, (level * 100));
        }
      }, duration);
    }

    ////
    // Fade flash messages out
    //
    for (var i = 0; i < alertItemCount; i += 1) {
      var item = alertItems[i];

      setTimeout(function() {
        fadeOutFlash(item, 1, 0, 50, function() {
          item.parentNode.removeChild(item);
        });
      }, 3000);
    }
  });
}());

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
archangel-0.0.5 app/themes/default/assets/javascripts/default/common/flash.js
archangel-0.0.4 app/themes/default/assets/javascripts/default/common/flash.js
archangel-0.0.3 app/themes/default/assets/javascripts/default/common/flash.js
archangel-0.0.2 app/themes/default/assets/javascripts/default/common/flash.js