|
276 | 276 | (when (not= "Identity" (:type card)) |
277 | 277 | (send-command "move" {:card card :server server})))) |
278 | 278 |
|
279 | | -;; touch support |
280 | | -(defonce touchmove (atom {})) |
281 | | - |
282 | | -(defn release-touch [^js/$ card] |
283 | | - (-> card (.removeClass "disable-transition")) |
284 | | - (-> card (.css "position" "")) |
285 | | - (-> card (.css "top" ""))) |
286 | | - |
287 | | -(defn update-card-position [^js/$ card touch] |
288 | | - (-> card (.css "left" (str (- (int (aget touch "pageX")) 30) "px"))) |
289 | | - (-> card (.css "top" (str (- (int (aget touch "pageY")) 42) "px")))) |
290 | | - |
291 | | -(defn get-card [e _server] |
292 | | - (-> e .-target js/$ (.closest ".card-wrapper"))) |
293 | | - |
294 | | -(defn get-server-from-touch [touch] |
295 | | - (let [cX (.. touch -clientX) |
296 | | - cY (.. touch -clientY) |
297 | | - server (-> (js/document.elementFromPoint cX cY) |
298 | | - js/$ |
299 | | - (.closest "[data-server]") |
300 | | - (.attr "data-server"))] |
301 | | - [server (> (+ (abs (- (:x @touchmove) cX)) |
302 | | - (abs (- (:y @touchmove) cY))) |
303 | | - 30)])) |
304 | | - |
305 | | -(defn handle-touchstart [e cursor] |
306 | | - (let [touch (aget (.. e -targetTouches) 0) |
307 | | - [server _] (get-server-from-touch touch) |
308 | | - card (get-card e server)] |
309 | | - (-> card (.addClass "disable-transition")) |
310 | | - (reset! touchmove {:card (.stringify js/JSON (clj->js @cursor)) |
311 | | - :x (.. touch -clientX) |
312 | | - :y (.. touch -clientY) |
313 | | - :start-server server}))) |
314 | | - |
315 | | -(defn handle-touchmove [e] |
316 | | - (let [touch (aget (.. e -targetTouches) 0) |
317 | | - card (get-card e (:start-server @touchmove))] |
318 | | - (-> card (.css "position" "fixed")) |
319 | | - (update-card-position card touch))) |
320 | | - |
321 | | -(defn handle-touchend [e] |
322 | | - (let [touch (aget (.. e -changedTouches) 0) |
323 | | - card (get-card e (:start-server @touchmove)) |
324 | | - [server moved-enough] (get-server-from-touch touch)] |
325 | | - (release-touch card) |
326 | | - (when (and server moved-enough (not= server (:start-server @touchmove))) |
327 | | - (let [cardinfo (-> @touchmove :card ((.-parse js/JSON)) (js->clj :keywordize-keys true))] |
328 | | - (send-command "move" {:card cardinfo :server server}))))) |
329 | | - |
330 | 279 | (defn remote->num [server] |
331 | 280 | (-> server str (clojure.string/split #":remote") last str->int)) |
332 | 281 |
|
|
786 | 735 | (playable? card))) |
787 | 736 | 0) |
788 | 737 | :draggable (when (and (not-spectator?) (not disable-click) (not flashback-fake-in-hand)) true) |
789 | | - :on-touch-start #(handle-touchstart % card) |
790 | | - :on-touch-end #(handle-touchend %) |
791 | | - :on-touch-move #(handle-touchmove %) |
792 | 738 | :on-drag-start #(handle-dragstart % card) |
793 | 739 | :on-drag-end #(-> % .-target js/$ (.removeClass "dragged")) |
794 | 740 | :on-mouse-enter #(when (or (not (or (not code) flipped facedown)) |
|
0 commit comments