|
7 | 7 | var onWheelCallback,
|
8 | 8 | zoomWidthStep = 0,
|
9 | 9 | zoomHeightStep = 0,
|
10 |
| - isDraggable = false; |
| 10 | + isDraggable = false, |
| 11 | + isZoomActive = false; |
11 | 12 |
|
12 | 13 | $.fn.magnify = function (options) {
|
13 | 14 | 'use strict';
|
|
643 | 644 | }
|
644 | 645 | });
|
645 | 646 | }
|
646 |
| - |
647 | 647 | $image
|
648 | 648 | .off(isTouchEnabled ? 'touchstart' : 'pointerdown mousedown MSPointerDown')
|
649 | 649 | .on(isTouchEnabled ? 'touchstart' : 'pointerdown mousedown MSPointerDown', function (e) {
|
|
653 | 653 | imagePosY = $image.offset().top;
|
654 | 654 | imagePosX = $image.offset().left;
|
655 | 655 |
|
| 656 | + startX = e.clientX || e.originalEvent.clientX; |
| 657 | + startY = e.clientY || e.originalEvent.clientY; |
656 | 658 | if (isTouchEnabled) {
|
657 | 659 | touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
|
658 |
| - e.clientX = touch.pageX; |
659 |
| - e.clientY = touch.pageY; |
| 660 | + startX = touch.pageX; |
| 661 | + startY = touch.pageY; |
660 | 662 | }
|
661 |
| - startX = e.clientX || e.originalEvent.clientX; |
662 |
| - startY = e.clientY || e.originalEvent.clientY; |
663 | 663 | isDragActive = true;
|
664 | 664 | }
|
665 | 665 | });
|
|
670 | 670 | .off(isTouchEnabled ? 'touchmove' : 'mousemove pointermove MSPointerMove')
|
671 | 671 | .on(isTouchEnabled ? 'touchmove' : 'mousemove pointermove MSPointerMove', function (e) {
|
672 | 672 | if (gallery.data('fotorama').fullScreen && isDragActive && isDraggable) {
|
673 |
| - |
674 | 673 | var top,
|
675 | 674 | left,
|
676 | 675 | startOffset = $image.offset(),
|
|
680 | 679 |
|
681 | 680 | e.preventDefault();
|
682 | 681 |
|
683 |
| - if (isTouchEnabled) { |
| 682 | + if (isTouchEnabled && !isZoomActive) { |
684 | 683 | touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
|
685 |
| - e.clientX = touch.pageX; |
686 |
| - e.clientY = touch.pageY; |
| 684 | + clientX = touch.pageX; |
| 685 | + clientY = touch.pageY; |
687 | 686 | }
|
688 | 687 | top = +imagePosY + (clientY - startY);
|
689 | 688 | left = +imagePosX + (clientX - startX);
|
|
711 | 710 | 'left': left
|
712 | 711 | });
|
713 | 712 | }
|
| 713 | + return false; |
714 | 714 | }
|
715 | 715 | });
|
716 | 716 |
|
|
803 | 803 | $image = $('[data-gallery-role="stage-shaft"] [data-active="true"] .fotorama__img--full');
|
804 | 804 | $imageContainer = $preview.parent();
|
805 | 805 | gallery = $('[data-gallery-role="gallery"]');
|
806 |
| - top = $image.offset().top; |
807 |
| - left = $image.offset().left; |
| 806 | + top = $image.position().top; |
| 807 | + left = $image.position().left; |
| 808 | + |
| 809 | + if ($imageContainer.width() < $image.width() - widthStep && $imageContainer.width() > $image.width()) { |
| 810 | + left = ($imageContainer.width() - $image.width()) / 2; |
| 811 | + } |
808 | 812 |
|
809 |
| - if ($image.height() > $imageContainer.height()) { |
810 |
| - if ($imageContainer.offset().top + $imageContainer.height() > top + $image.height() + heightStep/2) { |
811 |
| - top = $imageContainer.offset().top + $imageContainer.height() - $image.height() + heightStep/2; |
| 813 | + if ($imageContainer.height() < $image.height() - heightStep && $imageContainer.height() > $image.height()) { |
| 814 | + top = ($imageContainer.height() - $image.height()) / 2; |
| 815 | + } |
| 816 | + |
| 817 | + if ($image.height() - heightStep > $imageContainer.height()) { |
| 818 | + if (Math.abs(top + heightStep / 2) > $image.height() - $imageContainer.height() - heightStep) { |
| 819 | + top = $imageContainer.height() - $image.height() + heightStep; |
| 820 | + } else if (top + heightStep / 2 >= 0) { |
| 821 | + top = 0; |
812 | 822 | } else {
|
813 |
| - top = ($imageContainer.offset().top <= top + heightStep/2 && heightStep > 0) ? 0 : top + heightStep/2; |
| 823 | + top += heightStep / 2; |
814 | 824 | }
|
815 | 825 | $image.css({
|
816 | 826 | top: top,
|
|
823 | 833 | });
|
824 | 834 | }
|
825 | 835 |
|
826 |
| - if ($image.width() > $imageContainer.width()) { |
827 |
| - if (($imageContainer.offset().left + $imageContainer.width()) > (left + $image.width() + widthStep/2)) { |
828 |
| - left = $imageContainer.offset().left + $imageContainer.width() - $image.width() + widthStep/2; |
| 836 | + if ($image.width() - widthStep > $imageContainer.width()) { |
| 837 | + if (Math.abs(left + widthStep / 2) > $image.width() - $imageContainer.width() - widthStep) { |
| 838 | + left = $imageContainer.width() - $image.width() + widthStep; |
| 839 | + } else if (left + widthStep / 2 >= 0) { |
| 840 | + left = 0; |
829 | 841 | } else {
|
830 |
| - left = ($imageContainer.offset().left <= left + widthStep/2 && widthStep > 0) ? 0 : left - $imageContainer.offset().left + widthStep/2; |
| 842 | + left += widthStep / 2; |
831 | 843 | }
|
832 | 844 | $image.css({
|
833 | 845 | left: left,
|
|
868 | 880 | }
|
869 | 881 |
|
870 | 882 | if ($image.width() >= $image.height() && $image.width() !== imgOriginalSize.rw) {
|
| 883 | + checkFullscreenImagePosition(-zoomWidthStep, -zoomHeightStep); |
871 | 884 | $image.css({
|
872 | 885 | width: widthResult,
|
873 | 886 | height: 'auto'
|
874 | 887 | });
|
875 |
| - checkFullscreenImagePosition(-zoomWidthStep, -zoomHeightStep); |
876 | 888 | } else if ($image.width() < $image.height() && $image.height() !== imgOriginalSize.rh) {
|
| 889 | + checkFullscreenImagePosition(-zoomWidthStep, -zoomHeightStep); |
877 | 890 | $image.css({
|
878 | 891 | width: 'auto',
|
879 | 892 | height: heightResult
|
880 | 893 | });
|
881 |
| - checkFullscreenImagePosition(-zoomWidthStep, -zoomHeightStep); |
882 | 894 | }
|
883 | 895 | }
|
884 | 896 |
|
|
905 | 917 | return false;
|
906 | 918 | }
|
907 | 919 | }
|
908 |
| - |
909 |
| - $image.css({'width': setedResult, height: 'auto'}); |
910 | 920 | checkFullscreenImagePosition(zoomWidthStep, zoomHeightStep);
|
| 921 | + $image.css({'width': setedResult, height: 'auto'}); |
911 | 922 | }
|
912 | 923 |
|
913 | 924 | return false;
|
|
939 | 950 | .off('mouseup')
|
940 | 951 | .on('mouseup', zoomOut);
|
941 | 952 | $('.fotorama__zoom-in')
|
942 |
| - .off('touchstart') |
943 |
| - .on('touchstart', zoomIn); |
| 953 | + .off('touchend') |
| 954 | + .on('touchend', zoomIn); |
944 | 955 | $('.fotorama__zoom-out')
|
945 |
| - .off('touchstart') |
946 |
| - .on('touchstart', zoomOut); |
| 956 | + .off('touchend') |
| 957 | + .on('touchend', zoomOut); |
947 | 958 | }
|
948 | 959 |
|
949 | 960 | $(document).on('mousemove', onMousemove);
|
|
953 | 964 |
|
954 | 965 | if (!onWheelCallback) {
|
955 | 966 | onWheelCallback = function onWheel(e) {
|
| 967 | + var delta; |
| 968 | + |
956 | 969 | if ($('[data-gallery-role="gallery"]').data('fotorama').fullScreen) {
|
957 | 970 | e = e || window.event;
|
| 971 | + delta = e.deltaY || e.detail || e.wheelDelta; |
958 | 972 |
|
959 |
| - |
960 |
| - var delta = e.deltaY || e.detail || e.wheelDelta; |
961 |
| - |
962 |
| - if (delta > 0) { |
| 973 | + if (delta > 0 || (e.scale && e.scale < 1.0)) { |
963 | 974 | zoomOut(e);
|
964 |
| - } else { |
| 975 | + } else if (delta < 0 || (e.scale && e.scale > 1.0)) { |
965 | 976 | zoomIn(e);
|
966 | 977 | }
|
967 | 978 |
|
|
970 | 981 | };
|
971 | 982 | }
|
972 | 983 | $('.fotorama-item').on('fotorama:load', function () {
|
| 984 | + document.querySelector('.fotorama__stage').removeEventListener("gesturechange", onWheelCallback); |
| 985 | + document.querySelector('.fotorama__stage').addEventListener("gesturechange", onWheelCallback); |
| 986 | + document.querySelector('.fotorama__stage').addEventListener("gesturestart", function () { |
| 987 | + isZoomActive = true; |
| 988 | + }); |
| 989 | + document.querySelector('.fotorama__stage').addEventListener("gestureend", function () { |
| 990 | + isZoomActive = false; |
| 991 | + }); |
| 992 | + |
973 | 993 | if (document.querySelector('.fotorama__stage').addEventListener) {
|
974 | 994 | if ('onwheel' in document) {
|
975 | 995 | // IE9+, FF17+, Ch31+
|
|
0 commit comments