Merge branch 'master' into fix-3807

This commit is contained in:
Albert Yi
2018-08-13 18:21:53 -07:00
committed by GitHub
43 changed files with 171 additions and 450 deletions

View File

@@ -1,11 +1,8 @@
import Utility from "./utility";
let Artist = {};
Artist.initialize_all = function() {
if ($("#c-artists").length) {
Artist.initialize_check_name();
Artist.initialize_shortcuts();
}
}
@@ -29,18 +26,6 @@ Artist.initialize_check_name = function() {
});
}
Artist.initialize_shortcuts = function() {
if ($("#c-artists #a-show").length) {
Utility.keydown("e", "edit", function(e) {
$("#artist-edit a")[0].click();
});
Utility.keydown("shift+d", "delete", function(e) {
$("#artist-delete a")[0].click();
});
}
};
$(document).ready(function() {
Artist.initialize_all();
});

View File

@@ -5,29 +5,13 @@ let Comment = {};
Comment.initialize_all = function() {
if ($("#c-posts").length || $("#c-comments").length) {
this.initialize_response_link();
this.initialize_reply_links();
this.initialize_expand_links();
this.initialize_vote_links();
if (!$("#a-edit").length) {
this.initialize_edit_links();
}
$(document).on("click", ".reply-link", Comment.quote);
$(document).on("click", ".edit_comment_link", Comment.show_edit_form);
$(document).on("click", ".expand-comment-response", Comment.show_new_comment_form);
}
if ($("#c-posts").length && $("#a-show").length) {
Comment.highlight_threshold_comments(Utility.meta("post-id"));
}
$(window).on("danbooru:index_for_post", (post_id, current_comment_section, include_below_threshold) => {
if (include_below_threshold) {
$("#threshold-comments-notice-for-" + post_id).hide();
} else {
Comment.highlight_threshold_comments(post_id);
}
Comment.initialize_reply_links(current_comment_section);
Comment.initialize_edit_links(current_comment_section);
Comment.initialize_vote_links(current_comment_section);
$(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => {
$("#threshold-comments-notice-for-" + post_id).hide();
Dtext.initialize_expandables(current_comment_section);
});
}
@@ -51,69 +35,17 @@ Comment.quote = function(e) {
e.preventDefault();
}
Comment.initialize_reply_links = function($parent) {
$parent = $parent || $(document);
$parent.find(".reply-link").click(Comment.quote);
Comment.show_new_comment_form = function(e) {
$(e.target).hide();
var $form = $(e.target).closest("div.new-comment").find("form");
$form.show();
Utility.scroll_to($form);
e.preventDefault();
}
Comment.initialize_expand_links = function() {
$(".comment-section form").hide();
$(".comment-section input.expand-comment-response").click(function(e) {
var post_id = $(this).closest(".comment-section").data("post-id");
$(this).hide();
$(".comment-section[data-post-id=" + post_id + "] form").slideDown("fast");
e.preventDefault();
});
}
Comment.initialize_response_link = function() {
$("a.expand-comment-response").click(function(e) {
$(e.target).hide();
var $form = $(e.target).closest("div.new-comment").find("form");
$form.show();
Utility.scroll_to($form);
e.preventDefault();
});
$("div.new-comment form").hide();
}
Comment.initialize_edit_links = function($parent) {
$parent = $parent || $(document);
$parent.find(".edit_comment").hide();
$parent.find(".edit_comment_link").click(function(e) {
var link_id = $(this).attr("id");
var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1];
$("#edit_comment_" + comment_id).fadeToggle("fast");
e.preventDefault();
});
}
Comment.highlight_threshold_comments = function(post_id) {
var threshold = parseInt(Utility.meta("user-comment-threshold"));
var articles = $("article.comment[data-post-id=" + post_id + "]");
articles.each(function(i, v) {
var $comment = $(v);
if (parseInt($comment.data("score")) < threshold) {
$comment.addClass("below-threshold");
}
});
}
Comment.hide_threshold_comments = function(post_id) {
var threshold = parseInt(Utility.meta("user-comment-threshold"));
var articles = $("article.comment[data-post-id=" + post_id + "]");
articles.each(function(i, v) {
var $comment = $(v);
if (parseInt($comment.data("score")) < threshold) {
$comment.hide();
}
});
}
Comment.initialize_vote_links = function($parent) {
$parent = $parent || $(document);
$parent.find(".unvote-comment-link").hide();
Comment.show_edit_form = function(e) {
$(this).closest(".comment").find(".edit_comment").show();
e.preventDefault();
}
$(document).ready(function() {

View File

@@ -1,11 +1,8 @@
import Utility from './utility'
let FavoriteGroup = {};
FavoriteGroup.initialize_all = function() {
if ($("#c-posts").length && $("#a-show").length) {
this.initialize_add_to_favgroup_dialog();
Utility.keydown("1 2 3 4 5 6 7 8 9 0", "add_to_favgroup", FavoriteGroup.add_to_favgroup);
}
}
@@ -21,10 +18,6 @@ FavoriteGroup.initialize_add_to_favgroup_dialog = function() {
});
var open_favgroup_dialog = function(e) {
if (Utility.meta("current-user-id") === "") { // anonymous
return;
}
if ($(".add-to-favgroup").length === 1) {
// If the user only has one favorite group we don't need to ask which group to add the post to.
$(".add-to-favgroup").click();
@@ -34,18 +27,9 @@ FavoriteGroup.initialize_add_to_favgroup_dialog = function() {
e.preventDefault();
}
Utility.keydown("g", "open_favgroup_dialog", open_favgroup_dialog);
$("#open-favgroup-dialog-link").click(open_favgroup_dialog);
}
FavoriteGroup.add_to_favgroup = function(e) {
var favgroup_index = (e.key === "0") ? "10" : e.key;
var link = $("#add-to-favgroup-" + favgroup_index + ":visible");
if (link.length) {
link.click();
}
}
$(function() {
FavoriteGroup.initialize_all();
});

View File

@@ -1,24 +1,8 @@
import Utility from './utility'
let ForumPost = {};
ForumPost.initialize_all = function() {
if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) {
this.initialize_edit_links();
Utility.keydown("e", "edit", function(e) {
$(".edit_forum_topic_link")[0].click();
});
Utility.keydown("shift+d", "delete", function(e) {
$("#forum-topic-delete a")[0].click();
});
}
if ($("#c-forum-topics").length) {
Utility.keydown("shift+r", "mark_all_as_read", function(e) {
$("#forum-topic-mark-all-as-read a")[0].click();
});
}
}

View File

@@ -806,11 +806,7 @@ let Note = {
},
initialize_shortcuts: function() {
if ($("#note-locked-notice").length === 0) {
$("#translate").click(Note.TranslationMode.toggle);
Utility.keydown("n", "translation_mode", Note.TranslationMode.toggle);
}
$("#translate").click(Note.TranslationMode.toggle);
$("#image").click(Note.Box.toggle_all);
},

View File

@@ -1,26 +0,0 @@
import Utility from './utility'
let Paginator = {};
Paginator.next_page = function() {
var href = $(".paginator a[rel=next]").attr("href");
if (href) {
window.location = href;
}
}
Paginator.prev_page = function() {
var href = $(".paginator a[rel=prev]").attr("href");
if (href) {
window.location = href;
}
}
$(function() {
if ($(".paginator").length) {
Utility.keydown("d right", "next_page", Paginator.next_page);
Utility.keydown("a left", "prev_page", Paginator.prev_page);
}
});
export default Paginator

View File

@@ -1,12 +1,6 @@
import Utility from './utility'
let Pool = {};
Pool.initialize_all = function() {
if ($("#c-pools").length) {
this.initialize_shortcuts();
}
if ($("#c-posts").length && $("#a-show").length) {
this.initialize_add_to_pool_link();
}
@@ -30,18 +24,6 @@ Pool.initialize_add_to_pool_link = function() {
});
}
Pool.initialize_shortcuts = function() {
if ($("#c-pools #a-show").length) {
Utility.keydown("e", "edit", function(e) {
$("#pool-edit a")[0].click();
});
Utility.keydown("shift+d", "delete", function(e) {
$("#pool-delete a")[0].click();
});
}
};
Pool.initialize_simple_edit = function() {
$("#sortable").sortable({
placeholder: "ui-state-placeholder"

View File

@@ -1,38 +0,0 @@
import Utility from './utility'
let PostPopular = {};
PostPopular.nav_prev = function(e) {
if ($("#popular-nav-links").length) {
var href = $("#popular-nav-links a[rel=prev]").attr("href");
if (href) {
location.href = href;
}
}
e.preventDefault();
}
PostPopular.nav_next = function(e) {
if ($("#popular-nav-links").length) {
var href = $("#popular-nav-links a[rel=next]").attr("href");
if (href) {
location.href = href;
}
}
e.preventDefault();
}
PostPopular.initialize_all = function() {
if ($("#c-explore-posts").length) {
Utility.keydown("a left", "prev_page", PostPopular.nav_prev);
Utility.keydown("d right", "next_page", PostPopular.nav_next);
}
}
$(document).ready(function() {
PostPopular.initialize_all();
});
export default PostPopular

View File

@@ -95,6 +95,17 @@ Post.initialize_edit_dialog = function() {
}
Post.open_edit_dialog = function() {
if ($("#edit-dialog").length === 1) {
return;
}
$("#edit").show();
$("#comments").hide();
$("#share").hide();
$("#post-sections li").removeClass("active");
$("#post-edit-link").parent("li").addClass("active");
$("#related-tags-container").show();
var $tag_string = $("#post_tag_string,#upload_tag_string");
$("div.input").has($tag_string).prevAll().hide();
$("#open-edit-dialog").hide();
@@ -230,22 +241,8 @@ Post.swipe_next = function(e) {
Post.initialize_shortcuts = function() {
if ($("#a-show").length) {
Utility.keydown("e", "edit", function(e) {
$("#post-edit-link").trigger("click");
$("#post_tag_string").focus();
e.preventDefault();
});
if (Utility.meta("current-user-can-approve-posts") === "true") {
Utility.keydown("shift+o", "approve", function(e) {
$(".approve-link").click();
});
}
Utility.keydown("a", "prev_page", Post.nav_prev);
Utility.keydown("d", "next_page", Post.nav_next);
Utility.keydown("f", "favorite", Post.favorite);
Utility.keydown("shift+f", "unfavorite", Post.unfavorite);
}
}
@@ -591,22 +588,6 @@ Post.approve = function(post_id) {
});
}
Post.favorite = function (e) {
if ($("#add-to-favorites").is(":visible")) {
$("#add-to-favorites")[0].click();
} else if (Utility.meta("current-user-id") === "") {
$(window).trigger("danbooru:notice", "You must be logged in to favorite posts");
} else {
$(window).trigger("danbooru:notice", "You have already favorited this post");
}
};
Post.unfavorite = function (e) {
$.ajax("/favorites/" + Utility.meta("post-id") + ".js", {
type: "DELETE"
});
};
Post.initialize_saved_searches = function() {
$("#new_saved_search #saved_search_label_string").autocomplete({
search: function() {

View File

@@ -1,44 +1,47 @@
import Utility from './utility'
import Post from './posts.js.erb'
let Shortcuts = {};
Shortcuts.initialize = function() {
Utility.keydown("s", "scroll_down", Shortcuts.nav_scroll_down);
Utility.keydown("w", "scroll_up", Shortcuts.nav_scroll_up);
Utility.keydown("q", "focus_search", function(e) {
$("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd();
e.preventDefault();
});
if ($("#image").length) { // post page or bookmarklet upload page
Utility.keydown("shift+e", "edit_dialog", function(e) {
if (Utility.meta("current-user-id") === "") { // anonymous
return;
}
if (!$("#edit-dialog").length) {
$("#edit").show();
$("#comments").hide();
$("#share").hide();
$("#post-sections li").removeClass("active");
$("#post-edit-link").parent("li").addClass("active");
$("#related-tags-container").show();
Post.open_edit_dialog();
}
e.preventDefault();
});
}
if ($("#c-posts #a-index, #c-favorites #a-index").length) {
Utility.keydown("r", "random", function(e) {
$("#random-post")[0].click();
});
}
Shortcuts.initialize_data_shortcuts();
}
// Bind keyboard shortcuts to links that have a `data-shortcut="..."` attribute. If multiple links have the
// same shortcut, then only the first link will be triggered by the shortcut.
//
// Add `data-shortcut-when="$selector"`, where `selector` is any valid jQuery selector, to make the shortcut
// active only when the link matches the selector. For example, `data-shortcut-when=":visible"` makes the
// shortcut apply only when the link is visible.
Shortcuts.initialize_data_shortcuts = function() {
$(document).off("keydown.danbooru.shortcut");
$("[data-shortcut]").each((_i, element) => {
const id = $(element).attr("id");
const keys = $(element).attr("data-shortcut");
const namespace = `shortcut.${id}`;
const title = `Shortcut is ${keys.split(/\s+/).join(" or ")}`;
$(element).attr("title", title);
Utility.keydown(keys, namespace, event => {
const e = $(`[data-shortcut="${keys}"]`).get(0);
const condition = $(e).attr("data-shortcut-when") || "*";
if ($(e).is(condition)) {
if ($(e).is("input, textarea")) {
e.focus();
} else {
e.click();
}
event.preventDefault();
}
});
});
};
Shortcuts.nav_scroll_down = function() {
var scroll_top = $(window).scrollTop() + ($(window).height() * 0.15);
$(window).scrollTop(scroll_top);

View File

@@ -1,4 +1,3 @@
import Utility from './utility'
import Post from './posts.js.erb'
import RelatedTag from './related_tag.js.erb'
@@ -18,7 +17,6 @@ Upload.initialize_all = function() {
}
this.initialize_info_bookmarklet();
this.initialize_similar();
this.initialize_shortcuts();
this.initialize_submit();
$("#related-tags-button").trigger("click");
@@ -55,13 +53,6 @@ Upload.initialize_submit = function() {
});
}
Upload.initialize_shortcuts = function() {
Utility.keydown("e", "edit", function(e) {
$("#upload_tag_string").focus();
e.preventDefault();
});
};
Upload.initialize_iqdb_source = function() {
if (/^https?:\/\//.test($("#normalized_url").val())) {
$.get("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});

View File

@@ -1,25 +0,0 @@
import Utility from './utility'
let WikiPage = {};
WikiPage.initialize_all = function() {
if ($("#c-wiki-pages,#c-wiki-page-versions").length) {
this.initialize_shortcuts();
}
}
WikiPage.initialize_shortcuts = function() {
if ($("#a-show").length) {
Utility.keydown("e", "edit", function(e) {
$("#wiki-page-edit a")[0].click();
});
Utility.keydown("shift+d", "delete", function(e) {
$("#wiki-page-delete a")[0].click();
});
}
}
$(document).ready(function() {
WikiPage.initialize_all();
});