(post, owned, singleUser)
| 189 | return $tmpl.innerHTML.replace(/POST_ID/g, postID); |
| 190 | } |
| 191 | var createPostEl = function(post, owned, singleUser) { |
| 192 | var $post = document.createElement('div'); |
| 193 | let p = H.createPost(post.id, "", post.body) |
| 194 | var title = (post.title || p.title || post.id); |
| 195 | title = title.replace(/</g, "<"); |
| 196 | var postLink = (singleUser ? '/d/' : '/') + post.id |
| 197 | $post.id = 'post-' + post.id; |
| 198 | $post.className = 'post'; |
| 199 | $post.innerHTML = '<h3><a href="' + postLink + '">' + title + '</a></h3>'; |
| 200 | |
| 201 | var posted = ""; |
| 202 | if (post.created) { |
| 203 | posted = getFormattedDate(new Date(post.created)) |
| 204 | } |
| 205 | var hasDraft = H.exists('draft' + post.id); |
| 206 | $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>'; |
| 207 | |
| 208 | if (post.error) { |
| 209 | $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>'; |
| 210 | } |
| 211 | if (post.summary) { |
| 212 | // TODO: switch to using p.summary, after ensuring it matches summary generated on the backend. |
| 213 | $post.innerHTML += '<p>' + post.summary.replace(/</g, "<") + '</p>'; |
| 214 | } else if (post.body) { |
| 215 | var preview; |
| 216 | if (post.body.length > 140) { |
| 217 | preview = post.body.substr(0, 140) + '...'; |
| 218 | } else { |
| 219 | preview = post.body; |
| 220 | } |
| 221 | $post.innerHTML += '<p>' + preview.replace(/</g, "<") + '</p>'; |
| 222 | } |
| 223 | return $post; |
| 224 | }; |
| 225 | var loadPage = function(p, loadAll) { |
| 226 | if (loadAll) { |
| 227 | $posts.el.innerHTML = ''; |
no test coverage detected