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 = $('
') + + toast.data('autohide', this._config.autohide) + toast.data('animation', this._config.fade) + + if (this._config.class) { + toast.addClass(this._config.class) + } + + if (this._config.delay && this._config.delay != 500) { + toast.data('delay', this._config.delay) + } + + var toast_header = $('