|
903 | 903 | return origin;
|
904 | 904 | }
|
905 | 905 |
|
| 906 | + function calcInertia (status) { |
| 907 | + var inertiaOptions = status.target.options.inertia, |
| 908 | + lambda = inertiaOptions.resistance, |
| 909 | + inertiaDur = -Math.log(inertiaOptions.endSpeed / status.v0) / lambda; |
| 910 | + |
| 911 | + status.x0 = prevEvent.pageX; |
| 912 | + status.y0 = prevEvent.pageY; |
| 913 | + status.t0 = status.startEvent.timeStamp / 1000; |
| 914 | + status.sx = status.sy = 0; |
| 915 | + |
| 916 | + status.modifiedXe = status.xe = (status.vx0 - inertiaDur) / lambda; |
| 917 | + status.modifiedYe = status.ye = (status.vy0 - inertiaDur) / lambda; |
| 918 | + status.te = inertiaDur; |
| 919 | + |
| 920 | + status.lambda_v0 = lambda / status.v0; |
| 921 | + status.one_ve_v0 = 1 - inertiaOptions.endSpeed / status.v0; |
| 922 | + } |
| 923 | + |
906 | 924 | function inertiaFrame () {
|
907 | 925 | var options = inertiaStatus.target.options.inertia,
|
908 | 926 | lambda = options.resistance,
|
|
2670 | 2688 | }
|
2671 | 2689 |
|
2672 | 2690 | var endEvent,
|
2673 |
| - inertiaOptions = target && target.options.inertia, |
| 2691 | + options = target && target.options, |
| 2692 | + inertiaOptions = options && options.inertia, |
2674 | 2693 | prop;
|
2675 | 2694 |
|
2676 | 2695 | if (dragging || resizing || gesturing) {
|
2677 | 2696 |
|
2678 | 2697 | if (inertiaStatus.active) { return; }
|
2679 | 2698 |
|
2680 | 2699 | var deltaSource =target.options.deltaSource,
|
2681 |
| - pointerSpeed = pointerDelta[deltaSource + 'Speed']; |
| 2700 | + pointerSpeed = pointerDelta[deltaSource + 'Speed'], |
| 2701 | + inertia = false; |
2682 | 2702 |
|
2683 | 2703 | // check if inertia should be started
|
2684 |
| - if (target.options.inertiaEnabled |
| 2704 | + inertia = (target.options.inertiaEnabled |
2685 | 2705 | && prepared !== 'gesture'
|
2686 | 2706 | && indexOf(inertiaOptions.actions, prepared) !== -1
|
2687 | 2707 | && event !== inertiaStatus.startEvent
|
2688 | 2708 | && (new Date().getTime() - curCoords.timeStamp) < 50
|
2689 | 2709 | && pointerSpeed > inertiaOptions.minSpeed
|
2690 |
| - && pointerSpeed > inertiaOptions.endSpeed) { |
2691 |
| - |
| 2710 | + && pointerSpeed > inertiaOptions.endSpeed); |
2692 | 2711 |
|
2693 |
| - var lambda = inertiaOptions.resistance, |
2694 |
| - inertiaDur = -Math.log(inertiaOptions.endSpeed / pointerSpeed) / lambda, |
2695 |
| - startEvent; |
| 2712 | + // check if inertia should be started |
| 2713 | + if (inertia) { |
| 2714 | + var startEvent; |
2696 | 2715 |
|
2697 | 2716 | inertiaStatus.active = true;
|
2698 | 2717 | inertiaStatus.target = target;
|
|
2715 | 2734 | inertiaStatus.vx0 = pointerDelta[deltaSource + 'VX'];
|
2716 | 2735 | inertiaStatus.vy0 = pointerDelta[deltaSource + 'VY'];
|
2717 | 2736 | inertiaStatus.v0 = pointerSpeed;
|
2718 |
| - inertiaStatus.x0 = prevEvent.pageX; |
2719 |
| - inertiaStatus.y0 = prevEvent.pageY; |
2720 |
| - inertiaStatus.t0 = inertiaStatus.startEvent.timeStamp / 1000; |
2721 |
| - inertiaStatus.sx = inertiaStatus.sy = 0; |
2722 |
| - |
2723 |
| - inertiaStatus.modifiedXe = inertiaStatus.xe = (inertiaStatus.vx0 - inertiaDur) / lambda; |
2724 |
| - inertiaStatus.modifiedYe = inertiaStatus.ye = (inertiaStatus.vy0 - inertiaDur) / lambda; |
2725 |
| - inertiaStatus.te = inertiaDur; |
2726 | 2737 |
|
2727 |
| - inertiaStatus.lambda_v0 = lambda / inertiaStatus.v0; |
2728 |
| - inertiaStatus.one_ve_v0 = 1 - inertiaOptions.endSpeed / inertiaStatus.v0; |
| 2738 | + calcInertia(inertiaStatus); |
2729 | 2739 |
|
2730 | 2740 | var startX = startEvent.pageX,
|
2731 | 2741 | startY = startEvent.pageY,
|
2732 |
| - statusObject; |
| 2742 | + statusObject, |
| 2743 | + dx = 0, |
| 2744 | + dy = 0; |
2733 | 2745 |
|
2734 | 2746 | if (startEvent.snap && startEvent.snap.locked) {
|
2735 | 2747 | startX -= startEvent.snap.dx;
|
|
2756 | 2768 | var snap = setSnapping(event, statusObject);
|
2757 | 2769 |
|
2758 | 2770 | if (snap.locked) {
|
2759 |
| - inertiaStatus.modifiedXe += snap.dx; |
2760 |
| - inertiaStatus.modifiedYe += snap.dy; |
| 2771 | + dx += snap.dx; |
| 2772 | + dy += snap.dy; |
2761 | 2773 | }
|
2762 | 2774 | }
|
2763 | 2775 |
|
2764 | 2776 | if (target.options.restrictEnabled && target.options.restrict.endOnly) {
|
2765 | 2777 | var restrict = setRestriction(event, statusObject);
|
2766 | 2778 |
|
2767 |
| - inertiaStatus.modifiedXe += restrict.dx; |
2768 |
| - inertiaStatus.modifiedYe += restrict.dy; |
| 2779 | + dx += restrict.dx; |
| 2780 | + dy += restrict.dy; |
2769 | 2781 | }
|
2770 | 2782 |
|
| 2783 | + inertiaStatus.modifiedXe += dx; |
| 2784 | + inertiaStatus.modifiedYe += dy; |
| 2785 | + |
2771 | 2786 | cancelFrame(inertiaStatus.i);
|
2772 | 2787 | inertiaStatus.i = reqFrame(inertiaFrame);
|
2773 | 2788 |
|
|
0 commit comments