### Notification system in CSS3 @namespace Lungo @class Notification @author Javier Jimenez Villar || @soyjavi ### Lungo.Notification = do(lng = Lungo) -> _options = [] _el = null _window = null DELAY_TIME = 1 ATTRIBUTE = lng.Constants.ATTRIBUTE BINDING = lng.Constants.BINDING TRANSITION = lng.Constants.TRANSITION SELECTOR = BODY: "body" NOTIFICATION: ".notification" MODAL: ".notification .window" MODAL_HREF: ".notification .window a" WINDOW_CLOSABLE: ".notification [data-action=close], .notification > .error, .notification > .success" CONFIRM_BUTTONS: ".notification .confirm a.button, .notification .push" STYLE = MODAL: "modal" VISIBLE: "visible" SHOW: "show" WORKING: "working" INPUT: "input" MARKUP_NOTIFICATION = "
" ### ### show = (icon, title, seconds, callback) -> markup = undefined if icon? markup = _markup(title, null, icon) else data_loading = lng.Attributes.loading.html markup = data_loading.replace(BINDING.START + BINDING.KEY + BINDING.END, "icon white") _show markup, "growl" _hide seconds, callback ### ### hide = -> _window.removeClass("show") setTimeout (-> _el.removeClass("show").removeClass("html").removeClass("confirm").removeClass("notify").removeClass "growl" ), (TRANSITION.DURATION / 2) ### ### confirm = (options) -> _options = options markup = _markup(options.title, options.description, options.icon) markup += _button_markup(options.accept, "accept") markup += _button_markup(options.cancel, "cancel") _show markup, "confirm" ### ### success = (title, description, icon, seconds, callback) -> _notify title, description, icon, "success", seconds, callback ### ### error = (title, description, icon, seconds, callback) -> _notify title, description, icon, "error", seconds, callback ### ### html = (markup, button, style, seconds) -> if button markup += "" + button + "" _show markup, "html #{style}" _hide seconds ### ### push = (title, icon, style) -> _show _markup(title, null, icon), "push #{style}", false _hide 5 _init = -> lng.dom(SELECTOR.BODY).append MARKUP_NOTIFICATION _el = lng.dom(SELECTOR.NOTIFICATION) _window = _el.children(".window") _subscribeEvents() _show = (html, stylesheet, block = true) -> if block then _el.removeClass "push" else _el.addClass "push" unless _window.hasClass("show") _el.addClass("show") else _window.removeClass STYLE.SHOW setTimeout (-> _window.html html _window.attr "class", "window #{stylesheet} show" ), (TRANSITION.DURATION / 2) _hide = (seconds, callback) -> if seconds? and seconds > 0 setTimeout (=> if callback callback.call undefined, callback else do hide ), seconds * 1000 _notify = (title, description, icon, stylesheet, seconds, callback) -> _show _markup(title, description, icon), stylesheet _hide seconds, callback _markup = (title, description, icon) -> description = (if not description then " " else description) title = (if not title then " " else title) "" + title + "" + description + "" _button_markup = (options, callback) -> "" + options.label + "" _subscribeEvents = -> lng.dom(SELECTOR.CONFIRM_BUTTONS).tap (event) -> button = lng.dom(this) if _options[button.data("callback")]? callback = _options[button.data("callback")].callback callback.call callback if callback hide() lng.dom(SELECTOR.WINDOW_CLOSABLE).tap hide _init() show: show hide: hide error: error success: success confirm: confirm html: html push: push