Commit 46b5b337be23ffadeb73a973c5007b8426840483
Add markdown previewing for new issue form
Factor out preview tabs form elementsCharles Lehner committed on 3/27/2016, 12:48:21 PM
Parent: f6796afa2aa64a4b29be370cf2e10548f8745920
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -145,8 +145,25 @@ | ||
145 | 145 | ) + |
146 | 146 | '</form>' |
147 | 147 | } |
148 | 148 | |
149 | +function renderPostForm(placeholder, rows) { | |
150 | + return '<input type="radio" class="tab-radio" id="tab1" name="tab" checked="checked"/>' + | |
151 | + '<input type="radio" class="tab-radio" id="tab2" name="tab"/>' + | |
152 | + '<div class="tab-links">' + | |
153 | + '<label for="tab1" id="write-tab-link" class="tab1-link">Write</label>' + | |
154 | + '<label for="tab2" id="preview-tab-link" class="tab2-link">Preview</label>' + | |
155 | + '</div>' + | |
156 | + '<div id="write-tab" class="tab1">' + | |
157 | + '<textarea id="post-text" name="text" class="wide-input"' + | |
158 | + ' rows="' + (rows||4) + '" cols="77"' + | |
159 | + (placeholder ? ' placeholder="' + placeholder + '"' : '') + | |
160 | + '></textarea>' + | |
161 | + '</div>' + | |
162 | + '<div class="preview-text tab2" id="preview-tab"></div>' + | |
163 | + '<script>' + issueCommentScript + '</script>' | |
164 | +} | |
165 | + | |
149 | 166 | function wrap(tag) { |
150 | 167 | return function (read) { |
151 | 168 | return cat([ |
152 | 169 | pull.once('<' + tag + '>'), |
@@ -248,9 +265,9 @@ | ||
248 | 265 | onload = function() { |
249 | 266 | $('preview-tab').innerHTML = responseText |
250 | 267 | } |
251 | 268 | send('action=markdown&text=' + |
252 | - encodeURIComponent($('comment-text').value)) | |
269 | + encodeURIComponent($('post-text').value)) | |
253 | 270 | } |
254 | 271 | } |
255 | 272 | }.toString() + ')()' |
256 | 273 | |
@@ -1199,12 +1216,12 @@ | ||
1199 | 1216 | |
1200 | 1217 | function serveRepoNewIssue(repo, issueId, path) { |
1201 | 1218 | return renderRepoPage(repo, '', pull.once( |
1202 | 1219 | '<h3>New Issue</h3>' + |
1203 | - '<section><form class="new-issue" action="" method="post">' + | |
1220 | + '<section><form action="" method="post">' + | |
1204 | 1221 | '<input type="hidden" name="action" value="new-issue">' + |
1205 | 1222 | '<p><input class="wide-input" name="title" placeholder="Issue Title" size="77" /></p>' + |
1206 | - '<p><textarea class="wide-input" name="text" placeholder="Description" rows="12" cols="77"></textarea></p>' + | |
1223 | + renderPostForm('Description', 8) + | |
1207 | 1224 | '<button type="submit" class="btn">Create</button>' + |
1208 | 1225 | '</form></section>')) |
1209 | 1226 | } |
1210 | 1227 | |
@@ -1287,30 +1304,19 @@ | ||
1287 | 1304 | ])) |
1288 | 1305 | |
1289 | 1306 | function renderCommentForm(cb) { |
1290 | 1307 | cb(null, '<section><form action="" method="post">' + |
1291 | - '<input type="radio" class="tab-radio" id="tab1" name="tab" checked="checked"/>' + | |
1292 | - '<input type="radio" class="tab-radio" id="tab2" name="tab"/>' + | |
1293 | - '<div class="tab-links">' + | |
1294 | - '<label for="tab1" id="write-tab-link" class="tab1-link">Write</label>' + | |
1295 | - '<label for="tab2" id="preview-tab-link" class="tab2-link">Preview</label>' + | |
1296 | - '</div>' + | |
1297 | - '<div id="write-tab" class="tab1">' + | |
1298 | 1308 | '<input type="hidden" name="action" value="comment">' + |
1299 | 1309 | '<input type="hidden" name="id" value="' + issue.id + '">' + |
1300 | 1310 | '<input type="hidden" name="branch" value="' + newestMsg.key + '">' + |
1301 | - '<textarea id="comment-text" name="text" class="wide-input" rows="4" cols="77"></textarea>' + | |
1302 | - '</div>' + | |
1303 | - '<div class="preview-text tab2" id="preview-tab">' + | |
1304 | - '</div>' + | |
1311 | + renderPostForm() + | |
1312 | + '<input type="submit" class="btn open" value="Comment" />' + | |
1305 | 1313 | (isAuthor ? |
1306 | 1314 | '<input type="submit" class="btn"' + |
1307 | 1315 | ' name="' + (issue.open ? 'close' : 'open') + '"' + |
1308 | 1316 | ' value="' + (issue.open ? 'Close issue' : 'Reopen issue') + '"' + |
1309 | 1317 | '/>' : '') + |
1310 | - '<input type="submit" class="btn open" value="Comment" />' + | |
1311 | - '<script>' + issueCommentScript + '</script>' + | |
1312 | - '</section></form>') | |
1318 | + '</form></section>') | |
1313 | 1319 | } |
1314 | 1320 | } |
1315 | 1321 | |
1316 | 1322 | } |
Built with git-ssb-web