(function () {
function loadScript(uri, callback) {
var scriptTag = document.createElement("script");
scriptTag.setAttribute("type", "text/javascript");
scriptTag.setAttribute("src", uri);
scriptTag.setAttribute("async", "true");
if (scriptTag.readyState) {
scriptTag.onreadystatechange = function() {
if (this.readystate == "complete" || this.readyState == "loaded") {
callback();
}
};
} else {
scriptTag.onload = function () {
callback();
};
}
//append the script to the header or documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(scriptTag);
}
var jQuery;
if (typeof(window.jQuery) === "undefined" || window.jQuery.fn.jquery !== "1.8.3") {
loadScript("https://widgets.penguin.com/Include/JS/jquery-1.8.3.min.js", restoreGlobaljQuery);
} else {
jQuery = window.jQuery;
Init();
}
function restoreGlobaljQuery() {
// Restore $ and window.jQuery to their previous values and store the new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
Init();
}
function Init() {
jQuery(document).ready(function($) {
$("").appendTo($('head')).attr({type: 'text/css', rel: 'stylesheet', media: 'all'}).attr('href', 'http://widgets.penguin.com//AffiliateLinkSA/Styles.aspx');
$.getScript("https://widgets.penguin.com/Include/JS/Legacy/ScriptPackage.ashx?widgetid=15&exclude=1,2", Widgetize);
function Widgetize(data, textStatus, jqxhr) {
PGWidgets.$ = $;
$("body").prepend("
");
/* Required for all widgets */
if ((typeof (PGWidgets.$) == "undefined") || (PGWidgets.$ == null)) {
PGWidgets.$ = $;
}
PGWidgets.$("div.pgWidgetsAffiliateSA").each(function() {
var onSaleAttr = PGWidgets.$(this).attr("data-onsale");
if ((typeof (onSaleAttr) !== "undefined") && (PGWidgets.Utils.IsValidDateString(onSaleAttr))) {
var regex = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var match = onSaleAttr.match(regex);
var onSaleDate = new Date(match[5], match[1]-1, match[3]);
var curDate = new Date(2017, 6-1, 3);
if (onSaleDate > curDate) {
PGWidgets.$(this).html('Preorder ▼');
} else {
PGWidgets.$(this).html('Buy From ▼');
}
} else {
PGWidgets.$(this).html('Buy From ▼');
}
});
PGWidgets.$(document).on("click", function (event) {
var t = event.target;
if (PGWidgets.$(t).parents("div.pgWidgetsAffiliateSA").length > 0) {
var divWrap = PGWidgets.$(t).parents("div.pgWidgetsAffiliateSA");
var isbn13 = PGWidgets.$(divWrap).attr("data-isbn");
var randomId = PGWidgets.Utils.GenerateRandomId("xxx-xxx-xxx-xxx-xxx");
PGWidgets.$(divWrap).attr("data-ref", randomId);
PGWidgets.Books.GetAffiliateLinks("https://services.penguin.com/rest/v1.1/json/book/affiliate/data/get", "isbn=" + isbn13 + "&AffiliateSiteid=1&TitleSiteid=1&sort=1&uniqueid=" + randomId, "PGWidgets.Books.Callbacks.DrawAffiliateLinks");
} else {
PGWidgets.$("ul.pgWidgetsAffiliateSA").hide();
}
});
function affiliateLinkClick() {
var linkIsbn = PGWidgets.$(this).attr("data-isbn");
var uniqueId = PGWidgets.$(this).parents("ul.pgWidgetsAffiliateSA").attr("data-btnref");
var curBtn = PGWidgets.$("div.pgWidgetsAffiliateSA[data-ref=" + uniqueId + "]");
//set up floodlight tracking parameters
var objFl = {
"u1": "Penguin_Widget",
"u6": linkIsbn,
"u7": encodeURIComponent(PGWidgets.$(this).text())
};
//insert floodlight tag
PGWidgets.Tracking.InsertFloodlightTag(true, "4654163", "prhrlc1", "prhrlc1", 1, "0.00", objFl);
//now set up Omniture data insertion request
var data = new PGWidgets.Tracking.DataInsertion();
var link = PGWidgets.$(this).attr("data-link");
var bookTitle = PGWidgets.$(curBtn).attr("data-booktitle");
if ((typeof bookTitle) == "undefined") { bookTitle = ""; }
var affiliateName = PGWidgets.$(this).text();
var pageTitle = PGWidgets.$("title").text();
var authorName = PGWidgets.$(curBtn).attr("data-authorname");
if ((typeof authorName) == "undefined") { authorName = ""; }
var format = PGWidgets.$(curBtn).attr("data-format");
if ((typeof format) == "undefined") { format = ""; }
var authorId = PGWidgets.$(curBtn).attr("data-authorid");
if ((typeof authorId) == "undefined") { authorId = ""; }
var categories = PGWidgets.$(curBtn).attr("data-categories");
if ((typeof categories) == "undefined") { categories = ""; }
data.Tags.push(new PGWidgets.Tracking.Tag("linkType", "o"));
data.Tags.push(new PGWidgets.Tracking.Tag("linkURL", link));
data.PageName = "Affiliate Link Widget SA:Click:" + pageTitle;
data.Tags.push(new PGWidgets.Tracking.Tag("prop2", data.PageName));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar23", data.PageName));
data.PageURL = document.location.href;
data.Tags.push(new PGWidgets.Tracking.Tag("prop34", data.PageURL));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar51", data.PageURL));
data.Tags.push(new PGWidgets.Tracking.Tag("products", "Book;" + linkIsbn + ";1;0.00"));
data.Tags.push(new PGWidgets.Tracking.Tag("prop25", affiliateName));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar18", affiliateName));
data.Tags.push(new PGWidgets.Tracking.Tag("prop19", authorName));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar16", authorName));
data.Tags.push(new PGWidgets.Tracking.Tag("prop11", bookTitle));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar15", bookTitle));
data.Tags.push(new PGWidgets.Tracking.Tag("prop23", format));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar14", format));
data.Tags.push(new PGWidgets.Tracking.Tag("prop26", categories));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar19", categories));
data.Tags.push(new PGWidgets.Tracking.Tag("prop21", authorId));
data.Tags.push(new PGWidgets.Tracking.Tag("eVar28", authorId));
data.Tags.push(new PGWidgets.Tracking.Tag("events", "event14"));
PGWidgets.Tracking.Invoke(data, PGWidgets.Books.Callbacks.TrackAffiliateLinkSuccess(link));
}
PGWidgets.$("ul.pgWidgetsAffiliateSA li a").live("click", affiliateLinkClick);
//track affiliate widget page load
var dataInsertion = new PGWidgets.Tracking.DataInsertion();
var pageTitle = PGWidgets.$("title").text();
dataInsertion.PageName = "Affiliate Link Widget SA:Load:" + pageTitle;
dataInsertion.PageURL = document.location.href;
dataInsertion.Tags.push(new PGWidgets.Tracking.Tag("prop2", dataInsertion.PageName));
dataInsertion.Tags.push(new PGWidgets.Tracking.Tag("eVar23", dataInsertion.PageName));
dataInsertion.Tags.push(new PGWidgets.Tracking.Tag("prop34", document.location.href));
dataInsertion.Tags.push(new PGWidgets.Tracking.Tag("eVar51", document.location.href));
dataInsertion.Tags.push(new PGWidgets.Tracking.Tag("events", "event15"));
PGWidgets.Tracking.Invoke(dataInsertion, PGWidgets.Tracking.Callbacks.DataInsertionSuccess);
}
});
}
})();