diff --git a/app/controllers/dtext_controller.rb b/app/controllers/dtext_controller.rb
new file mode 100644
index 000000000..2461712ae
--- /dev/null
+++ b/app/controllers/dtext_controller.rb
@@ -0,0 +1,5 @@
+class DtextController < ApplicationController
+ def preview
+ render :inline => "
Preview
<%= format_text(params[:body]) %>"
+ end
+end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 13c6e987e..de0478d9d 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -7,7 +7,7 @@ class SessionsController < ApplicationController
if User.authenticate(params[:name], params[:password])
@user = User.find_by_name(params[:name])
session[:user_id] = @user.id
- redirect_to(params[:url] || posts_path, :notice => "You are now logged in.")
+ redirect_to(params[:url] || session[:previous_uri] || posts_path, :notice => "You are now logged in.")
else
redirect_to(new_session_path, :notice => "Password was incorrect.")
end
diff --git a/app/views/comments/partials/index/_list.html.erb b/app/views/comments/partials/index/_list.html.erb
deleted file mode 100644
index 1c01c75b3..000000000
--- a/app/views/comments/partials/index/_list.html.erb
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
diff --git a/app/views/comments/partials/index/_list.html.haml b/app/views/comments/partials/index/_list.html.haml
new file mode 100644
index 000000000..4a31b0d3e
--- /dev/null
+++ b/app/views/comments/partials/index/_list.html.haml
@@ -0,0 +1,6 @@
+%div{:class => "comments-for-post", "data-post-id" => post.id}
+ %div{:class => "list-of-comments"}
+ = render :partial => "comments/partials/show/comment", :collection => comments
+ %div{:class => "new-comment"}
+ %p= link_to "Post comment", new_comment_path, :class => "expand-comment-response"
+ = render :partial => "comments/partials/new/form", :locals => {:post => post}
diff --git a/app/views/comments/partials/new/_form.html.haml b/app/views/comments/partials/new/_form.html.haml
new file mode 100644
index 000000000..0f0956a11
--- /dev/null
+++ b/app/views/comments/partials/new/_form.html.haml
@@ -0,0 +1,7 @@
+%div{:class => "comment-preview dtext"}
+= form_tag(comments_path) do
+ = hidden_field "comment", "post_id", :value => post.id
+ = text_area "comment", "body", :size => "60x7"
+ %br
+ = submit_tag "Post"
+ = submit_tag "Preview"
diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb
deleted file mode 100644
index ed840dc36..000000000
--- a/app/views/comments/partials/show/_comment.html.erb
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- <%= link_to comment.creator_name, user_path(comment.creator_id) %>
-
-
-
-
- <%= format_text(comment.body) %>
-
-
-
-
-
\ No newline at end of file
diff --git a/app/views/comments/partials/show/_comment.html.haml b/app/views/comments/partials/show/_comment.html.haml
new file mode 100644
index 000000000..5259d029f
--- /dev/null
+++ b/app/views/comments/partials/show/_comment.html.haml
@@ -0,0 +1,16 @@
+%article{"data-comment-id" => comment.id}
+ %div{:class => "author"}
+ %h1= link_to comment.creator_name, user_path(comment.creator_id)
+ %time{:datetime => comment.created_at}
+ = time_ago_in_words(comment.created_at)
+ = " ago"
+ %div{:class => "content"}
+ %div= format_text(comment.body)
+ %menu
+ %li
+ %span{:class => "link"} Quote
+ - if CurrentUser.user.is_janitor? || CurrentUser.user.id == comment.creator_id
+ %li= link_to "Delete", comment_path(comment.id), :confirm => "Do you really want to delete this comment?", :method => :delete
+ %li= link_to "Vote up", comment_vote_path(comment.id, :is_positive => true), :method => :post
+ %li= link_to "Vote down", comment_vote_path(comment.id, :is_positive => false), :method => :post
+ %div{:class => "clearfix"}
diff --git a/app/views/posts/partials/show/_edit.html.erb b/app/views/posts/partials/show/_edit.html.erb
index 0ac29e457..1db239b01 100644
--- a/app/views/posts/partials/show/_edit.html.erb
+++ b/app/views/posts/partials/show/_edit.html.erb
@@ -5,7 +5,7 @@
<% end %>
- <% form_for(post, :html => {:class => "simple_form"}) do |f| %>
+ <%= form_for(post, :html => {:class => "simple_form"}) do |f| %>
<%= f.hidden_field :old_tags, :value => post.tag_string %>
diff --git a/config/routes.rb b/config/routes.rb
index 380ad3917..5181ff0c9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -62,6 +62,7 @@ Danbooru::Application.routes.draw do
end
resources :wiki_page_versions
+ match '/dtext/preview' => 'dtext#preview', :via => :post
match "/site_map" => "static#site_map", :as => "site_map"
match "/terms_of_service" => "static#terms_of_service", :as => "terms_of_service"
match "/user_maintenance/delete_account" => "user_maintenance#delete_account", :as => "delete_account_info"
diff --git a/public/javascripts/compiled/default.js b/public/javascripts/compiled/default.js
index 9f54c7b7c..ccabbbfa3 100644
--- a/public/javascripts/compiled/default.js
+++ b/public/javascripts/compiled/default.js
@@ -991,10 +991,12 @@ var Danbooru = {};
Danbooru.Post.initialize_tag_list = function() {
$("#tag-box a.search-inc-tag").click(function(e) {
$("#tags").val($("#tags").val() + " " + $(e.target).parent("li").attr("data-tag-name"));
+ return false;
});
$("#tag-box a.search-exl-tag").click(function(e) {
$("#tags").val($("#tags").val() + " -" + $(e.target).parent("li").attr("data-tag-name"));
+ return false;
});
}
@@ -1006,6 +1008,7 @@ var Danbooru = {};
var name = e.target.hash;
$(name).show();
e.stopPropagation();
+ return false;
});
$("#tag-and-wiki-box menu li:first-child").addClass("active");
@@ -1022,6 +1025,7 @@ var Danbooru = {};
var name = e.target.hash;
$(name).show();
e.stopPropagation();
+ return false;
});
$("#post-sections li:first-child").addClass("active");
@@ -1036,6 +1040,48 @@ $(document).ready(function() {
Danbooru.Post.initialize_all();
});
+(function() {
+ Danbooru.Comment = {};
+
+ Danbooru.Comment.initialize_all = function() {
+ this.initialize_response_link();
+ this.initialize_preview_button();
+ }
+
+ Danbooru.Comment.initialize_response_link = function() {
+ $("a.expand-comment-response").click(function(e) {
+ e.stopPropagation();
+ $(e.target).closest("div.new-comment").find("form").show();
+ $(e.target).hide();
+ return false;
+ });
+
+ $("div.new-comment form").hide();
+ }
+
+ Danbooru.Comment.initialize_preview_button = function() {
+ $("div.new-comment input[type=submit][value=Preview]").click(function(e) {
+ e.stopPropagation();
+ $.ajax({
+ context: e.target,
+ url: "/dtext/preview",
+ data: {
+ body: $(e.target).closest("form").find("textarea").val()
+ },
+ success: function(data, text_status, xhr) {
+ console.log($(this).closest("div.new-comment").find("div.comment-preview"));
+ $(this).closest("div.new-comment").find("div.comment-preview").show().html(data);
+ },
+ type: "post"
+ });
+ return false;
+ });
+ }
+})();
+
+$(document).ready(function() {
+ Danbooru.Comment.initialize_all();
+});
$(document).ready(function() {
var img = $("#image-preview img");
if (img) {
diff --git a/public/javascripts/src/app/comments.js b/public/javascripts/src/app/comments.js
new file mode 100644
index 000000000..e0f35b9a9
--- /dev/null
+++ b/public/javascripts/src/app/comments.js
@@ -0,0 +1,42 @@
+(function() {
+ Danbooru.Comment = {};
+
+ Danbooru.Comment.initialize_all = function() {
+ this.initialize_response_link();
+ this.initialize_preview_button();
+ }
+
+ Danbooru.Comment.initialize_response_link = function() {
+ $("a.expand-comment-response").click(function(e) {
+ e.stopPropagation();
+ $(e.target).closest("div.new-comment").find("form").show();
+ $(e.target).hide();
+ return false;
+ });
+
+ $("div.new-comment form").hide();
+ }
+
+ Danbooru.Comment.initialize_preview_button = function() {
+ $("div.new-comment input[type=submit][value=Preview]").click(function(e) {
+ e.stopPropagation();
+ $.ajax({
+ context: e.target,
+ url: "/dtext/preview",
+ data: {
+ body: $(e.target).closest("form").find("textarea").val()
+ },
+ success: function(data, text_status, xhr) {
+ console.log($(this).closest("div.new-comment").find("div.comment-preview"));
+ $(this).closest("div.new-comment").find("div.comment-preview").show().html(data);
+ },
+ type: "post"
+ });
+ return false;
+ });
+ }
+})();
+
+$(document).ready(function() {
+ Danbooru.Comment.initialize_all();
+});
diff --git a/public/javascripts/src/app/posts.js b/public/javascripts/src/app/posts.js
index 7147ca8e5..783afc84f 100644
--- a/public/javascripts/src/app/posts.js
+++ b/public/javascripts/src/app/posts.js
@@ -174,10 +174,12 @@
Danbooru.Post.initialize_tag_list = function() {
$("#tag-box a.search-inc-tag").click(function(e) {
$("#tags").val($("#tags").val() + " " + $(e.target).parent("li").attr("data-tag-name"));
+ return false;
});
$("#tag-box a.search-exl-tag").click(function(e) {
$("#tags").val($("#tags").val() + " -" + $(e.target).parent("li").attr("data-tag-name"));
+ return false;
});
}
@@ -189,6 +191,7 @@
var name = e.target.hash;
$(name).show();
e.stopPropagation();
+ return false;
});
$("#tag-and-wiki-box menu li:first-child").addClass("active");
@@ -205,6 +208,7 @@
var name = e.target.hash;
$(name).show();
e.stopPropagation();
+ return false;
});
$("#post-sections li:first-child").addClass("active");
diff --git a/public/stylesheets/compiled/default.css b/public/stylesheets/compiled/default.css
index a6c8e852c..610a3f034 100644
--- a/public/stylesheets/compiled/default.css
+++ b/public/stylesheets/compiled/default.css
@@ -205,6 +205,24 @@ form.simple_form div.input {
width: auto;
margin-right: 2em; }
+/*** DText Preview ***/
+div.dtext p {
+ margin-bottom: 1em; }
+
+/*** Comments ***/
+div.comments-for-post div.list-of-comments article {
+ margin-bottom: 2em; }
+ div.comments-for-post div.list-of-comments article div.author {
+ width: 20%;
+ float: left; }
+ div.comments-for-post div.list-of-comments article div.content {
+ margin-left: 2em;
+ width: 40em;
+ float: left; }
+div.comments-for-post div.comment-preview {
+ width: 40em;
+ margin-bottom: 2em; }
+
/*** Posts ***/
div.posts h1 {
font-size: 1.2em; }
diff --git a/public/stylesheets/src/default.scss b/public/stylesheets/src/default.scss
index 0a4295f96..b46b164b6 100644
--- a/public/stylesheets/src/default.scss
+++ b/public/stylesheets/src/default.scss
@@ -285,6 +285,42 @@ form.simple_form {
}
+/*** DText Preview ***/
+
+div.dtext {
+ p {
+ margin-bottom: 1em;
+ }
+}
+
+
+/*** Comments ***/
+
+div.comments-for-post {
+ div.list-of-comments {
+ article {
+ margin-bottom: 2em;
+
+ div.author {
+ width: 20%;
+ float: left;
+ }
+
+ div.content {
+ margin-left: 2em;
+ width: 40em;
+ float: left;
+ }
+ }
+ }
+
+ div.comment-preview {
+ width: 40em;
+ margin-bottom: 2em;
+ }
+}
+
+
/*** Posts ***/
div.posts {
@@ -363,7 +399,6 @@ div.posts {
}
-
/*** Comments ***/
div.comment-response {
}
diff --git a/script/custom/compile_javascripts b/script/custom/compile_javascripts
index a022e41bd..0e7547148 100755
--- a/script/custom/compile_javascripts
+++ b/script/custom/compile_javascripts
@@ -8,4 +8,5 @@ cat public/javascripts/src/lib/rails.js >> public/javascripts/compiled/default.j
cat public/javascripts/src/app/cookie.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/application.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/posts.js >> public/javascripts/compiled/default.js
+cat public/javascripts/src/app/comments.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/uploads.js >> public/javascripts/compiled/default.js
<%= submit_tag "Post comment", :class => "expand-comment-response" %>
- - - - <%= form_tag(comments_path) do %> - <%= hidden_field "comment", "post_id", :value => post.id%> - <%= text_area "comment", "body", :size => "60x7" %>- <%= submit_tag "Post" %> - <%= submit_tag "Preview" %> - <% end %> -