2011-12-13 18:22:40 +00:00
|
|
|
var $j = jQuery.noConflict();
|
2011-10-14 05:23:46 +00:00
|
|
|
|
2011-12-13 18:22:40 +00:00
|
|
|
$j(document).ready(function() {
|
|
|
|
|
|
|
|
$j(".add-wishlist").each(function (index, element) {
|
|
|
|
$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;
|
2011-12-07 17:04:49 +00:00
|
|
|
jQuery.post('/wishlist/', {'googlebooks_id': gb_id}, function(data) {
|
2011-10-14 05:23:46 +00:00
|
|
|
span.fadeOut();
|
2011-12-28 00:17:44 +00:00
|
|
|
var newSpan = $j('<span class="on-wishlist">On Wishlist!</span>').hide();
|
2011-10-14 05:23:46 +00:00
|
|
|
span.replaceWith(newSpan);
|
2011-10-18 02:32:31 +00:00
|
|
|
newSpan.fadeIn('slow');
|
2011-10-14 05:23:46 +00:00
|
|
|
newSpan.removeAttr("id");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-12-13 18:22:40 +00:00
|
|
|
$j(".remove-wishlist").each(function (index, element) {
|
|
|
|
$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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-12-13 18:22:40 +00:00
|
|
|
$j(".create-account").each(function (index, element) {
|
|
|
|
$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
|
|
|
|
$j(".remove-wishlist-workpage").each(function (index, element) {
|
|
|
|
$j(element).click(function() {
|
|
|
|
var span = $j(element).find("span");
|
|
|
|
var work_id = span.attr('id')
|
|
|
|
jQuery.post('/wishlist/', {'remove_work_id': work_id}, function(data) {
|
|
|
|
span.parent().fadeOut();
|
|
|
|
var newDiv = $j('<div class="add-wishlist-workpage"><span class="'+work_id+'">Add to Wishlist</span></div>').hide();
|
|
|
|
span.parent().replaceWith(newDiv);
|
|
|
|
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)
|
|
|
|
$k(document).delegate(".add-wishlist-workpage span", "click", 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");
|
|
|
|
});
|
2011-10-14 05:23:46 +00:00
|
|
|
});
|
|
|
|
|