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

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