* Creates a post element.
( postId: string, title: string, text: string, author?: string, authorId?: string, authorPic?: string, )
| 173 | * Creates a post element. |
| 174 | */ |
| 175 | function createPostElement( |
| 176 | postId: string, |
| 177 | title: string, |
| 178 | text: string, |
| 179 | author?: string, |
| 180 | authorId?: string, |
| 181 | authorPic?: string, |
| 182 | ) { |
| 183 | const uid = auth.currentUser!.uid; |
| 184 | |
| 185 | const html = |
| 186 | '<div class="post post-' + |
| 187 | postId + |
| 188 | ' mdl-cell mdl-cell--12-col ' + |
| 189 | 'mdl-cell--6-col-tablet mdl-cell--4-col-desktop mdl-grid mdl-grid--no-spacing">' + |
| 190 | '<div class="mdl-card mdl-shadow--2dp">' + |
| 191 | '<div class="mdl-card__title mdl-color--light-blue-600 mdl-color-text--white">' + |
| 192 | '<h4 class="mdl-card__title-text"></h4>' + |
| 193 | '</div>' + |
| 194 | '<div class="header">' + |
| 195 | '<div>' + |
| 196 | '<div class="avatar"></div>' + |
| 197 | '<div class="username mdl-color-text--black"></div>' + |
| 198 | '</div>' + |
| 199 | '</div>' + |
| 200 | '<span class="star">' + |
| 201 | '<div class="not-starred material-icons">star_border</div>' + |
| 202 | '<div class="starred material-icons">star</div>' + |
| 203 | '<div class="star-count">0</div>' + |
| 204 | '</span>' + |
| 205 | '<div class="text"></div>' + |
| 206 | '<div class="comments-container"></div>' + |
| 207 | '<form class="add-comment" action="#">' + |
| 208 | '<div class="mdl-textfield mdl-js-textfield">' + |
| 209 | '<input class="mdl-textfield__input new-comment" type="text">' + |
| 210 | '<label class="mdl-textfield__label">Comment...</label>' + |
| 211 | '</div>' + |
| 212 | '</form>' + |
| 213 | '</div>' + |
| 214 | '</div>'; |
| 215 | |
| 216 | // Create the DOM element from the HTML. |
| 217 | const div = document.createElement('div'); |
| 218 | div.innerHTML = html; |
| 219 | const postElement = div.firstChild as HTMLElement; |
| 220 | if (window.componentHandler) { |
| 221 | window.componentHandler.upgradeElements( |
| 222 | postElement.getElementsByClassName('mdl-textfield')[0], |
| 223 | ); |
| 224 | } |
| 225 | |
| 226 | const addCommentForm = postElement.getElementsByClassName( |
| 227 | 'add-comment', |
| 228 | )[0] as HTMLFormElement; |
| 229 | const commentInput = postElement.getElementsByClassName( |
| 230 | 'new-comment', |
| 231 | )[0] as HTMLInputElement; |
| 232 | const star = postElement.getElementsByClassName( |
no test coverage detected