Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pkamenarsky/tellme
base: b2fb3f7079
...
head fork: pkamenarsky/tellme
compare: 624429b467
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 02, 2012
Philip Kamenarsky clean up 67ac3b9
Commits on May 03, 2012
Philip Kamenarsky throttle auth input 62e1929
Philip Kamenarsky escape closes quote mode 0adc253
Philip Kamenarsky fix distance when not quoting rest text ca17723
Philip Kamenarsky fix distance when not quoting rest text 624429b
View
8 src/clj/tellme/base/fsm_macros.clj
@@ -112,8 +112,14 @@
; Comm ---------------------------------------------------------------------
+(defmacro defer-later [interval & body]
+ `(js/setTimeout (fn [] ~@body) ~interval))
+
(defmacro defer [& body]
- `(js/setTimeout (fn [] ~@body) 0))
+ `(defer-later 0 ~@body))
+
+(defmacro stop-defer [d]
+ `(js/clearInterval ~d))
(defmacro remote
"params :: array
View
116 src/cljs/tellme/core.cljs
@@ -17,7 +17,7 @@
[tellme.table :as table]
[tellme.quote :as qt])
(:use [tellme.base.fsm :only [fsm stateresult data state next-state ignore-msg send-message goto]])
- (:use-macros [tellme.base.fsm-macros :only [defer remote view defdep defreaction defsm set-style set-styles css]]))
+ (:use-macros [tellme.base.fsm-macros :only [dowith defer defer-later stop-defer remote view defdep defreaction defsm set-style set-styles css]]))
; Utils --------------------------------------------------------------------
@@ -51,28 +51,35 @@
(dm/set-style! (.-quoteButton (.-currentTarget event)) :visibility "hidden"))
(defn- add-quote [{:keys [table shadow self] :as data} {:keys [quotes slide]}]
- (let [[height rows]
+ (let [[lq lr] (last quotes)
+ adj-quotes (if (zero? (.-length lr)) (butlast quotes) quotes)
+
+ [height rows]
(reduce (fn [[height rows] [q r]]
(let [qh (- (text-height shadow q) 10)
rh (if (zero? (.-length r)) 0 (- (text-height shadow r) 10))]
; FIXME: 20
- [(+ (if (zero? rh) 10 20) height qh rh)
+ [(+ height qh rh (if (zero? rh) 10 20))
(-> rows
(conj (view :div.quote-row nil {:text q :style.height [qh :px]}))
(conj (view :div.retort-row nil {:text r :style.height [rh :px]})))]))
- [0 []] quotes)
- msg-container (view :div.message rows {:style.height [height :px]})
- row (table/add-row table)]
+ [0 []] adj-quotes)]
+
+ (if-not (empty? rows)
+ (let [row (table/add-row table)]
- (table/set-row-contents table row msg-container)
+ (table/set-row-contents
+ table row
+ (view :div.message rows {:style.height [height :px]}))
- (if slide
- (do (ui/animate [table row [height :px] :duration 200
- :onend #(swap! self fsm/send-message :go-to-dispatch)])
- :locked)
- (do (ui/animate [table row [height :px] :duration 0])
- :dispatch))))
+ (if slide
+ (do (ui/animate [table row [height :px] :duration 200
+ :onend #(swap! self fsm/send-message :go-to-dispatch)])
+ :locked)
+ (do (ui/animate [table row [height :px] :duration 0])
+ :dispatch)))
+ :dispatch)))
(defn- quote-message [{:keys [input main-container quote-overlay table self uuid sid] :as sm}
{:keys [text row height]} event]
@@ -88,27 +95,36 @@
help (view :div.quote-help nil {:html quote-help-text})
help-container (view :div.quote-help-container [help button-container])
- qt (dm/add-class! (qt/create-quote text (fn [qt]
- (events/unlistenByKey @event-key)
-
- (swap! self fsm/send-message :go-to-dispatch)
- (swap! self fsm/send-message {:site :local
- :slide false
- :quotes (qt/get-quotes qt)})
-
- (dm/set-style! main-container :visibility "visible")
- (dm/set-style! table :bottom (* client-height 0.3) "px")
- (ui/resized table)
-
- (ui/animate [table :scroll-bottom 0 :duration 0]
- [main-container :style.opacity 1
- :onend #(do
- (dm/detach! qt)
- (dm/detach! help-container)
- (ui/select input)
- (ui/animate [table :style.bottom [(+ 31 bottom-padding) :px]]))]
- [quote-overlay :style.opacity 0
- :onend #(dm/set-style! quote-overlay :visibility "hidden")])))
+ qt (dm/add-class!
+ (qt/create-quote text (fn [qt]
+ (events/unlistenByKey @event-key)
+ (swap! self fsm/send-message :go-to-dispatch)
+
+ (when-let [quotes (qt/get-quotes qt)]
+ ; if we actually got some quotes, send message to fsm &
+ ; set up chat table to match up with quotes (for cool slide-down
+ ; animation)
+ (swap! self fsm/send-message {:site :local
+ :slide false
+ :quotes quotes})
+
+ (if (zero? (.-length (second (last quotes))))
+ ; if last and only retor is empty, do nothing
+ (when (> (count quotes) 1)
+ (dm/set-style! table :bottom (+ 56 (* client-height 0.3)) "px"))
+ (dm/set-style! table :bottom (* client-height 0.3) "px"))
+ (ui/resized table))
+
+ (dm/set-style! main-container :visibility "visible")
+ (ui/animate [table :scroll-bottom 0 :duration 0]
+ [main-container :style.opacity 1
+ :onend #(do
+ (dm/detach! qt)
+ (dm/detach! help-container)
+ (ui/select input)
+ (ui/animate [table :style.bottom [(+ 28 bottom-padding) :px]]))]
+ [quote-overlay :style.opacity 0
+ :onend #(dm/set-style! quote-overlay :visibility "hidden")])))
"quote-table")
bottom (+ height (- (table/row-top table row) (table/scroll-top table)))
@@ -155,21 +171,19 @@
(defn set-message-at-row [{:keys [table] :as data} row
{:keys [text site height] :as message}]
- (let [msg-container (view :div.message)
+ (let [msg-container (view :div.message nil {:text text})
quote-button (view :div.quote-button)
- container (view :div.fill-width [msg-container quote-button])]
+ container (view :div.fill-width [msg-container quote-button] {:style.height [height :px]})]
- (dm/set-style! container :height height "px")
(set! (.-quoteButton (dm/single-node container)) quote-button)
-
- (dm/set-text! msg-container text)
(table/set-row-contents table row container)
; events
- (dme/listen! container :mouseover show-quote-button)
- (dme/listen! container :mouseout hide-quote-button)
- (dme/listen! quote-button :click (partial quote-message data message))))
+ (dowith dme/listen!
+ (container :mouseover show-quote-button)
+ (container :mouseout hide-quote-button)
+ (quote-button :click (partial quote-message data message)))))
; UI -----------------------------------------------------------------------
@@ -192,7 +206,9 @@
main-container (view :div.main)
quote-overlay (view :div.quote-overlay)
- _ (view (dmc/sel "body") [left-column right-column main-container quote-overlay])]
+ _ (view (dmc/sel "body") [left-column right-column main-container quote-overlay])
+
+ input-defer (atom nil)]
(dme/listen! button-container :click
; we want to distribute the margins between page border,
@@ -238,13 +254,17 @@
; handle auth
(events/listen (events/KeyHandler. (dm/single-node number2)) "key"
(fn [event]
- ; TODO: throttle
(let [code (.-keyCode event)]
+ (stop-defer @input-defer)
(if (or (and (>= code 48) (<= code 57)) (= code keycodes/BACKSPACE))
- (defer
- (when-not (js/isNaN (js/parseInt (dm/value number2)))
- (remote [:command :auth :uuid uuid :sid sid :osid
- (js/parseInt (dm/value number2))] _)))
+ ; throttling should be done with defdep/defreaction in a FRP style,
+ ; but since those macros are pretty limited anyway (glitches), we do
+ ; it the old fashioned way here
+ (reset! input-defer
+ (defer-later 500
+ (when-not (js/isNaN (js/parseInt (dm/value number2)))
+ (remote [:command :auth :uuid uuid :sid sid :osid
+ (js/parseInt (dm/value number2))] _))))
(.preventDefault event))))))
; update our internal state
View
41 src/cljs/tellme/quote.cljs
@@ -66,13 +66,19 @@
(ui/animate [input :style.height [(+ 20 sheight) :px]]
[table row (+ 20 sheight)]))))
-(defn- add-finished-listener [input callback quotable]
+(declare gen-quotes)
+
+(defn- add-finished-listener [input callback {:keys [table] :as quotable}]
(events/listen (events/KeyHandler. (dm/single-node input))
"key"
(fn [event]
(when (= (.-keyCode event) keycodes/ENTER)
- (callback quotable)
- (.preventDefault event)))))
+ (.preventDefault event)
+ (callback (assoc quotable :quotes (gen-quotes table))))
+ (when (= (.-keyCode event) keycodes/ESC)
+ (.preventDefault event)
+ (when (js/confirm "Your comment will be lost, is this OK?")
+ (callback quotable))))))
(defn- add-selection-listener [selection-timer dcontent f]
(dme/listen! dcontent
@@ -92,13 +98,19 @@
(def quote-ms 150)
(def quote-selection-timeout 800)
+(defn- gen-quotes [table]
+ ; partition quotes and retorts into an array of [quote retort] pairs
+ (map (fn [[q a]] [(dm/text q) (dm/value a)])
+ (partition 2 (map (partial table/row-contents table)
+ (range (table/row-count table))))))
+
(defprotocol IQuote
(add-quotable [this row content])
(slice-quotable [this row dcontent content])
(get-quotes [this]))
(defrecord Quote
- [callback table shadow retort-input selection-timer]
+ [callback table shadow retort-input selection-timer quotes]
dm/DomContent
(single-node [this] (dm/single-node table))
@@ -134,7 +146,8 @@
rest-row (table/add-row table (inc input-row))
drest (view :div.quote-text)
- input (view :textarea.retort-input)]
+ input (view :textarea.retort-input nil {:style.height [0 :px]
+ :style.padding [0 :px]})]
(dm/remove-class! dcontent "quote-text-inactive")
(dm/add-class! dcontent "quote-text-unselectable")
@@ -146,9 +159,6 @@
; FIXME: 31
(table/set-row-contents table input-row input)
- (dm/set-styles! input {:height (px 0)
- :padding (px 0)})
-
(ui/animate [input :style.height [38 :px] :duration quote-ms]
[input :style.paddingTop [10 :px] :duration quote-ms]
[input :style.paddingBottom [10 :px] :duration quote-ms]
@@ -207,12 +217,8 @@
(add-selection-listener selection-timer dcontent
(partial slice-quotable this row dcontent content))
dcontent))
-
- (get-quotes [this]
- ; partition quotes and retorts into an array of [quote retort] pairs
- (map (fn [[q a]] [(dm/text q) (dm/value a)])
- (partition 2 (map (partial table/row-contents table)
- (range (table/row-count table)))))))
+
+ (get-quotes [this] quotes))
; Constructor --------------------------------------------------------------
@@ -225,7 +231,7 @@
div))
retort-input (view :textarea.retort-input nil {:style.height [38 :px]})
- this (Quote. callback table shadow retort-input (atom nil))]
+ this (Quote. callback table shadow retort-input (atom nil) nil)]
; add initial quotable
(add-quotable this (table/add-row table) content)
@@ -249,7 +255,10 @@
; Tests --------------------------------------------------------------------
(defn test-quote []
- (let [qt (dm/add-class! (create-quote "There's one major problem. This doesn't fit into the monadic interface. Monads are (a -> m b), they're based around functions only. There's no way to attach static information. You have only one choice, throw in some input, and see if it passes or fails.") "chat-table")]
+ (let [qt (dm/add-class! (create-quote "There's one major problem. This doesn't fit into the monadic interface. Monads are (a -> m b), they're based around functions only. There's no way to attach static information. You have only one choice, throw in some input, and see if it passes or fails."
+ #(dm/log-debug (pr-str (if %
+ (get-quotes %)
+ "No quotes.")))) "chat-table")]
(dm/set-style! qt :bottom 200 "px")
(dm/append! (dmc/sel "body") qt)

No commit comments for this range

Something went wrong with that request. Please try again.