git ssb

30+

cel / git-ssb-web



Commit 46b5b337be23ffadeb73a973c5007b8426840483

Add markdown previewing for new issue form

Factor out preview tabs form elements
Charles Lehner committed on 3/27/2016, 12:48:21 PM
Parent: f6796afa2aa64a4b29be370cf2e10548f8745920

Files changed

index.jschanged
index.jsView
@@ -145,8 +145,25 @@
145145 ) +
146146 '</form>'
147147 }
148148
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+
149166 function wrap(tag) {
150167 return function (read) {
151168 return cat([
152169 pull.once('<' + tag + '>'),
@@ -248,9 +265,9 @@
248265 onload = function() {
249266 $('preview-tab').innerHTML = responseText
250267 }
251268 send('action=markdown&text=' +
252- encodeURIComponent($('comment-text').value))
269+ encodeURIComponent($('post-text').value))
253270 }
254271 }
255272 }.toString() + ')()'
256273
@@ -1199,12 +1216,12 @@
11991216
12001217 function serveRepoNewIssue(repo, issueId, path) {
12011218 return renderRepoPage(repo, '', pull.once(
12021219 '<h3>New Issue</h3>' +
1203- '<section><form class="new-issue" action="" method="post">' +
1220+ '<section><form action="" method="post">' +
12041221 '<input type="hidden" name="action" value="new-issue">' +
12051222 '<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) +
12071224 '<button type="submit" class="btn">Create</button>' +
12081225 '</form></section>'))
12091226 }
12101227
@@ -1287,30 +1304,19 @@
12871304 ]))
12881305
12891306 function renderCommentForm(cb) {
12901307 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">' +
12981308 '<input type="hidden" name="action" value="comment">' +
12991309 '<input type="hidden" name="id" value="' + issue.id + '">' +
13001310 '<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" />' +
13051313 (isAuthor ?
13061314 '<input type="submit" class="btn"' +
13071315 ' name="' + (issue.open ? 'close' : 'open') + '"' +
13081316 ' value="' + (issue.open ? 'Close issue' : 'Reopen issue') + '"' +
13091317 '/>' : '') +
1310- '<input type="submit" class="btn open" value="Comment" />' +
1311- '<script>' + issueCommentScript + '</script>' +
1312- '</section></form>')
1318+ '</form></section>')
13131319 }
13141320 }
13151321
13161322 }

Built with git-ssb-web