Created
July 27, 2014 13:13
-
-
Save ProTip/af0927483200b9bcacd1 to your computer and use it in GitHub Desktop.
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
(defn enable-edit [owner] | |
(let [input (om/get-node owner "input-box")] | |
(set! (-> input .-style .-display) "") | |
(.focus input) | |
(set! (.-value input) (.-value input)) | |
(om/set-state! owner :editing true))) | |
(defn editable [text owner] | |
(reify | |
om/IInitState | |
(init-state [_] | |
{:editing false}) | |
om/IRenderState | |
(render-state [_ {:keys [editing]}] | |
(dom/li nil | |
(dom/span #js {:style (display (not editing)) | |
:onClick #(enable-edit owner)} | |
(om/value text)) | |
(dom/input | |
#js { | |
:style (display editing) | |
:ref "input-box" | |
:value (om/value text) | |
:onChange #(handle-change % text owner) | |
:onKeyPress #(when (== (.-keyCode %) 13) | |
(commit-change text owner)) | |
:onBlur (fn [e] (commit-change text owner))}))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment