Sha256: ca603080e2a5821b376731740ad5f403979bcd228b817bc1dda125d032126390

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 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
window.UnobtrusiveFlash.flashOptions = {type: 'notice', timeout: 0};

$(function() {
  $('<div id="unobtrusive-flash-messages"></div>').prependTo('body');

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

  UnobtrusiveFlash.showFlashMessage = function(message, options) {
    options = $.extend(UnobtrusiveFlash.flashOptions, 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) {
    UnobtrusiveFlash.showFlashMessage(params.message, {type: params.type});
  };

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unobtrusive_flash-3.1.0 lib/assets/javascripts/unobtrusive_flash_ui.js