Hi, I am trying to do something with Clojurescript using Domina etc. Here is my project.clj -
(defproject maze "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.4.0"] [org.clojure/clojure-contrib "1.2.0"] [hiccup "1.0.1"] [noir "1.3.0-beta10"] [cssgen "0.2.6"] [jayq "0.1.0-alpha4"] [crate "0.2.1"] [domina "1.0.0"]] :plugins [[lein-cljsbuild "0.2.1"]] :hooks [leiningen.cljsbuild] :jvm-opts ["-Dfile.encoding=utf-8"] :cljsbuild {:builds [{ :source-path "src-cljs", :compiler {:output-dir "resources/public/cljs/", :output-to "resources/public/cljs/main.js", :optimizations :whitespace, :pretty-print true}}]} :main maze.server) Here is my main page - (ns maze.views.mm (:use [noir.core :only [defpartial]] [hiccup.core :only [html]] [hiccup.page :only [html5 include-js]] [hiccup.element :only [javascript-tag]] [maze.views.cssgenerator] [maze.constants])) (defn generate-options [] (map #(html [:option {:value %1} %2]) (range 0 4) difficulty-levels)) ;; Creates the main html layout (defpartial generate-layout [params title & content] (html5 [:head [:title title] [:meta {:charset "UTF-8"}] [:style {:type "text/css"} (global-css params)] (include-js "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js")] [:body {:bgcolor "#FFFFFF"} [:table {:cellpading 20 :cellspacing 0 :width "100%" :border 0} [:tr [:td {:width "70%" :align "center"} [:div#mazediv]] [:td {:width "30%" :align "center" :valign "top"} [:h1 "Mysterious" [:br "Maze"]] [:small directions] [:p] [:div#scorediv {:style "background-color: grey;color: yellow"} "SCORE : 0"] [:p] [:div#statdiv {:style "background-color: grey;color: yellow"} "WAITING..."] [:p] [:select#level (generate-options)] [:p] [:input#start {:type :button :value "Start New Game"}]]]] [:div.copy "Copyright © 2012 Manoj Waikar. All Rights Reserved."] (javascript-tag "var CLOSURE_NO_DEPS = true;") (include-js "/cljs/main.js")])) And my main.cljs - (ns maze.main (:use [jayq.core :only [$]]) (:use-macros [crate.def-macros :only [defpartial]]) (:require [domina :as d] [crate.core :as crate] [clojure.browser.event :as event])) ;; frequently used selectors (def start-button (d/by-id "start")) (def level-combo (d/by-id "level")) (def maze-div (d/by-id "mazediv")) (defpartial columns [n] (map #([:td] %) (range 1 n))) (defpartial table [n] [:table (map #([:tr (columns n)]) (range 1 n))]) ;; (defn generate-table [rows-columns] (event/listen start-button "click" (fn [] (js/alert "hey!"))) (event/listen level-combo "change" (fn [e] (let [option-val (js/parseInt (.-value (.-target e)))] (if (> 0 option-val) (fn [e] (.log js/console "enter") (d/destroy-children! maze-div) (d/append! maze-div [:h1 "do it"])))))) I am able to see the js/alert on click of the start button. I was also able to get the value of the level select using (js/parseInt (.-value (.-target e))). However, I am not able to append any new dom elements to maze-div? (First I was trying to add a table, and now I am trying to add an h1 tag, but it doesn't seem to work. Any idea what is incorrect here? Thanks in advance for your suggestions. Regards, Manoj. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en