Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 114 lines (111 sloc) 4.277 kb
d2c5a08 editing textile and markdown
Chris Anderson authored
1 <!DOCTYPE html>
2 <html>
3 <head>
303ce4e @jchris change all templates to mustache
authored
4 <title>{{ blog.title }}</title>
2c9cb21 @jchris move scripts to partial
authored
5 <link rel="stylesheet" href="{{ assets }}/style/screen.css" type="text/css">
d2c5a08 editing textile and markdown
Chris Anderson authored
6 </head>
7 <body>
dcd2011 @jchris removing extra code from edit and post pages
authored
8 {{>header}}
77c3de9 @jchris tagcloud can add tags to posts
authored
9 <div id="tagcloud"></div>
26c90eb convert to new posts format
Chris Anderson authored
10 <div id="content">
d2c5a08 editing textile and markdown
Chris Anderson authored
11 <!-- form to create a post -->
12 <form id="new-post" action="new.html" method="post">
dcd2011 @jchris removing extra code from edit and post pages
authored
13 <h1>{{pageTitle}}</h1>
d2c5a08 editing textile and markdown
Chris Anderson authored
14 <p><label>Title</label>
15 <input type="text" size="50" name="title" value=""></p>
16 <p><label for="body">Body</label>
17 <textarea name="body" rows="28" cols="80"></textarea></p>
b85f13b doc deleting
Chris Anderson authored
18 <p>
77c3de9 @jchris tagcloud can add tags to posts
authored
19 <label for="tags">Click tags to add them. (split by ',')</label><input size="50" type="text" name="tags" value="" id="tags">
821edc7 add tags & tag cloud
Jan Lehnardt authored
20 </p>
21 <p>
b85f13b doc deleting
Chris Anderson authored
22 <input id="preview" type="button" value="Preview"/>
23 <input type="submit" value="Save &rarr;"/> <span id="saved" style="display:none;">Saved</span>
24 </p>
d2c5a08 editing textile and markdown
Chris Anderson authored
25 </form>
338a2da @jchris got preview working
authored
26 <a target="_new" href="http://warpedvisions.org/projects/markdown-cheat-sheet/">Markdown help</a>
7c07d3e post preview
Chris Anderson authored
27 <div id="show-preview"></div>
28 </div>
d2c5a08 editing textile and markdown
Chris Anderson authored
29 </body>
2c9cb21 @jchris move scripts to partial
authored
30 {{>scripts}}
01eb095 @jchris update validation for multi author
authored
31 <script src="../../script/jquery.scrollTo.js"></script>
d2c5a08 editing textile and markdown
Chris Anderson authored
32 <script type="text/javascript" charset="utf-8">
dcd2011 @jchris removing extra code from edit and post pages
authored
33 $.couch.app(function(app) {
77c3de9 @jchris tagcloud can add tags to posts
authored
34 // extend the tagcloud so that clicks add tags to the current post
35 var tagcloud = $.extend(true, {}, this.ddoc.evently.tagcloud, {
36 _init : {
37 selectors : {
38 a : {
39 click : function() {
40 var tag = $(this).text();
41 var tags = $("input[name=tags]").val();
42 if (tags) tags = tags+", ";
43 $("input[name=tags]").val(tags + tag);
44 return false;
45 }
46 }
47 }
48 }
49 });
50 $("#tagcloud").evently(tagcloud, this);
51
f53f413 @jchris rename commonjs to lib
authored
52 var path = app.require("vendor/couchapp/lib/path").init(app.req);
338a2da @jchris got preview working
authored
53 var postForm, blog = app.require("lib/blog");
77c3de9 @jchris tagcloud can add tags to posts
authored
54
01eb095 @jchris update validation for multi author
authored
55 // apply docForm at login.
dcd2011 @jchris removing extra code from edit and post pages
authored
56 $("#account").evently({
57 loggedIn : function(e,r) {
58 var userCtx = r.userCtx;
338a2da @jchris got preview working
authored
59 postForm = app.docForm("form#new-post", {
dcd2011 @jchris removing extra code from edit and post pages
authored
60 id : {{ docid }},
61 fields : ["title", "body", "tags"],
62 template : {
63 type : "post",
64 format : "markdown",
65 author : userCtx.name
66 },
67 onLoad : function(doc) {
68 if (doc._id) {
77c3de9 @jchris tagcloud can add tags to posts
authored
69 $('h1').html('Editing <a href="'+path.show('post',doc._id)+'">'+doc._id+'</a> by '+doc.author);
dcd2011 @jchris removing extra code from edit and post pages
authored
70 $('#preview').before('<input type="button" id="delete" value="Delete Post"/> ');
71 $("#delete").click(function() {
72 postForm.deleteDoc({
73 success: function(resp) {
74 $("h1").text("Deleted "+resp.id);
75 $('form#new-post input').attr('disabled', true);
76 }
77 });
78 return false;
79 });
80 }
81 $('label[for=body]').append(' <em>with '+(doc.format||'html')+'</em>');
82 },
83 beforeSave : function(doc) {
84 if (!doc.created_at) {
85 doc.created_at = new Date();
86 }
fc66430 @jchris validation works
authored
87 if (!doc._id) {
88 doc._id = blog.slugifyString(doc.title);
dcd2011 @jchris removing extra code from edit and post pages
authored
89 }
90 if(doc.tags) {
91 doc.tags = doc.tags.split(",");
92 for(var idx in doc.tags) {
93 doc.tags[idx] = $.trim(doc.tags[idx]);
b85f13b doc deleting
Chris Anderson authored
94 }
dcd2011 @jchris removing extra code from edit and post pages
authored
95 }
96 },
97 success : function(resp) {
fc66430 @jchris validation works
authored
98 $("#saved").text("Saved _rev: "+resp.rev).fadeIn(500).fadeOut(6000);
5cd6618 @jchris start doing comments with evently
authored
99 $('h1').html('Editing <a href="'+path.show('post',resp.id)+'">'+resp.id+'</a> by '+doc.author);
821edc7 add tags & tag cloud
Jan Lehnardt authored
100 }
dcd2011 @jchris removing extra code from edit and post pages
authored
101 });
d2c5a08 editing textile and markdown
Chris Anderson authored
102 }
ce43ff2 @jchris validation works better for deletion.
authored
103 });
338a2da @jchris got preview working
authored
104
26c90eb convert to new posts format
Chris Anderson authored
105 $("#preview").click(function() {
ce43ff2 @jchris validation works better for deletion.
authored
106 var markdown = app.require("vendor/markdown/lib/markdown");
ac89b08 refactor formatting to helper
Chris Anderson authored
107 var doc = postForm.localDoc();
ce43ff2 @jchris validation works better for deletion.
authored
108 var html = markdown.encode(doc.body);
c3c2af1 validation framework, comments
Chris Anderson authored
109 $('#show-preview').html(html);
b3d5425 add scrolling to preview
Jan Lehnardt authored
110 $('body').scrollTo('#show-preview', {duration: 500});
26c90eb convert to new posts format
Chris Anderson authored
111 });
41181f1 refactor for style
Chris Anderson authored
112 });
d2c5a08 editing textile and markdown
Chris Anderson authored
113 </script>
114 </html>
Something went wrong with that request. Please try again.