Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Reagent of Clojurescript, how do I add event listeners for drag and drop?

For example, how do I perform these listener without falling back into imperative style cljs?

var cols = document.querySelectorAll('#columns .column');
[].forEach.call(cols, function(col) {
  col.addEventListener('dragstart', handleDragStart, false);
  col.addEventListener('dragenter', handleDragEnter, false);
  col.addEventListener('dragover', handleDragOver, false);
  col.addEventListener('dragleave', handleDragLeave, false);
});
like image 217
gzmask Avatar asked Apr 08 '14 21:04

gzmask


1 Answers

Found this online: https://www.refheap.com/73581

(defn allow-drop [e]
  (.preventDefault e)) ;; because DnD in HTMl5 is crazy...

:draggable true ; -> otherwise the browser won't let you drag it
:on-drag-over allow-drop
:on-drag-enter allow-drop
:on-drag-start #(.setData (.-dataTransfer %) "text/plain" "") ;; for Firefox. You MUST set something as data.
:on-drag-end some-action
:on-drop some-other-action
like image 73
Noam Ben Ari Avatar answered Oct 16 '22 23:10

Noam Ben Ari