I am trying to use the "sweetAlert" library (http://t4t5.github.io/sweetalert/)
from my core.cljs file. I created my project using the following command:
lein new figwheel baconbot-dot-js -- --reagent
The sweetAlert.js file provides a global "sweetAlert" function that I would
invoke like this if I was using Javascript:
sweetAlert("Here's a message!")
To make this work in my project I did the following (based on the
http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html
tutorial). To add the JS file to my global namespace I added the
":foreign-libs" property to my :compiler map:
:compiler {:output-to "resources/public/js/compiled/baconbot_dot_js.js"
:main baconbot-dot-js.core
:optimizations :advanced
:foreign-libs [{:file "resources/public/js/sweetalert-dev.js"
:provides ["sweetAlert"]}]}]
:externs ["src/baconbot_dot_js/externs.js"]
:pretty-print false}}]}
I didn't add anything to my externs.js file. Here's its contents:
// Speech synthesis functions
var SpeechSynthesisUtterance = {};
SpeechSynthesisUtterance.speechSynthesis.speak = function() {};
I then restarted Figwheel and added the following to my core.cljs file:
(ns baconbot-dot-js.core
(:require [reagent.core :as reagent :refer [atom]]
[sweetAlert :as sweetAlert]))
...
(defn play-video
"Play the video in an iframe"
[]
(.sweetAlert js/sweetAlert "Test!"))
However, I get the following error when I start figwheel:
Compiling "resources/public/js/compiled/baconbot_dot_js.js" from ["src"]...
{:tag :cljs/analysis-error}
ANALYSIS ERROR: No such namespace: sweetAlert, could not locate
sweetAlert.cljs, sweetAlert.cljc, or Closure namespace "sweetAlert" on file
null, line null, column null
I then removed the :require statement from core.cljs and then changed the
play-video function to look like this:
(defn play-video
"Play the video in an iframe"
[]
(js/sweetAlert "Test!"))
However, I know get this error in the Chrome JS console:
Uncaught ReferenceError: sweetAlert is not defined
Does anyone see what I'm missing?
Thanks in advance!
Tom Purl
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.