I would really like to say many thanks to the Karl for creating this tool, it's really very useful. One critical thing for me is the possibility of mousewheel zoom option, centered at current cursor. I spend some days while trying to figure out how the main program works and its a really complex creation of piecing together many libs and logic. I also looked at forum post about mousewheel, and to continue this discussion there really is no need to update the photoswipe library! It can be reimplemented in current version without many changes.
I have made a patch for current 0.8.4 version which seems to be working very good.
We need to patch functions setupDesktopZoom, handleMouseWheel, toggleDesktopZoom
in local assets main program _files/assets/files.photo.gallery@0.8.4/js/files.js :
- Locate setupDesktopZoom:function(t) and replace function content with
Xt={};var i="wheel mousewheel DOMMouseScroll";re.bind(e,i,n.handleMouseWheel);xe("unbindEvents",(function(){Xt&&re.unbind(e,i,n.handleMouseWheel)})),n.mouseZoomedIn=!1;var a,o=function(){n.mouseZoomedIn&&(e.classList.remove("pswp--zoomed-in"),n.mouseZoomedIn=!1),re.toggle_class(e,"pswp--zoom-allowed",g<=1),l()},l=function(){a&&(e.classList.remove("pswp--dragging"),a=!1)};xe("resize",o),xe("afterChange",o),xe("pointerDown",(function(){n.mouseZoomedIn&&(a=!0,e.classList.add("pswp--dragging"))})),xe("pointerUp",l),t||o()
What is changed: call re.bind(e,i,n.handleMouseWheel) without listen function, because it prevents wheel bind function at the first run and some changes in "current zoom equal or less 1" logic, which allow us to show zoom button always.
- Locate handleMouseWheel:function(e) and replace it
if (n.currItem.type == "video") return; let zoomFactor = -e.deltaY; if (e.deltaMode === 1) { zoomFactor *= 0.05; } else { zoomFactor *= e.deltaMode ? 1 : 0.005; } if (e.ctrlKey) {event.preventDefault(); zoomFactor *= 2;} if (e.shiftKey) zoomFactor *= 0.1; zoomFactor = 2 ** zoomFactor; const destZoomLevel = g * zoomFactor; centerPoint = { x: e.clientX, y: e.clientY }; var zoomOut = destZoomLevel < n.currItem.initialZoomLevel; n.mouseZoomedIn = !zoomOut; n.zoomTo(destZoomLevel, centerPoint, 333); re.toggle_class(e, 'pswp--zoomed-in', !zoomOut); if(g<=n.currItem.fitRatio)return!o.closeOnScroll||qe||R?e.preventDefault():Math.abs(e.deltaY)>2&&(r=!0,n.close()),!0; e.stopPropagation(), Xt.x = 0; e.preventDefault();
Here is the main wheel function, it was taken partially from latest photoswipe sources and adopted to current version. Some part of the code related to panTo function was deleted intentionally as it was only making interference. Also it changes the zoom button +/- status depending on current zoom value more or less than initial.
Video object zooming is not working right as intended, so processing a wheel for it is skipped.
Additional functions:
[shift] + wheel = slower zooming
[ctrl] + wheel = faster zooming
- And the same with function toggleDesktopZoom:function(t)
t=t||{x:ce.x/2+de.x,y:ce.y/2+de.y};var i=o.getDoubleTapZoom(!0,n.currItem),a=g>n.currItem.initialZoomLevel||g<n.currItem.initialZoomLevel;n.mouseZoomedIn=!a,n.zoomTo(a?n.currItem.initialZoomLevel:i,t,333),re.toggle_class(e,"pswp--zoomed-in",!a)
This updates zoom button logic. If current zoom more or less that initial then it will return to it, but will still toggle between double tap and initial zoom as it behaved previously.
So it's the main piece of code, which is effectively enabling mousewheel zoom + additional logic behind it.
I must also note some other fixes/updated which i consider significant.
More zoom on touchscreen device, this allows more detailed zoom.
Locate part of string
e||t.initialZoomLevel<.7?1:1.33},maxSpreadZoom:1};Object.assign(o,a);var
and replace it with
e||t.initialZoomLevel<.7?4:1.33},maxSpreadZoom:4};Object.assign(o,a);var
File information window not working in chrome, i don't know why it can't find the BBB function, but replacing this with null fixed it, working in chrome and firefox and on mobile devices.
--type-color-hsl:"+c.split(")")[0].split("(")[1].split(",").join(""):BBB},R(P.preview,"modal-preview
--type-color-hsl:"+c.split(")")[0].split("(")[1].split(",").join(""):null},R(P.preview,"modal-preview