Last active
August 14, 2018 09:00
-
-
Save 1990prashant/f50bc0ebbfda0b7f6d08 to your computer and use it in GitHub Desktop.
Noty in rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add cdn js for jquery noty | |
# Make sure jquery is loaded before jquery.noty | |
script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-noty/2.3.8/packaged/jquery.noty.packaged.min.js" | |
script type="text/javascript" | |
| var noty_option = | |
= flash_message.to_json.html_safe | |
|; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add some dependencies for noty | |
//= require noty/jquery.noty | |
//= require noty/layouts/topCenter | |
//= require noty/themes/default | |
showNoty: function() { | |
$.noty.defaults = { | |
layout: 'topCenter', | |
theme: 'defaultTheme', // or 'relax' | |
type: 'alert', | |
text: '', // can be html or string | |
dismissQueue: true, // If you want to use queue feature set this true | |
template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>', | |
animation: { | |
open: {height: 'toggle'}, // or Animate.css class names like: 'animated bounceInLeft' | |
close: {height: 'toggle'}, // or Animate.css class names like: 'animated bounceOutLeft' | |
easing: 'swing', | |
speed: 500 // opening & closing animation speed | |
}, | |
timeout: 5000, // delay for closing event. Set false for sticky notifications | |
force: false, // adds notification to the beginning of queue when set to true | |
modal: false, | |
maxVisible: 5, // you can set max visible notification for dismissQueue true option, | |
killer: false, // for close all notifications before show | |
closeWith: ['click'], // ['click', 'button', 'hover', 'backdrop'] // backdrop click will close all notifications | |
callback: { | |
onShow: function() {}, | |
afterShow: function() {}, | |
onClose: function() {}, | |
afterClose: function() {}, | |
onCloseClick: function() {}, | |
}, | |
buttons: false // an array of buttons | |
}; | |
if ( !! noty_option) { | |
noty(noty_option); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flash_message | |
message = "" | |
[:notice, :alert, :success, :error, :warning, :information, :confirm].each do |type| | |
if(!flash[type].blank?) | |
return { | |
text: flash[type], | |
type: ((type == :notice) ? 'information' : type) | |
} | |
end | |
end | |
return nil; | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Add noty gem | |
gem 'noty-rails' | |
# Run bundle command from your terminal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment