|
1 | 1 | /**
|
2 |
| - * interact.js v1.0.26 |
| 2 | + * interact.js v1.0.27 |
3 | 3 | *
|
4 | 4 | * Copyright (c) 2012, 2013, 2014 Taye Adeyemi <dev@taye.me>
|
5 | 5 | * Open source under the MIT License.
|
|
23 | 23 | tmpXY = {}, // reduce object creation in getXY()
|
24 | 24 |
|
25 | 25 | interactables = [], // all set interactables
|
26 |
| - dropzones = [], // all dropzone element interactables |
27 | 26 | interactions = [],
|
28 | 27 |
|
29 | 28 | dynamicDrop = false,
|
|
474 | 473 | removeFromElement: remove,
|
475 | 474 | useAttachEvent: useAttachEvent,
|
476 | 475 |
|
477 |
| - indexOf: indexOf |
| 476 | + _elements: elements, |
| 477 | + _targets: targets, |
| 478 | + _attachedListeners: attachedListeners |
478 | 479 | };
|
479 | 480 | }());
|
480 | 481 |
|
|
1479 | 1480 | ? this.inertiaStatus.startEvent
|
1480 | 1481 | : undefined);
|
1481 | 1482 |
|
| 1483 | + if (this.pointerWasMoved |
| 1484 | + && this.curCoords.page.x === this.prevCoords.page.x |
| 1485 | + && this.curCoords.page.y === this.prevCoords.page.y |
| 1486 | + && this.curCoords.client.x === this.prevCoords.client.x |
| 1487 | + && this.curCoords.client.y === this.prevCoords.client.y) { |
| 1488 | + |
| 1489 | + this.checkAndPreventDefault(event, this.target, this.element); |
| 1490 | + return; |
| 1491 | + } |
| 1492 | + |
| 1493 | + // set pointer coordinate, time changes and speeds |
| 1494 | + setEventDeltas(this.pointerDelta, this.prevCoords, this.curCoords); |
| 1495 | + |
1482 | 1496 | var dx, dy;
|
1483 | 1497 |
|
1484 | 1498 | // register movement of more than 1 pixel
|
|
1665 | 1679 | }
|
1666 | 1680 | }
|
1667 | 1681 |
|
1668 |
| - // set pointer coordinate, time changes and speeds |
1669 |
| - setEventDeltas(this.pointerDelta, this.prevCoords, this.curCoords); |
1670 | 1682 | copyCoords(this.prevCoords, this.curCoords);
|
1671 | 1683 |
|
1672 | 1684 | if (this.dragging || this.resizing) {
|
|
1778 | 1790 |
|
1779 | 1791 | if (inertiaStatus.active) { return; }
|
1780 | 1792 |
|
1781 |
| - var deltaSource = options.deltaSource, |
1782 |
| - pointerSpeed = this.pointerDelta[deltaSource].speed, |
| 1793 | + var pointerSpeed, |
1783 | 1794 | now = new Date().getTime(),
|
1784 | 1795 | inertiaPossible = false,
|
1785 | 1796 | inertia = false,
|
|
1790 | 1801 | dy = 0,
|
1791 | 1802 | startEvent;
|
1792 | 1803 |
|
| 1804 | + if (this.dragging) { |
| 1805 | + if (options.dragAxis === 'x' ) { pointerSpeed = Math.abs(this.pointerDelta.client.vx); } |
| 1806 | + else if (options.dragAxis === 'y' ) { pointerSpeed = Math.abs(this.pointerDelta.client.vy); } |
| 1807 | + else /*options.dragAxis === 'xy'*/{ pointerSpeed = this.pointerDelta.client.speed; } |
| 1808 | + } |
| 1809 | + |
1793 | 1810 | // check if inertia should be started
|
1794 | 1811 | inertiaPossible = (options.inertiaEnabled
|
1795 | 1812 | && this.prepared !== 'gesture'
|
|
1839 | 1856 | target.fire(inertiaStatus.startEvent);
|
1840 | 1857 |
|
1841 | 1858 | if (inertia) {
|
1842 |
| - inertiaStatus.vx0 = this.pointerDelta[deltaSource].vx; |
1843 |
| - inertiaStatus.vy0 = this.pointerDelta[deltaSource].vy; |
| 1859 | + inertiaStatus.vx0 = this.pointerDelta.client.vx; |
| 1860 | + inertiaStatus.vy0 = this.pointerDelta.client.vy; |
1844 | 1861 | inertiaStatus.v0 = pointerSpeed;
|
1845 | 1862 |
|
1846 | 1863 | this.calcInertia(inertiaStatus);
|
|
1938 | 1955 |
|
1939 | 1956 | var dropEvents = this.getDropEvents(event, endEvent);
|
1940 | 1957 |
|
1941 |
| - target.fire(endEvent); |
1942 |
| - |
1943 | 1958 | if (dropEvents.leave) { this.prevDropTarget.fire(dropEvents.leave); }
|
1944 | 1959 | if (dropEvents.enter) { this.dropTarget.fire(dropEvents.enter); }
|
1945 | 1960 | if (dropEvents.drop ) { this.dropTarget.fire(dropEvents.drop ); }
|
1946 | 1961 | if (dropEvents.deactivate) {
|
1947 | 1962 | this.fireActiveDrops(dropEvents.deactivate);
|
1948 | 1963 | }
|
| 1964 | + |
| 1965 | + target.fire(endEvent); |
1949 | 1966 | }
|
1950 | 1967 | else if (this.resizing) {
|
1951 | 1968 | endEvent = new InteractEvent(this, event, 'resize', 'end', this.element);
|
|
1967 | 1984 | element = element || this.element;
|
1968 | 1985 |
|
1969 | 1986 | // collect all dropzones and their elements which qualify for a drop
|
1970 |
| - for (i = 0; i < dropzones.length; i++) { |
1971 |
| - var current = dropzones[i]; |
| 1987 | + for (i = 0; i < interactables.length; i++) { |
| 1988 | + if (!interactables[i].options.dropzone) { continue; } |
| 1989 | + |
| 1990 | + var current = interactables[i]; |
1972 | 1991 |
|
1973 | 1992 | // test the draggable element against the dropzone's accept setting
|
1974 | 1993 | if ((isElement(current.options.accept) && current.options.accept !== element)
|
|
1979 | 1998 | }
|
1980 | 1999 |
|
1981 | 2000 | // query for new elements if necessary
|
1982 |
| - if (current.selector) { |
1983 |
| - current._dropElements = current._context.querySelectorAll(current.selector); |
1984 |
| - } |
| 2001 | + var dropElements = current.selector? current._context.querySelectorAll(current.selector) : [current._element]; |
1985 | 2002 |
|
1986 |
| - for (var j = 0, len = current._dropElements.length; j < len; j++) { |
1987 |
| - var currentElement = current._dropElements[j]; |
| 2003 | + for (var j = 0, len = dropElements.length; j < len; j++) { |
| 2004 | + var currentElement = dropElements[j]; |
1988 | 2005 |
|
1989 | 2006 | if (currentElement === element) {
|
1990 | 2007 | continue;
|
|
2158 | 2175 |
|
2159 | 2176 | if (this.dragging) {
|
2160 | 2177 | this.activeDrops.dropzones = this.activeDrops.elements = this.activeDrops.rects = null;
|
2161 |
| - |
2162 |
| - for (var i = 0; i < dropzones.length; i++) { |
2163 |
| - if (dropzones[i].selector) { |
2164 |
| - dropzones[i]._dropElements = null; |
2165 |
| - } |
2166 |
| - } |
2167 | 2178 | }
|
2168 | 2179 |
|
2169 | 2180 | this.clearTargets();
|
|
3009 | 3020 | // Use natural event coordinates (without snapping/restricions)
|
3010 | 3021 | // subtract modifications from previous event if event given is
|
3011 | 3022 | // not a native event
|
3012 |
| - if (ending || event instanceof InteractEvent) { |
| 3023 | + if (event instanceof InteractEvent) { |
3013 | 3024 | // change in time in seconds
|
3014 | 3025 | // use event sequence duration for end events
|
3015 | 3026 | // => average speed of the event sequence
|
|
3226 | 3237 | return delegateListener.call(this, event, true);
|
3227 | 3238 | }
|
3228 | 3239 |
|
3229 |
| - interactables.indexOfElement = dropzones.indexOfElement = function indexOfElement (element, context) { |
| 3240 | + interactables.indexOfElement = function indexOfElement (element, context) { |
3230 | 3241 | for (var i = 0; i < this.length; i++) {
|
3231 | 3242 | var interactable = this[i];
|
3232 | 3243 |
|
|
3241 | 3252 | return -1;
|
3242 | 3253 | };
|
3243 | 3254 |
|
3244 |
| - interactables.get = dropzones.get = function interactableGet (element, options) { |
| 3255 | + interactables.get = function interactableGet (element, options) { |
3245 | 3256 | return this[this.indexOfElement(element, options && options.context)];
|
3246 | 3257 | };
|
3247 | 3258 |
|
|
3484 | 3495 | this.options.dropOverlap = Math.max(Math.min(1, options.overlap), 0);
|
3485 | 3496 | }
|
3486 | 3497 |
|
3487 |
| - this._dropElements = this.selector? null: [this._element]; |
3488 |
| - dropzones.push(this); |
3489 |
| - |
3490 | 3498 | return this;
|
3491 | 3499 | }
|
3492 | 3500 |
|
3493 | 3501 | if (isBool(options)) {
|
3494 |
| - if (options) { |
3495 |
| - this._dropElements = this.selector? null: [this._element]; |
3496 |
| - dropzones.push(this); |
3497 |
| - } |
3498 |
| - else { |
3499 |
| - var index = indexOf(dropzones, this); |
3500 |
| - |
3501 |
| - if (index !== -1) { |
3502 |
| - dropzones.splice(index, 1); |
3503 |
| - } |
3504 |
| - } |
3505 |
| - |
3506 | 3502 | this.options.dropzone = options;
|
3507 | 3503 |
|
3508 | 3504 | return this;
|
|
5036 | 5032 | Interactable : Interactable,
|
5037 | 5033 | IOptions : IOptions,
|
5038 | 5034 | interactables : interactables,
|
5039 |
| - dropzones : dropzones, |
5040 | 5035 | pointerIsDown : interaction.pointerIsDown,
|
5041 | 5036 | defaultOptions : defaultOptions,
|
5042 | 5037 | defaultActionChecker : defaultActionChecker,
|
|
0 commit comments