Sha256: 5ea8efeeeff37f5409ba1fbba53f63f551b96112a59e2a9075f57cc3438b9f28

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

var SimpleMessages = {
  alert: function (data) {
    var msg = "",
      i;

    for (i = 0; i < data.length; i += 1) {
      msg = msg + data[i] + "\n";
    }

    alert(msg);
  },

  flash: function (data, settings) {
    if (settings === undefined) {
      settings = {};
    }

    $.extend(settings, {
      context: '#content'
    });

    if (typeof(data) === 'object' && data.success !== undefined && (data.notice !== undefined || data.alert !== undefined)) {
      if (data.notice !== undefined) {
        Message.flash_notice(data.notice);
      } else {
        Message.flash_alert(data.alert);
      }
    } else if ($.isArray(data)) {
      Message.flash_alert(data.join('<br>'));
    } else {
      $(settings.context).before(data).show();
      $.goTo('body');
    }
  },

  flash_notice: function (data) {
    Message.flash($('<div />', { 'class' : "alert alert-success", 'text' : data }));
  },

  flash_alert: function (data) {
    Message.flash($('<div />', { 'class' : "alert alert-danger", 'text' : data }));
  },

  show: function (data, type) {
    if (type === undefined) {
      type = 'alert';
    }
    Message[type](data);
  },

  hide: function () {
    return $(".alert").alert();
  },
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simple_messages-1.1.0 vendor/assets/javascripts/simple_messages.js
simple_messages-1.0.1 vendor/assets/javascripts/simple_messages.js
simple_messages-1.0.0 vendor/assets/javascripts/simple_messages.js