bootstrapToastWrapper.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. (function ($) {
  2. $.fn.bootstrapToastWrapper = function (content) {
  3. var type = {
  4. 'primary': '#084298',
  5. 'secondary': '#41464b',
  6. 'success': '#0f5132',
  7. 'danger': '#842029',
  8. 'warning': '#664d03',
  9. 'info': '#055160',
  10. 'light': '#636464',
  11. 'dark': '#141619'
  12. }
  13. var toastContent = "<div class='toast show'> <div class='toast-header'> {{type}} <strong class='me-auto'>{{title}}</strong> <button type='button' class='btn-close' data-bs-dismiss='toast' aria-label='Close'></button> </div> <div class='toast-body'>{{body}}</div> </div>";
  14. var rect = '<svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false"><rect width="100%" height="100%" fill="{{type}}"></rect></svg>';
  15. rect = rect.replace('{{type}}', type[content['type']]);
  16. toastContent = toastContent.replace('{{type}}', rect);
  17. for(key in content){
  18. toastContent = toastContent.replace('{{'+key+'}}', content[key] );
  19. }
  20. var a = $(this).append(toastContent).children("div:last-child");;
  21. if(content.timeout){
  22. setTimeout(function(){
  23. $(a).remove();
  24. }, content.timeout);
  25. }
  26. }
  27. })(jQuery);