Merge pull request #1103 from vtyeh/drafts-with-load-more-have-broken-links-1054
Fix broken links in drafts loaded with "load more" #1054
This commit is contained in:
commit
6384f4667b
|
@ -188,21 +188,22 @@ var movePostHTML = function(postID) {
|
||||||
}
|
}
|
||||||
return $tmpl.innerHTML.replace(/POST_ID/g, postID);
|
return $tmpl.innerHTML.replace(/POST_ID/g, postID);
|
||||||
}
|
}
|
||||||
var createPostEl = function(post, owned) {
|
var createPostEl = function(post, owned, singleUser) {
|
||||||
var $post = document.createElement('div');
|
var $post = document.createElement('div');
|
||||||
let p = H.createPost(post.id, "", post.body)
|
let p = H.createPost(post.id, "", post.body)
|
||||||
var title = (post.title || p.title || post.id);
|
var title = (post.title || p.title || post.id);
|
||||||
title = title.replace(/</g, "<");
|
title = title.replace(/</g, "<");
|
||||||
|
var postLink = (singleUser ? '/d/' : '/') + post.id
|
||||||
$post.id = 'post-' + post.id;
|
$post.id = 'post-' + post.id;
|
||||||
$post.className = 'post';
|
$post.className = 'post';
|
||||||
$post.innerHTML = '<h3><a href="/' + post.id + '">' + title + '</a></h3>';
|
$post.innerHTML = '<h3><a href="' + postLink + '">' + title + '</a></h3>';
|
||||||
|
|
||||||
var posted = "";
|
var posted = "";
|
||||||
if (post.created) {
|
if (post.created) {
|
||||||
posted = getFormattedDate(new Date(post.created))
|
posted = getFormattedDate(new Date(post.created))
|
||||||
}
|
}
|
||||||
var hasDraft = H.exists('draft' + post.id);
|
var hasDraft = H.exists('draft' + post.id);
|
||||||
$post.innerHTML += '<h4><date>' + posted + '</date> <a class="action" href="/pad/' + post.id + '">edit' + (hasDraft ? 'ed' : '') + '</a> <a class="delete action" href="/' + post.id + '" onclick="delPost(event, \'' + post.id + '\'' + (owned === true ? ', true' : '') + ')">delete</a> '+movePostHTML(post.id)+'</h4>';
|
$post.innerHTML += '<h4><date>' + posted + '</date> <a class="action" href="' + postLink + '/edit">edit' + (hasDraft ? 'ed' : '') + '</a> <a class="delete action" href="/' + post.id + '" onclick="delPost(event, \'' + post.id + '\'' + (owned === true ? ', true' : '') + ')">delete</a> '+movePostHTML(post.id)+'</h4>';
|
||||||
|
|
||||||
if (post.error) {
|
if (post.error) {
|
||||||
$post.innerHTML += '<p class="error"><strong>Sync error:</strong> ' + post.error + ' <nav><a href="#" onclick="localPosts.dismissError(event, this)">dismiss</a> <a href="#" onclick="localPosts.deletePost(event, this, \''+post.id+'\')">remove post</a></nav></p>';
|
$post.innerHTML += '<p class="error"><strong>Sync error:</strong> ' + post.error + ' <nav><a href="#" onclick="localPosts.dismissError(event, this)">dismiss</a> <a href="#" onclick="localPosts.deletePost(event, this, \''+post.id+'\')">remove post</a></nav></p>';
|
||||||
|
|
|
@ -202,8 +202,9 @@ function loadMorePosts() {
|
||||||
if (http.readyState == 4) {
|
if (http.readyState == 4) {
|
||||||
if (http.status == 200) {
|
if (http.status == 200) {
|
||||||
var data = JSON.parse(http.responseText);
|
var data = JSON.parse(http.responseText);
|
||||||
|
var singleUser = {{ .SingleUser }};
|
||||||
for (var i=0; i<data.data.length; i++) {
|
for (var i=0; i<data.data.length; i++) {
|
||||||
$posts.el.appendChild(createPostEl(data.data[i], true));
|
$posts.el.appendChild(createPostEl(data.data[i], true, singleUser));
|
||||||
}
|
}
|
||||||
if (data.data.length < 10) {
|
if (data.data.length < 10) {
|
||||||
$loadMore.el.parentNode.removeChild($loadMore.el);
|
$loadMore.el.parentNode.removeChild($loadMore.el);
|
||||||
|
|
Loading…
Reference in New Issue