Browse Source

Fix not reloading comments when switching images

k4be 1 year ago
parent
commit
87654dbe9a
3 changed files with 19 additions and 14 deletions
  1. 6 0
      comment.js
  2. 3 3
      dirlist.php
  3. 10 11
      image.js

+ 6 - 0
comment.js

@@ -50,6 +50,8 @@ function refreshComments() {
 	var commentType = $('#comment-type').val();
 	var commentType = $('#comment-type').val();
 	var commentId = $('#comment-id').val();
 	var commentId = $('#comment-id').val();
 
 
+	$('#comments').text('Wczytywanie komentarzy...');
+
 	var formData = {
 	var formData = {
 		'type': commentType,
 		'type': commentType,
 		'id': commentId,
 		'id': commentId,
@@ -66,6 +68,10 @@ function refreshComments() {
 	});
 	});
 }
 }
 
 
+function commentsImageReplace(image) {
+	$('#comment-id').val(image.id);
+}
+
 $(document).ready(function() {
 $(document).ready(function() {
 	$('#comment-form').on('submit', commentFormSubmit);
 	$('#comment-form').on('submit', commentFormSubmit);
 });
 });

+ 3 - 3
dirlist.php

@@ -11,11 +11,11 @@ function dirlist($dir) {
 	if (!$images) {
 	if (!$images) {
 		throw new Exception('Brak wyników');
 		throw new Exception('Brak wyników');
 	}
 	}
-	$id = 0;
+	$ord = 0;
 	$res = [];
 	$res = [];
 	foreach ($images as $image) {
 	foreach ($images as $image) {
-		$res[] = array('id' => $id, 'name' => $image['path']);
-		$id++;
+		$res[] = array('id' => $image['id'], 'name' => $image['path'], 'ord' => $ord);
+		$ord++;
 	}
 	}
 	return $res;
 	return $res;
 }
 }

+ 10 - 11
image.js

@@ -32,16 +32,15 @@ function setLinks(e) {
 		$('#imagelink').removeAttr('href');
 		$('#imagelink').removeAttr('href');
 	}
 	}
     var image = $("#image");
     var image = $("#image");
- //   image.fadeTo('fast', 0.2, function () {
- 	image.css('opacity', '0.2');
-        image.attr('src', imageUrlPrefix + dirname + '/' + filename);
-		image.on('load', function() {
-//		    image.fadeTo('fast', 1);
-			image.css('opacity', '1');
-		});
-        if (doPush)
-		window.history.pushState(currId, '', scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + filename);
-//    });
+    image.css('opacity', '0.2');
+    image.attr('src', imageUrlPrefix + dirname + '/' + filename);
+    image.on('load', function() {
+	image.css('opacity', '1');
+    });
+    if (doPush)
+	window.history.pushState(currId, '', scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + filename);
+    commentsImageReplace(imglist[currId]);
+    refreshComments();
 }
 }
 
 
 function nextImage(e) {
 function nextImage(e) {
@@ -69,7 +68,7 @@ function imglistReceived(data) {
 	for (var i=0; i<data.length; i++) {
 	for (var i=0; i<data.length; i++) {
 		file = data[i];
 		file = data[i];
 		if(file.name == filename) {
 		if(file.name == filename) {
-			currId = file.id;
+			currId = file.ord;
 			found = true;
 			found = true;
 			break;
 			break;
 		}
 		}