MCPcopy Index your code
hub / github.com/writefreely/writefreely / createPostEl

Function createPostEl

static/js/posts.js:191–224  ·  view source on GitHub ↗
(post, owned, singleUser)

Source from the content-addressed store, hash-verified

189 return $tmpl.innerHTML.replace(/POST_ID/g, postID);
190}
191var 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, "&lt;");
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, "&lt;") + '</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, "&lt;") + '</p>';
222 }
223 return $post;
224};
225var loadPage = function(p, loadAll) {
226 if (loadAll) {
227 $posts.el.innerHTML = '';

Callers 2

delPostFunction · 0.85
loadPageFunction · 0.85

Calls 2

getFormattedDateFunction · 0.85
movePostHTMLFunction · 0.85

Tested by

no test coverage detected