unified js for dtext previews
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
Danbooru.Comment = {};
|
||||
|
||||
Danbooru.Comment.initialize_all = function() {
|
||||
$("div.dtext-preview").hide();
|
||||
this.initialize_response_link();
|
||||
this.initialize_preview_button();
|
||||
this.initialize_reply_links();
|
||||
}
|
||||
|
||||
@@ -42,21 +40,6 @@
|
||||
$("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) {
|
||||
var threshold = parseInt(Danbooru.meta("user-comment-threshold"));
|
||||
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
||||
|
||||
@@ -2,25 +2,6 @@
|
||||
Danbooru.Dmail = {};
|
||||
|
||||
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.initialize_all = function() {
|
||||
$("#c-forum-topics #preview").hide();
|
||||
|
||||
this.initialize_preview_link();
|
||||
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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
ul {
|
||||
margin-left: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
div.dtext-preview {
|
||||
border: 2px dashed #AAA;
|
||||
padding: 1em;
|
||||
margin: 1em 0;
|
||||
width: 30em;
|
||||
}
|
||||
|
||||
@@ -18,4 +18,7 @@ span.wait {
|
||||
span.count {
|
||||
color: #CCC;
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
span.edit-options {
|
||||
}
|
||||
@@ -5,10 +5,12 @@ div#search {
|
||||
}
|
||||
|
||||
div#page {
|
||||
overflow: hidden;
|
||||
width: 85em;
|
||||
margin: 0 30px;
|
||||
|
||||
aside#sidebar {
|
||||
width: 20%;
|
||||
width: 15em;
|
||||
float: left;
|
||||
|
||||
h1 {
|
||||
@@ -29,9 +31,9 @@ div#page {
|
||||
}
|
||||
|
||||
section#content {
|
||||
width: 75%;
|
||||
width: 65em;
|
||||
float: left;
|
||||
margin-left: 2em;
|
||||
padding-left: 2em;
|
||||
overflow: visible;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,24 +34,7 @@ div#c-forum-topics {
|
||||
tr.new-topic {
|
||||
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 {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
@@ -6,20 +6,5 @@ div#c-wiki-pages {
|
||||
div#form-content {
|
||||
float: left;
|
||||
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 {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user