implemented favorites on post/show page

This commit is contained in:
albert
2011-02-07 18:57:33 -05:00
parent c80df378d8
commit 76a7594a97
16 changed files with 164 additions and 32 deletions

View File

@@ -27,7 +27,6 @@
body: $(e.target).closest("form").find("textarea").val()
},
success: function(data, text_status, xhr) {
console.log($(this).closest("div.new-comment").find("div.comment-preview"));
$(this).closest("div.new-comment").find("div.comment-preview").show().html(data);
},
type: "post"

View File

@@ -0,0 +1,69 @@
(function() {
Danbooru.Favorite = {};
Danbooru.Favorite.initialize_all = function() {
this.initialize_add_to_favorites();
this.initialize_remove_from_favorites();
this.hide_or_remove_add_to_favorites_link();
}
Danbooru.Favorite.hide_or_remove_add_to_favorites_link = function() {
var favorites = $("meta[name=favorites]").attr("content");
var current_user = $("meta[name=current-user-id]").attr("content");
var regexp = new RegExp("\\bfav:" + current_user + "\\b");
if (favorites.match(regexp)) {
$("a#add-to-favorites").hide();
} else {
$("a#remove-from-favorites").hide();
}
}
Danbooru.Favorite.initialize_add_to_favorites = function() {
$("a#add-to-favorites").click(function(e) {
e.stopPropagation();
$.ajax({
url: "/favorites",
data: {
id: $("meta[name=post-id]").attr("content")
},
beforeSend: function() {
$("img#add-to-favorites-wait").show();
},
success: function(data, text_status, xhr) {
$("a#add-to-favorites").hide();
$("a#remove-from-favorites").show();
$("img#add-to-favorites-wait").hide();
},
type: "post"
});
return false;
});
}
Danbooru.Favorite.initialize_remove_from_favorites = function() {
$("a#remove-from-favorites").click(function(e) {
e.stopPropagation();
$.ajax({
url: "/favorites/" + $("meta[name=post-id]").attr("content"),
beforeSend: function() {
$("img#remove-from-favorites-wait").show();
},
success: function(data, text_status, xhr) {
$("a#add-to-favorites").show();
$("a#remove-from-favorites").hide();
$("img#remove-from-favorites-wait").hide();
},
type: "delete"
});
return false;
});
}
})();
$(document).ready(function() {
Danbooru.Favorite.initialize_all();
});