Markets
Other markets
Favourites
'; //see which section to append to if (data.ItemType && isInvestmentType(data.ItemType)) { $('.jsInvestmentHeading').removeClass('.investmentHeading--hidden'); $(placeholder).insertAfter($investmentHeading); } else if ((data.ItemType) && data.ItemType.toLocaleLowerCase() === 'manager') { $managerHeading.removeClass('managerHeading--hidden'); $(placeholder).insertAfter($managerHeading); } } }, removeFinished: function(data) { //only select visible items as we have duplicates for wide and narrow view var $favouriteItemToRemove = $('.jsFavouriteItem_' + data.ItemType + '_' + data.ItemID), itemType = $($favouriteItemToRemove[0]).data('type'), itemID = $($favouriteItemToRemove[0]).data('id'), itemName = $.trim($('.favouritesItem__name', $($favouriteItemToRemove[0])).text()), that = this, message = itemName + ' has been removed from your favourites.' + ' Undo '; $favouriteItemToRemove.remove(); favouritesWidget.displayMessage(message); $('#undoLink').click(function(e) { that.handleAdd({ ItemType: itemType, ItemID: itemID, ItemName: itemName }); favouritesWidget.undoRemove(itemName, itemID, itemType); e.preventDefault(); }); favouritesWidget.updateItemCounts(); if (document.citywire && document.citywire.pubsub) { document.citywire.pubsub.publish('citywire.favourites.deleted.' + data.ItemType + '.' + data.ItemID); } favouritesWidget.setSize(); }, handleRemoveFinished: function(data) { if (data.ItemID && data.ItemType) { this.removeFinished(data); } }, addingFinished: function(itemData) { var itemClass = 'jsFavouriteItem_' + itemData.ItemType + '_' + itemData.ItemID; $.ajax({ url: '/favourites/getitemview.aspx?section=investment-trust-insider', data: itemData, success: function(favItem) { $('#' + itemData.ItemType + '_' + itemData.ItemID).remove(); if ($('#favouritesWidget').find('.' + itemClass).length === 0) { if (itemData.ItemType && itemData.ItemType.toLocaleLowerCase() === 'manager') { $(favItem).insertAfter($('.jsManagerHeading')); } else if (itemData.ItemType && isInvestmentType(itemData.ItemType)) { $(favItem).insertAfter($('.jsInvestmentHeading')); } favouritesWidget.updateItemCounts(); favouritesWidget.setSize(); } }, error: function(error) { favouritesWidget.handleError(); } }); }, buyNow: function() { var models = []; if (isModalOpen === false) { $('.jsfavouritesBuyButtonIcon').addClass('hidden'); $('#buyAllSpinner').addClass('busy'); $('.favouritesItem__checkbox:checked').each(function(index, favouriteItem) { var $item = $(favouriteItem).closest('.jsFavouriteItem'); models.push({ ItemName: $item.data('name'), ItemID: $item.data('id'), ItemType: $item.data('type'), BasketCode: $item.data('basketcode') }); }); if (models.length <= 10) { buyInvestment.getCheckout(models, 'Favourites'); } else { favouritesWidget.displayMessage("You can purchase a maximum of 10 investments at one time"); } } } }; } ()); $.ajax({ url: '/favourites/get.aspx?section=investment-trust-insider', success: function(data) { favouritesWidget.loadingFinished(data); }, error: function(error) { favouritesWidget.handleError('Apologies, we could not load your favourites at this time. Please try again later'); } }); if (document.citywire && document.citywire.pubsub) { document.citywire.pubsub.subscribe('citywire.favourites.add', eventHandler, eventHandler.handleAdd, 'favouritesWidget'); document.citywire.pubsub.subscribe('citywire.favourites.added', eventHandler, eventHandler.addingFinished, 'favouritesWidget'); document.citywire.pubsub.subscribe('citywire.favourites.removeFinished', eventHandler, eventHandler.handleRemoveFinished, 'favouritesWidget'); document.citywire.pubsub.subscribe('citywire.favourites.checkoutclosed', eventHandler, eventHandler.modalClosed, 'favouritesWidget'); document.citywire.pubsub.subscribe('citywire.favourites.checkoutloaded', eventHandler, eventHandler.modalOpened, 'favouritesWidget'); } $('#favouritesShowMore').click(function(e) { favouritesWidget.showAll(e); }); $('#buyButton').click(function(e) { eventHandler.buyNow(); e.preventDefault(); }); })