Sha256: dc89615ad751feccfdcba38a13514cbdfe31555c3aa6a94e3ba59b9248d801a5

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

// Unobtrusive flash UI implementation, design agnostic
// Remember to link unobtrusive_flash_ui.css as well
//
// Shows flash messages as translucent bars on top of the page
$(function() {
  $('<div id="unobtrusive-flash-messages"></div>').prependTo('body');

  function hideFlash($flash) {
    $flash.slideUp(100,function(){
      $flash.remove();
    });
  }

  $.showFlashMessage = function(message, options) {
    options = $.extend({type: 'notice', timeout: 5000}, options);

    var $flash = $('<div class="unobtrusive-flash-message-wrapper unobtrusive-flash-'+options.type+'"><div class="unobtrusive-flash-message">'+message+'</div></div>');

    $('#unobtrusive-flash-messages').prepend($flash);
    $flash.hide().delay(300).slideDown(100);

    $flash.click(function() {
      hideFlash($flash);
    });

    if (options.timeout>0) {
      setTimeout(function() {
        hideFlash($flash);
      },options.timeout);
    }
  };

  flashHandler = function(e, params) {
    $.showFlashMessage(params.message, {type: params.type});
  };

  $(window).bind('rails:flash', flashHandler);
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unobtrusive_flash-2.1.0 lib/assets/javascripts/unobtrusive_flash_ui.js
unobtrusive_flash-2.0.0 vendor/assets/javascripts/unobtrusive_flash_ui.js