unified js for dtext previews

This commit is contained in:
albert
2011-10-20 18:50:16 -04:00
parent f630365c3b
commit e8808987d5
21 changed files with 101 additions and 190 deletions

View File

@@ -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 + "]");

View File

@@ -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();
});
}
})();

View 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();
});

View File

@@ -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() {

View File

@@ -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();
});