![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A simple generalized drag-and-drop module that abstracts away most of the drag-and-drop APIs weirdness and surprises.
drip-drop
Drip-drop is a simple generalized drag-and-drop module that abstracts away most of the drag-and-drop APIs weirdness and surprises. This library simply handles drag-and-drop events in all the major cases:
It can be this easy:
var dd = require("drip-drop")
var draghandle = dd.drag(myDomNode), {
image: true, // default drag image
})
draghandle.on('start', function(setData, e) {
setData('myCustomData', JSON.stringify({a:1, b:"NOT THE BEES"})) // camel case types are allowed!*
})
dd.drop(myDropzone).on('drop', function(data, e) {
myDropzone.innerHTML = data.myCustomData
})
Check out the demo!
Man does the HTML5 drag and drop API suck big giant donkey balls! And all the existing drag-and-drop modules I could find are either tied to a framework like Angular or React, or are trying to give you complex libraries for moving elements around on the page. I wanted a generalized library I could use as the basis for any drag-and-drop situation without being bloated by code that is only needed in a subset of the situations.
npm install drip-drop
Accessing drip-drop:
// node.js
var dd = require('drip-drop')
// amd
require.config({paths: {'drip-drop': '../generatedBuilds/drip-drop.umd.js'}})
require(['drip-drop'], function(dd) { /* your code */ })
// global variable
<script src="drip-drop.umd.js"></script>
dripDrop; // drip-drop.umd.js can define dripDrop globally if you really
// want to shun module-based design
Using drip-drop:
dd.drag(domNode, options)
- Sets up drag-related events on the domNode
. Returns an (EmitterB)[https://github.com/Tixit/EmitterB] instance that emits the drag events described below.
domNode
- The domNode to be set as a drag source (you can then drag from that element).options
image
- Can take on one of the following possible values:
false
- (Default) No image.true
- The default generated drag image.aString
- The path to an image to show next to the cursor while dragging.imageObject
- If this is an Image object, the image it represents will be usedstart(setData, e)
- This function will be called when dragging starts. Use setData to set the data for each type.
setData(type,stringData)
- Sets data for a particular type.
drop
function will convert back to camel case. Eg. using the type "camelCase" will set the value on both the type "camelcase" and "camel-case"."text"
and "url"
. IE isn't making any friends here. Complain about it: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/329509/e
- The original Drag Event object.
e.dataTransfer.effectAllowed
can be set to an allowedEffect - defaults to "all".move(e)
- This function will be called when the drag event moves position. Note that the pointer position can be grabbed from e.pageX
and e.pageY
.end(e)
- This function will be called when the drag event has been either completed or canceled.dd.drop(domNode, options)
- Sets up drop-related events on the domNode
. Returns an (EmitterB)[https://github.com/Tixit/EmitterB] instance that emits the drag events described below.
domNode
- The domNode to be set as a drop-zone.options
allow
- A list of types to allow the event handlers be called for. If this is passed and the current drag operation doesn't have an allowed type, the handlers will not be called. If this isn't passed, all types are allowed.enter(types, e)
- A function called when a drag action enters the node
["text", "camel-case"]
will be transformed into ["text", "camel-case", "camelCase"]
. Also note that the data associated with the types is only available in the 'drop' event for security reasons (imagine if someone was dragging a password from one program to another, but passed over a browser window first).e
- The original Drag Event object.in(types, e)
- A function called when the dragging pointer crosses in over a child-boundary of a descendant nodemove(types, e)
- This function will be called when the drag event moves position over the drop-zone. The return value of this will be set as the dropEffect.
e.dataTransfer.dropEffect
can be set to a dropEffect.e.pageX
and e.pageY
.out(types, e)
- A function called when the dragging pointer crosses out over a child-boundary of a descendant nodeleave(types,e)
- A function called with the dragging pointer moves out of the node or is canceled.drop(data, e)
- This function will be called when the dragging pointer releases above the node.
data
- An object where each key is a data type. If a type contains dashes, the type will be available as-is and with dash-lowercase converted to camel case (matching the types
described above). The value with either be:
getText(errback)
- Returns the text of the file in a call to the the errback.getBuffer(errback)
- Returns a Buffer of the file contents in a call to the the errback.dd.dontPreventDefault()
- Unsets some document-level handlers that prevent the defaults for 'dragenter' and 'dragover'. If you call this, you will need to call event.preventDefault()
in the appropriate dd.drop
'event' and 'move' handlers.
dd.ghostItem(domNode[, zIndex])
- Returns a semi-transparent clone of the passed dom node ready to be moved with dd.moveAbsoluteNode
.
dd.moveAbsoluteNode(domNode, x, y)
- Moves an absolutely positioned element to the position by x and y.
dd.drop(myDropzone).on('drop', function(data, e) {
if(data.Files) {
data.Files.forEach(function(file) {
console.log("Name: "+file.name)
console.log("Size: "+file.size)
var fileContents = file.getText()
// do something with the contents
})
}
})
ghostItem
and moveAbsoluteNode
exampleThese two functions are basic helper functions for doing the common drag visualization of creating a semi-transparent clone of what you're dragging and moving it along with your mouse.
var ghostItem, draghandle = dd.drag(myDomNode)
draghandle.on('start', function(setData, e) {
setData('myCustomData', "Through counter-intelligence it should be possible to pinpoint potential troublemakers, and neutralize them.")
ghostItem = dd.ghostItem(myDomNode.parent)
document.body.appendChild(ghostItem)
})
draghandle.on('move', function(event) {
dd.moveAbsoluteNode(ghostItem, event.pageX, event.pageY)
})
draghandle.on('end', function() {
document.body.removeChild(ghostItem)
})
If you want to detect when drag events are occuring and when they end, set up drag
events on the document body:
document.body.addEventListener('dragstart', function() {
// dragging has started somewhere
})
document.body.addEventListener('dragend', function() {
// dragging has ended somewhere (works even if dragging ended off screen)
})
Drip drop should work on all desktop browsers. However, Android and iOS browsers don't support the html5 drag and drop API for touch events. So if you want to translate touch events into html5 drag events, you can do that with a polyfill. See here: https://www.codeproject.com/Articles/1091766/Add-support-for-standard-HTML-Drag-and-Drop-operat
Tricks
section)Anything helps:
How to submit pull requests:
npm install
at its rootin
and out
to fire for every child-node boundary crossing (because I don't think drop zones can be programatically detected)in
and out
drop event handlers.e.preventDefault()
that was breaking thisReleased under the MIT license: http://opensource.org/licenses/MIT
FAQs
A simple generalized drag-and-drop module that abstracts away most of the drag-and-drop APIs weirdness and surprises.
The npm package drip-drop receives a total of 6 weekly downloads. As such, drip-drop popularity was classified as not popular.
We found that drip-drop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.