2011-12-13 18:22:40 +00:00
|
|
|
var $j = jQuery.noConflict();
|
2011-10-14 05:23:46 +00:00
|
|
|
|
2012-02-06 18:53:25 +00:00
|
|
|
$j('#content-block').ready(function() {
|
2011-12-13 18:22:40 +00:00
|
|
|
|
2012-02-07 18:41:21 +00:00
|
|
|
$j("div.add-wishlist").each(function (index, element) {
|
2011-12-13 18:22:40 +00:00
|
|
|
$j(element).click(function() {
|
|
|
|
var span = $j(element).find("span");
|
2011-10-14 05:23:46 +00:00
|
|
|
var gb_id = span.attr('id')
|
|
|
|
if (!gb_id) return;
|
2012-02-03 17:04:54 +00:00
|
|
|
|
|
|
|
// give immediate feedback that action is in progress
|
2012-02-07 17:01:00 +00:00
|
|
|
newSpan = $j('<span style="font-weight: bold;">Adding...</span>').hide();
|
2012-02-03 17:04:54 +00:00
|
|
|
span.replaceWith(newSpan);
|
|
|
|
newSpan.show();
|
|
|
|
|
|
|
|
// actually perform action
|
2011-12-07 17:04:49 +00:00
|
|
|
jQuery.post('/wishlist/', {'googlebooks_id': gb_id}, function(data) {
|
2012-02-03 17:04:54 +00:00
|
|
|
newSpan.fadeOut();
|
|
|
|
var nextSpan = $j('<span class="on-wishlist">On Wishlist!</span>').hide();
|
|
|
|
newSpan.replaceWith(nextSpan);
|
2012-02-06 18:53:25 +00:00
|
|
|
nextSpan.fadeIn('fast');
|
2012-02-03 17:04:54 +00:00
|
|
|
nextSpan.removeAttr("id");
|
2011-10-14 05:23:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-02-07 18:41:21 +00:00
|
|
|
$j("div.remove-wishlist").each(function (index, element) {
|
2011-12-13 18:22:40 +00:00
|
|
|
$j(element).click(function() {
|
|
|
|
var span = $j(element).find("span");
|
2011-10-14 05:23:46 +00:00
|
|
|
var work_id = span.attr('id')
|
2011-12-07 17:04:49 +00:00
|
|
|
jQuery.post('/wishlist/', {'remove_work_id': work_id}, function(data) {
|
2011-12-28 00:17:44 +00:00
|
|
|
var book = $j(element).closest('.thewholebook');
|
2011-10-14 05:23:46 +00:00
|
|
|
book.fadeOut();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-02-07 18:41:21 +00:00
|
|
|
$j("div.create-account").each(function (index, element) {
|
2011-12-13 18:22:40 +00:00
|
|
|
$j(element).click(function() {
|
|
|
|
var span = $j(element).find("span");
|
2011-12-06 04:31:03 +00:00
|
|
|
var work_url = span.attr('title')
|
|
|
|
window.location = "/accounts/login/?next=" + work_url;
|
2011-10-18 02:32:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-12-28 02:39:40 +00:00
|
|
|
// in panel view on the supporter page we want to remove the entire book listing from view upon wishlist-remove
|
|
|
|
// but on the work page, we only want to toggle the add/remove functionality
|
|
|
|
// so: slightly different versions ahoy
|
|
|
|
// note also that we don't have the Django ORM here so we can't readily get from work.id to googlebooks_id
|
|
|
|
// we're going to have to tell /wishlist/ that we're feeding it a different identifier
|
2012-02-07 18:41:21 +00:00
|
|
|
$j("div.remove-wishlist-workpage").each(function (index, element) {
|
2011-12-28 02:39:40 +00:00
|
|
|
$j(element).click(function() {
|
|
|
|
var span = $j(element).find("span");
|
|
|
|
var work_id = span.attr('id')
|
2012-02-03 17:04:54 +00:00
|
|
|
|
|
|
|
// provide feedback
|
|
|
|
var newSpan = $j('<span>Removing...</span>').hide();
|
|
|
|
span.replaceWith(newSpan);
|
|
|
|
newSpan.show();
|
|
|
|
|
|
|
|
// perform action
|
2011-12-28 02:39:40 +00:00
|
|
|
jQuery.post('/wishlist/', {'remove_work_id': work_id}, function(data) {
|
2012-02-03 17:04:54 +00:00
|
|
|
newSpan.parent().fadeOut();
|
2011-12-28 02:39:40 +00:00
|
|
|
var newDiv = $j('<div class="add-wishlist-workpage"><span class="'+work_id+'">Add to Wishlist</span></div>').hide();
|
2012-02-03 17:04:54 +00:00
|
|
|
newSpan.parent().replaceWith(newDiv);
|
2011-12-28 02:39:40 +00:00
|
|
|
newDiv.fadeIn('slow');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var $k = jQuery.noConflict();
|
|
|
|
|
|
|
|
// can't bind this to document ready because the .add-wishlist-workpage div doesn't exist until remove-wishlist is executed
|
|
|
|
// need to use delegate and listen for it
|
|
|
|
// fyi delegate will be deprecated in favor of live() in jquery 1.7 (this was written for 1.6.3)
|
2012-02-07 18:41:21 +00:00
|
|
|
$k(document).delegate("div.add-wishlist-workpage span", "click", function() {
|
2011-12-28 02:39:40 +00:00
|
|
|
var span = $k(this);
|
|
|
|
var work_id = span.attr("class");
|
2012-02-06 19:24:15 +00:00
|
|
|
if (!work_id || work_id === "on-wishlist") return;
|
2012-02-03 17:04:54 +00:00
|
|
|
|
|
|
|
// give immediate feedback that action is in progress
|
2012-02-07 17:01:00 +00:00
|
|
|
newSpan = $j('<span style="font-weight: bold;">Adding...</span>').hide();
|
2012-02-03 17:04:54 +00:00
|
|
|
span.replaceWith(newSpan);
|
|
|
|
newSpan.show();
|
|
|
|
|
2011-12-28 02:39:40 +00:00
|
|
|
jQuery.post('/wishlist/', {'add_work_id': work_id}, function(data) {
|
2012-02-03 17:04:54 +00:00
|
|
|
newSpan.fadeOut();
|
|
|
|
var nextSpan = $k('<span class="on-wishlist">On Wishlist!</span>').hide();
|
|
|
|
newSpan.replaceWith(nextSpan);
|
|
|
|
nextSpan.fadeIn('slow');
|
|
|
|
nextSpan.removeAttr("id");
|
2011-12-28 02:39:40 +00:00
|
|
|
});
|
2011-10-14 05:23:46 +00:00
|
|
|
});
|
|
|
|
|