added more conditional checks for javascripts to reduce computation load

This commit is contained in:
albert
2011-11-02 12:27:40 -04:00
parent 10141af07d
commit 02eac64bd9
20 changed files with 193 additions and 176 deletions

View File

@@ -9,16 +9,12 @@ group :test do
end
group :assets do
gem "uglifier"
gem "uglifier-rails"
gem "therubyracer"
gem "sass"
end
gem "rails", "3.1.0"
gem "rails", "3.1.1"
gem "pg"
gem "memcache-client", :require => "memcache"
# gem "imagesize", :require => "image_size"
gem "delayed_job"
gem "super_exception_notifier"
gem "simple_form"
@@ -28,7 +24,7 @@ gem "meta_search", :git => "git://github.com/ernie/meta_search.git"
gem "silent-postgres"
gem "whenever", :require => false
gem "sanitize", :git => "git://github.com/rgrove/sanitize.git"
gem 'rmagick', :require => "RMagick"
gem 'mini_magick'
group :development do
gem 'pry'

View File

@@ -10,52 +10,50 @@ GIT
GIT
remote: git://github.com/rgrove/sanitize.git
revision: afdfa8f7f4129820c573f94f79b99aed715a385d
revision: 052abea134e409c7f676f0cf56e6a2315b2a150b
specs:
sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6)
GIT
remote: http://github.com/EmmanuelOga/ffaker.git
revision: f94bcf502fcdd4ba5f29155a3df1811af2663950
revision: 80dc4cf8531b12bf6f5425d2a35b27be91acc447
specs:
ffaker (1.8.1)
GEM
remote: http://gemcutter.org/
specs:
actionmailer (3.1.0)
actionpack (= 3.1.0)
actionmailer (3.1.1)
actionpack (= 3.1.1)
mail (~> 2.3.0)
actionpack (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
actionpack (3.1.1)
activemodel (= 3.1.1)
activesupport (= 3.1.1)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.2)
rack-cache (~> 1.0.3)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.0)
activemodel (3.1.0)
activesupport (= 3.1.0)
bcrypt-ruby (~> 3.0.0)
sprockets (~> 2.0.2)
activemodel (3.1.1)
activesupport (= 3.1.1)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
activerecord (3.1.1)
activemodel (= 3.1.1)
activesupport (= 3.1.1)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
activesupport (3.1.0)
activeresource (3.1.1)
activemodel (= 3.1.1)
activesupport (= 3.1.1)
activesupport (3.1.1)
multi_json (~> 1.0)
arel (2.2.1)
awesome_print (0.4.0)
bcrypt-ruby (3.0.1)
builder (3.0.0)
chronic (0.6.4)
coderay (0.9.8)
@@ -64,13 +62,11 @@ GEM
activesupport (~> 3.0)
daemons
erubis (2.7.0)
execjs (1.2.9)
multi_json (~> 1.0)
factory_girl (2.1.2)
factory_girl (2.2.0)
activesupport
hike (1.2.1)
i18n (0.6.0)
libv8 (3.3.10.2)
json (1.6.1)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -82,9 +78,11 @@ GEM
webrobots (~> 0.0, >= 0.0.9)
memcache-client (1.8.5)
metaclass (0.0.1)
method_source (0.6.5)
ruby_parser (>= 2.0.5)
mime-types (1.16)
method_source (0.6.7)
ruby_parser (>= 2.3.1)
mime-types (1.17.2)
mini_magick (3.3)
subexec (~> 0.1.0)
mocha (0.10.0)
metaclass (~> 0.0.1)
multi_json (1.0.3)
@@ -94,14 +92,14 @@ GEM
pg (0.11.0)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.2)
pry (0.9.6.2)
polyglot (0.3.3)
pry (0.9.7.3)
coderay (~> 0.9.8)
method_source (~> 0.6.5)
ruby_parser (~> 2.0.5)
method_source (~> 0.6.7)
ruby_parser (>= 2.3.1)
slop (~> 2.1.0)
rack (1.3.3)
rack-cache (1.0.3)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
@@ -109,59 +107,52 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.0)
actionmailer (= 3.1.0)
actionpack (= 3.1.0)
activerecord (= 3.1.0)
activeresource (= 3.1.0)
activesupport (= 3.1.0)
rails (3.1.1)
actionmailer (= 3.1.1)
actionpack (= 3.1.1)
activerecord (= 3.1.1)
activeresource (= 3.1.1)
activesupport (= 3.1.1)
bundler (~> 1.0)
railties (= 3.1.0)
railties (3.1.0)
actionpack (= 3.1.0)
activesupport (= 3.1.0)
railties (= 3.1.1)
railties (3.1.1)
actionpack (= 3.1.1)
activesupport (= 3.1.1)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2)
rdoc (3.9.4)
rmagick (2.13.1)
ruby_parser (2.0.6)
rake (0.9.2.2)
rdoc (3.11)
json (~> 1.4)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
sass (3.1.7)
sass (3.1.10)
sexp_processor (3.0.7)
shoulda (2.11.3)
silent-postgres (0.1.1)
simple_form (1.5.2)
actionpack (~> 3.0)
activemodel (~> 3.0)
simplecov (0.5.3)
simplecov (0.5.4)
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
slop (2.1.0)
sprockets (2.0.0)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
subexec (0.1.0)
super_exception_notifier (3.0.13)
actionmailer
rake
therubyracer (0.9.4)
libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.29)
uglifier (1.0.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
uglifier-rails (3.1.0.rc.2)
railties (~> 3.1.0.rc1)
uglifier (>= 1.0.0)
tzinfo (0.3.30)
webrobots (0.0.12)
nokogiri (>= 1.4.4)
whenever (0.7.0)
@@ -179,12 +170,12 @@ DEPENDENCIES
mechanize
memcache-client
meta_search!
mini_magick
mocha
nokogiri
pg
pry
rails (= 3.1.0)
rmagick
rails (= 3.1.1)
sanitize!
sass
shoulda
@@ -192,7 +183,4 @@ DEPENDENCIES
simple_form
simplecov
super_exception_notifier
therubyracer
uglifier
uglifier-rails
whenever

View File

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

View File

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

View File

@@ -3,7 +3,6 @@
Danbooru.Dtext.initialize_links = function() {
$(".simple_form .dtext-preview").hide();
$(".simple_form input[value=Preview]").click(Danbooru.Dtext.click_button);
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -18,8 +18,8 @@
});
}
}
$(function() {
Danbooru.NewsUpdate.initialize();
});
})();
$(function() {
Danbooru.NewsUpdate.initialize();
});

View File

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

View File

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

View File

@@ -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,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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