Skip to content

Add DataTransfer.setDragImage #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ New features:
- Added `languages` value for `Navigator` (#59 by @toastal)
- Added `HTMLHtmlElement` module and `documentElement` function `HTMLDocument` (#60 by @toastal)
- Added `onLine` value for `Navigator` (#61 by @toastal)
- Added `setDragImage` function for `DataTransfer` (#65 by @ajarista)

Bugfixes:

Expand Down
12 changes: 12 additions & 0 deletions src/Web/HTML/Event/DataTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ exports._setData = function (format) {
};
};

exports._setDragImage = function (dataTransfer) {
return function (image) {
return function (x) {
return function (y) {
return function () {
return dataTransfer.setDragImage(image, x, y);
};
};
};
};
};

exports._dropEffect = function (dataTransfer) {
return function () {
return dataTransfer.dropEffect;
Expand Down
9 changes: 9 additions & 0 deletions src/Web/HTML/Event/DataTransfer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Web.HTML.Event.DataTransfer
, types
, getData
, setData
, setDragImage
, DropEffect(..)
, dropEffect
, setDropEffect
Expand All @@ -15,6 +16,7 @@ import Data.Maybe (Maybe)
import Data.MediaType (MediaType(..))
import Data.Nullable (Nullable, toMaybe)
import Effect (Effect)
import Web.DOM.Element (Element)
import Web.File.FileList (FileList)

foreign import data DataTransfer :: Type
Expand Down Expand Up @@ -57,6 +59,13 @@ setData
-> Effect Unit
setData (MediaType format) dat dt = _setData format dat dt

foreign import _setDragImage :: DataTransfer -> Element -> Int -> Int -> Effect Unit

-- | Sets the image to be used for dragging if a custom one is desired.
-- | The image will typically be an <image> but could be any other *visible* element.
-- | The x and y coordinates define where the image appears relative to the mouse.
setDragImage :: DataTransfer -> Element -> Int -> Int -> Effect Unit
setDragImage = _setDragImage
foreign import _dropEffect :: DataTransfer -> Effect String

data DropEffect = Copy | Link | Move | None
Expand Down