unified js for dtext previews
This commit is contained in:
@@ -2,9 +2,7 @@
|
|||||||
Danbooru.Comment = {};
|
Danbooru.Comment = {};
|
||||||
|
|
||||||
Danbooru.Comment.initialize_all = function() {
|
Danbooru.Comment.initialize_all = function() {
|
||||||
$("div.dtext-preview").hide();
|
|
||||||
this.initialize_response_link();
|
this.initialize_response_link();
|
||||||
this.initialize_preview_button();
|
|
||||||
this.initialize_reply_links();
|
this.initialize_reply_links();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,21 +40,6 @@
|
|||||||
$("div.new-comment form").hide();
|
$("div.new-comment form").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Comment.initialize_preview_button = function() {
|
|
||||||
$("div.new-comment input[type=submit][value=Preview]").click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
$.ajax("/dtext_preview", {
|
|
||||||
type: "post",
|
|
||||||
data: {
|
|
||||||
body: $(e.target).closest("form").find("textarea").val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
$(e.target).closest("div.new-comment").find("div.comment-preview").show().html(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Comment.highlight_threshold_comments = function(post_id) {
|
Danbooru.Comment.highlight_threshold_comments = function(post_id) {
|
||||||
var threshold = parseInt(Danbooru.meta("user-comment-threshold"));
|
var threshold = parseInt(Danbooru.meta("user-comment-threshold"));
|
||||||
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
||||||
|
|||||||
@@ -2,25 +2,6 @@
|
|||||||
Danbooru.Dmail = {};
|
Danbooru.Dmail = {};
|
||||||
|
|
||||||
Danbooru.Dmail.initialize_all = function() {
|
Danbooru.Dmail.initialize_all = function() {
|
||||||
$("#c-dmails #preview").hide();
|
|
||||||
|
|
||||||
this.initialize_preview_link();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Dmail.initialize_preview_link = function() {
|
|
||||||
$("#c-dmails #preview-button").click(function(e) {
|
|
||||||
$.ajax({
|
|
||||||
type: "post",
|
|
||||||
url: "/dtext_preview",
|
|
||||||
data: {
|
|
||||||
body: $("#dmail_body").val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
$("#preview").html(data).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
48
app/assets/javascripts/dtext.js
Normal file
48
app/assets/javascripts/dtext.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
(function() {
|
||||||
|
Danbooru.Dtext = {};
|
||||||
|
|
||||||
|
Danbooru.Dtext.initialize_links = function() {
|
||||||
|
$(".simple_form .dtext-preview").hide();
|
||||||
|
|
||||||
|
$(".simple_form input[value=Preview]").click(Danbooru.Dtext.click_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.Dtext.call_preview = function(e, $button, $input, $preview) {
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: "/dtext_preview",
|
||||||
|
data: {
|
||||||
|
body: $input.val()
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$button.val("Edit");
|
||||||
|
$input.hide();
|
||||||
|
$preview.html(data).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.Dtext.call_edit = function(e, $button, $input, $preview) {
|
||||||
|
$button.val("Preview");
|
||||||
|
$preview.hide();
|
||||||
|
$input.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.Dtext.click_button = function(e) {
|
||||||
|
var $button = $(e.target);
|
||||||
|
var $input = $("#" + $button.data("input-id"));
|
||||||
|
var $preview = $("#" + $button.data("preview-id"));
|
||||||
|
|
||||||
|
if ($button.val().match(/preview/i)) {
|
||||||
|
Danbooru.Dtext.call_preview(e, $button, $input, $preview);
|
||||||
|
} else {
|
||||||
|
Danbooru.Dtext.call_edit(e, $button, $input, $preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Danbooru.Dtext.initialize_links();
|
||||||
|
});
|
||||||
@@ -2,9 +2,6 @@
|
|||||||
Danbooru.ForumPost = {};
|
Danbooru.ForumPost = {};
|
||||||
|
|
||||||
Danbooru.ForumPost.initialize_all = function() {
|
Danbooru.ForumPost.initialize_all = function() {
|
||||||
$("#c-forum-topics #preview").hide();
|
|
||||||
|
|
||||||
this.initialize_preview_link();
|
|
||||||
this.initialize_last_forum_read_at();
|
this.initialize_last_forum_read_at();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,30 +16,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.ForumPost.initialize_preview_link = function() {
|
|
||||||
$("#c-forum-topics #preview a[name=toggle-preview]").click(function(e) {
|
|
||||||
$("#preview").toggle();
|
|
||||||
$("#dtext-help").toggle();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#c-forum-topics input[value=Preview]").click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
$.ajax({
|
|
||||||
type: "post",
|
|
||||||
url: "/dtext_preview",
|
|
||||||
data: {
|
|
||||||
body: $("#forum_post_body").val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
$("#dtext-help").hide();
|
|
||||||
$("#preview").show();
|
|
||||||
$("#preview .content").html(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|||||||
@@ -1,37 +1 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.WikiPage = {};
|
|
||||||
|
|
||||||
Danbooru.WikiPage.initialize_all = function() {
|
|
||||||
$("#c-wiki-pages #preview").hide();
|
|
||||||
|
|
||||||
this.initialize_preview_link();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.WikiPage.initialize_preview_link = function() {
|
|
||||||
$("#c-wiki-pages #preview a[name=toggle-preview]").click(function(e) {
|
|
||||||
$("#preview").toggle();
|
|
||||||
$("#dtext-help").toggle();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#c-wiki-pages input[value=Preview]").click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
$.ajax({
|
|
||||||
type: "post",
|
|
||||||
url: "/dtext_preview",
|
|
||||||
data: {
|
|
||||||
body: $("#wiki_page_body").val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
$("#dtext-help").hide();
|
|
||||||
$("#preview").show();
|
|
||||||
$("#preview .content").html(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
Danbooru.WikiPage.initialize_all();
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -31,17 +31,10 @@ div.prose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div.dtext {
|
div.dtext-preview {
|
||||||
width: 30em;
|
width: 30em;
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div.dtext-preview {
|
|
||||||
border: 2px dashed #AAA;
|
|
||||||
padding: 1em;
|
|
||||||
margin: 1em 0;
|
|
||||||
width: 30em;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,3 +19,6 @@ span.count {
|
|||||||
color: #CCC;
|
color: #CCC;
|
||||||
margin-left: 0.5em;
|
margin-left: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.edit-options {
|
||||||
|
}
|
||||||
@@ -5,10 +5,12 @@ div#search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div#page {
|
div#page {
|
||||||
|
overflow: hidden;
|
||||||
|
width: 85em;
|
||||||
margin: 0 30px;
|
margin: 0 30px;
|
||||||
|
|
||||||
aside#sidebar {
|
aside#sidebar {
|
||||||
width: 20%;
|
width: 15em;
|
||||||
float: left;
|
float: left;
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@@ -29,9 +31,9 @@ div#page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
section#content {
|
section#content {
|
||||||
width: 75%;
|
width: 65em;
|
||||||
float: left;
|
float: left;
|
||||||
margin-left: 2em;
|
padding-left: 2em;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,23 +35,6 @@ div#c-forum-topics {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
div#form-content {
|
|
||||||
float: left;
|
|
||||||
width: 450px;
|
|
||||||
padding-right: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#form-aside {
|
|
||||||
float: left;
|
|
||||||
width: 400px;
|
|
||||||
|
|
||||||
div#preview > p {
|
|
||||||
margin-top: 0.5em;
|
|
||||||
padding-top: 0.5em;
|
|
||||||
border-top: 1px solid #AAA;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
a.last-page {
|
a.last-page {
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,20 +6,5 @@ div#c-wiki-pages {
|
|||||||
div#form-content {
|
div#form-content {
|
||||||
float: left;
|
float: left;
|
||||||
width: 30em;
|
width: 30em;
|
||||||
padding-right: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#form-aside {
|
|
||||||
float: left;
|
|
||||||
width: 20em;
|
|
||||||
|
|
||||||
div#preview > p {
|
|
||||||
margin-top: 0.5em;
|
|
||||||
padding-top: 0.5em;
|
|
||||||
border-top: 1px solid #AAA;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
div#preview {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
class DtextPreviewsController < ApplicationController
|
class DtextPreviewsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
render :inline => "<h1 class=\"preview-header\">Preview</h1><%= format_text(params[:body]) %>"
|
render :inline => "<%= format_text(params[:body]) %>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
<%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5"} %>
|
<%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5"} %>
|
||||||
<%= f.input :is_active %>
|
<%= f.input :is_active %>
|
||||||
<%= f.input :is_banned %>
|
<%= f.input :is_banned %>
|
||||||
<%= f.input :notes, :as => :text %>
|
|
||||||
<%= f.button :submit %>
|
<%= render "dtext/form", :name => "Notes", :input_id => "artist_notes", :input_name => "artist[notes]", :value => @artist.notes, :preview_id => "dtext-preview" %>
|
||||||
|
<%= f.button :submit, "Submit" %>
|
||||||
|
<%= f.button :submit, "Preview", "data-input-id" => "artist_notes", "data-preview-id" => "dtext-preview" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="index">
|
<div class="index">
|
||||||
<h1>Bans</h1>
|
<h1>Bans</h1>
|
||||||
|
|
||||||
<table>
|
<table class="striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>User</th>
|
<th>User</th>
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
<h1>Edit Comment</h1>
|
<h1>Edit Comment</h1>
|
||||||
|
|
||||||
<%= simple_form_for(@comment) do |f| %>
|
<%= simple_form_for(@comment) do |f| %>
|
||||||
<%= f.input :body %>
|
<%= render "dtext/form", :name => "Body", :input_id => "comment_body", :input_name => "comment[body]", :value => @comment.body, :preview_id => "dtext-preview" %>
|
||||||
<%= f.button :submit %>
|
<%= f.button :submit, "Submit" %>
|
||||||
|
<%= f.button :submit, "Preview", "data-input-id" => "comment_body", "data-preview-id" => "dtext-preview" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
<div class="comment-preview dtext dtext-preview">
|
<div class="comment-preview dtext dtext-preview">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= form_tag(comments_path) do %>
|
<%= form_tag(comments_path, :class => "simple_form") do %>
|
||||||
<%= hidden_field "comment", "post_id", :value => post.id %>
|
<%= hidden_field "comment", "post_id", :value => post.id %>
|
||||||
<%= text_area "comment", "body", :size => "60x7" %>
|
<%= render "dtext/form", :name => "Response", :input_id => "comment_response_for_#{post.id}", :input_name => "comment[body]", :value => "", :preview_id => "dtext-preview-for-#{post.id}" %>
|
||||||
<br>
|
|
||||||
<%= submit_tag "Post" %>
|
<%= submit_tag "Post" %>
|
||||||
<%= submit_tag "Preview" %>
|
<%= submit_tag "Preview", "data-input-id" => "comment_response_for_#{post.id}", "data-preview-id" => "dtext-preview-for-#{post.id}" %>
|
||||||
<%= link_to "Formatting", wiki_pages_path(:title => "help:dtext") %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<div id="preview">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<%= simple_form_for(dmail) do |f| %>
|
<%= simple_form_for(dmail) do |f| %>
|
||||||
<%= f.input :to_name, :label => "To" %>
|
<%= f.input :to_name, :label => "To" %>
|
||||||
<%= f.input :title %>
|
<%= f.input :title %>
|
||||||
<%= f.input :body, :input_html => {:size => "50x25"} %>
|
|
||||||
|
<%= render "dtext/form", :name => "Body", :input_id => "dmail_body", :input_name => "dmail[body]", :value => dmail.body, :preview_id => "dtext-preview" %>
|
||||||
|
|
||||||
<%= f.button :submit, "Send" %>
|
<%= f.button :submit, "Send" %>
|
||||||
<%= submit_tag "Preview", :id => "preview-button" %>
|
<%= f.button :submit, "Preview", "data-input-id" => "dmail_body", "data-preview-id" => "dtext-preview" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
16
app/views/dtext/_form.html.erb
Normal file
16
app/views/dtext/_form.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!--
|
||||||
|
- name
|
||||||
|
- input_id
|
||||||
|
- input_name
|
||||||
|
- preview_id
|
||||||
|
- value
|
||||||
|
-->
|
||||||
|
<div class="input text optional">
|
||||||
|
<label class="text optional" for="<%= input_id %>"><%= name %></label>
|
||||||
|
|
||||||
|
<div class="dtext-previewable">
|
||||||
|
<textarea id="<%= input_id %>" class="text optional" rows="20" name="<%= input_name %>" cols="30"><%= value %></textarea>
|
||||||
|
<div id="<%= preview_id %>" class="dtext-preview"></div>
|
||||||
|
</div>
|
||||||
|
<span class="hint">All text is formatted using <%= link_to "DText", wiki_pages_path(:title => "help:dtext") %></span>
|
||||||
|
</div>
|
||||||
@@ -22,7 +22,8 @@ Or alias a URL: [url=http://www.google.com]Google[/url]
|
|||||||
|
|
||||||
A [[wiki link]] (underscores are not needed).
|
A [[wiki link]] (underscores are not needed).
|
||||||
|
|
||||||
A {{post link}}. Alternatively, post #1234 (also works with forum posts, comments and pools).
|
A {{post link}}. Alternatively, post #1234.
|
||||||
|
Also works with forum posts, comments and pools.
|
||||||
|
|
||||||
<%= link_to "Read more", wiki_pages_path(:title => "help:dtext") %>.
|
<%= link_to "Read more", wiki_pages_path(:title => "help:dtext") %>.
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
<% unless @forum_topic.new_record? %>
|
<% unless @forum_topic.new_record? %>
|
||||||
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= pf.input :body, :input_html => {:id => "forum_post_body"} %>
|
|
||||||
|
<%= render "dtext/form", :name => "Body", :input_id => "forum_post_body", :input_name => "forum_topic[original_post_attributes][body]", :value => @forum_topic.original_post.body, :preview_id => "dtext-preview" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if CurrentUser.is_moderator? %>
|
<% if CurrentUser.is_moderator? %>
|
||||||
@@ -17,18 +18,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= f.button :submit, "Submit" %>
|
<%= f.button :submit, "Submit" %>
|
||||||
<%= f.button :submit, "Preview" %>
|
<%= f.button :submit, "Preview", "data-input-id" => "forum_post_body", "data-preview-id" => "dtext-preview" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="form-aside">
|
|
||||||
<div id="preview">
|
|
||||||
<div class="content dtext">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<p><a href="#" name="toggle-preview">Hide</a></p>
|
|
||||||
</div>
|
|
||||||
<div id="dtext-help">
|
|
||||||
<%= render "dtext/help" %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -3,25 +3,15 @@
|
|||||||
|
|
||||||
<%= simple_form_for(@wiki_page) do |f| %>
|
<%= simple_form_for(@wiki_page) do |f| %>
|
||||||
<%= f.input :title %>
|
<%= f.input :title %>
|
||||||
<%= f.input :body %>
|
|
||||||
|
<%= render "dtext/form", :name => "Body", :input_id => "wiki_page_body", :input_name => "wiki_page[body]", :value => @wiki_page.body, :preview_id => "dtext-preview" %>
|
||||||
|
|
||||||
<% if CurrentUser.is_janitor? %>
|
<% if CurrentUser.is_janitor? %>
|
||||||
<%= f.input :is_locked %>
|
<%= f.input :is_locked %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= f.button :submit, "Submit" %>
|
<%= f.button :submit, "Submit" %>
|
||||||
<%= f.button :submit, "Preview" %>
|
<%= f.button :submit, "Preview", "data-input-id" => "wiki_page_body", "data-preview-id" => "dtext-preview" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="form-aside">
|
|
||||||
<div id="preview">
|
|
||||||
<div class="content dtext">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<p><a href="#" name="toggle-preview">Hide</a></p>
|
|
||||||
</div>
|
|
||||||
<div id="dtext-help">
|
|
||||||
<%= render "dtext/help" %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<%= render "sidebar" %>
|
<%= render "sidebar" %>
|
||||||
|
|
||||||
<section id="content">
|
<section id="content">
|
||||||
<h1>Edit Wiki Page: <%= @wiki_page.title %></h1>
|
<h1>Edit Wiki Page</h1>
|
||||||
<%= render "form" %>
|
<%= render "form" %>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user