comparison examples/tutorial/geddit/templates/info.html @ 625:dba522b4c31d

GenshiTutorial: implemented AJAX commenting.
author cmlenz
date Fri, 31 Aug 2007 17:01:00 +0000
parents dc35e9882390
children 693a7212b348
comparison
equal deleted inserted replaced
624:1d23dddd6c2d 625:dba522b4c31d
3 xmlns:xi="http://www.w3.org/2001/XInclude" 3 xmlns:xi="http://www.w3.org/2001/XInclude"
4 xmlns:py="http://genshi.edgewall.org/"> 4 xmlns:py="http://genshi.edgewall.org/">
5 <xi:include href="layout.html" /> 5 <xi:include href="layout.html" />
6 <head> 6 <head>
7 <title>${link.title}</title> 7 <title>${link.title}</title>
8 <link rel="alternate" type="application/atom+xml" title="Geddit: ${link.title}" 8 <link rel="alternate" title="Geddit: ${link.title}"
9 href="${url('/feed/%s/' % link.id)}" /> 9 type="application/atom+xml" href="${url('/feed/%s/' % link.id)}" />
10 <script type="text/javascript">
11 function loadCommentForm(a) {
12 $.get("${url('/comment/%s/' % link.id)}", {}, function(html) {
13 var form = a.hide().parent().after(html).next();
14 function closeForm() {
15 form.slideUp("fast", function() { a.fadeIn(); form.remove() });
16 return false;
17 }
18 function initForm() {
19 form.find("input[@name='cancel']").click(closeForm);
20 form.submit(function() {
21 var data = form.find("input[@type='text'], textarea").serialize();
22 $.post("${url('/comment/%s/' % link.id)}", data, function(html) {
23 var elem = $(html).get(0);
24 if (/form/i.test(elem.tagName)) {
25 form.after(elem).remove();
26 form = $(elem);
27 initForm();
28 } else {
29 if ($("ul.comments").length == 0) {
30 a.parent().before('<ul class="comments"></ul>');
31 }
32 $("ul.comments")
33 .find("li.hilite").removeClass("hilite").end()
34 .append($(elem).addClass("hilite")).slideDown();
35 closeForm();
36 }
37 });
38 return false;
39 });
40 }
41 initForm();
42 });
43 }
44 $(document).ready(function() {
45 $("a.action").click(function() {
46 loadCommentForm($(this));
47 return false;
48 });
49 });
50 </script>
10 </head> 51 </head>
11 <body> 52 <body>
12 <h1>${link.title}</h1> 53 <h1>${link.title}</h1>
13 <a href="${link.url}">${link.url}</a><br /> 54 <a href="${link.url}">${link.url}</a><br />
14 posted by ${link.username} at ${link.time.strftime('%x %X')}<br /> 55 posted by ${link.username} at ${link.time.strftime('%x %X')}<br />
15 56
57 <ul py:if="link.comments" class="comments">
58 <xi:include href="_comment.html"
59 py:for="num, comment in enumerate(link.comments)" />
60 </ul>
61
16 <p><a class="action" href="${url('/comment/%s/' % link.id)}">comment</a></p> 62 <p><a class="action" href="${url('/comment/%s/' % link.id)}">comment</a></p>
17
18 <ul py:if="link.comments" class="comments">
19 <li py:for="idx, comment in enumerate(link.comments)" id="comment$idx">
20 <strong>${comment.username}</strong>
21 at ${comment.time.strftime('%x %X')}
22 <blockquote>${comment.content}</blockquote>
23 </li>
24 </ul>
25 </body> 63 </body>
26 </html> 64 </html>
Copyright (C) 2012-2017 Edgewall Software