From e95321f50c22bd452bcfb0fc8c088dbf5264183c Mon Sep 17 00:00:00 2001 From: Script47 Date: Tue, 19 Feb 2019 11:21:21 +0000 Subject: [PATCH] Add files via upload --- css/toast.css | 16 ++++++++++ dist/toast.min.js | 4 +-- js/toast.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 css/toast.css create mode 100644 js/toast.js diff --git a/css/toast.css b/css/toast.css new file mode 100644 index 0000000..af4e659 --- /dev/null +++ b/css/toast.css @@ -0,0 +1,16 @@ +#toast-container { + position: sticky; + z-index: 1055; + top: 0; +} + +#toast-wrapper { + position: absolute; + top: 0; + right: 0; + margin: 5px; +} + +.toast { + min-width: 150px; +} \ No newline at end of file diff --git a/dist/toast.min.js b/dist/toast.min.js index afa762a..93d744e 100644 --- a/dist/toast.min.js +++ b/dist/toast.min.js @@ -1,3 +1,3 @@ -(function(b){b.toast=function(a,h,g,l,k){b("#toast-container").length||(b("body").prepend('
'),b("#toast-container").append('
'));var c="",d="",e="text-muted",f="",m="object"===typeof a?a.title||"":a||"Notice!";h="object"===typeof a?a.subtitle||"":h||"";g="object"===typeof a?a.content||"":g||"";k="object"===typeof a?a.delay||3E3:k||3E3;switch("object"===typeof a?a.type||"":l||""){case "success":c="bg-success"; -f=e=d="text-white";break;case "info":c="bg-info";f=e=d="text-white";break;case "warning":case "warn":c="bg-warning";f=e=d="text-white";break;case "error":case "danger":c="bg-danger",f=e=d="text-white"}a='";b("#toast-wrapper").append(a);b("#toast-wrapper .toast:last").toast("show")}})(jQuery); \ No newline at end of file diff --git a/js/toast.js b/js/toast.js new file mode 100644 index 0000000..0a2e8ae --- /dev/null +++ b/js/toast.js @@ -0,0 +1,75 @@ +(function ($) { + const TOAST_CONTAINER_HTML = '
'; + const TOAST_WRAPPER_HTML = '
'; + + $.toast = function (opts) { + if (!$('#toast-container').length) { + $('body').prepend(TOAST_CONTAINER_HTML); + + $('#toast-container').append(TOAST_WRAPPER_HTML); + } + + let bg_header_class = '', + fg_header_class = '', + fg_subtitle = 'text-muted', + fg_dismiss = '', + title = typeof opts === 'object' ? opts.title || '' : arguments[0] || 'Notice!', + subtitle = typeof opts === 'object' ? opts.subtitle || '' : arguments[1] || '', + content = typeof opts === 'object' ? opts.content || '' : arguments[2] || '', + type = typeof opts === 'object' ? opts.type || '' : arguments[3] || 'info', + delay = typeof opts === 'object' ? opts.delay || 3000 : arguments[4] || 3000; + + switch (type) { + case 'info': + bg_header_class = 'bg-info'; + fg_header_class = 'text-white'; + fg_subtitle = 'text-white'; + fg_dismiss = 'text-white'; + break; + + case 'success': + bg_header_class = 'bg-success'; + fg_header_class = 'text-white'; + fg_subtitle = 'text-white'; + fg_dismiss = 'text-white'; + break; + + case 'warning': + case 'warn': + bg_header_class = 'bg-warning'; + fg_header_class = 'text-white'; + fg_subtitle = 'text-white'; + fg_dismiss = 'text-white'; + break; + + case 'error': + case 'danger': + bg_header_class = 'bg-danger'; + fg_header_class = 'text-white'; + fg_subtitle = 'text-white'; + fg_dismiss = 'text-white'; + break; + } + + let html = ''; + html += ''; + + $('#toast-wrapper').append(html); + $('#toast-wrapper .toast:last').toast('show'); + } +}(jQuery)); \ No newline at end of file