2011-12-13 18:22:40 +00:00
|
|
|
var $j = jQuery.noConflict();
|
2011-10-14 05:23:46 +00:00
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
$j().ready(function() {
|
|
|
|
// only do the lookup once, then cache it
|
|
|
|
var contentblock = $j('#content-block');
|
|
|
|
|
2012-08-24 19:13:29 +00:00
|
|
|
contentblock.on("click", ".add-wishlist", function () {
|
2001-01-01 00:12:10 +00:00
|
|
|
var span = $j(this).find("span");
|
2012-05-12 01:28:25 +00:00
|
|
|
var id_val = span.attr('id').substring(1);
|
|
|
|
var id_type = span.attr('class');
|
|
|
|
if (!id_val) {span.html('<i>an error occurred.</i>'); return;}
|
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
// give immediate feedback that action is in progress
|
|
|
|
span.html('<b>Adding...</b>');
|
2012-02-03 17:04:54 +00:00
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
// actually perform action
|
2012-05-12 01:28:25 +00:00
|
|
|
if (id_type=='work_id'){
|
|
|
|
jQuery.post('/wishlist/', { 'add_work_id': id_val}, function(data) {
|
2012-02-14 15:15:45 +00:00
|
|
|
span.html('On Wishlist!').addClass('on-wishlist');
|
2012-05-12 01:28:25 +00:00
|
|
|
});}
|
|
|
|
else if (id_type=='gb_id'){
|
|
|
|
jQuery.post('/wishlist/', { 'googlebooks_id': id_val}, function(data) {
|
|
|
|
span.html('On Wishlist!').addClass('on-wishlist');
|
|
|
|
});}
|
|
|
|
else {
|
|
|
|
span.html('a type error occurred');
|
|
|
|
}
|
2012-08-24 19:13:29 +00:00
|
|
|
|
|
|
|
// prevent perversities on download page
|
|
|
|
if ($j(this).is("a")) {
|
|
|
|
$j(this).removeClass("add-wishlist").addClass("success");
|
|
|
|
}
|
2011-10-14 05:23:46 +00:00
|
|
|
});
|
2012-05-12 01:28:25 +00:00
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
contentblock.on("click", "div.remove-wishlist", function() {
|
|
|
|
var span = $j(this).find("span");
|
|
|
|
var book = $j(this).closest('.thewholebook');
|
2012-03-09 18:59:24 +00:00
|
|
|
var work_id = span.attr('id').substring(1)
|
2001-01-01 00:12:10 +00:00
|
|
|
span.html('Removing...');
|
|
|
|
jQuery.post('/wishlist/', {'remove_work_id': work_id}, function(data) {
|
|
|
|
book.fadeOut();
|
2011-10-14 05:23:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
contentblock.on("click", "div.create-account", function () {
|
|
|
|
var span = $j(this).find("span");
|
|
|
|
var work_url = span.attr('title')
|
2012-07-12 01:05:58 +00:00
|
|
|
top.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
|
2001-01-01 00:12:10 +00:00
|
|
|
contentblock.on("click", "div.remove-wishlist-workpage", function () {
|
|
|
|
var span = $j(this).find("span");
|
2012-09-14 13:21:05 +00:00
|
|
|
var work_id = span.attr('id').substring(1);
|
2012-02-03 17:04:54 +00:00
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
// provide feedback
|
|
|
|
span.html('Removing...');
|
2012-02-03 17:04:54 +00:00
|
|
|
|
2001-01-01 00:12:10 +00:00
|
|
|
// perform action
|
|
|
|
jQuery.post('/wishlist/', {'remove_work_id': work_id}, function(data) {
|
|
|
|
var parent = span.parent();
|
|
|
|
parent.fadeOut();
|
|
|
|
var newDiv = $j('<div class="add-wishlist-workpage"><span class="'+work_id+'">Add to Wishlist</span></div>').hide();
|
|
|
|
parent.replaceWith(newDiv);
|
|
|
|
newDiv.fadeIn('slow');
|
2011-12-28 02:39:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2012-09-14 13:21:05 +00:00
|
|
|
|
|
|
|
var $k = jQuery.noConflict();
|
|
|
|
// allows user to re-add on work page after erroneously removing, without page reload
|
|
|
|
// can't bind this to document ready because the .add-wishlist-workpage div doesn't exist until remove-wishlist is executed
|
|
|
|
$k(document).on("click", ".add-wishlist-workpage span", function() {
|
|
|
|
var span = $k(this);
|
|
|
|
var work_id = span.attr("class");
|
|
|
|
if (!work_id) return;
|
|
|
|
jQuery.post('/wishlist/', {'add_work_id': work_id}, function(data) {
|
|
|
|
span.fadeOut();
|
|
|
|
var newSpan = $k('<span class="on-wishlist">On Wishlist!</span>').hide();
|
|
|
|
span.replaceWith(newSpan);
|
|
|
|
newSpan.fadeIn('slow');
|
|
|
|
newSpan.removeAttr("id");
|
|
|
|
});
|
|
|
|
});
|