Skip to content

Instantly share code, notes, and snippets.

@atomgiant
Created August 19, 2013 15:03
Show Gist options
  • Select an option

  • Save atomgiant/6270147 to your computer and use it in GitHub Desktop.

Select an option

Save atomgiant/6270147 to your computer and use it in GitHub Desktop.
Notification box css for full width
<style>
#notification-box {
position: absolute;
top: 25px; left: 0;
width: 100%;
padding: 0; margin: 0;
}
</style>
<div id="notification-box">
<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
<div id="flash_alert">There was a problem...</div>
</div>
</div>
</div>
@lojic
Copy link
Copy Markdown

lojic commented Sep 6, 2013

<%# This file is structured in such a way as to allow both Rails and JavaScript
  # to use the same DOM for displaying flash messages.
  # %>

<% parent_display = flash.present? ? 'block' : 'none' -%>

<div class="flash-alerts" style="display: <%= parent_display %>;">
<%
   [ [ :error,   'alert-danger'  ],
     [ :warning, 'alert-warning' ],
     [ :info,    'alert-info'    ],
     [ :message, 'alert-success' ] ].each do |key, class_str|
       display = flash[key].present? ? 'block' : 'none'
-%>
  <div class="alert <%= "#{class_str}" %>" style="display: <%= display %>;">
    <a class="close" data-dismiss="alert">&#215</a>
    <div class="flash-msg">
      <% if flash[key] -%>
      <%= flash[key] %>
      <% end -%>
    </div>
  </div>
<% end -%>  
</div>

<% if flash.present? -%>
<script>
  $(".flash-alerts").delay(5000).fadeOut();
</script>
<% end -%>

@lojic
Copy link
Copy Markdown

lojic commented Sep 6, 2013

    var setAlert = function (msg) {
      $('.flash-alerts .alert-danger .flash-msg').text(msg);
      $(".flash-alerts").show();
      $(".flash-alerts .alert-danger").show();
      $(".flash-alerts").delay(5000).fadeOut();
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment