major refactoring of javascripts

This commit is contained in:
albert
2011-03-10 17:59:42 -05:00
parent efa6856b4a
commit 9c0a961ab2
28 changed files with 168 additions and 415 deletions

View File

@@ -15,6 +15,15 @@ $(document).ready(function() {
$(".comment-section[data-post-id=" + post_id + "] form").show();
$(this).hide();
});
// Ajax links
$("a[data-remote=true]").click(function(e) {
Danbooru.ajax_start(e.target);
})
$("a[data-remote=true]").ajaxComplete(function(e) {
Danbooru.ajax_stop(e.target);
})
// Image resize sidebar
$("#resize-links").hide();

View File

@@ -2,8 +2,6 @@
Danbooru.Favorite = {};
Danbooru.Favorite.initialize_all = function() {
this.initialize_add_to_favorites();
this.initialize_remove_from_favorites();
this.hide_or_show_add_to_favorites_link();
}
@@ -22,51 +20,6 @@
$("a#remove-from-favorites").hide();
}
}
Danbooru.Favorite.initialize_add_to_favorites = function() {
$("a#add-to-favorites").click(function(e) {
e.preventDefault();
$.ajax({
type: "post",
url: "/favorites",
data: {
id: Danbooru.meta("post-id")
},
beforeSend: function() {
Danbooru.ajax_start(e.target);
},
success: function() {
$("a#add-to-favorites").hide();
$("a#remove-from-favorites").show();
},
complete: function() {
Danbooru.ajax_stop(e.target);
}
});
});
}
Danbooru.Favorite.initialize_remove_from_favorites = function() {
$("a#remove-from-favorites").click(function(e) {
e.preventDefault();
$.ajax({
type: "delete",
url: "/favorites/" + Danbooru.meta("post-id"),
beforeSend: function() {
Danbooru.ajax_start(e.target);
},
success: function() {
$("a#add-to-favorites").show();
$("a#remove-from-favorites").hide();
},
complete: function() {
Danbooru.ajax_stop(e.target);
}
});
});
}
})();
$(document).ready(function() {

View File

@@ -2,12 +2,8 @@
Danbooru.PostModeration = {};
Danbooru.PostModeration.initialize_all = function() {
this.initialize_approve_link();
this.initialize_disapprove_link();
this.hide_or_show_approve_and_disapprove_links();
this.hide_or_show_delete_and_undelete_links();
this.initialize_delete_link();
this.initialize_undelete_link();
}
Danbooru.PostModeration.hide_or_show_approve_and_disapprove_links = function() {
@@ -24,82 +20,6 @@
$("a#undelete").hide();
}
}
Danbooru.PostModeration.initialize_delete_link = function() {
$("a#delete").click(function(e) {
e.preventDefault();
$.ajax({
type: "post",
url: "/post_moderation/delete.js",
data: {
post_id: Danbooru.meta("post-id")
},
beforeSend: function() {
Danbooru.ajax_start(e.target);
},
complete: function() {
Danbooru.ajax_stop(e.target);
}
});
});
}
Danbooru.PostModeration.initialize_undelete_link = function() {
$("a#undelete").click(function(e) {
e.preventDefault();
$.ajax({
type: "post",
url: "/post_moderation/undelete.js",
data: {
post_id: Danbooru.meta("post-id")
},
beforeSend: function() {
Danbooru.ajax_start(e.target);
},
complete: function() {
Danbooru.ajax_stop(e.target);
}
});
});
}
Danbooru.PostModeration.initialize_disapprove_link = function() {
$("a#disapprove").click(function(e) {
e.preventDefault();
$.ajax({
type: "put",
url: "/post_moderation/disapprove.js",
data: {
post_id: Danbooru.meta("post-id")
},
beforeSend: function() {
Danbooru.ajax_start(e.target);
},
complete: function() {
Danbooru.ajax_stop(e.target);
}
});
});
}
Danbooru.PostModeration.initialize_approve_link = function() {
$("a#approve").click(function(e) {
e.preventDefault();
$.ajax({
type: "put",
url: "/post_moderation/approve.js",
data: {
post_id: Danbooru.meta("post-id")
},
beforeSend: function() {
Danbooru.ajax_start(e.target);
},
complete: function() {
Danbooru.ajax_stop(e.target);
}
});
});
}
})();
$(document).ready(function() {

View File

@@ -11,11 +11,11 @@
this.j_alert("Error", msg);
}
Danbooru.ajax_start = function(element) {
$(element).after(' <span class="wait">...</span>');
Danbooru.ajax_start = function(target) {
$(target).after(' <img src="/images/wait.gif" width="15" height="5" class="wait">');
}
Danbooru.ajax_stop = function(element) {
$(element).next("span.wait").remove();
Danbooru.ajax_stop = function(target) {
$(target).next("img.wait").remove();
}
})();