Created
April 13, 2014 17:11
-
-
Save johnbintz/10593080 to your computer and use it in GitHub Desktop.
Board directive for Can't Catch Me, Olivia!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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