diff options
| -rw-r--r-- | .gitignore | 15 | ||||
| -rw-r--r-- | project.clj | 11 | ||||
| -rw-r--r-- | src/org_ckons_cljs/notifications/core.cljs | 36 |
3 files changed, 62 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1cd79c --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +target +classes +resources +checkouts +pom.xml +pom.xml.asc +*.jar +*.class +.lein-* +.nrepl-port +.hgignore +.hg +profiles.clj +figwheel_server.log +.rebel_readline_history diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..ead4ea0 --- /dev/null +++ b/project.clj @@ -0,0 +1,11 @@ +(defproject org-ckons-cljs.notifications "0.1.0-SNAPSHOT" + :description "A small library which manages the message and errormsg + browser notifications." + :url "FIXME" + :license "public domain" + :dependencies [[org.clojure/clojure "LATEST"] + [org.clojure/clojurescript "LATEST"] + [prismatic/dommy "LATEST"] + [hiccups "LATEST"]] + :plugins [[lein-cljsbuild "LATEST"]] + :clean-targets ^{:protect false} [:target-path "out" "resources/public/cljs"]) diff --git a/src/org_ckons_cljs/notifications/core.cljs b/src/org_ckons_cljs/notifications/core.cljs new file mode 100644 index 0000000..8fc7926 --- /dev/null +++ b/src/org_ckons_cljs/notifications/core.cljs @@ -0,0 +1,36 @@ +(ns org-ckons-cljs.notifications.core + (:require-macros [hiccups.core :as hiccups :refer [html]]) + (:require [dommy.core :as dommy])) + +(declare template-message) +(declare template-error) +(declare maybe-error) +(declare maybe-message) + +(hiccups/defhtml template-message [message] + [:div {:class "alert alert-success"} message]) + +(hiccups/defhtml template-error [errormsg] + [:div {:class "alert alert-danger"} errormsg]) + +(defn maybe-message [jsonobj] + (when (get jsonobj "locationP") + (let [message (get jsonobj "message")] + (cond (empty? message) + (dommy/set-style! (dommy/sel1 :#message) :display "none") + :else + (do + (dommy/set-style! (dommy/sel1 :#message) :display "block") + (dommy/set-html! (dommy/sel1 :#message) + (template-message message))))))) + +(defn maybe-error [jsonobj] + (when (get jsonobj "locationP") + (let [errormsg (get jsonobj "errormsg")] + (cond (empty? errormsg) + (dommy/set-style! (dommy/sel1 :#errormsg) :display "none") + :else + (do + (dommy/set-style! (dommy/sel1 :#errormsg) :display "block") + (dommy/set-html! (dommy/sel1 :#errormsg) + (template-error errormsg))))))) |
