Fork me on GitHub
#clojure-europe
<
2023-09-21
>
vemv07:09:47

Morning! Today I'm (clojure.math/pow 2 5)

🎂 3
teodorlu07:09:40

Happy binary anniversary!

❤️ 1
schmalz07:09:47

Morning all.

teodorlu07:09:56

Good morning!

maleghast07:09:09

maidin mhaith!

maleghast07:09:54

How is everyone feeling on this weird Thursday..? (for context, bright blue skies right now in Glasgow, but apparently it will be raining torrentially in about 2 hours' time)

thomas07:09:47

Here we have rain forecast for the whole day 😞

simongray07:09:36

Wind and a clear blue sky in Copenhagen, just the way I like it!

thomas08:09:03

very grey here, but not cold.

ray08:09:43

it's giving Drizzle in Belgium

reefersleep08:09:32

Good morning 🙂

ray08:09:03

Good morning

😍 2
reefersleep08:09:54

it's just data

🤯 1
pez09:09:34

TIL: If you attach mouse events to document, they will keep firing when the mouse cursor leaves the viewport, even the browser window itself. If you attach the events to document.body they only fire over the viewport. (Yes, I’m making draggable things).

simongray09:09:50

Really? That seems almost like an exploit. 😮

jkxyz09:09:10

What happens if you attach them to window? I do that when I’m making draggable things

pez09:09:37

It’s probably well defined behaviour. 😃 I tested in both Safari and Brave. Here’s the code so far:

#?(:cljs
   (defn make-draggable [el]
     (events/listen
      el "mousedown"
      (fn [e]
        (when (.contains (-> e .-target .-classList) "dragger")
          (let [from (atom {:x (.-clientX e)
                            :y (.-clientY e)})]
            (letfn [(mousemove-fn [e]
                      (let [{:keys [x y]} @from
                            x' (.-clientX e)
                            y' (.-clientY e)]
                        (reset! from {:x x' :y y'})
                        (set! (-> el .-style .-left) (str (+ (.-offsetLeft el) (- x' x)) "px"))
                        (set! (-> el .-style .-top) (str (+ (.-offsetTop el) (- y' y)) "px"))
                        (set! (-> el .-style .-right) "unset")))
                    (mouseup-fn [_]
                      (events/unlisten js/document.body "mousemove" mousemove-fn)
                      (events/unlisten js/document "mouseup" mouseup-fn))]
              (events/listen js/document.body "mousemove" mousemove-fn)
              (events/listen js/document "mouseup" mouseup-fn))))
        (.stopPropagation e)))))
Before I discovered this with the document events (by pure chance) I had to track mouseleave and got into trouble making that stable. It also didn’t allow me let the user drag a bit outside the viewport and keep dragging when the cursor entered again. The above creates a lot of the behaviour I’m after, with less irrelevant logic.

pez09:09:56

(It’s the mouseup-fn that I want firing outside the viewport, unless that wasn’t super clear 😃 ).

pez09:09:52

Haven’t tried with window, @UE72GJS7J. I came from the other direction, having had attached them the events to the element itself. 😃 I’ll try with window now and see what gives.

pez09:09:24

Now tried with window and afaict I get the exact same behaviour as with document. Dunno what to make of that…

jkxyz09:09:10

I think window is the top-level of the event chain, so events will always bubble up to the global event handler on window unless you call stopPropagation

pez10:09:21

I needed to call stopPropagation in my case… and have already forgotten why. 😃

pez10:09:25

Maybe it was because I can have draggables inside draggables…

jkxyz10:09:04

Yeah probably! It will bubble up to all event handlers on the parent elements unless you stop it

jkxyz10:09:29

There are also events specifically related to dragging btw... they let you put data onto the clipboard so it can be pasted when you drag outside of the browser window: https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Drag_operations

pez11:09:57

Yeah, it’s a bit confusing with the naming of that draggable attribute. But it sure is great for those drag-n-drop situations. Too bad it’s not available for SVG.

dharrigan14:09:39

Just noticed that a new update to slack restores the ability to expand out all the workspaces that one is participating in - workspace switcher. Phew! Anxiety levels decreasing....

❤️ 1
reefersleep16:09:20

Good morning! Taught a coworker some vim editing stuff today. Feels like sharing spells wizard

mario-star 4
❤️ 2
vim 1