Semantic-UI-Alert.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. $.uiAlert = function(options) {
  2. var setUI = $.extend({
  3. textHead: 'Your user registration was successful.',
  4. text: 'You may now log-in with the username you have chosen',
  5. textcolor: '#19c3aa',
  6. bgcolors: '#fff',
  7. position: 'top-right',
  8. icon: '',
  9. time: 5,
  10. permanent: false
  11. }, options);
  12. var ui_alert = 'ui-alert-content';
  13. ui_alert += '-' + setUI.position;
  14. setUI.bgcolors = 'style="background-color: ' + setUI.bgcolor + '; box-shadow: 0 0 0 1px rgba(255,255,255,.5) inset,0 0 0 0 transparent;"';
  15. if (setUI.bgcolors === '') setUI.bgcolors = 'style="background-color: ; box-shadow: 0 0 0 1px rgba(255,255,255,.5) inset,0 0 0 0 transparent;"';
  16. if (!$('body > .' + ui_alert).length) {
  17. $('body').append('<div class="ui-alert-content ' + ui_alert + '" style="width: inherit;"></div>');
  18. }
  19. var message = $('<div id="messages" class="ui icon message" ' + setUI.bgcolors + '><i class="' + setUI.icon + ' icon" style="color: ' + setUI.textcolor + ';"></i><i class="close icon" style="color: ' + setUI.textcolor + ';" id="messageclose"></i><div style="color: ' + setUI.textcolor + '; margin-right: 10px;"> <div class="header">' + setUI.textHead + '</div> <p> ' + setUI.text + '</p></div> </div>');
  20. $('.' + ui_alert).prepend(message);
  21. message.animate({
  22. opacity: '1',
  23. }, 800);
  24. if (setUI.permanent === false) {
  25. var timer = 0;
  26. $(message).mouseenter(function() {
  27. clearTimeout(timer);
  28. }).mouseleave(function() {
  29. uiAlertHide();
  30. });
  31. uiAlertHide();
  32. }
  33. function uiAlertHide() {
  34. timer = setTimeout(function() {
  35. message.animate({
  36. opacity: '0',
  37. }, 300, function() {
  38. message.remove();
  39. });
  40. }, (setUI.time * 1000));
  41. }
  42. $('#messageclose')
  43. .on('click', function() {
  44. $(this)
  45. .closest('#messages')
  46. .transition('fade');
  47. });
  48. };