Fix #3867: Add namespaces to all Javascript events.

This commit is contained in:
evazion
2018-09-04 11:58:09 -05:00
parent c03af7f563
commit 3bed5f3cf9
23 changed files with 121 additions and 119 deletions

View File

@@ -13,7 +13,7 @@ ArtistCommentary.initialize_all = function() {
} }
ArtistCommentary.initialize_commentary_display_tabs = function() { ArtistCommentary.initialize_commentary_display_tabs = function() {
$("#commentary-sections li a").click(function(e) { $("#commentary-sections li a").on("click.danbooru", function(e) {
if (e.target.hash === "#original") { if (e.target.hash === "#original") {
$("#original-artist-commentary").show(); $("#original-artist-commentary").show();
$("#translated-artist-commentary").hide(); $("#translated-artist-commentary").hide();
@@ -47,7 +47,7 @@ ArtistCommentary.initialize_edit_commentary_dialog = function() {
$('#add-commentary-dialog').dialog('close'); $('#add-commentary-dialog').dialog('close');
}); });
$("#add-commentary").click(function(e) { $("#add-commentary").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$("#add-commentary-dialog").dialog("open"); $("#add-commentary-dialog").dialog("open");
}); });
@@ -56,7 +56,7 @@ ArtistCommentary.initialize_edit_commentary_dialog = function() {
$("#fetch-commentary input").toggle(); $("#fetch-commentary input").toggle();
}); });
$('#fetch-commentary button[type="submit"]').click(ArtistCommentary.fetch_commentary); $('#fetch-commentary button[type="submit"]').on("click.danbooru", ArtistCommentary.fetch_commentary);
} }
ArtistCommentary.fetch_commentary = function() { ArtistCommentary.fetch_commentary = function() {

View File

@@ -7,7 +7,7 @@ Artist.initialize_all = function() {
} }
Artist.initialize_check_name = function() { Artist.initialize_check_name = function() {
$("#artist_name").keyup(function(e) { $("#artist_name").on("keyup.danbooru", function(e) {
if ($("#artist_name").val().length > 0) { if ($("#artist_name").val().length > 0) {
$("#check-name-result").html(""); $("#check-name-result").html("");

View File

@@ -343,7 +343,7 @@ Autocomplete.render_item = function(list, item) {
var $link = $("<a/>"); var $link = $("<a/>");
$link.text(item.label); $link.text(item.label);
$link.attr("href", "/posts?tags=" + encodeURIComponent(item.value)); $link.attr("href", "/posts?tags=" + encodeURIComponent(item.value));
$link.click(function(e) { $link.on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
}); });

View File

@@ -71,7 +71,7 @@ Blacklist.update_sidebar = function() {
link.text(entry.tags); link.text(entry.tags);
link.attr("href", `/posts?tags=${encodeURIComponent(entry.tags)}`); link.attr("href", `/posts?tags=${encodeURIComponent(entry.tags)}`);
link.attr("title", entry.tags); link.attr("title", entry.tags);
link.click(Blacklist.toggle_entry); link.on("click.danbooru", Blacklist.toggle_entry);
count.html(entry.hits); count.html(entry.hits);
count.addClass("count"); count.addClass("count");
item.append(link); item.append(link);
@@ -93,7 +93,7 @@ Blacklist.initialize_disable_all_blacklists = function() {
$("#disable-all-blacklists").show() $("#disable-all-blacklists").show()
} }
$("#disable-all-blacklists").click(function(e) { $("#disable-all-blacklists").on("click.danbooru", function(e) {
$("#disable-all-blacklists").hide(); $("#disable-all-blacklists").hide();
$("#re-enable-all-blacklists").show(); $("#re-enable-all-blacklists").show();
Cookie.put("dab", "1"); Cookie.put("dab", "1");
@@ -101,7 +101,7 @@ Blacklist.initialize_disable_all_blacklists = function() {
e.preventDefault(); e.preventDefault();
}); });
$("#re-enable-all-blacklists").click(function(e) { $("#re-enable-all-blacklists").on("click.danbooru", function(e) {
$("#disable-all-blacklists").show(); $("#disable-all-blacklists").show();
$("#re-enable-all-blacklists").hide(); $("#re-enable-all-blacklists").hide();
Cookie.put("dab", "0"); Cookie.put("dab", "0");

View File

@@ -4,9 +4,9 @@ let Comment = {};
Comment.initialize_all = function() { Comment.initialize_all = function() {
if ($("#c-posts").length || $("#c-comments").length) { if ($("#c-posts").length || $("#c-comments").length) {
$(document).on("click", ".reply-link", Comment.quote); $(document).on("click.danbooru.comment", ".reply-link", Comment.quote);
$(document).on("click", ".edit_comment_link", Comment.show_edit_form); $(document).on("click.danbooru.comment", ".edit_comment_link", Comment.show_edit_form);
$(document).on("click", ".expand-comment-response", Comment.show_new_comment_form); $(document).on("click.danbooru.comment", ".expand-comment-response", Comment.show_new_comment_form);
} }
$(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => { $(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => {

View File

@@ -3,19 +3,19 @@ import Utility from './utility'
$(function() { $(function() {
// Account notices // Account notices
$("#hide-sign-up-notice").click(function(e) { $("#hide-sign-up-notice").on("click.danbooru", function(e) {
$("#sign-up-notice").hide(); $("#sign-up-notice").hide();
Cookie.put("hide_sign_up_notice", "1", 7); Cookie.put("hide_sign_up_notice", "1", 7);
e.preventDefault(); e.preventDefault();
}); });
$("#hide-upgrade-account-notice").click(function(e) { $("#hide-upgrade-account-notice").on("click.danbooru", function(e) {
$("#upgrade-account-notice").hide(); $("#upgrade-account-notice").hide();
Cookie.put('hide_upgrade_account_notice', '1', 7); Cookie.put('hide_upgrade_account_notice', '1', 7);
e.preventDefault(); e.preventDefault();
}); });
$("#hide-dmail-notice").click(function(e) { $("#hide-dmail-notice").on("click.danbooru", function(e) {
var $dmail_notice = $("#dmail-notice"); var $dmail_notice = $("#dmail-notice");
$dmail_notice.hide(); $dmail_notice.hide();
var dmail_id = $dmail_notice.data("id"); var dmail_id = $dmail_notice.data("id");
@@ -23,12 +23,12 @@ $(function() {
e.preventDefault(); e.preventDefault();
}); });
$("#close-notice-link").click(function(e) { $("#close-notice-link").on("click.danbooru", function(e) {
$('#notice').fadeOut("fast"); $('#notice').fadeOut("fast");
e.preventDefault(); e.preventDefault();
}); });
$("#desktop-version-link a").click(function(e) { $("#desktop-version-link a").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", { $.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
method: "PUT", method: "PUT",

View File

@@ -6,12 +6,12 @@ Dtext.initialize_all = function() {
} }
Dtext.initialize_links = function() { Dtext.initialize_links = function() {
$(".simple_form input[value=Preview]").click(Dtext.click_button); $(".simple_form input[value=Preview]").on("click.danbooru", Dtext.click_button);
} }
Dtext.initialize_expandables = function($parent) { Dtext.initialize_expandables = function($parent) {
$parent = $parent || $(document); $parent = $parent || $(document);
$parent.find(".expandable-button").click(function(e) { $parent.find(".expandable-button").on("click.danbooru", function(e) {
var button = $(this); var button = $(this);
button.parent().next().fadeToggle("fast"); button.parent().next().fadeToggle("fast");
if (button.val() === "Show") { if (button.val() === "Show") {

View File

@@ -17,17 +17,17 @@ FavoriteGroup.initialize_add_to_favgroup_dialog = function() {
} }
}); });
var open_favgroup_dialog = function(e) { $("#open-favgroup-dialog-link").on("click.danbooru", FavoriteGroup.open_favgroup_dialog);
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();
} else if ($(".add-to-favgroup").length > 1) {
$("#add-to-favgroup-dialog").dialog("open");
}
e.preventDefault();
}
$("#open-favgroup-dialog-link").click(open_favgroup_dialog); FavoriteGroup.open_favgroup_dialog = function(e) {
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();
} else if ($(".add-to-favgroup").length > 1) {
$("#add-to-favgroup-dialog").dialog("open");
}
e.preventDefault();
} }
$(function() { $(function() {

View File

@@ -7,14 +7,14 @@ ForumPost.initialize_all = function() {
} }
ForumPost.initialize_edit_links = function() { ForumPost.initialize_edit_links = function() {
$(".edit_forum_post_link").click(function(e) { $(".edit_forum_post_link").on("click.danbooru", function(e) {
var link_id = $(this).attr("id"); var link_id = $(this).attr("id");
var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1]; var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1];
$("#edit_forum_post_" + forum_post_id).fadeToggle("fast"); $("#edit_forum_post_" + forum_post_id).fadeToggle("fast");
e.preventDefault(); e.preventDefault();
}); });
$(".edit_forum_topic_link").click(function(e) { $(".edit_forum_topic_link").on("click.danbooru", function(e) {
var link_id = $(this).attr("id"); var link_id = $(this).attr("id");
var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1]; var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1];
$("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast"); $("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast");

View File

@@ -2,7 +2,7 @@ let JanitorTrials = {};
JanitorTrials.initialize_all = function() { JanitorTrials.initialize_all = function() {
if ($("#c-janitor-trials").length) { if ($("#c-janitor-trials").length) {
$("input[value=Test]").click(function(e) { $("input[value=Test]").on("click.danbooru", function(e) {
$.ajax({ $.ajax({
type: "get", type: "get",
url: "/janitor_trials/test.json", url: "/janitor_trials/test.json",

View File

@@ -31,7 +31,7 @@ ModQueue.initialize_hilights = function() {
} }
ModQueue.initialize_detailed_rejection_links = function() { ModQueue.initialize_detailed_rejection_links = function() {
$(".detailed-rejection-link").click(ModQueue.detailed_rejection_dialog) $(".detailed-rejection-link").on("click.danbooru", ModQueue.detailed_rejection_dialog)
} }
ModQueue.detailed_rejection_dialog = function() { ModQueue.detailed_rejection_dialog = function() {

View File

@@ -10,7 +10,7 @@ NewsUpdate.initialize = function() {
} else { } else {
$("#news-updates").show(); $("#news-updates").show();
$("#close-news-ticker-link").click(function(e) { $("#close-news-ticker-link").on("click.danbooru", function(e) {
$("#news-updates").hide(); $("#news-updates").hide();
Cookie.put("news-ticker", key); Cookie.put("news-ticker", key);

View File

@@ -65,7 +65,7 @@ let Note = {
bind_events: function($note_box) { bind_events: function($note_box) {
$note_box.on( $note_box.on(
"dragstart resizestart", "dragstart.danbooru resizestart.danbooru",
function(e) { function(e) {
var $note_box_inner = $(e.currentTarget); var $note_box_inner = $(e.currentTarget);
$note_box_inner.find(".note-box-inner-border").addClass("unsaved"); $note_box_inner.find(".note-box-inner-border").addClass("unsaved");
@@ -82,7 +82,7 @@ let Note = {
} }
); );
$note_box.resize( $note_box.on("resize.danbooru",
function(e) { function(e) {
var $note_box_inner = $(e.currentTarget); var $note_box_inner = $(e.currentTarget);
Note.Box.resize_inner_border($note_box_inner); Note.Box.resize_inner_border($note_box_inner);
@@ -91,7 +91,7 @@ let Note = {
); );
$note_box.on( $note_box.on(
"dragstop resizestop", "dragstop.danbooru resizestop.danbooru",
function(e) { function(e) {
Note.dragging = false; Note.dragging = false;
if (Note.embed) { if (Note.embed) {
@@ -107,7 +107,7 @@ let Note = {
); );
$note_box.on( $note_box.on(
"mouseover mouseout", "mouseover.danbooru mouseout.danbooru",
function(e) { function(e) {
if (Note.dragging) { if (Note.dragging) {
return; return;
@@ -334,20 +334,20 @@ let Note = {
}, },
bind_events: function($note_body) { bind_events: function($note_body) {
$note_body.mouseover(function(e) { $note_body.on("mouseover.danbooru", function(e) {
var $note_body_inner = $(e.currentTarget); var $note_body_inner = $(e.currentTarget);
Note.Body.show($note_body_inner.data("id")); Note.Body.show($note_body_inner.data("id"));
e.stopPropagation(); e.stopPropagation();
}); });
$note_body.mouseout(function(e) { $note_body.on("mouseout.danbooru", function(e) {
var $note_body_inner = $(e.currentTarget); var $note_body_inner = $(e.currentTarget);
Note.Body.hide($note_body_inner.data("id")); Note.Body.hide($note_body_inner.data("id"));
e.stopPropagation(); e.stopPropagation();
}); });
if (Utility.meta("current-user-name") !== "Anonymous") { if (Utility.meta("current-user-name") !== "Anonymous") {
$note_body.click(function(e) { $note_body.on("click.danbooru", function(e) {
if (e.target.tagName !== "A") { if (e.target.tagName !== "A") {
var $note_body_inner = $(e.currentTarget); var $note_body_inner = $(e.currentTarget);
Note.Edit.show($note_body_inner); Note.Edit.show($note_body_inner);
@@ -355,7 +355,7 @@ let Note = {
e.stopPropagation(); e.stopPropagation();
}); });
} else { } else {
$note_body.click(function(e) { $note_body.on("click.danbooru", function(e) {
if (e.target.tagName !== "A") { if (e.target.tagName !== "A") {
Utility.notice("You must be logged in to edit notes"); Utility.notice("You must be logged in to edit notes");
} }
@@ -419,7 +419,7 @@ let Note = {
} }
$dialog.dialog("option", "title", 'Edit note #' + id + ' (<a href="/wiki_pages/help:notes">view help</a>)'); $dialog.dialog("option", "title", 'Edit note #' + id + ' (<a href="/wiki_pages/help:notes">view help</a>)');
$dialog.on("dialogclose", function() { $dialog.on("dialogclose.danbooru", function() {
Note.editing = false; Note.editing = false;
$(".note-box").resizable("enable"); $(".note-box").resizable("enable");
$(".note-box").draggable("enable"); $(".note-box").draggable("enable");
@@ -585,12 +585,12 @@ let Note = {
$(document.body).addClass("mode-translation"); $(document.body).addClass("mode-translation");
$("#original-file-link").click(); $("#original-file-link").click();
$("#image").off("click", Note.Box.toggle_all); $("#image").off("click", Note.Box.toggle_all);
$("#image").mousedown(Note.TranslationMode.Drag.start); $("#image").on("mousedown.danbooru.note", Note.TranslationMode.Drag.start);
$(window).mouseup(Note.TranslationMode.Drag.stop); $(document).on("mouseup.danbooru.note", Note.TranslationMode.Drag.stop);
$("#mark-as-translated-section").show(); $("#mark-as-translated-section").show();
Utility.notice('Translation mode is on. Drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).'); Utility.notice('Translation mode is on. Drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).');
$("#notice a:contains(Turn translation mode off)").click(Note.TranslationMode.stop); $("#notice a:contains(Turn translation mode off)").on("click.danbooru", Note.TranslationMode.stop);
}, },
stop: function(e) { stop: function(e) {
@@ -598,9 +598,9 @@ let Note = {
Note.TranslationMode.active = false; Note.TranslationMode.active = false;
$("#image").css("cursor", "auto"); $("#image").css("cursor", "auto");
$("#image").click(Note.Box.toggle_all); $("#image").on("click.danbooru", Note.Box.toggle_all);
$("#image").off("mousedown", Note.TranslationMode.Drag.start); $("#image").off("mousedown", Note.TranslationMode.Drag.start);
$(window).off("mouseup", Note.TranslationMode.Drag.stop); $(document).off("mouseup", Note.TranslationMode.Drag.stop);
$(document.body).removeClass("mode-translation"); $(document.body).removeClass("mode-translation");
$("#close-notice-link").click(); $("#close-notice-link").click();
$("#mark-as-translated-section").hide(); $("#mark-as-translated-section").hide();
@@ -639,7 +639,7 @@ let Note = {
return; return;
} }
e.preventDefault(); /* don't drag the image */ e.preventDefault(); /* don't drag the image */
$(window).mousemove(Note.TranslationMode.Drag.drag); $(document).on("mousemove.danbooru", Note.TranslationMode.Drag.drag);
Note.TranslationMode.Drag.dragStartX = e.pageX; Note.TranslationMode.Drag.dragStartX = e.pageX;
Note.TranslationMode.Drag.dragStartY = e.pageY; Note.TranslationMode.Drag.dragStartY = e.pageY;
}, },
@@ -703,7 +703,7 @@ let Note = {
if (Note.TranslationMode.Drag.dragStartX === 0) { if (Note.TranslationMode.Drag.dragStartX === 0) {
return; /* 'stop' is bound to window, don't create note if start wasn't triggered */ return; /* 'stop' is bound to window, don't create note if start wasn't triggered */
} }
$(window).off("mousemove"); $(document).off("mousemove", Note.TranslationMode.Drag.drag);
if (Note.TranslationMode.Drag.dragging) { if (Note.TranslationMode.Drag.dragging) {
$('#note-preview').css({ display: 'none' }); $('#note-preview').css({ display: 'none' });
@@ -802,12 +802,12 @@ let Note = {
this.initialize_shortcuts(); this.initialize_shortcuts();
this.initialize_highlight(); this.initialize_highlight();
$(window).on("hashchange", this.initialize_highlight); $(document).on("hashchange.danbooru.note", this.initialize_highlight);
}, },
initialize_shortcuts: function() { initialize_shortcuts: function() {
$("#translate").click(Note.TranslationMode.toggle); $("#translate").on("click.danbooru", Note.TranslationMode.toggle);
$("#image").click(Note.Box.toggle_all); $("#image").on("click.danbooru", Note.Box.toggle_all);
}, },
initialize_highlight: function() { initialize_highlight: function() {

View File

@@ -13,12 +13,12 @@ Pool.initialize_all = function() {
Pool.initialize_add_to_pool_link = function() { Pool.initialize_add_to_pool_link = function() {
$("#add-to-pool-dialog").dialog({autoOpen: false}); $("#add-to-pool-dialog").dialog({autoOpen: false});
$("#pool").click(function(e) { $("#pool").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$("#add-to-pool-dialog").dialog("open"); $("#add-to-pool-dialog").dialog("open");
}); });
$("#recent-pools li").click(function(e) { $("#recent-pools li").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$("#pool_name").val($(this).attr("data-value")); $("#pool_name").val($(this).attr("data-value"));
}); });

View File

@@ -22,7 +22,7 @@ PostAppeal.initialize_appeal = function() {
} }
}); });
$("#appeal").click(function(e) { $("#appeal").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$("#appeal-dialog").dialog("open"); $("#appeal-dialog").dialog("open");
}); });

View File

@@ -26,7 +26,7 @@ PostFlag.initialize_flag = function() {
$('#flag-dialog').dialog('close'); $('#flag-dialog').dialog('close');
}); });
$("#flag").click(function(e) { $("#flag").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$("#flag-dialog").dialog("open"); $("#flag-dialog").dialog("open");
}); });

View File

@@ -49,24 +49,24 @@ PostModeMenu.initialize_selector = function() {
$("#mode-box select").val(Cookie.get("mode")); $("#mode-box select").val(Cookie.get("mode"));
} }
$("#mode-box select").change(function(e) { $("#mode-box select").on("change.danbooru", function(e) {
PostModeMenu.change(); PostModeMenu.change();
$("#tag-script-field:visible").focus().select(); $("#tag-script-field:visible").focus().select();
}); });
} }
PostModeMenu.initialize_preview_link = function() { PostModeMenu.initialize_preview_link = function() {
$(".post-preview a").click(PostModeMenu.click); $(".post-preview a").on("click.danbooru", PostModeMenu.click);
} }
PostModeMenu.initialize_edit_form = function() { PostModeMenu.initialize_edit_form = function() {
$("#quick-edit-div").hide(); $("#quick-edit-div").hide();
$("#quick-edit-form input[value=Cancel]").click(function(e) { $("#quick-edit-form input[value=Cancel]").on("click.danbooru", function(e) {
PostModeMenu.close_edit_form(); PostModeMenu.close_edit_form();
e.preventDefault(); e.preventDefault();
}); });
$("#quick-edit-form").submit(function(e) { $("#quick-edit-form").on("submit.danbooru", function(e) {
$.ajax({ $.ajax({
type: "put", type: "put",
url: $("#quick-edit-form").attr("action"), url: $("#quick-edit-form").attr("action"),

View File

@@ -63,7 +63,7 @@ PostTooltip.QTIP_OPTIONS = {
}; };
PostTooltip.initialize = function () { PostTooltip.initialize = function () {
$(document).on("mouseenter", PostTooltip.POST_SELECTOR, function (event) { $(document).on("mouseenter.danbooru.postTooltip", PostTooltip.POST_SELECTOR, function (event) {
if (PostTooltip.disabled()) { if (PostTooltip.disabled()) {
$(this).qtip("disable"); $(this).qtip("disable");
} else { } else {
@@ -73,20 +73,20 @@ PostTooltip.initialize = function () {
PostTooltip.lostFocus = false; PostTooltip.lostFocus = false;
}); });
$(document).on("mouseleave", PostTooltip.POST_SELECTOR, function (event) { $(document).on("mouseleave.danbooru.postTooltip", PostTooltip.POST_SELECTOR, function (event) {
PostTooltip.lostFocus = true; PostTooltip.lostFocus = true;
}); });
$(document).on("click", ".post-tooltip-disable", PostTooltip.on_disable_tooltips); $(document).on("click.danbooru.postTooltip", ".post-tooltip-disable", PostTooltip.on_disable_tooltips);
// Hide tooltips when pressing keys or clicking thumbnails. // Hide tooltips when pressing keys or clicking thumbnails.
$(document).on("keydown", PostTooltip.hide); $(document).on("keydown.danbooru.postTooltip", PostTooltip.hide);
$(document).on("click", PostTooltip.POST_SELECTOR, PostTooltip.hide); $(document).on("click.danbooru.postTooltip", PostTooltip.POST_SELECTOR, PostTooltip.hide);
// Disable tooltips on touch devices. https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent // Disable tooltips on touch devices. https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
PostTooltip.isTouching = false; PostTooltip.isTouching = false;
$(document).on("touchstart", function (event) { PostTooltip.isTouching = true; }); $(document).on("touchstart.danbooru.postTooltip", function (event) { PostTooltip.isTouching = true; });
$(document).on("touchend", function (event) { PostTooltip.isTouching = false; }); $(document).on("touchend.danbooru.postTooltip", function (event) { PostTooltip.isTouching = false; });
}; };
PostTooltip.hide = function (event) { PostTooltip.hide = function (event) {

View File

@@ -82,12 +82,12 @@ Post.initialize_gestures = function() {
} }
Post.initialize_edit_dialog = function() { Post.initialize_edit_dialog = function() {
$("#open-edit-dialog").button().show().click(function(e) { $("#open-edit-dialog").button().show().on("click.danbooru", function(e) {
Post.open_edit_dialog(); Post.open_edit_dialog();
e.preventDefault(); e.preventDefault();
}); });
$("#toggle-related-tags-link").click(function(e) { $("#toggle-related-tags-link").on("click.danbooru", function(e) {
RelatedTag.toggle(); RelatedTag.toggle();
e.preventDefault(); e.preventDefault();
}); });
@@ -133,7 +133,7 @@ Post.open_edit_dialog = function() {
var pin_button = $("<button/>").button({icons: {primary: "ui-icon-pin-w"}, label: "pin", text: false}); var pin_button = $("<button/>").button({icons: {primary: "ui-icon-pin-w"}, label: "pin", text: false});
pin_button.css({width: "20px", height: "20px", position: "absolute", right: "28.4px"}); pin_button.css({width: "20px", height: "20px", position: "absolute", right: "28.4px"});
dialog.parent().children(".ui-dialog-titlebar").append(pin_button); dialog.parent().children(".ui-dialog-titlebar").append(pin_button);
pin_button.click(function(e) { pin_button.on("click.danbooru", function(e) {
var dialog_widget = $('.ui-dialog:has(#edit-dialog)'); var dialog_widget = $('.ui-dialog:has(#edit-dialog)');
var pos = dialog_widget.offset(); var pos = dialog_widget.offset();
@@ -176,7 +176,7 @@ Post.close_edit_dialog = function(e, ui) {
} }
Post.initialize_similar = function() { Post.initialize_similar = function() {
$("#similar-button").click(function(e) { $("#similar-button").on("click.danbooru", function(e) {
$.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); $.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
e.preventDefault(); e.preventDefault();
}); });
@@ -246,7 +246,7 @@ Post.initialize_shortcuts = function() {
} }
Post.initialize_links = function() { Post.initialize_links = function() {
$("#copy-notes").click(function(e) { $("#copy-notes").on("click.danbooru", function(e) {
var current_post_id = $("meta[name=post-id]").attr("content"); var current_post_id = $("meta[name=post-id]").attr("content");
var other_post_id = parseInt(prompt("Enter the ID of the post to copy all notes to:"), 10); var other_post_id = parseInt(prompt("Enter the ID of the post to copy all notes to:"), 10);
@@ -284,12 +284,12 @@ Post.initialize_post_relationship_previews = function() {
this.toggle_relationship_preview($("#has-parent-relationship-preview"), $("#has-parent-relationship-preview-link")); this.toggle_relationship_preview($("#has-parent-relationship-preview"), $("#has-parent-relationship-preview-link"));
} }
$("#has-children-relationship-preview-link").click(function(e) { $("#has-children-relationship-preview-link").on("click.danbooru", function(e) {
Post.toggle_relationship_preview($("#has-children-relationship-preview"), $(this)); Post.toggle_relationship_preview($("#has-children-relationship-preview"), $(this));
e.preventDefault(); e.preventDefault();
}); });
$("#has-parent-relationship-preview-link").click(function(e) { $("#has-parent-relationship-preview-link").on("click.danbooru", function(e) {
Post.toggle_relationship_preview($("#has-parent-relationship-preview"), $(this)); Post.toggle_relationship_preview($("#has-parent-relationship-preview"), $(this));
e.preventDefault(); e.preventDefault();
}); });
@@ -307,7 +307,7 @@ Post.toggle_relationship_preview = function(preview, preview_link) {
} }
Post.initialize_favlist = function() { Post.initialize_favlist = function() {
$("#show-favlist-link, #hide-favlist-link").click(function(e) { $("#show-favlist-link, #hide-favlist-link").on("click.danbooru", function(e) {
$("#favlist, #show-favlist-link, #hide-favlist-link").toggle(); $("#favlist, #show-favlist-link, #hide-favlist-link").toggle();
e.preventDefault(); e.preventDefault();
}); });
@@ -326,7 +326,7 @@ Post.expand_image = function(e) {
$image.css("opacity", "0.25"); $image.css("opacity", "0.25");
$image.width($image.data("original-width")); $image.width($image.data("original-width"));
$image.height($image.data("original-height")); $image.height($image.data("original-height"));
$image.on("load", function() { $image.on("load.danbooru", function() {
$image.css("opacity", "1"); $image.css("opacity", "1");
$notice.hide(); $notice.hide();
}); });
@@ -338,7 +338,7 @@ Post.expand_image = function(e) {
} }
Post.initialize_post_image_resize_links = function() { Post.initialize_post_image_resize_links = function() {
$("#image-resize-link").click(Post.expand_image); $("#image-resize-link").on("click.danbooru", Post.expand_image);
if ($("#image-resize-notice").length) { if ($("#image-resize-notice").length) {
Utility.keydown("v", "resize", function(e) { Utility.keydown("v", "resize", function(e) {
@@ -353,7 +353,7 @@ Post.initialize_post_image_resize_links = function() {
$image.height($image.data("large-height")); $image.height($image.data("large-height"));
$notice.children().eq(0).show(); $notice.children().eq(0).show();
$notice.children().eq(1).hide(); // Loading message $notice.children().eq(1).hide(); // Loading message
$image.on("load", function() { $image.on("load.danbooru", function() {
$image.css("opacity", "1"); $image.css("opacity", "1");
$notice.show(); $notice.show();
}); });
@@ -395,7 +395,7 @@ Post.resize_image_to_window = function($img) {
} }
Post.initialize_post_image_resize_to_window_link = function() { Post.initialize_post_image_resize_to_window_link = function() {
$("#image-resize-to-window-link").click(function(e) { $("#image-resize-to-window-link").on("click.danbooru", function(e) {
Post.resize_image_to_window($("#image")); Post.resize_image_to_window($("#image"));
e.preventDefault(); e.preventDefault();
}); });
@@ -404,7 +404,7 @@ Post.initialize_post_image_resize_to_window_link = function() {
Post.initialize_excerpt = function() { Post.initialize_excerpt = function() {
$("#excerpt").hide(); $("#excerpt").hide();
$("#show-posts-link").click(function(e) { $("#show-posts-link").on("click.danbooru", function(e) {
$("#show-posts-link").parent("li").addClass("active"); $("#show-posts-link").parent("li").addClass("active");
$("#show-excerpt-link").parent("li").removeClass("active"); $("#show-excerpt-link").parent("li").removeClass("active");
$("#posts").show(); $("#posts").show();
@@ -412,7 +412,7 @@ Post.initialize_excerpt = function() {
e.preventDefault(); e.preventDefault();
}); });
$("#show-excerpt-link").click(function(e) { $("#show-excerpt-link").on("click.danbooru", function(e) {
if ($(this).parent("li").hasClass("active")) { if ($(this).parent("li").hasClass("active")) {
return; return;
} }
@@ -429,7 +429,7 @@ Post.initialize_excerpt = function() {
} }
Post.initialize_post_sections = function() { Post.initialize_post_sections = function() {
$("#post-sections li a").click(function(e) { $("#post-sections li a").on("click.danbooru", function(e) {
if (e.target.hash === "#comments") { if (e.target.hash === "#comments") {
$("#comments").show(); $("#comments").show();
$("#edit").hide(); $("#edit").hide();
@@ -596,7 +596,7 @@ Post.initialize_saved_searches = function() {
} }
}); });
$("#save-search").click(function(e) { $("#save-search").on("click.danbooru", function(e) {
$("#save-search-dialog #saved_search_query").val($("#tags").val()); $("#save-search-dialog #saved_search_query").val($("#tags").val());
if (Utility.meta("disable-labeled-saved-searches") === "false") { if (Utility.meta("disable-labeled-saved-searches") === "false") {
@@ -636,7 +636,7 @@ Post.initialize_replace_image_dialog = function() {
$('#replace-image-dialog').dialog('close'); $('#replace-image-dialog').dialog('close');
}); });
$("#replace-image").click(function(e) { $("#replace-image").on("click.danbooru", function(e) {
e.preventDefault(); e.preventDefault();
$("#replace-image-dialog").dialog("open"); $("#replace-image-dialog").dialog("open");
}); });

View File

@@ -6,8 +6,8 @@ let RelatedTag = {};
RelatedTag.initialize_all = function() { RelatedTag.initialize_all = function() {
if ($("#c-posts #a-show").length || $("#c-uploads #a-new").length) { if ($("#c-posts #a-show").length || $("#c-uploads #a-new").length) {
this.initialize_buttons(); this.initialize_buttons();
$("#upload_tag_string,#post_tag_string").keyup(RelatedTag.update_selected); $("#upload_tag_string,#post_tag_string").on("keyup.danbooru.relatedTags", RelatedTag.update_selected);
$("body").on("click", "#artist-related-tags-column a.del", RelatedTag.disable_artist_url) $("#related-tags-container").on("click.danbooru", "#artist-related-tags-column a.del", RelatedTag.disable_artist_url)
} }
} }
@@ -16,7 +16,7 @@ RelatedTag.initialize_buttons = function() {
<% TagCategory.related_button_list.each do |category| %> <% TagCategory.related_button_list.each do |category| %>
RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>"); // eslint-disable-line indent RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>"); // eslint-disable-line indent
<% end %> <% end %>
$("#find-artist-button").click(RelatedTag.find_artist); $("#find-artist-button").on("click.danbooru", RelatedTag.find_artist);
} }
RelatedTag.tags_include = function(name) { RelatedTag.tags_include = function(name) {
@@ -25,7 +25,7 @@ RelatedTag.tags_include = function(name) {
} }
RelatedTag.common_bind = function(button_name, category) { RelatedTag.common_bind = function(button_name, category) {
$(button_name).click(function(e) { $(button_name).on("click.danbooru", function(e) {
var $dest = $("#related-tags"); var $dest = $("#related-tags");
$dest.empty(); $dest.empty();
RelatedTag.build_recent_and_frequent($dest); RelatedTag.build_recent_and_frequent($dest);
@@ -216,7 +216,7 @@ RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
$link.text(tag[0].replace(/_/g, " ")); $link.text(tag[0].replace(/_/g, " "));
$link.addClass("tag-type-" + tag[1]); $link.addClass("tag-type-" + tag[1]);
$link.attr("href", "/posts?tags=" + encodeURIComponent(tag[0])); $link.attr("href", "/posts?tags=" + encodeURIComponent(tag[0]));
$link.click(RelatedTag.toggle_tag); $link.on("click.danbooru", RelatedTag.toggle_tag);
if (RelatedTag.tags_include(tag[0])) { if (RelatedTag.tags_include(tag[0])) {
$link.addClass("selected"); $link.addClass("selected");
} }

View File

@@ -1,5 +1,5 @@
$(function() { $(function() {
$("#maintoggle").click(function() { $("#maintoggle").on("click.danbooru", function() {
$('#nav').toggle(); $('#nav').toggle();
$('#maintoggle-on').toggle(); $('#maintoggle-on').toggle();
$('#maintoggle-off').toggle(); $('#maintoggle-off').toggle();

View File

@@ -24,11 +24,11 @@ Ugoira.create_player = (mime_type, frames, file_url) => {
Ugoira.player = new ZipImagePlayer(options); Ugoira.player = new ZipImagePlayer(options);
Ugoira.player_manually_paused = false; Ugoira.player_manually_paused = false;
$(Ugoira.player).on("loadProgress", (ev, progress) => { $(Ugoira.player).on("loadProgress.danbooru", (ev, progress) => {
$("#seek-slider").progressbar("value", Math.floor(progress * 100)); $("#seek-slider").progressbar("value", Math.floor(progress * 100));
}); });
$("#ugoira-play").click(e => { $("#ugoira-play").on("click.danbooru", e => {
Ugoira.player.play(); Ugoira.player.play();
$("#ugoira-play").hide(); $("#ugoira-play").hide();
$("#ugoira-pause").show(); $("#ugoira-pause").show();
@@ -36,7 +36,7 @@ Ugoira.create_player = (mime_type, frames, file_url) => {
e.preventDefault(); e.preventDefault();
}) })
$("#ugoira-pause").click(e => { $("#ugoira-pause").on("click.danbooru", e => {
Ugoira.player.pause(); Ugoira.player.pause();
$("#ugoira-pause").hide(); $("#ugoira-pause").hide();
$("#ugoira-play").show(); $("#ugoira-play").show();
@@ -67,7 +67,7 @@ Ugoira.create_player = (mime_type, frames, file_url) => {
} }
}); });
$(Ugoira.player).on("frame", (frame, frame_number) => { $(Ugoira.player).on("frame.danbooru", (frame, frame_number) => {
$("#seek-slider").slider("option", "value", frame_number); $("#seek-slider").slider("option", "value", frame_number);
}); });
} }

View File

@@ -13,14 +13,14 @@ Upload.initialize_all = function() {
if ($("#image").prop("complete")) { if ($("#image").prop("complete")) {
this.initialize_image(); this.initialize_image();
} else { } else {
$("#image").on("load error", this.initialize_image); $("#image").on("load.danbooru error.danbooru", this.initialize_image);
} }
this.initialize_info_bookmarklet(); this.initialize_info_bookmarklet();
this.initialize_similar(); this.initialize_similar();
this.initialize_submit(); this.initialize_submit();
$("#related-tags-button").trigger("click"); $("#related-tags-button").trigger("click");
$("#toggle-artist-commentary").click(function(e) { $("#toggle-artist-commentary").on("click.danbooru", function(e) {
Upload.toggle_commentary(); Upload.toggle_commentary();
e.preventDefault(); e.preventDefault();
}); });
@@ -32,25 +32,27 @@ Upload.initialize_all = function() {
} }
Upload.initialize_submit = function() { Upload.initialize_submit = function() {
$("#form").submit(function(e) { $("#form").on("submit.danbooru", Upload.validate_upload);
var error_messages = []; }
if (($("#upload_file").val() === "") && ($("#upload_source").val() === "") && $("#upload_md5_confirmation").val() === "") {
error_messages.push("Must choose file or specify source"); Upload.validate_upload = function (e) {
} var error_messages = [];
if (!$("#upload_rating_s").prop("checked") && !$("#upload_rating_q").prop("checked") && !$("#upload_rating_e").prop("checked") && if (($("#upload_file").val() === "") && ($("#upload_source").val() === "") && $("#upload_md5_confirmation").val() === "") {
($("#upload_tag_string").val().search(/\brating:[sqe]/i) < 0)) { error_messages.push("Must choose file or specify source");
error_messages.push("Must specify a rating"); }
} if (!$("#upload_rating_s").prop("checked") && !$("#upload_rating_q").prop("checked") && !$("#upload_rating_e").prop("checked") &&
if (error_messages.length === 0) { ($("#upload_tag_string").val().search(/\brating:[sqe]/i) < 0)) {
$("#submit-button").prop("disabled", "true"); error_messages.push("Must specify a rating");
$("#submit-button").prop("value", "Submitting..."); }
$("#client-errors").hide(); if (error_messages.length === 0) {
} else { $("#submit-button").prop("disabled", "true");
$("#client-errors").html("<strong>Error</strong>: " + error_messages.join(", ")); $("#submit-button").prop("value", "Submitting...");
$("#client-errors").show(); $("#client-errors").hide();
e.preventDefault(); } else {
} $("#client-errors").html("<strong>Error</strong>: " + error_messages.join(", "));
}); $("#client-errors").show();
e.preventDefault();
}
} }
Upload.initialize_iqdb_source = function() { Upload.initialize_iqdb_source = function() {
@@ -70,14 +72,14 @@ Upload.initialize_enter_on_tags = function() {
} }
Upload.initialize_similar = function() { Upload.initialize_similar = function() {
$("#similar-button").click(function(e) { $("#similar-button").on("click.danbooru", function(e) {
$.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); $.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
e.preventDefault(); e.preventDefault();
}); });
} }
Upload.initialize_info_bookmarklet = function() { Upload.initialize_info_bookmarklet = function() {
$("#upload_source").change(function (e) { $("#upload_source").on("change.danbooru", function (e) {
$("#fetch-data-manual").click(); $("#fetch-data-manual").click();
}); });
@@ -85,7 +87,7 @@ Upload.initialize_info_bookmarklet = function() {
} }
Upload.initialize_info_manual = function() { Upload.initialize_info_manual = function() {
$("#fetch-data-manual").click(function(e) { $("#fetch-data-manual").on("click.danbooru", function(e) {
var source = $("#upload_source,#post_source").val(); var source = $("#upload_source,#post_source").val();
var referer = $("#upload_referer_url").val(); var referer = $("#upload_referer_url").val();
@@ -178,7 +180,7 @@ Upload.initialize_image = function() {
Post.resize_image_to_window($image); Post.resize_image_to_window($image);
Post.initialize_post_image_resize_to_window_link(); Post.initialize_post_image_resize_to_window_link();
Upload.update_scale(); Upload.update_scale();
$("#image-resize-to-window-link").click(Upload.update_scale); $("#image-resize-to-window-link").on("click.danbooru", Upload.update_scale);
} }
Upload.toggle_commentary = function() { Upload.toggle_commentary = function() {