From ec008a693f235e3563198e87b0f667a6db259eb9 Mon Sep 17 00:00:00 2001 From: REJack Date: Mon, 16 Sep 2019 12:05:25 +0200 Subject: [PATCH] added Toasts.js & enhanced toasts style - created Toasts.js - updated build/js/scss/plugins/_toastr.scss - added toast-variant mixin in build/scss/_mixinis.scss - created build/scss/_toasts.scss - added zindex-toasts variable in build/scss/_variables.scss - updated build/scss/AdminLTE.scss & build/scss/AdminLTE-raw.scss - updated pages/UI/modals.html - created docs/javascript/toasts.md - updated docs/_config.yml --- build/js/AdminLTE.js | 4 +- build/js/Toasts.js | 229 ++++++++++++++++++++++++++++++++ build/scss/AdminLTE-raw.scss | 1 + build/scss/AdminLTE.scss | 1 + build/scss/_mixins.scss | 18 +++ build/scss/_toasts.scss | 56 ++++++++ build/scss/_variables.scss | 1 + build/scss/plugins/_toastr.scss | 32 ++--- docs/_config.yml | 2 + docs/javascript/toasts.md | 71 ++++++++++ pages/UI/modals.html | 159 +++++++++++++++++++++- 11 files changed, 557 insertions(+), 17 deletions(-) create mode 100644 build/js/Toasts.js create mode 100644 build/scss/_toasts.scss create mode 100644 docs/javascript/toasts.md diff --git a/build/js/AdminLTE.js b/build/js/AdminLTE.js index 0c0a84c11..3658c1351 100644 --- a/build/js/AdminLTE.js +++ b/build/js/AdminLTE.js @@ -7,6 +7,7 @@ import TodoList from './TodoList' import CardWidget from './CardWidget' import CardRefresh from './CardRefresh' import Dropdown from './Dropdown' +import Toasts from './Toasts' export { ControlSidebar, @@ -17,5 +18,6 @@ export { TodoList, CardWidget, CardRefresh, - Dropdown + Dropdown, + Toasts } diff --git a/build/js/Toasts.js b/build/js/Toasts.js new file mode 100644 index 000000000..d06561f43 --- /dev/null +++ b/build/js/Toasts.js @@ -0,0 +1,229 @@ +/** + * -------------------------------------------- + * AdminLTE Toasts.js + * License MIT + * -------------------------------------------- + */ + +const Toasts = (($) => { + /** + * Constants + * ==================================================== + */ + + const NAME = 'Toasts' + const DATA_KEY = 'lte.toasts' + const EVENT_KEY = `.${DATA_KEY}` + const JQUERY_NO_CONFLICT = $.fn[NAME] + + const Event = { + INIT: `init${EVENT_KEY}`, + CREATED: `created${EVENT_KEY}`, + REMOVED: `removed${EVENT_KEY}`, + } + + const Selector = { + BODY: 'toast-body', + CONTAINER_TOP_RIGHT: '#toastsContainerTopRight', + CONTAINER_TOP_LEFT: '#toastsContainerTopLeft', + CONTAINER_BOTTOM_RIGHT: '#toastsContainerBottomRight', + CONTAINER_BOTTOM_LEFT: '#toastsContainerBottomLeft', + } + + const ClassName = { + TOP_RIGHT: 'toasts-top-right', + TOP_LEFT: 'toasts-top-left', + BOTTOM_RIGHT: 'toasts-bottom-right', + BOTTOM_LEFT: 'toasts-bottom-left', + FADE: 'fade', + } + + const Position = { + TOP_RIGHT: 'topRight', + TOP_LEFT: 'topLeft', + BOTTOM_RIGHT: 'bottomRight', + BOTTOM_LEFT: 'bottomLeft', + } + + const Id = { + CONTAINER_TOP_RIGHT: 'toastsContainerTopRight', + CONTAINER_TOP_LEFT: 'toastsContainerTopLeft', + CONTAINER_BOTTOM_RIGHT: 'toastsContainerBottomRight', + CONTAINER_BOTTOM_LEFT: 'toastsContainerBottomLeft', + } + + const Default = { + position: Position.TOP_RIGHT, + fixed: true, + autohide: false, + autoremove: true, + delay: 1000, + fade: true, + icon: null, + image: null, + imageAlt: null, + imageHeight: '25px', + title: null, + subtitle: null, + close: true, + body: null, + class: null, + } + + /** + * Class Definition + * ==================================================== + */ + class Toasts { + constructor(element, config) { + this._config = config + + this._prepareContainer(); + + const initEvent = $.Event(Event.INIT) + $('body').trigger(initEvent) + } + + // Public + + create() { + var toast = $(' +

@@ -789,7 +846,7 @@

-
+

@@ -1157,6 +1214,106 @@ $('.toastrDefaultWarning').click(function() { toastr.warning('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.') }); + + $('.toastsDefaultDefault').click(function() { + $(document).Toasts('create', { + title: 'Toast Title', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultTopLeft').click(function() { + $(document).Toasts('create', { + title: 'Toast Title', + position: 'topLeft', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultBottomRight').click(function() { + $(document).Toasts('create', { + title: 'Toast Title', + position: 'bottomRight', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultBottomLeft').click(function() { + $(document).Toasts('create', { + title: 'Toast Title', + position: 'bottomLeft', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultAutohide').click(function() { + $(document).Toasts('create', { + title: 'Toast Title', + autohide: true, + delay: 750, + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultNotFixed').click(function() { + $(document).Toasts('create', { + title: 'Toast Title', + fixed: false, + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultFull').click(function() { + $(document).Toasts('create', { + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.', + title: 'Toast Title', + subtitle: 'Subtitle', + icon: 'fas fa-envelope fa-lg', + }) + }); + $('.toastsDefaultFullImage').click(function() { + $(document).Toasts('create', { + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.', + title: 'Toast Title', + subtitle: 'Subtitle', + image: '../../dist/img/user3-128x128.jpg', + imageAlt: 'User Picture', + }) + }); + $('.toastsDefaultSuccess').click(function() { + $(document).Toasts('create', { + class: 'bg-success', + title: 'Toast Title', + subtitle: 'Subtitle', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultInfo').click(function() { + $(document).Toasts('create', { + class: 'bg-info', + title: 'Toast Title', + subtitle: 'Subtitle', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultWarning').click(function() { + $(document).Toasts('create', { + class: 'bg-warning', + title: 'Toast Title', + subtitle: 'Subtitle', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultDanger').click(function() { + $(document).Toasts('create', { + class: 'bg-danger', + title: 'Toast Title', + subtitle: 'Subtitle', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); + $('.toastsDefaultMaroon').click(function() { + $(document).Toasts('create', { + class: 'bg-maroon', + title: 'Toast Title', + subtitle: 'Subtitle', + body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.' + }) + }); });