|
@@ -30,17 +30,40 @@
|
|
.right.arrow{
|
|
.right.arrow{
|
|
right: 2em;
|
|
right: 2em;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ .zoom{
|
|
|
|
+ width: 2em;
|
|
|
|
+ opacity: 0.5;
|
|
|
|
+ position: fixed;
|
|
|
|
+ bottom: 1em;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .zoom.out{
|
|
|
|
+ right: 1em;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .zoom.in{
|
|
|
|
+ right: 3.2em;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
</style>
|
|
</style>
|
|
</head>
|
|
</head>
|
|
<body>
|
|
<body>
|
|
<img id="img" style="max-height: 100vh;max-width: 100%;">
|
|
<img id="img" style="max-height: 100vh;max-width: 100%;">
|
|
<img class="left arrow" onclick="previousImage();" src="embedded/arrow-left.svg">
|
|
<img class="left arrow" onclick="previousImage();" src="embedded/arrow-left.svg">
|
|
<img class="right arrow" onclick="nextImage();" src="embedded/arrow-right.svg">
|
|
<img class="right arrow" onclick="nextImage();" src="embedded/arrow-right.svg">
|
|
|
|
+ <img class="zoom in" onclick="zoomIn();" src="embedded/zoom-in.svg">
|
|
|
|
+ <img class="zoom out" onclick="zoomOut();" src="embedded/zoom-out.svg">
|
|
<script>
|
|
<script>
|
|
//Get file playback info from hash
|
|
//Get file playback info from hash
|
|
var playbackFile = ao_module_loadInputFiles();
|
|
var playbackFile = ao_module_loadInputFiles();
|
|
var nearbyFileList = [];
|
|
var nearbyFileList = [];
|
|
var currentViewingIndex = 0;
|
|
var currentViewingIndex = 0;
|
|
|
|
+ var zoomLevel = 1;
|
|
|
|
+ var initMargin = [];
|
|
|
|
+
|
|
//Only handle one file
|
|
//Only handle one file
|
|
playbackFile = playbackFile[0];
|
|
playbackFile = playbackFile[0];
|
|
loadImage(playbackFile.filename, playbackFile.filepath);
|
|
loadImage(playbackFile.filename, playbackFile.filepath);
|
|
@@ -49,6 +72,94 @@
|
|
updateImgSize();
|
|
updateImgSize();
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ Zooming related functions
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ function zoomIn(){
|
|
|
|
+ zoomLevel+= 0.5;
|
|
|
|
+ applyZoom();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function zoomOut(){
|
|
|
|
+ zoomLevel-= 0.5;
|
|
|
|
+ applyZoom();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $(window).bind('mousewheel DOMMouseScroll', function(event){
|
|
|
|
+ if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
|
|
|
|
+ // scroll up
|
|
|
|
+ zoomIn();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // scroll down
|
|
|
|
+ zoomOut();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ function applyZoom(){
|
|
|
|
+ if (zoomLevel < 1){
|
|
|
|
+ zoomLevel = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (zoomLevel == 1){
|
|
|
|
+ //Reset offsets
|
|
|
|
+ updateImgSize();
|
|
|
|
+ }
|
|
|
|
+ $("#img").css("transform", `scale(${zoomLevel})`);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Event binding for photo draging
|
|
|
|
+ var isDragging = false;
|
|
|
|
+ var initPositions = [];
|
|
|
|
+ $("#img").mousedown(function(evt) {
|
|
|
|
+ evt.preventDefault();
|
|
|
|
+ handleZoomMousedown(evt.clientX, evt.clientY);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $("#img").mousemove(function(evt) {
|
|
|
|
+ handleZoomMouseMove(evt.clientX, evt.clientY);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $("#img").mouseup(function() {
|
|
|
|
+ handleZoomMouseUp();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ function getCurrentImageMargins(){
|
|
|
|
+ var accLeft = $("#img").css("margin-left").replace("px","");
|
|
|
|
+ var accTop = $("#img").css("margin-top").replace("px","");
|
|
|
|
+ return [parseFloat(accLeft), parseFloat(accTop)];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function handleZoomMousedown(x,y){
|
|
|
|
+ if (zoomLevel > 1){
|
|
|
|
+ //Only allow dragging when zoomlv > 1
|
|
|
|
+ isDragging = true;
|
|
|
|
+ var accLeft = $("#img").css("margin-left").replace("px","");
|
|
|
|
+ var accTop = $("#img").css("margin-top").replace("px","");
|
|
|
|
+ initPositions = [JSON.parse(JSON.stringify(x - accLeft)), JSON.parse(JSON.stringify(y - accTop))];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function handleZoomMouseMove(x,y){
|
|
|
|
+ if (isDragging){
|
|
|
|
+ console.log("dragging");
|
|
|
|
+ var offsetsToStartPoint = [initPositions[0] - x, initPositions[1] - y];
|
|
|
|
+ MoveImage(-offsetsToStartPoint[0], -offsetsToStartPoint[1]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function MoveImage(x,y){
|
|
|
|
+ $("#img").css("margin-left", x + "px");
|
|
|
|
+ $("#img").css("margin-top", y + "px");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function handleZoomMouseUp(){
|
|
|
|
+ isDragging = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
//Load the nearby image files and allow swapping using <- and -> key
|
|
//Load the nearby image files and allow swapping using <- and -> key
|
|
function loadNearbyFiles(filepath){
|
|
function loadNearbyFiles(filepath){
|
|
ao_module_agirun("Photo/embedded/listNearbyImage.js", {
|
|
ao_module_agirun("Photo/embedded/listNearbyImage.js", {
|
|
@@ -124,6 +235,8 @@
|
|
|
|
|
|
//realigin to center
|
|
//realigin to center
|
|
$('#img').on('load', function() {
|
|
$('#img').on('load', function() {
|
|
|
|
+ zoomLevel = 1;
|
|
|
|
+ applyZoom();
|
|
updateImgSize();
|
|
updateImgSize();
|
|
$("#img").show();
|
|
$("#img").show();
|
|
});
|
|
});
|
|
@@ -132,6 +245,7 @@
|
|
function updateImgSize() {
|
|
function updateImgSize() {
|
|
$('#img').css("margin-top", (window.innerHeight - $("#img").height()) / 2);
|
|
$('#img').css("margin-top", (window.innerHeight - $("#img").height()) / 2);
|
|
$('#img').css("margin-left", (window.innerWidth - $("#img").width()) / 2);
|
|
$('#img').css("margin-left", (window.innerWidth - $("#img").width()) / 2);
|
|
|
|
+ initMargin = [(window.innerWidth - $("#img").width()) / 2, (window.innerHeight - $("#img").height()) / 2];
|
|
}
|
|
}
|
|
|
|
|
|
//Touch gesture detections
|
|
//Touch gesture detections
|
|
@@ -145,7 +259,7 @@
|
|
return evt.touches || // browser API
|
|
return evt.touches || // browser API
|
|
evt.originalEvent.touches; // jQuery
|
|
evt.originalEvent.touches; // jQuery
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function handleTouchStart(evt) {
|
|
function handleTouchStart(evt) {
|
|
const firstTouch = getTouches(evt)[0];
|
|
const firstTouch = getTouches(evt)[0];
|
|
xDown = firstTouch.clientX;
|
|
xDown = firstTouch.clientX;
|
|
@@ -161,28 +275,43 @@
|
|
var xUp = evt.touches[0].clientX;
|
|
var xUp = evt.touches[0].clientX;
|
|
var yUp = evt.touches[0].clientY;
|
|
var yUp = evt.touches[0].clientY;
|
|
|
|
|
|
|
|
+ var imgmg = getCurrentImageMargins();
|
|
var xDiff = xDown - xUp;
|
|
var xDiff = xDown - xUp;
|
|
|
|
+ var xDiffAcc = xDiff - imgmg[0];
|
|
var yDiff = yDown - yUp;
|
|
var yDiff = yDown - yUp;
|
|
-
|
|
|
|
- if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
|
|
|
|
- if ( xDiff > 0 ) {
|
|
|
|
- /* right swipe */
|
|
|
|
- nextImage();
|
|
|
|
|
|
+ var yDiffAcc = yDiff - imgmg[1];
|
|
|
|
+
|
|
|
|
+ if (zoomLevel == 1){
|
|
|
|
+ if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
|
|
|
|
+ if ( xDiff > 0 ) {
|
|
|
|
+ /* right swipe */
|
|
|
|
+ nextImage();
|
|
|
|
+ } else {
|
|
|
|
+ /* left swipe */
|
|
|
|
+ previousImage();
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- /* left swipe */
|
|
|
|
- previousImage();
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if ( yDiff > 0 ) {
|
|
|
|
- /* down swipe */
|
|
|
|
- } else {
|
|
|
|
- /* up swipe */
|
|
|
|
- }
|
|
|
|
|
|
+ if ( yDiff > 0 ) {
|
|
|
|
+ /* down swipe */
|
|
|
|
+ } else {
|
|
|
|
+ /* up swipe */
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ MoveImage(-xDiffAcc, -yDiffAcc);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
/* reset values */
|
|
/* reset values */
|
|
- xDown = null;
|
|
|
|
- yDown = null;
|
|
|
|
|
|
+ if (zoomLevel == 1){
|
|
|
|
+ xDown = null;
|
|
|
|
+ yDown = null;
|
|
|
|
+ }else{
|
|
|
|
+ xDown = xUp;
|
|
|
|
+ yDown = yUp;
|
|
|
|
+ }
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
function isZoomed(){
|
|
function isZoomed(){
|