From 6ba9ecac4d99b04b0981c24eb5d2bd7f5a273651 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Sun, 22 Sep 2013 22:05:23 +0200 Subject: [PATCH] HTMl generation delayed to the last key press --- src-cljs/main.cljs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src-cljs/main.cljs b/src-cljs/main.cljs index 625facb..f1936c2 100644 --- a/src-cljs/main.cljs +++ b/src-cljs/main.cljs @@ -25,14 +25,24 @@ ; try to detect iOS (def ios-detected (.match (.-userAgent js/navigator) "(iPad|iPod|iPhone)")) +(def timer nil) + +(def timerDelay + ; TODO: also test for Android + (if ios-detected 800 400)) + (defn update-preview "Updates the preview" [] (do - (show $dashed-line) - (show $input-elems) - (inner $preview - (.makeHtml md-converter (val $draft))))) + (js/clearTimeout timer) + (def timer + (js/setTimeout + #(do + (show $dashed-line) + (show $input-elems) + (inner $preview + (.makeHtml md-converter (val $draft)))) timerDelay)))) ; set focus to the draft textarea (if there is one) (when $action