Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 4 support #42

Closed
zedtux opened this issue May 19, 2017 · 3 comments · May be fixed by #45
Closed

Bootstrap 4 support #42

zedtux opened this issue May 19, 2017 · 3 comments · May be fixed by #45

Comments

@zedtux
Copy link
Contributor

zedtux commented May 19, 2017

I'm using this gem in a Rails 5.1 and Bootstrap 4 alpha 6 project and it is working fine excepted that the alert requires the show class instead of in.

As of now, it's the only issue I found.

@pabse
Copy link
Contributor

pabse commented Sep 18, 2017

Opened a PR for this.

As a workaround until merged you can use

flashHandler = function(e, params) {
  var message = params.message
  var options = { type: params.type }

  options = $.extend(UnobtrusiveFlash.flashOptions, options);

  // Workaround for common Rails flash type to match common Bootstrap alert type
  switch (options.type) {
    case 'notice':
    case 'alert':
    case 'error':
      options.type = options.mapping[options.type]
  }

  // Bootstrap class for showing alert
  var showClass = 'in';
  // If we have Bootstrap 4 use the show class instead
  if ( parseInt($.fn.alert.Constructor.VERSION.split('.')[0]) == 4 ) {
    showClass = 'show';
  }

  var $flash = $('<div class="alert alert-'+options.type+' fade '+showClass+'"><button type="button" class="close" data-dismiss="alert">&times;</button>'+message+'</div>');

  var $flashContainer = $($('.unobtrusive-flash-container')[0] || $('.container')[0] || $('.container-fluid')[0] || $('body')[0]);
  $flashContainer.prepend($flash);

  $flash.hide().delay(300).slideDown(100);

  $flash.alert();

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

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

@zedtux
Copy link
Contributor Author

zedtux commented Sep 18, 2017

Thank you @pabse 👍

@zedtux
Copy link
Contributor Author

zedtux commented Nov 14, 2017

I'm closing this issue as the PR #45 has been opened.

@zedtux zedtux closed this as completed Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants