Git Product home page Git Product logo

mobile-drag-drop's Introduction

npmversion license issues size gzippedsize

Polyfill for HTML 5 drag'n'drop

The HTML 5 drag'n'drop API allows you to implement drag'n'drop on most desktop browsers and some mobile browsers.

Unfortunately, you'll notice most mobile browsers don't support it, so no iPad (or Nexus) action for you!

Chrome>=96 on Android>=7 and Safari on iOS/iPadOS>=15 are reported to support drag and drop natively! This means native support for drag and drop is growing but some browsers still need polyfilling. It is advised to keep an eye on caniuse and test for your userbase. In the case of iOS native support and the polyfill seem to be able to coexist without issues.

See #167 for state of drag and drop in iOS/iPad>=15.

Chrome>=96 on Android>=7 behaviour is under investigation.

Luckily, browsers give us enough tools to make it happen ourselves if needed. If you drop this package in your page your existing HTML 5 drag'n'drop code should just work (*almost).

Demos

Demo

Check out the demo to see it in action and monitor the console to see the events firing.

Install

npm

npm install mobile-drag-drop --save

jspm

jspm install npm:mobile-drag-drop

Include

global

<link rel="stylesheet" href="libs/mobile-drag-drop/release/default.css">
<script src="libs/mobile-drag-drop/release/index.min.js"></script>

<!--optional import of scroll behaviour-->
<script src="libs/mobile-drag-drop/release/scroll-behaviour.min.js"></script>

<script>
    // options are optional ;)
    MobileDragDrop.polyfill({
        // use this to make use of the scroll behaviour
        dragImageTranslateOverride: MobileDragDrop.scrollBehaviourDragImageTranslateOverride
    });
</script>

SystemJS/JSPM

System.import("mobile-drag-drop");
// import css if using system-js css loader plugin 
System.import("mobile-drag-drop/default.css!");

ES2015/TypeScript/webpack

import {polyfill} from "mobile-drag-drop";

// optional import of scroll behaviour
import {scrollBehaviourDragImageTranslateOverride} from "mobile-drag-drop/scroll-behaviour";

// options are optional ;)
polyfill({
    // use this to make use of the scroll behaviour
    dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride
});

Make sure to implement a dragenter-listener! (read here why)

// dragenter listener
(event)=> {
    event.preventDefault();
}

If you're targeting iOS Safari 10.x and higher

// iOS>=10 supports passive event listeners
// but make sure to catch or check passive event listener support
// regarding this code running on other platforms.
window.addEventListener( 'touchmove', function() {}, {passive: false});

See #77 and #124 for details.

webpack/scss

@import "~mobile-drag-drop/default.css";

API & Options

export interface Point {
    x: number;
    y: number;
}

// function signature for the dragImageTranslateOverride hook
export type DragImageTranslateOverrideFn = (
    // corresponding touchmove event
    event: TouchEvent, 
    // the processed touch event viewport coordinates
    hoverCoordinates: Point, 
    // the element under the calculated touch coordinates
    hoveredElement: HTMLElement, 
    // callback for updating the drag image offset
    translateDragImageFn: (offsetX: number, offsetY: number) => void;
) => void;

export interface Config {

    // flag to force the polyfill being applied and not rely on internal feature detection
    forceApply?:boolean;

    // useful for when you want the default drag image but still want to apply
    // some static offset from touch coordinates to drag image coordinates
    // defaults to (0,0)
    dragImageOffset?:Point;

    // if the dragImage shall be centered on the touch coordinates
    // defaults to false
    dragImageCenterOnTouch?:boolean;

    // the drag and drop operation involves some processing. here you can specify in what interval this processing takes place.
    // defaults to 150ms
    iterationInterval?:number;

    // hook for custom logic that decides if a drag operation should start
    dragStartConditionOverride?:( event:TouchEvent ) => boolean;

    // hook for custom logic that can manipulate the drag image translate offset
    dragImageTranslateOverride?:DragImageTranslateOverrideFn;

    // hook for custom logic that can override the default action based on the original touch event when the drag never started
    // be sure to call event.preventDefault() if handling the default action in the override to prevent the browser default.
    defaultActionOverride?:( event:TouchEvent ) => void;

    // Drag action delay on touch devices ("hold to drag" functionality, useful for scrolling draggable items). Defaults to no delay.
    holdToDrag?:number;

    /**
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     *
     * THE FOLLOWING OPTIONS ARE ONLY AVAILABLE IN v2.3.0-rc.0
     *
     */

    // function invoked for each touchstart event to determine if and which touched element is detected as "draggable"
    tryFindDraggableTarget?:( event:TouchEvent ) => HTMLElement | undefined;

    // function implementing how a copy of the dragged element is created
    // NOTE! this function is for customizing HOW an element is transformed to a drag image element
    // if you're looking for setting a custom drag image please use [setDragImage()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setDragImage)
    dragImageSetup?:( element:HTMLElement ) => HTMLElement;

    // function for determining element that is currently hovered while dragging
    // defaults to `document.elementFromPoint()`
    elementFromPoint?:( x:number, y:number ) => Element;

    /**
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     */
}

// invoke for initializing the polyfill => returns true if polyfill is applied
export function polyfill(override?: Config):boolean;

Custom events

When setting the option holdToDrag the draggable element will emit custom events:

  • dnd-poly-dragstart-pending as soon as the touchstart event is detected and a drag operation is about to be started after the delay specified with holdToDrag
  • dnd-poly-dragstart-cancel when the drag operation will not be started due to touchmove, touchend, touchcancel or scroll within the holdToDrag delay.

Those events can be used to visualize the holdToDrag so the user is informed that a drag operation is about to start.

DragImage Customization

If you want to set a custom drag image use setDragImage().

Override the classes that are applied by the polyfill for customizing the drag image appearance and snapback behaviour. Mind the !important.

.dnd-poly-drag-image {
    opacity: .5 !important;
}
/* applied when the drag effect is none and the operation ends */
.dnd-poly-drag-image.dnd-poly-snapback {
    -webkit-transition: -webkit-transform 250ms ease-out !important;
    -moz-transition: -moz-transform 250ms ease-out !important;
    -o-transition: -o-transform 250ms ease-out !important;
    transition: transform 250ms ease-out !important;
}
/* applied always as a base class for drop effect styles */
.dnd-poly-drag-icon {
}

CSS classes are applied to the dragImage-element according to the current drop effect: none, copy, move, link.

There is icons.css which defines default styles and icons. Feel free to use this as a starting point.

<link rel="stylesheet" href="[...]/mobile-drag-drop/icons.css">

Custom drag image setup function

One can also set a custom dragImageSetup() function in the polyfill config. This allows to completely customize the routine used to create a copy of the dragged element.

Checkout the default implementation as a starting point.

Known issues and limitations

  • iFrames are currently not supported. Please see #5 for the current state.

  • :before/:after css pseudo styles can't be copied to the drag image. By default classes are removed on the drag image recursively to avoid side-effects. You can pass a custom dragImageSetup function in the config.

Contributions welcome!

Browser compatibility

Browser Support Known issues
Chrome Native No known issues. More info
Firefox Native No known issues. More info
Safari Native No known issues.
Opera Native Same as Chrome.
Brave Native Same as Chrome.
Internet Explorer 11 Native No known issues.
Edge Native No known issues. More info
Mobile Safari (<iOS 10) Polyfill No known issues.
Mobile Safari (>=iOS 10) Polyfill #77
Mobile Safari (>=iOS 15) Native & Polyfill #167
Chrome on iOS Polyfill See Mobile Safari since it's the same engine inside.
Chrome on Android Polyfill No known issues. Needs investigation regarding native capabilities!
Chrome on touch device Polyfill No known issues. More info
Firefox on touch device Native No known issues.
Firefox on Android Polyfill No known issues.
Amazon Silk Unknown Unknown
Ubuntu Phone Polyfill No known issues.
IEMobile Native Unknown

Chrome: Chrome supports touch devices/events. When run on a desktop touch device like MS Surface it turns on touch events which also disables native drag-and-drop support. Touch events can also be set by a user in chrome://flags to auto, on, off.
There is also a flag for enabling drag-and-drop through touch interaction but only for Windows and the option is off by default. The polyfill still works if this setting is active. We cannot detect if this flag is set so we just stick to applying the polyfill when Chrome is detected with touch events enabled.

Firefox: Touch events can be activated by a user in about:config to 0 (off), 1 (on), 2(auto). As of today (FF39.0) touch behavior is off. When touch events are active drag-and-drop interaction will still work, so no need to polyfill.

Cross-browser differences in HTML5 drag'n'drop API

The drag'n'drop API is not implemented consistently in all browsers. This table is an effort to list all things required to make drag'n'drop work in all browsers and with the polyfill.

Browser dragstart drag dragend dragenter dragover dragleave dragexit
Firefox event.dataTransfer.setData(type, data) effectAllowed,dropEffect effectAllowed,dropEffect
IE11 event.preventDefault() when registered on body
Polyfill event.preventDefault() or dropzone required

empty cells mean there is nothing special to take into account

Polyfill requires dragenter listener

On desktop browsers if no dragenter-handler is registered the drag-operation is silently allowed. Browsers don't implement dropzone-attribute according to caniuse which is why they allow it by default, which violates the spec.

If a handler is set up it has to call event.preventDefault() to allow dropping.

This is pretty bad for the polyfill since JS doesn't allow to check how many listeners were invoked when the event is dispatched, which forces the polyfill to rely on a listener being present calling event.preventDefault() to make it work.

Further notices:

  • FF: If effectAllowed or dropEffect is set in dragstart then dragenter/dragover also need to set it.
  • When using a MS Surface tablet a drag-operation is initiated by touch and hold on a draggable.
  • IE11, Chrome (and all other browsers using the same engine), Firefox scroll automatically when dragging close to a viewport edge.

Baseline recommendations for cross-browser/-platform support:

  • Always set drag data on dragstart by calling event.dataTransfer.setData(type, data).
  • Always handle dragenter-event on possible dropzones if the drop is allowed by calling event.preventDefault().
  • Handle dragover-event on dropzone when the drop is allowed by calling event.preventDefault(), otherwise the drag-operation is aborted.

Contribute

Contributions are welcome.

For more details on development setup see CONTRIBUTING.md

Thanks

To the amazing contributors who've provided massive extensions and fixes to the original.

@rem - who created the original demo used to demo this shim's drop-in nature.

License

MIT License

mobile-drag-drop's People

Contributors

altschuler avatar antkozlo avatar anwarjaved avatar bhollis avatar chocolateloverraj avatar dependabot[bot] avatar dmcinnes avatar fresswolf avatar jamesplease avatar jhickner avatar jogibear9988 avatar johanquiroga avatar jondum avatar laurentvd avatar layerssss avatar linuss avatar markleusink avatar mostr avatar nathanbedford avatar pleku avatar reppners avatar shirro avatar timruffles avatar xstrom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobile-drag-drop's Issues

Drop (dragend) does not work on iOS 8.4.1

This shim does not seem to work on iOS 8.4.1: While starting a drag operation and dragging itself works, dropping does not. On previous versions of iOS, this works as expected.

Fix for iPad1

Hi,
We have an iPad 1 that we were testing on an noticed that this library wasn't working. When we use chrome emulator we can reproduce the problem.
line 338 looks like it needs a check if srcNode.nodeType is an element before cloning the node. It was throwing an error here.

  // Clone the style
   if (srcNode.nodeType == 1) {
    var cs = window.getComputedStyle(srcNode);
    for (var i = 0; i < cs.length; i++) {
      var csName = cs[i];
      dstNode.style.setProperty(csName, cs.getPropertyValue(csName), cs.getPropertyPriority(csName));
    }
  }

image of dragged element is centered on this element

Hello,

This issue is a bit hard to explain. I have created some illustration to show the issue.

When I start to drag an element on mobile, the "image" of this element is automatically centered where my finger is, which lead to very poor UX experience if the div is big, or if we use a specific element to reorder a list. Example:

bug

On this example, I can only drag element by the small icon. When I start to drag an element by touching the small icon, the semi-transparent image (which represent the dragged element) is centered on the position of my finger.

I think it will be better to don't center the semi-transparent image. Instead, the semi-transparent image should be positioned where the user touch the element.

behavior

thanks

Add delay to enable scrolling on mobile

When working on a touch device the shim cant distinguish between scrolling and dragging.
Would be great to have a config to set a delay (typically 300ms) to hold before dragging is enabled.

This is closer to how it works on a native device.

Release on bower/npm

I'd resolve #30 then release this lib. Atm I'm using git SHAs to track the dep, which works but semver versions are betta'

PreventDefault on drag start supported?

Hi,

Thanks a lot for writing this. You have made my life very easy.

There is one thing I am not able to work out. I need to prevent drag start on certain condition. preventDefault on drag start is not sufficient.

I tried changing the code: called cleanup(making the function member of DragDrop and other necessary changes) but it wont work.

Please help

originalEvent.offsetX and offsetY are NaN

on drop, the offsetX and offsetY values are NaN, because on line 136 there is:

dropEvt.offsetX = x - target.x;

and target.x is undefined. Target is just the target dom element

make a new release with most recent changes

Can you folks make another release that includes the most recent changes, like the one that puts the drag image off screen instead of in the top-left-corner before the start of the drag event? The most recent release version 1.0.1 doesn't include those commits, which means I can't get them via bower. Thanks!

Conflict Hammer JS iOS

First of all, thanks for the awesome library, it helps save a lot of time.
On the other hand, I'm trying to use enter leave with with hammer js, but events like press don't work anymore when I set enableEnterLeave: true. this doesn't happen on chrome browser but happens on iOS UiWebView. any suggestion on what might be the problem or how to find it please.

Thanks

2.x Demos

  • cleanup demo/test page and provide usage examples with code snippets
    • examples of drag and drop with different effects
    • example of nested draggables
    • example of using custom drag start condition override
      • showcase limitation when doing deferred drag start
    • example of implementing drag-handle
    • example of using scroll plugin

Enter/Leave Support and Z issues

I just updated to your latest version, and I made a couple changes that I've been using. I figured I'd pass them along, in case you want them.

  1. Give the dragged element a high z-index, so that if you are in the neighborhood of absolute-positioned stuff, it doesn't go under that stuff.
  2. Instead of removing the dragged element to figure out where to put it, instead just give it pointer-events=none, so that it is ignored. That removes the need to wrestle with the DOM, which is important for the next item.
  3. Send dragenter and dragleave events, so the caller can fiddle CSS classes to give the user a hint about what's going to happen.
***************
*** 74,80 ****
--- 74,90 ----

        this.elTranslation.x += average(deltas.x);
        this.elTranslation.y += average(deltas.y);
+       this.el.style["z-index"] = "999999";
+       this.el.style["pointer-events"] = "none";
        writeTransform(this.el, this.elTranslation.x, this.elTranslation.y);
+ 
+         var target = elementFromTouchEvent(this.el,event)
+         if (target != this.lastEnter) {
+             if (this.lastEnter)
+                 this.dispatchLeave();
+             this.lastEnter = target;
+             this.dispatchEnter();
+         }
      },
      dragend: function(event) {

***************
*** 83,88 ****
--- 93,101 ----
        // drop comes first http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#drag-and-drop-processing-model
        log("dragend");

+         if (this.lastEnter)
+             this.dispatchLeave();
+ 
        var target = elementFromTouchEvent(this.el,event)

        if (target) {
***************
*** 97,102 ****
--- 110,140 ----
        dragendEvt.initEvent("dragend", true, true);
        this.el.dispatchEvent(dragendEvt);
      },
+     dispatchEnter: function() {
+ 
+       var enterEvt = doc.createEvent("Event");
+       enterEvt.initEvent("dragenter", true, true);
+       enterEvt.dataTransfer = {
+         getData: function(type) {
+           return this.dragData[type];
+         }.bind(this)
+       };
+ 
+       this.lastEnter.dispatchEvent(enterEvt);
+     },
+     dispatchLeave: function() {
+ 
+       var leaveEvt = doc.createEvent("Event");
+       leaveEvt.initEvent("dragleave", true, true);
+       leaveEvt.dataTransfer = {
+         getData: function(type) {
+           return this.dragData[type];
+         }.bind(this)
+       };
+ 
+       this.lastEnter.dispatchEvent(leaveEvt);
+       this.lastEnter = null;
+     },
      dispatchDrop: function() {
        var snapBack = true;

***************
*** 109,114 ****
--- 147,154 ----
        };
        dropEvt.preventDefault = function() {
           // https://www.w3.org/Bugs/Public/show_bug.cgi?id=14638 - if we don't cancel it, we'll snap back
+         this.el.style["z-index"] = "";
+         this.el.style["pointer-events"] = "auto";
          snapBack = false;
          writeTransform(this.el, 0, 0);
        }.bind(this);
***************
*** 122,127 ****
--- 162,169 ----
      },
      snapBack: function() {
        once(this.el, "webkitTransitionEnd", function() {
+         this.el.style["z-index"] = "";
+         this.el.style["pointer-events"] = "auto";
          this.el.style["-webkit-transition"] = "none";
        },this);
        setTimeout(function() {
***************
*** 155,163 ****

    // DOM helpers
    function elementFromTouchEvent(el,event) {
!     var parent = el.parentElement;
!     var next = el.nextSibling
!     parent.removeChild(el);

      var touch = event.changedTouches[0];
      target = doc.elementFromPoint(
--- 197,205 ----

    // DOM helpers
    function elementFromTouchEvent(el,event) {
! //    var parent = el.parentElement;
! //    var next = el.nextSibling
! //    parent.removeChild(el);

      var touch = event.changedTouches[0];
      target = doc.elementFromPoint(
***************
*** 165,175 ****
        touch[coordinateSystemForElementFromPoint + "Y"]
      );

!     if(next) {
!       parent.insertBefore(el, next);
!     } else {
!       parent.appendChild(el);
!     }

      return target
    }
--- 207,217 ----
        touch[coordinateSystemForElementFromPoint + "Y"]
      );

! //    if(next) {
! //      parent.insertBefore(el, next);
! //    } else {
! //      parent.appendChild(el);
! //    }

      return target
    }

Click event not triggered for drag target

Hi,

Version: Master as at 06-Sep-2015

The click event is not being triggered for drag sources. Here is a fiddle that demonstrates the problem.

In the fiddle, the click event is bound for both the #source and #target elements. When tested on iOS 8.4.1, tapping on the drop target should alert 'target clicked'. However, tapping on the drag source does not alert anything.

There is some documentation on this on MDN.

Thanks.

Parity with default drag image

When dragging something with the HTML5 drag & drop API, the element itself remains unchanged. Instead a partially transparent snapshot of that element is being dragged around. It would be nice to replicate this functionality.

Pull request #14 tries to move in that direction, however it creates more problems than it solves. Cloning an element can have serious side-effects. These side-effects are very real in my own uses. Some examples of things that break:

  1. My code contains assumptions that a draggable

    is followed by a another special non-draggable
    . With the #14 patch, that would no longer be the case, as the draggable
    would be followed by its own clone instead. The clone can't really be placed far away from this DOM spot either, because it may depend on CSS that only applies in that position. In fact, this very close clone will not receive the proper adjacent sibling styles.

  2. My code does some basic counting of elements with specific properties. The clone would cause off-by-one errors.

I would be more than happy to hear how these problems could be avoided with cloning. Until then, I think it's safe to say cloning does more harm than good.

Lets look at some alternative options.

There's html2canvas which is a sort of emulated screenshot taking library. It works similarly to how the Google feedback tool does it. However this library seems limited in its ability, is in a "very experimental state", and would be a fairly sizable addition to this otherwise slim shim.

Then there's the CSS element() function, which could work nicely.

<div style="background: element(#draggableEl);"></div>

The above code would give us a new element with its background set to the appearance of the draggable element. Perfect!

If only ..

This part of CSS is only functional in Firefox, and looking at the WebKit tracker it's nowhere near close to being added to webkit.

I also searched around for more alternative CSS ways, perhaps a fancy -webkit-transform-duplicate-position property, but no such luck.

Right now, I don't see a way to move closer to parity and show a drag image, instead of moving around the element itself. I'm hoping someone else can give some ideas how this could be achieved.

update `<a>` handling to match browser behaviour - fire clicks unless moving, when drag

as per #22

However the browsers initiate their native drag handling only in special cases, when the mouse is moved a certain amount after being pressed down. Without sufficient movement, it's handled as a classic click.

Ideally we would like to have similar handling via touchmove and fallback to clicks without enough movement, however I've cooked up a faster fix for now.

With this patch, anchors are still draggable by default and handled as such. However if an anchor element doesn't have the draggable attribute explicitly set, then we also simulate a click event.

Ready for a release?

@timruffles, @xStrom, I'd like to create release v1.3.0 so we can publish the fixes / features. Thoughts?

Diff between last release (1.2.0) and master:
v1.2.0...master

Features

  • Added commonjs support

Bugfixes

  • fixed issue with Chrome and addEventListener defaulting to {passive:true} in v56
  • when dragstart occurs on anchor element, defaulting to not send mouse events
  • will search upwards for a draggable element in touchstartDelay now

ClientX and ClientY for Drop

Many thanks for the code, saved me a lot of pain! ClientX and ClientY are not currently included for Drop. I added them into dispatchDrop and they worked as expected.

  dropEvt.clientX = touch.clientX;
  dropEvt.clientY = touch.clientY;

Alternate way of setting enter / leave support

Great library. Yet I'm having a problem enabling enter / leave support. There are frameworks out there that do not allow you to place static JS code before embedding a library, like Meteor (at least, they don't allow it without some hacking). So it would be great if enter / leave support would either be enabled by default, or if there were an explicit function call to trigger that support.

Ability to set needsPatch to `true` through config

I've run into enough issues with userAgent sniffing that I want to be able to force this patch, if necessary.

Example use case is when the userAgent has been altered.

var needsPatch = !(dragDiv || evts) || /iPad|iPhone|iPod|Android|/i.test(navigator.userAgent) || !!config.needsPatch;

Bug with deep hierarchies

When the dragged item has several DIVs, it is dragging the internal DIV, not the external one.

The reason is that dragstart function is not propagating the "el" element passed to it.

The fix is simply:

dragstart = (evt) ->
evt.preventDefault()
new DragDrop(evt)

should be:

dragstart = (evt, el) ->
evt.preventDefault()
new DragDrop(evt, el)

Ability to "bind" only specif elements not the whole document

Hey! First, thanks for the library, is awesome!
So, there's a way to bind only specif elements? e.g bind only a modal or a dropdown?
I'm having problems with a project. In this project with have a map using OpenMaps. This map is working with iPad, but once I activate the plugin (for another parts of the project) it's stop to work.

Thank you in advance.

v2.0.0-beta.1: Lost cursor and controls interaction on Android version 4.4.2 stock browser

First of all thanks for a great library.

It works fine in Chrome in modern touch devices but on Galaxy S3, I lost control of the forms and cursor after enabling the library (Example: input type "text" etc.). Is this a known issue? This happens with the stock Android browser with Android version 4.4.2. Verified that it works fine in Chrome on same Galaxy S3 device.

Suggestion - Dynamic element selection

Hi all,

First of all, my thanks to @timruffles for this nice script, it really takes the pain away from handling drag-n-drop on mobile devices.

In my implementation I noticed that on mobile safari (on iOS 10.2), after activating the script, suddenly all elements seemed to become draggable (= on drag, every element stuck to the cursor as a real draggable element).

I solved this issue by adding a custom attribute only to those elements that I really wanted to drag and change rule 323 in the script to

if (el.draggable === true && el.getAttribute("<custom_attribute>") === "<specific_value>") {

I thought I'd share this solution and maybe make a suggestion to integrate this into the master version (or maybe with the possibility to give a querySelector upon construction of the main object).

Regards,

Robbie

Uncaught ReferenceError: DEBUG is not defined

I installed release 2.0.0-beta.0 with bower and imported drag-drop-polyfill.js and drag-drop-polyfill.css in my EmberJS app, but when invoking DragDropPolyfill.Initialize() I get:

Uncaught ReferenceError: DEBUG is not defined

I see DEBUG defined here but afaik I can't import that source in my EmberJS app as it's TypeScript.
Shouldn't DEBUG be defined in drag-drop-polyfill.js for better compatibility?

'event' is undefined on line 48

Dropping this into my code gives me an error during page load.

Here is the line in question:

touch = event.changedTouches[0];

rename

this should be renamed to 'mobile-html5-drag-drop', as it supports Android.

Unexpected behaviour on Nexus 7

This shim causes a quite weird behaviour on Nexus 7 devices (running stock Android Lollipop). If you add the shim to your page, all images become automatically draggable (even if the "draggable" attribute has not been set on them) - and all other events on these images are prevented. In effect, you can now drag nearly every image, but you cannot interact with them anymore (e.g. if you use them as buttons)...

Angular Dependency

Can you put angular dependency at bower.json?

Because automated build that read bower.json to inject index.html.

Logic error in drag end handler

The code tests for nextSibling after removing the element from the DOM, which causes it to always drop the element at the end, instead of where it came from.

The code currently reads:

  # ensure we get the element beneath the dragged item
  parent = @el.parentElement
  parent.removeChild(@el)

  target = elementFromTouchEvent(event)

  if next = @el.nextSibling
    parent.insertBefore @el, next
  else
    parent.appendChild @el

But it should read:

  # ensure we get the element beneath the dragged item
  parent = @el.parentElement
  next = @el.nextSibling
  parent.removeChild(@el)

  target = elementFromTouchEvent(event)

  if next
    parent.insertBefore @el, next
  else
    parent.appendChild @el

[2.0.0] Impossible to use as a module?

Trying to pull the 2.0.0-beta.3 polyfill in to our project that uses TypeScript and WebPack2, and it seems effectively impossible to pull in as a module.

import 'drag-drop-polyfill';
DragDropPolyfill.Initialize(); // Compiler Error:
// error TS2304: Cannot find name 'DragDropPolyfill'.
import DragDropPolyfill from 'drag-drop-polyfill';
DragDropPolyfill.Initialize(); // Runtime Error:
// Uncaught TypeError: Cannot read property 'Initialize' of undefined
import * as DragDropPolyfill from 'drag-drop-polyfill';
DragDropPolyfill.Initialize(); // Runtime Error:
// Uncaught TypeError: DragDropPolyfill.Initialize is not a function

What is the proper way to use this with WebPack/Browserify/Rollup?

How to import to typescript

I use import { DragDropPolyfill } from "drag-drop-polyfill";
and error is "Cannot find module 'drag-drop-polyfill'."
help me please.

Cross iFrame Drag'n'Drop

Would be cool to have this feature included.

Unfortunately, your code is written in CoffeeScript, so I can't contribute this feature.

Investigate passive document level event listeners

https://www.chromestatus.com/feature/5093566007214080

https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md

The new passive-option for on addEventListener is there to let the browser know in advance if your event listener will call preventDefault(). The reason is scrolling performance.

This polyfill is a primary user of document level event listeners and I experienced issues on latest stable chromium 54.0.2840.99 where the new behaviour is already activated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.