added more conditional checks for javascripts to reduce computation load
This commit is contained in:
@@ -103,16 +103,19 @@
|
||||
$post.addClass("blacklisted").addClass("blacklisted-active");
|
||||
}
|
||||
|
||||
Danbooru.Blacklist.initialize = function() {
|
||||
Danbooru.Blacklist.parse_entries();
|
||||
if (Danbooru.Blacklist.apply() > 0) {
|
||||
Danbooru.Blacklist.update_sidebar();
|
||||
} else {
|
||||
$("#blacklist-box").hide();
|
||||
Danbooru.Blacklist.initialize_all = function() {
|
||||
if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) {
|
||||
Danbooru.Blacklist.parse_entries();
|
||||
|
||||
if (Danbooru.Blacklist.apply() > 0) {
|
||||
Danbooru.Blacklist.update_sidebar();
|
||||
} else {
|
||||
$("#blacklist-box").hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.Blacklist.initialize();
|
||||
Danbooru.Blacklist.initialize_all();
|
||||
});
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
Danbooru.Comment = {};
|
||||
|
||||
Danbooru.Comment.initialize_all = function() {
|
||||
this.initialize_response_link();
|
||||
this.initialize_reply_links();
|
||||
this.initialize_expand_links();
|
||||
if ($("#c-posts").length || $("#c-comments").length) {
|
||||
this.initialize_response_link();
|
||||
this.initialize_reply_links();
|
||||
this.initialize_expand_links();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Comment.quote_message = function(data) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
Danbooru.Dtext.initialize_links = function() {
|
||||
$(".simple_form .dtext-preview").hide();
|
||||
|
||||
$(".simple_form input[value=Preview]").click(Danbooru.Dtext.click_button);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
Danbooru.Favorite = {};
|
||||
|
||||
Danbooru.Favorite.initialize_all = function() {
|
||||
this.hide_or_show_add_to_favorites_link();
|
||||
if ($("#c-posts").length) {
|
||||
this.hide_or_show_add_to_favorites_link();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Favorite.hide_or_show_add_to_favorites_link = function() {
|
||||
var favorites = Danbooru.meta("favorites");
|
||||
var current_user_id = Danbooru.meta("current-user-id");
|
||||
if (current_user_id == "") {
|
||||
$("a#add-to-favorites").hide();
|
||||
$("a#remove-from-favorites").hide();
|
||||
$("#add-to-favorites").hide();
|
||||
$("#remove-from-favorites").hide();
|
||||
return;
|
||||
}
|
||||
var regexp = new RegExp("\\bfav:" + current_user_id + "\\b");
|
||||
if ((favorites != undefined) && (favorites.match(regexp))) {
|
||||
$("a#add-to-favorites").hide();
|
||||
$("#add-to-favorites").hide();
|
||||
} else {
|
||||
$("a#remove-from-favorites").hide();
|
||||
$("#remove-from-favorites").hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
Danbooru.JanitorTrials = {};
|
||||
|
||||
Danbooru.JanitorTrials.initialize_all = function() {
|
||||
$("#c-janitor-trials input[value=Test]").click(function(e) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/janitor_trials/test.json",
|
||||
data: {
|
||||
janitor_trial: {
|
||||
user_name: $("#janitor_trial_user_name").val()
|
||||
if ($("#c-janitor-trials").length) {
|
||||
$("input[value=Test]").click(function(e) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/janitor_trials/test.json",
|
||||
data: {
|
||||
janitor_trial: {
|
||||
user_name: $("#janitor_trial_user_name").val()
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
$("#test-results").html(data);
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
$("#test-results").html(data);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
$(function() {
|
||||
$("#c-landings div.data").each(function(i, div) {
|
||||
var $div = $(div);
|
||||
var $image = $div.prev();
|
||||
|
||||
$div.width($image.width() - 10).height($image.height() - 10).offset({top: $image.position().top, left: $image.position().left});
|
||||
});
|
||||
if ($("#c-landings").length) {
|
||||
$(".data").each(function(i, div) {
|
||||
var $div = $(div);
|
||||
var $image = $div.prev();
|
||||
|
||||
$div.width($image.width() - 10).height($image.height() - 10).offset({top: $image.position().top, left: $image.position().left});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Danbooru.ModQueue = {};
|
||||
|
||||
Danbooru.ModQueue.initialize_approve_all_button = function() {
|
||||
$("#c-moderator-post-queues #approve-all-button").click(function(e) {
|
||||
$("#approve-all-button").click(function(e) {
|
||||
if (!confirm("Are you sure you want to approve every post on this page?")) {
|
||||
return;
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
}
|
||||
|
||||
Danbooru.ModQueue.initialize_hide_all_button = function() {
|
||||
$("#c-moderator-post-queues #hide-all-button").click(function(e) {
|
||||
$("#hide-all-button").click(function(e) {
|
||||
if (!confirm("Are you sure you want to hide every post on this page?")) {
|
||||
return;
|
||||
}
|
||||
@@ -25,6 +25,8 @@
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.ModQueue.initialize_approve_all_button();
|
||||
Danbooru.ModQueue.initialize_hide_all_button();
|
||||
if ($("#c-moderator-post-queues").length) {
|
||||
Danbooru.ModQueue.initialize_approve_all_button();
|
||||
Danbooru.ModQueue.initialize_hide_all_button();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
Danbooru.NewsUpdate.initialize();
|
||||
});
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.NewsUpdate.initialize();
|
||||
});
|
||||
|
||||
@@ -425,8 +425,8 @@ Danbooru.Note = {
|
||||
height: h
|
||||
});
|
||||
|
||||
$("div#note-container").append($note_box);
|
||||
$("div#note-container").append($note_body);
|
||||
$("#note-container").append($note_box);
|
||||
$("#note-container").append($note_body);
|
||||
$note_body.data("original-body", text);
|
||||
Danbooru.Note.Box.scale($note_box);
|
||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
||||
@@ -442,8 +442,8 @@ Danbooru.Note = {
|
||||
});
|
||||
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
||||
$note_body.html("<em>Click to edit</em>");
|
||||
$("div#note-container").append($note_box);
|
||||
$("div#note-container").append($note_body);
|
||||
$("#note-container").append($note_box);
|
||||
$("#note-container").append($note_body);
|
||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
||||
Danbooru.Note.id += "x";
|
||||
},
|
||||
@@ -457,7 +457,7 @@ Danbooru.Note = {
|
||||
},
|
||||
|
||||
load_all: function() {
|
||||
$.each($("section#notes article"), function(i, article) {
|
||||
$.each($("#notes article"), function(i, article) {
|
||||
var $article = $(article);
|
||||
Danbooru.Note.add(
|
||||
$article.data("id"),
|
||||
@@ -472,7 +472,7 @@ Danbooru.Note = {
|
||||
}
|
||||
|
||||
$(function() {
|
||||
if ($("#c-posts #a-show").size() > 0) {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
$("#translate").one("click", Danbooru.Note.TranslationMode.start);
|
||||
key("n", Danbooru.Note.TranslationMode.start);
|
||||
Danbooru.Note.load_all();
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
(function() {
|
||||
Danbooru.Paginator = {};
|
||||
|
||||
Danbooru.Paginator.next_page = function() {
|
||||
if($('.paginator li span').parent().next().length != 0)
|
||||
{
|
||||
if ($('.paginator li span').parent().next().length) {
|
||||
window.location = $('.paginator li span').parent().next().find('a').attr('href');
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Paginator.prev_page = function() {
|
||||
if($('.paginator li span').parent().prev().length != 0)
|
||||
{
|
||||
if ($('.paginator li span').parent().prev().length) {
|
||||
window.location = $('.paginator li span').parent().prev().find('a').attr('href');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,13 @@
|
||||
Danbooru.Pool = {};
|
||||
|
||||
Danbooru.Pool.initialize_all = function() {
|
||||
this.initialize_add_to_pool_link();
|
||||
this.initialize_simple_edit();
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_add_to_pool_link();
|
||||
}
|
||||
|
||||
if ($("#c-pool-orders").length) {
|
||||
this.initialize_simple_edit();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Pool.initialize_add_to_pool_link = function() {
|
||||
@@ -21,24 +26,24 @@
|
||||
minLength: 4,
|
||||
});
|
||||
|
||||
$("a#pool").click(function(e) {
|
||||
$("#pool").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#add-to-pool-dialog").dialog("open");
|
||||
});
|
||||
|
||||
$("ul#recent-pools li").click(function(e) {
|
||||
$("#recent-pools li").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#pool_name").val($(this).html());
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Pool.initialize_simple_edit = function() {
|
||||
$("ul#sortable").sortable({
|
||||
$("#sortable").sortable({
|
||||
placeholder: "ui-state-placeholder"
|
||||
});
|
||||
$("ul#sortable").disableSelection();
|
||||
$("#sortable").disableSelection();
|
||||
|
||||
$("div#c-pool-orders div#a-edit form#ordering-form").submit(function(e) {
|
||||
$("#ordering-form").submit(function(e) {
|
||||
$.ajax({
|
||||
type: "put",
|
||||
url: e.target.action,
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
Danbooru.PostAppeal = {};
|
||||
|
||||
Danbooru.PostAppeal.initialize_all = function() {
|
||||
this.initialize_appeal();
|
||||
this.hide_or_show_appeal_link();
|
||||
if ($("#c-posts") && $("#a-show")) {
|
||||
this.initialize_appeal();
|
||||
this.hide_or_show_appeal_link();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostAppeal.hide_or_show_appeal_link = function() {
|
||||
if (Danbooru.meta("post-is-flagged") !== "true") {
|
||||
$("#c-posts #appeal").hide();
|
||||
$("#appeal").hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +30,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
$("a#appeal").click(function(e) {
|
||||
$("#appeal").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#appeal-dialog").dialog("open");
|
||||
});
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
Danbooru.PostFlag = {};
|
||||
|
||||
Danbooru.PostFlag.initialize_all = function() {
|
||||
this.initialize_flag();
|
||||
this.hide_or_show_flag_link();
|
||||
if ($("#c-posts") && $("#a-show")) {
|
||||
this.initialize_flag();
|
||||
this.hide_or_show_flag_link();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostFlag.hide_or_show_flag_link = function() {
|
||||
if (Danbooru.meta("post-is-deleted") == "true") {
|
||||
$("a#flag").hide();
|
||||
$("#flag").hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +30,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
$("a#flag").click(function(e) {
|
||||
$("#flag").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#flag-dialog").dialog("open");
|
||||
});
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
Danbooru.PostModeMenu = {};
|
||||
|
||||
Danbooru.PostModeMenu.initialize = function() {
|
||||
this.initialize_selector();
|
||||
this.initialize_preview_link();
|
||||
this.initialize_edit_form();
|
||||
if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) {
|
||||
this.initialize_selector();
|
||||
this.initialize_preview_link();
|
||||
this.initialize_edit_form();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostModeMenu.initialize_selector = function() {
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
Danbooru.PostModeration = {};
|
||||
|
||||
Danbooru.PostModeration.initialize_all = function() {
|
||||
this.hide_or_show_approve_and_disapprove_links();
|
||||
this.hide_or_show_delete_and_undelete_links();
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.hide_or_show_approve_and_disapprove_links();
|
||||
this.hide_or_show_delete_and_undelete_links();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostModeration.hide_or_show_approve_and_disapprove_links = function() {
|
||||
if (Danbooru.meta("post-is-approvable") != "true") {
|
||||
$("a#approve").hide();
|
||||
$("a#disapprove").hide();
|
||||
$("#approve").hide();
|
||||
$("#disapprove").hide();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostModeration.hide_or_show_delete_and_undelete_links = function() {
|
||||
if (Danbooru.meta("post-is-deleted") == "true") {
|
||||
$("a#delete").hide();
|
||||
$("#delete").hide();
|
||||
} else {
|
||||
$("a#undelete").hide();
|
||||
$("#undelete").hide();
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -4,13 +4,19 @@
|
||||
Danbooru.Post.pending_update_count = 0;
|
||||
|
||||
Danbooru.Post.initialize_all = function() {
|
||||
this.initialize_post_sections();
|
||||
this.initialize_wiki_page_excerpt();
|
||||
this.initialize_post_image_resize_links();
|
||||
this.initialize_image_resize();
|
||||
this.initialize_titles();
|
||||
this.initialize_links();
|
||||
this.initialize_resize_links();
|
||||
|
||||
if ($("#c-posts").length && $("#a-index").length) {
|
||||
this.initialize_wiki_page_excerpt();
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_resize_links();
|
||||
this.initialize_links();
|
||||
this.initialize_image_resize();
|
||||
this.initialize_post_sections();
|
||||
this.initialize_post_image_resize_links();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_links = function() {
|
||||
@@ -32,7 +38,7 @@
|
||||
image.attr("height", target.data("height"));
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
$("#resize-link a").click(function(e) {
|
||||
$("#resize-links").toggle();
|
||||
e.preventDefault();
|
||||
@@ -40,7 +46,7 @@
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_titles = function() {
|
||||
$("article.post-preview").each(function(i, v) {
|
||||
$(".post-preview").each(function(i, v) {
|
||||
Danbooru.Post.initialize_title_for(v);
|
||||
});
|
||||
}
|
||||
@@ -69,19 +75,17 @@
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_image_resize = function() {
|
||||
if ($("#c-posts #a-show").size() > 0) {
|
||||
var default_image_size = Danbooru.meta("default-image-size");
|
||||
var original_width = parseInt($("#image").data("original-width"));
|
||||
var medium_width = parseInt(Danbooru.meta("config-medium-width"));
|
||||
var large_width = parseInt(Danbooru.meta("config-large-width"));
|
||||
var default_image_size = Danbooru.meta("default-image-size");
|
||||
var original_width = parseInt($("#image").data("original-width"));
|
||||
var medium_width = parseInt(Danbooru.meta("config-medium-width"));
|
||||
var large_width = parseInt(Danbooru.meta("config-large-width"));
|
||||
|
||||
if ((default_image_size === "medium") && (original_width > medium_width)) {
|
||||
$("#medium-file-link").trigger("click");
|
||||
} else if ((default_image_size === "large") && (original_width > large_width)) {
|
||||
$("#large-file-link").trigger("click");
|
||||
} else {
|
||||
$("#original-file-link").trigger("click");
|
||||
}
|
||||
if ((default_image_size === "medium") && (original_width > medium_width)) {
|
||||
$("#medium-file-link").trigger("click");
|
||||
} else if ((default_image_size === "large") && (original_width > large_width)) {
|
||||
$("#large-file-link").trigger("click");
|
||||
} else {
|
||||
$("#original-file-link").trigger("click");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
Danbooru.RelatedTag = {};
|
||||
|
||||
Danbooru.RelatedTag.initialize_all = function() {
|
||||
this.initialize_buttons();
|
||||
$("#related-tags-container").hide();
|
||||
if ($("#c-posts").length || $("#c-uploads").length) {
|
||||
this.initialize_buttons();
|
||||
$("#related-tags-container").hide();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.RelatedTag.initialize_buttons = function() {
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
Danbooru.Upload.initialize_all = function() {
|
||||
this.initialize_image();
|
||||
this.initialize_info();
|
||||
this.initialize_similar();
|
||||
|
||||
if ($("#c-uploads").length) {
|
||||
this.initialize_info();
|
||||
this.initialize_similar();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_similar = function() {
|
||||
@@ -31,8 +34,8 @@
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_info = function() {
|
||||
$("#c-uploads #source-info ul").hide();
|
||||
$("#c-uploads #fetch-data").click(function(e) {
|
||||
$("#source-info ul").hide();
|
||||
$("#fetch-data").click(function(e) {
|
||||
Danbooru.ajax_start(e.target);
|
||||
$.get(e.target.href).success(function(data) {
|
||||
var tag_html = "";
|
||||
@@ -61,7 +64,7 @@
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_image = function() {
|
||||
var $image = $("#c-uploads #image");
|
||||
var $image = $("#image");
|
||||
if ($image.size() > 0) {
|
||||
var height = $image.height();
|
||||
var width = $image.width();
|
||||
|
||||
Reference in New Issue
Block a user