');
$(document.body).append('
loading reading lists ...
');
function adjustReadingListIcon(isInReadingList){
$readingListToggle.toggleClass("fa-plus", !isInReadingList);
$readingListToggle.toggleClass("fa-check", isInReadingList);
var tooltipMessage = isInReadingList ? "edit in reading lists" : "add to reading list";
$readingListToggle.attr("title", tooltipMessage);
$readingListToggle.attr("data-original-title", tooltipMessage);
}
$.ajax({
url: "/readingList/isInReadingList",
data: {
productId: 3798
}
}).done(function (data) {
adjustReadingListIcon(data && data.hasProductInReadingList);
}).catch(function(e){
console.log(e);
adjustReadingListIcon(false);
});
$readingListToggle.on("click", function(){
if(codePromise == null){ showToast() }
loadCode().then(function(store){
store.requestReadingListSpecificationForProduct({
id: window.readingListsServerVars.externalId,
manningId: window.readingListsServerVars.productId,
title: window.readingListsServerVars.title
});
ReadingLists.ReactDOM.render(
ReadingLists.React.createElement(ReadingLists.ManningOnlineReadingListModal, {
store: store,
}),
document.getElementById("reading-lists-modal")
);
}).catch(function(e){
console.log("Error loading code reading list code");
});
});
var codePromise
var readingListStore
function loadCode(){
if(codePromise) { return codePromise }
return codePromise = new Promise(function (resolve, reject){
$.getScript(window.readingListsServerVars.libraryLocation).done(function(){
hideToast()
readingListStore = new ReadingLists.ReadingListStore(
new ReadingLists.ReadingListProvider(
new ReadingLists.ReadingListWebProvider(
ReadingLists.SourceApp.marketplace,
getDeploymentType()
)
)
);
readingListStore.onReadingListChange(handleChange);
readingListStore.onReadingListModalChange(handleChange);
resolve(readingListStore);
}).catch(function(){
hideToast();
console.log("Error downloading reading lists source");
$readingListToggle.css("display", "none");
reject();
});
});
}
function handleChange(){
if(readingListStore != null) {
adjustReadingListIcon(readingListStore.isInAtLeastOneReadingList({
id: window.readingListsServerVars.externalId,
manningId: window.readingListsServerVars.productId
}));
}
}
var $readingListToast = $("#reading-list-toast");
function showToast(){
$readingListToast.css("display", "flex");
setTimeout(function(){
$readingListToast.addClass("shown");
}, 16);
}
function hideToast(){
$readingListToast.removeClass("shown");
setTimeout(function(){
$readingListToast.css("display", "none");
}, 150);
}
function getDeploymentType(){
switch(window.readingListsServerVars.deploymentType){
case "development":
case "test":
return ReadingLists.DeploymentType.dev;
case "qa":
return ReadingLists.DeploymentType.qa;
case "production":
return ReadingLists.DeploymentType.prod;
case "docker":
return ReadingLists.DeploymentType.docker;
default:
console.error("Unknown deployment environment, defaulting to production");
return ReadingLists.DeploymentType.prod;
}
}
});
}
});