Skip to content

Instantly share code, notes, and snippets.

@sjungling
Last active December 15, 2015 05:19
Show Gist options
  • Save sjungling/5208421 to your computer and use it in GitHub Desktop.
Save sjungling/5208421 to your computer and use it in GitHub Desktop.
un-class-ified wishlist for display_simple
// Generated by CoffeeScript 1.6.1
jQuery(function($) {
var addProductToWishList, addToWishList, button, collapse, container, createForm, createWishList, expand, icon, listsContainer, node, resizeWidget, toggleDropdown, updateWishlistLists;
collapse = function() {
console.log("Collapse it");
if ((typeof node !== "undefined" && node !== null) && (typeof container !== "undefined" && container !== null)) {
node.removeClass('is-expanded').addClass('is-collapsed');
return container.animate({
'height': 0
}, 250, function() {
container.hide().attr('style', null);
return icon.removeClass('icon-down-arrow-grey').addClass('icon-right-arrow-grey');
});
}
};
expand = function() {
var expandedHeight;
console.log("Expand it");
if ((typeof node !== "undefined" && node !== null) && (typeof container !== "undefined" && container !== null)) {
node.removeClass('is-collapsed').addClass('is-expanded');
expandedHeight = "" + (container.outerHeight(true)) + "px";
container.css({
height: '0'
}).show().animate({
height: expandedHeight
}, '250');
return icon.removeClass('icon-right-arrow-grey').addClass('icon-down-arrow-grey');
}
};
toggleDropdown = function(e) {
console.log("toggleDropdown called");
e.preventDefault();
if (node.hasClass('is-collapsed')) {
return expand();
} else if (node.hasClass('is-expanded')) {
return collapse();
}
};
addToWishList = function(e) {
var productQuantity, wishListContainer, wishListId;
console.log("addToWishList called");
e.preventDefault();
wishListId = $(e.currentTarget).data('wishlistid');
wishListContainer = $(e.currentTarget).parent('ul');
productQuantity = $('#qtyselected').attr('value');
return addProductToWishList(wishListId, wishListContainer.data('productid'), wishListContainer.data('manufacturer'), productQuantity);
};
addProductToWishList = function(wishListId, productId, manufacturer, quantity) {
if (quantity == null) {
quantity = 1;
}
return $.ajax({
url: '/index.cfm?page=wishlists:addProductByProductIDManufacturer&fmt=json',
type: 'POST',
dataType: 'json',
data: {
wishlistID: wishListId,
productID: productId,
manufacturer: manufacturer,
qty: quantity
},
success: function(res) {
var loc;
console.log('Successfully added item to wishlist');
loc = window.location;
return window.location.href = "https://" + loc.hostname + "/index.cfm?page=wishlists:index&id=" + wishListId;
},
error: function(res) {
return console.error(res);
}
});
};
createWishList = function(e) {
var createForm, wishlistName;
console.log("createWishList called");
e.preventDefault();
createForm = $(e.currentTarget);
wishlistName = $('#wishlist-new');
if (wishlistName.attr('value') !== "") {
return $.ajax({
url: '/index.cfm?page=wishlists:createWishlist&fmt=json',
type: 'POST',
dataType: 'json',
data: createForm.serialize(),
success: function(res) {
return updateWishlistLists().done(function() {
resizeWidget();
return createForm[0].reset();
});
},
error: function(res) {
return console.error("Could not create new list");
}
});
} else {
console.error('No value');
return false;
}
};
toggleDropdown = function(e) {
console.log("toggleDropdown called");
e.preventDefault();
if (node.hasClass('is-collapsed')) {
return expand();
} else if (node.hasClass('is-expanded')) {
return collapse();
}
};
resizeWidget = function() {
var newHeight;
console.log("resizeWidget called");
if ((typeof node !== "undefined" && node !== null) && (typeof container !== "undefined" && container !== null)) {
newHeight = container.find('ul').outerHeight(true) + container.find('form').outerHeight(true);
return container.animate({
'height': newHeight + 'px'
}, 250);
}
};
updateWishlistLists = function() {
console.log("updateWishlistLists called");
return $.ajax({
url: '/index.cfm?page=wishlists:lists_widget&fmt=pjax',
success: function(res) {
var listContainer;
listContainer = $('.wishlist-lists ul');
return listContainer.html(res);
},
error: function(res) {
return console.error("could not fetch fu");
}
});
};
node = $('#wishlist-dropdown');
node.addClass('is-collapsed');
listsContainer = node.find('.wishlist-lists');
createForm = node.find('#wishlist-create');
container = node.find('.expandable');
button = node.find('.button');
icon = node.find('.icon');
createForm.on('submit', createWishList);
listsContainer.on('click', 'li', addToWishList);
return button.on('click', toggleDropdown);
});
// Generated by CoffeeScript 1.6.1
jQuery(function($) {
var addProductToWishList, addToWishList, button, collapse, container, createForm, createWishList, expand, icon, listsContainer, node, resizeWidget, toggleDropdown, updateWishlistLists;
collapse = function() {
console.log("Collapse it");
if ((typeof node !== "undefined" && node !== null) && (typeof container !== "undefined" && container !== null)) {
node.removeClass('is-expanded').addClass('is-collapsed');
return container.animate({
'height': 0
}, 250, function() {
container.hide().attr('style', null);
return icon.removeClass('icon-down-arrow-grey').addClass('icon-right-arrow-grey');
});
}
};
expand = function() {
var expandedHeight;
console.log("Expand it");
if ((typeof node !== "undefined" && node !== null) && (typeof container !== "undefined" && container !== null)) {
node.removeClass('is-collapsed').addClass('is-expanded');
expandedHeight = "" + (container.outerHeight(true)) + "px";
container.css({
height: '0'
}).show().animate({
height: expandedHeight
}, '250');
return icon.removeClass('icon-right-arrow-grey').addClass('icon-down-arrow-grey');
}
};
toggleDropdown = function(e) {
console.log("toggleDropdown called");
e.preventDefault();
if (node.hasClass('is-collapsed')) {
return expand();
} else if (node.hasClass('is-expanded')) {
return collapse();
}
};
addToWishList = function(e) {
var productQuantity, wishListContainer, wishListId;
console.log("addToWishList called");
e.preventDefault();
if (window.configurator && window.configurator.verifyChoices().length > 0 ) {
console.error('Finish configuring your product before adding to wish list');
configurator.showErrorPopup($$('.wishlist-title'), configurator.verifyChoices());
return false;
};
wishListId = $(e.currentTarget).data('wishlistid');
wishListContainer = $(e.currentTarget).parent('ul');
productQuantity = $('#qtyselected').attr('value');
productOptions = configurator.getSelectedOptionList();
return addProductToWishList(wishListId, wishListContainer.data('productid'), wishListContainer.data('manufacturer'), productQuantity, productOptions);
};
addProductToWishList = function(wishListId, productId, manufacturer, quantity, options) {
if (quantity == null) {
quantity = 1;
}
if (options === "") {
options = null;
}
return $.ajax({
url: '/index.cfm?page=wishlists:addProductByProductIDManufacturer&fmt=json',
type: 'POST',
dataType: 'json',
data: {
wishlistID: wishListId,
productID: productId,
manufacturer: manufacturer,
qty: quantity,
optionsList: options
},
success: function(res) {
var loc;
console.log('Successfully added item to wishlist');
loc = window.location;
return window.location.href = "https://" + loc.hostname + "/index.cfm?page=wishlists:index&id=" + wishListId;
},
error: function(res) {
return console.error(res);
}
});
};
createWishList = function(e) {
var createForm, wishlistName;
console.log("createWishList called");
e.preventDefault();
createForm = $(e.currentTarget);
wishlistName = $('#wishlist-new');
if (wishlistName.attr('value') !== "") {
return $.ajax({
url: '/index.cfm?page=wishlists:createWishlist&fmt=json',
type: 'POST',
dataType: 'json',
data: createForm.serialize(),
success: function(res) {
return updateWishlistLists().done(function() {
resizeWidget();
return createForm[0].reset();
});
},
error: function(res) {
return console.error("Could not create new list");
}
});
} else {
console.error('No value');
return false;
}
};
toggleDropdown = function(e) {
console.log("toggleDropdown called");
e.preventDefault();
if (node.hasClass('is-collapsed')) {
return expand();
} else if (node.hasClass('is-expanded')) {
return collapse();
}
};
resizeWidget = function() {
var newHeight;
console.log("resizeWidget called");
if ((typeof node !== "undefined" && node !== null) && (typeof container !== "undefined" && container !== null)) {
newHeight = container.find('ul').outerHeight(true) + container.find('form').outerHeight(true);
return container.animate({
'height': newHeight + 'px'
}, 250);
}
};
updateWishlistLists = function() {
console.log("updateWishlistLists called");
return $.ajax({
url: '/index.cfm?page=wishlists:lists_widget&fmt=pjax',
success: function(res) {
var listContainer;
listContainer = $('.wishlist-lists ul');
return listContainer.html(res);
},
error: function(res) {
return console.error("could not fetch fu");
}
});
};
node = $('#wishlist-dropdown');
node.addClass('is-collapsed');
listsContainer = node.find('.wishlist-lists');
createForm = node.find('#wishlist-create');
container = node.find('.expandable');
button = node.find('.button');
icon = node.find('.icon');
createForm.on('submit', createWishList);
listsContainer.on('click', 'li', addToWishList);
return button.on('click', toggleDropdown);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment