index.jsView |
---|
239 | 239 | }) |
240 | 240 | ) |
241 | 241 | } |
242 | 242 | |
| 243 | +var issueCommentScript = '(' + function () { |
| 244 | + var $ = document.getElementById.bind(document) |
| 245 | + $('preview-tab-link').onclick = function (e) { |
| 246 | + with (new XMLHttpRequest()) { |
| 247 | + open('POST', '', true) |
| 248 | + onload = function() { |
| 249 | + $('preview-tab').innerHTML = responseText |
| 250 | + } |
| 251 | + send('action=markdown&text=' + |
| 252 | + encodeURIComponent($('comment-text').value)) |
| 253 | + } |
| 254 | + } |
| 255 | +}.toString() + ')()' |
| 256 | + |
243 | 257 | var msgTypes = { |
244 | 258 | 'git-repo': true, |
245 | 259 | 'git-update': true, |
246 | 260 | 'issue': true |
369 | 383 | |
370 | 384 | case 'comment': |
371 | 385 | if (!data.id) |
372 | 386 | return cb(null, serveError(new Error('Missing id'), 400)) |
| 387 | + |
373 | 388 | |
374 | 389 | var msg = schemas.post(data.text, data.id, data.branch || data.id) |
375 | 390 | if (data.open != null) |
376 | 391 | Issues.schemas.opens(msg, data.id) |
390 | 405 | if (err) return cb(null, serveError(err)) |
391 | 406 | cb(null, serveRedirect(encodeLink(issue.id))) |
392 | 407 | }) |
393 | 408 | |
| 409 | + case 'markdown': |
| 410 | + return cb(null, serveMarkdown(data.text)) |
| 411 | + |
394 | 412 | default: |
395 | 413 | cb(null, servePlainError(400, 'What are you trying to do?')) |
396 | 414 | } |
397 | 415 | }) |
465 | 483 | msg |
466 | 484 | ]) |
467 | 485 | } |
468 | 486 | |
| 487 | + function serveMarkdown(text) { |
| 488 | + var html = markdown(text) |
| 489 | + return pull.values([ |
| 490 | + [200, { |
| 491 | + 'Content-Length': Buffer.byteLength(html), |
| 492 | + 'Content-Type': 'text/html; charset=utf-8' |
| 493 | + }], |
| 494 | + html |
| 495 | + ]) |
| 496 | + } |
| 497 | + |
469 | 498 | function renderTry(read) { |
470 | 499 | var ended |
471 | 500 | return function (end, cb) { |
472 | 501 | if (ended) return cb(ended) |
1172 | 1201 | return renderRepoPage(repo, '', pull.once( |
1173 | 1202 | '<h3>New Issue</h3>' + |
1174 | 1203 | '<section><form class="new-issue" action="" method="post">' + |
1175 | 1204 | '<input type="hidden" name="action" value="new-issue">' + |
1176 | | - '<p><input class="wide-input" name="title" placeholder="Issue Title" size="69" /></p>' + |
1177 | | - '<p><textarea class="wide-input" name="text" placeholder="Description" rows="12" cols="69"></textarea></p>' + |
| 1205 | + '<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>' + |
1178 | 1207 | '<button type="submit" class="btn">Create</button>' + |
1179 | 1208 | '</form></section>')) |
1180 | 1209 | } |
1181 | 1210 | |
1251 | 1280 | } |
1252 | 1281 | }) |
1253 | 1282 | ), |
1254 | 1283 | pull.once(isPublic ? '' : '<section><form action="" method="post">' + |
| 1284 | + '<input type="radio" class="tab-radio" id="tab1" name="tab" checked="checked"/>' + |
| 1285 | + '<input type="radio" class="tab-radio" id="tab2" name="tab"/>' + |
| 1286 | + '<div class="tab-links">' + |
| 1287 | + '<label for="tab1" id="write-tab-link" class="tab1-link">Write</label>' + |
| 1288 | + '<label for="tab2" id="preview-tab-link" class="tab2-link">Preview</label>' + |
| 1289 | + '</div>' + |
| 1290 | + '<div id="write-tab" class="tab1">' + |
1255 | 1291 | '<input type="hidden" name="action" value="comment">' + |
1256 | 1292 | '<input type="hidden" name="id" value="' + issue.id + '">' + |
1257 | | - '<textarea name="text" class="wide-input" rows="6" cols="69"></textarea>' + |
| 1293 | + '<textarea id="comment-text" name="text" class="wide-input" rows="4" cols="77"></textarea>' + |
| 1294 | + '</div>' + |
| 1295 | + '<div class="preview-text tab2" id="preview-tab">' + |
| 1296 | + '</div>' + |
1258 | 1297 | (isAuthor ? |
1259 | 1298 | '<input type="submit" class="btn"' + |
1260 | 1299 | ' name="' + (issue.open ? 'close' : 'open') + '"' + |
1261 | 1300 | ' value="' + (issue.open ? 'Close issue' : 'Reopen issue') + '"' + |
1262 | 1301 | '/>' : '') + |
1263 | 1302 | '<input type="submit" class="btn open" value="Comment" />' + |
1264 | | - '</form></section>') |
| 1303 | + '<script>' + issueCommentScript + '</script>' + |
| 1304 | + '</section></form>') |
1265 | 1305 | ])) |
1266 | 1306 | } |
1267 | 1307 | |
1268 | 1308 | } |