Skip to content

Instantly share code, notes, and snippets.

@johnbintz
Created April 13, 2014 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbintz/10593080 to your computer and use it in GitHub Desktop.
Save johnbintz/10593080 to your computer and use it in GitHub Desktop.
Board directive for Can't Catch Me, Olivia!
(def.directive cant_catch_me_olivia.board []
(obj :restrict "E"
:replace true
:templateUrl "partials/board.html"
:link (fn [scope element attrs]
(let [board (.find element ".board")
cells (atom [])
each-span (fn [code] (doseq [data @cells] (apply code data)))]
(doseq [y (range 0 5)]
(let [row (js/$ "<li class='row'><ol class='board-row'></ol></li>")
ol-in-row (.find row "ol")]
(doseq [x (range 0 5)]
(let [column (js/$ "<li class='column'><span></span></li>")]
(.append ol-in-row column)
)
)
(.append board row)
)
)
(let [rows (.find board "li.row")]
(doseq [y (range 0 5)]
(let [row (js/$ (.get rows y))
columns (.find row "li.column")]
(doseq [x (range 0 5)]
(let [column (js/$ (.get columns x))
span (.find column "span")]
(swap! cells #(conj % [x y span]))
)
)
)
)
)
(each-span (fn [x y span]
(.on span "click" (fn []
(.$apply scope #(.handleClick scope x y))
))
))
(.$watch scope "boardData" (fn []
(each-span (fn [x y span]
(let [card-class-for (.cardClassFor scope x y)]
(.attr span "class" card-class-for)
)))
) true)
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment