Nisha Garg
').appendTo(flyout.elem());var panelGroup=flyout.getName()+'SubCats';var hideTimeout=null;var sloppyTrigger=createSloppyTrigger($parent);var showParent=function(){if(hideTimeout){clearTimeout(hideTimeout);hideTimeout=null;} if(visible){return;} var height=$('#nav-flyout-shopAll').height(); $parent.css({'height': height});$parent.animate({width:'show'},{duration:200,complete:function(){$parent.css({overflow:'visible'});}});visible=true;};var hideParentNow=function(){$parent.stop().css({overflow:'hidden',display:'none',width:'auto',height:'auto'});panels.hideAll({group:panelGroup});visible=false;if(hideTimeout){clearTimeout(hideTimeout);hideTimeout=null;}};var hideParent=function(){if(!visible){return;} if(hideTimeout){clearTimeout(hideTimeout);hideTimeout=null;} hideTimeout=setTimeout(hideParentNow,10);};flyout.onHide(function(){sloppyTrigger.disable();hideParentNow();this.elem().hide();});var addPanel=function($link,panelKey){var panel=dataPanel({className:'nav-subcat',dataKey:panelKey,groups:[panelGroup],spinner:false,visible:false});if(!flyoutDebug){var mouseout=mouseOutUtility();mouseout.add(flyout.elem());mouseout.action(function(){panel.hide();});mouseout.enable();} var a11y=a11yHandler({link:$link,onEscape:function(){panel.hide();$link.focus();}});var logPanelInteraction=function(promoID,wlTriggers){var logNow=$F.once().on(function(){var panelEvent=$.extend({},event,{id:promoID});if(config.browsePromos&&!!config.browsePromos[promoID]){panelEvent.bp=1;} logEvent(panelEvent);phoneHome.trigger(wlTriggers);});if(panel.isVisible()&&panel.hasInteracted()){logNow();}else{panel.onInteract(logNow);}};panel.onData(function(data){renderPromo(data.promoID,panel.elem());logPanelInteraction(data.promoID,data.wlTriggers);});panel.onShow(function(){var columnCount=$('.nav-column',panel.elem()).length;panel.elem().addClass('nav-colcount-'+columnCount);showParent();var $subCatLinks=$('.nav-subcat-links > a',panel.elem());var length=$subCatLinks.length;if(length>0){var firstElementLeftPos=$subCatLinks.eq(0).offset().left;for(var i=1;i "},"url":"/cart/ewc/compact?hostPageType=Detail&hostSubPageType=Glance&hostPageRID=H3MCP5KKHJAKY4BZJ74G&prerender=0&storeName=books","cartCount":0,"freshCartCount":0,"almCartCount":0,"primeWardrobeCartCount":0,"isCompactViewEnabled":true,"isCompactEWCRendered":true,"isWiderCompactEWCRendered":true,"EWCBrowserCacheKey":"EWC_Cache_135-8583978-5838312__USD_en_US","isContentRepainted":false,"clearCache":false,"loadFromCacheWithDelay":0,"delayRenderingTillATF":false,"EarlyLoadEWCContentTreatment":"T3"}; config.flyout = (function() { var getDocumentScrollTop = function() { var isWindow = function(obj) { var getWindow = function(elem) { var getOffset = function(elem) { var rect = elem.getBoundingClientRect if (rect.width || rect.height) { flyout.align = function() { flyout.hide = function() { if(typeof config.isCompactEWCRendered === 'undefined') { var viewportQualifyForPersistent = function () { flyout.hasQualifiedViewportForPersistent = viewportQualifyForPersistent; var getEWCRightOffset = function() { var $navbelt = document.getElementById('nav-belt'); var EWCCompactViewWidth = (config.isWiderCompactEWCRendered && viewportWidth() >= 1280) ? 130 : 100; if (isPartOfNavbarNotVisible) { flyout.getEWCRightOffsetCssProperty = function () { if (config.isCompactEWCRendered) { flyout.show = function() { var isIOSDevice = function() { var checkForPersistent = function() { flyout.ableToPersist = function() { flyout.unapplyPageLayoutForPersistent = function() { flyout.persist = function() { flyout.unpersist = function() { var persistentCheck = checkForPersistent(); var resizeCallback = function() { if (flyout.ableToPersist()) { flyout.bindEvents = function() { if (config.isCompactEWCRendered) { flyout.unbindEvents = function() { if (config.isCompactEWCRendered) { var ewcDefaultPersistence = function() { if (persistentCheck.result) { ewcDefaultPersistence(); if (window.ue && ue.tag) { '); $Nav.when("config").run('ewc.pageload-content-load-wrapper', function(config) { $Nav.when("config") P.when('A').execute(function(A){ var displayErrorContent = function(){ var getUrlParams = function(isReloaded) { config.ewc.flyout.loadEwcContent = function _loadEwcContent(isReloaded) { var cache = config.ewc.flyout.cache(); } const CACHE_KEY = "EWCBrowserCacheKey"; const isCacheValid = function () { return config; if (typeof uet === 'function') { if (window.ue && ue.tag) { if ( window.P && window.P.AUI_BUILD_DATE ) {
var hasAui = window.P && window.P.AUI_BUILD_DATE;
var isRTLEnabled = (document.dir === 'rtl');
config.pinnable = config.pinnable && hasAui;
config.isMigrationTreatment = true;
var navbelt = document.getElementById('nav-belt');
var navCart = document.getElementById('nav-cart');
var ewcFlyout = document.getElementById('nav-flyout-ewc');
var persistentClassOnBody = 'nav-ewc-persistent-hover nav-ewc-full-height-persistent-hover';
var flyout = {};
return (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
};
return obj != null && obj === obj.window;
};
return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView;
};
if (elem.getClientRects && !elem.getClientRects().length) {
return {top: 0};
}
? elem.getBoundingClientRect()
: {top: 0};
var doc = elem.ownerDocument;
var win = getWindow(doc);
return {
top: rect.top + win.pageYOffset - doc.documentElement.clientTop
};
}
return rect;
};
var newTop = getOffset(navbelt).top - getDocumentScrollTop();
ewcFlyout.style.top = (newTop > 0 ? newTop + 'px' : 0);
};
isRTLEnabled
? (ewcFlyout.style.left = '')
: (ewcFlyout.style.right = '');
};
if (
(config.isSmallScreenEnabled && viewportWidth() < 1400) ||
(config.isCompactViewEnabled && viewportWidth() >= 1400)
) {
config.isCompactEWCRendered = true;
config.isEWCStateExpanded = true;
config.url = config.url.replace("/gp/navcart/sidebar", "/cart/ewc/compact");
} else {
config.isCompactEWCRendered = false;
}
}
return (config.isCompactEWCRendered)
? true
: viewportWidth() >= 1400;
}
if (!config.isCompactEWCRendered) {
return 0;
}
if ($navbelt === undefined || $navbelt === null) {
return 0;
}
var scrollLeft = (window.pageXOffset !== undefined)
? window.pageXOffset
: (document.documentElement || document.body.parentNode || document.body).scrollLeft;
var scrollXAxis = Math.abs(scrollLeft);
var windowWidth = document.documentElement.clientWidth;
var navbeltWidth = $navbelt.offsetWidth;
var isPartOfNavbarNotVisible = (navbeltWidth + EWCCompactViewWidth) > windowWidth;
return 0 - (navbeltWidth - scrollXAxis - windowWidth + EWCCompactViewWidth);
} else {
return 0;
}
}
return getEWCRightOffset() + 'px';
}
persistentClassOnBody = 'nav-ewc-persistent-hover nav-ewc-compact-view';
if (config.isWiderCompactEWCRendered) { persistentClassOnBody += ' nav-ewc-wider-compact-view'; }
}
isRTLEnabled
? (ewcFlyout.style.left = flyout.getEWCRightOffsetCssProperty())
: (ewcFlyout.style.right = flyout.getEWCRightOffsetCssProperty());
};
return (/iPad|iPhone|iPod/.test(navigator.platform) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!window.MSStream;
}
if (!hasAui) {
return { result: false, reason: 'noAui' };
}
if (!config.enablePersistent) {
return { result: false, reason: 'config' };
}
if (!viewportQualifyForPersistent()) {
return { result: false, reason: 'viewport' };
}
if (isIOSDevice()) {
return { result: false, reason: 'iOS' };
}
if (!config.cartCount > 0) {
return { result: false, reason: 'emptycart' };
}
return { result: true };
};
return checkForPersistent().result;
};
var persistentClassRegExp = '(?:^|\s)' + persistentClassOnBody + '(?!\S)';
flyout.applyPageLayoutForPersistent = function() {
if (!document.documentElement.className.match( new RegExp(persistentClassRegExp) )) {
document.documentElement.className += ' ' + persistentClassOnBody;
}
};
document.documentElement.className = document.documentElement.className.replace( new RegExp(persistentClassRegExp, 'g'), '');
};
flyout.applyPageLayoutForPersistent();
flyout.show();
if (config.isCompactEWCRendered) {
flyout.align();
}
};
flyout.unapplyPageLayoutForPersistent();
flyout.hide();
};
flyout.persist();
}
else {
flyout.unpersist();
}
};
if (window.addEventListener) {
window.addEventListener('resize', resizeCallback, false);
window.addEventListener('scroll', flyout.align, false);
}
}
};
if (window.removeEventListener) {
window.removeEventListener('resize', resizeCallback, false);
window.removeEventListener('scroll', flyout.align, false);
}
}
};
flyout.persist();
if (window.ue && ue.tag) {
ue.tag('ewc:persist');
}
} else {
if (window.ue && ue.tag) {
ue.tag('ewc:unpersist');
if (persistentCheck.reason === 'noAui') {
ue.tag('ewc:unpersist:noAui');
}
if (persistentCheck.reason === 'viewport') {
ue.tag('ewc:unpersist:viewport');
}
if (persistentCheck.reason === 'emptycart') {
ue.tag('ewc:unpersist:emptycart');
}
if (persistentCheck.reason === 'iOS') {
ue.tag('ewc:unpersist:iOS');
}
}
}
};
if (flyout.hasQualifiedViewportForPersistent()) {
ue.tag('ewc:bview');
}
else {
ue.tag('ewc:sview');
}
}
flyout.bindEvents();
flyout.cache = function () {
const cache = window.sessionStorage;
const CACHE_KEY = "EWCBrowserCacheKey";
const CACHE_EXPIRY = "EWCBrowserCacheExpiry";
const CACHE_VALUE = "EWCBrowserCacheValue";
const isSessionStorageValid = function () {
return window && cache && cache instanceof Storage;
};
const isCachePresent = function (key) {
return cache.length > 0 && cache.getItem(key);
}
const isValidType = function (value) {
// Prevents accessing empty key-value and internal methods(prototypes) of storage
// TODO: Log metrics for invalid access;
return value && value.constructor == String;
}
return {
getCache: function (key) {
const value = isCachePresent(key);
return (isValidType(value)) ? value : null;
},
setCache: function (key, value) {
const oldValue = isCachePresent(key);
const cacheExpiryTime = isCachePresent(CACHE_EXPIRY);
// Set the expiry when there's no existing cache - to prevent resetting expiry on page navigation
if (!cacheExpiryTime) {
var currentTime = new Date();
cache.setItem(CACHE_EXPIRY, new Date(currentTime.getTime() + 5 * 60000))
}
// TODO: Log length of old and new cache values when logMetrics is true
cache.setItem(key, value);
},
updateCacheAndEwcContainer: function (cacheKey, newEwcContent) {
const $ = $Nav.getNow("$");
const $currentEwc = $("#ewc-content");
if (!$currentEwc.length) {
var $content = $('#nav-flyout-ewc .nav-ewc-content');
$content.html(newEwcContent);
this.setCache(CACHE_KEY, cacheKey);
if (window.ue && window.ue.count) {
var current = window.ue.count("ewc-init-cache") || 0;
window.ue.count("ewc-init-cache", current + 1);
}
} else {
var $newEwcContent = $('
var EWC_CONTENT_BODY_SCROLL_SELECTOR = ".ewc-scroller--selected";
if (newEwcContent) { // 1. Updates EWC container with new HTML
const $newEwcHtml = $newEwcContent.html(newEwcContent).find("#ewc-content");
const offSet = $currentEwc.find(EWC_CONTENT_BODY_SCROLL_SELECTOR).position().top - $currentEwc.find(".ewc-active-cart--selected").position().top;
$currentEwc.html($newEwcHtml.html());
$currentEwc.find(EWC_CONTENT_BODY_SCROLL_SELECTOR).scrollTop(offSet);
if (typeof window.uex === 'function') {
window.uex('ld', 'ewc-reflect-new-state', {wb: 1});
}
} else {
// 2. Fetches cached response and updates it's html with new state on EWC Update
const cachedEwc = this.getCache(CACHE_VALUE);
$newEwcContent = $newEwcContent[0];
$(cachedEwc).map(function (elementIndex, element) {
$newEwcContent.appendChild((element.id === "ewc-content") ? $currentEwc.clone()[0] : element);
});
newEwcContent = $newEwcContent.innerHTML;
if (window.ue && window.ue.count) {
var current = window.ue.count("ewc-update-cache") || 0;
window.ue.count("ewc-update-cache", current + 1);
}
}
$newEwcContent.remove();
}
this.setCache(CACHE_VALUE, newEwcContent);
},
removeCache: function (key) {
return cache.removeItem(key);
}
}
}
;
return flyout;
}());
P.register('ewc.pageload-content-loader', function(){
var isEwcLoadedOnLanding = false;
if(config.ewc.EarlyLoadEWCContentTreatment){
return {
loadContent: function(isFallback) {
if(!isEwcLoadedOnLanding) {
if (config.ewc.flyout.ableToPersist()) {
if(config.ewc.EarlyLoadEWCContentTreatment === "T2"){
setTimeout(function() {config.ewc.flyout.loadEwcContent()}, 500);
} else if (config.ewc.EarlyLoadEWCContentTreatment === "T3") {
setTimeout(function() {config.ewc.flyout.loadEwcContent()}, 1000);
} else if (config.ewc.EarlyLoadEWCContentTreatment === "T4") {
setTimeout(function() {config.ewc.flyout.loadEwcContent()}, 2000);
} else {
config.ewc.flyout.loadEwcContent();
}
}
if(isFallback){
if (window.ue && window.ue.count) {
var current = window.ue.count("ewc-load-content-fallback") || 0;
window.ue.count("ewc-load-content-fallback", current + 1);
}
}
}
isEwcLoadedOnLanding = true;
}
}} else {
return {}};
});
});
.run("ewc.inline.ajax", function(config) {
var $ = A.$;
var $content = $('#nav-flyout-ewc .nav-ewc-content');
$content.html(config.ewc.errorContent.html).addClass('nav-tpl-flyoutError');
};
var urlParams = {};
if (isReloaded) {
urlParams['isReloaded'] = true;
} else {
if (config.ewc.freshCartCount !== undefined) {
urlParams['freshCartCount'] = config.ewc.freshCartCount;
}
if (config.ewc.almCartCount !== undefined) {
urlParams['almCartCount'] = config.ewc.almCartCount;
}
if (config.ewc.primeWardrobeCartCount !== undefined) {
urlParams['primeWardrobeCartCount'] = config.ewc.primeWardrobeCartCount;
}
}
urlParams.widerCompactView = window.innerWidth > 1280;
return urlParams;
};
$.ajax({
url: config.ewc.url,
data: getUrlParams(isReloaded),
type: "GET",
dataType: config.ewc.isCompactEWCRendered ? "html" : "json",
cache: false,
timeout: config.ewc.timeout || 30000,
beforeSend: function() {
if (!config.ewc.isCompactEWCRendered) {
$content.addClass('nav-spinner');
if (typeof window.uet === 'function') {
window.uet('af', 'ewc', {wb: 1});
}
} else {
if (typeof window.uet === 'function') {
window.uet('af', 'ewc2-compact', {wb: 1});
}
}
},
error: displayErrorContent,
success: function(result) {
if (typeof window.uet === 'function') {
window.uet('bb', 'ewc', {wb: 1});
}
if (config.ewc.isCompactEWCRendered) {
if (!isReloaded) {
P.register('EWC', function () {
if (window.EwcP === undefined) {
window.EwcP = (window.AmazonUIPageJS || P);
}
return {
refresh : function () {
if (window.ue && window.ue.count) {
window.ue.count("ewc2-refresh", 1);
}
config.ewc.flyout.loadEwcContent(true);
P.when('EWCRefreshCallback').execute(function(callback) {
callback.update();
});
}
}
});
} else {
var cartQuantity = $(result).find('#ewc-total-quantity').val();
if (window.$Nav && cartQuantity) {
window.$Nav.when('api.setCartCount').run(function(setCartCount) {
setCartCount(parseInt(cartQuantity), true);
});
};
}
cache.updateCacheAndEwcContainer("EWC_Cache_135-8583978-5838312__USD_en_US", result);
if (typeof window.uet === 'function') {
window.uet('be', 'ewc', {wb: 1});
}
},
complete: function() {
if (!config.ewc.isCompactEWCRendered) {
$content.removeClass('nav-spinner');
}
if (typeof window.uet === 'function') {
window.uet('cf', 'ewc', {wb: 1});
}
if (typeof window.uex === 'function') {
window.uex('ld', 'ewc', {wb: 1});
}
}
});
};
});
(window.P && window.P.AUI_BUILD_DATE) && (window.AmazonUIPageJS ? AmazonUIPageJS : P)
.when('ewc.pageload-content-loader','atf').execute('ewcPageLoadContentLoader' , function(ewcPageLoadContentLoader,atf) {
if (window.ue && window.ue.count) {
var current = window.ue.count("ewc-load-content") || 0;
window.ue.count("ewc-load-content", current + 1);
}
ewcPageLoadContentLoader.loadContent(false);
});
});
const CACHE_VALUE = "EWCBrowserCacheValue";
const CACHE_EXPIRY = "EWCBrowserCacheExpiry";
var cache = config.flyout.cache();
// Check for page types and tenure of the cache
const clearCache = config.clearCache;
const cacheExpiryTime = cache.getCache(CACHE_EXPIRY);
const isCacheExpired = new Date() > new Date(cacheExpiryTime);
const cacheKey = config.EWCBrowserCacheKey;
const oldCacheKey = cache.getCache(CACHE_KEY);
const isCacheValid = !clearCache && !isCacheExpired && cacheKey == oldCacheKey;
if (!isCacheValid && window.ue && window.ue.count) {
var current = window.ue.count("ewc-cache-invalidated") || 0;
window.ue.count("ewc-cache-invalidated", current + 1);
}
return isCacheValid;
}
function loadFromCache() {
if (window.uet && typeof window.uet === 'function') {
window.uet('bb', 'ewc-loaded-from-cache', {wb: 1});
}
if (cache) {
if (isCacheValid()) {
var content = cache.getCache(CACHE_VALUE);
if (content) {
var $ewcContainer = document.getElementById("nav-flyout-ewc").getElementsByClassName("nav-ewc-content")[0];
var $ewcContent = document.getElementById("ewc-content");
if ($ewcContainer && !$ewcContent) {
$ewcContainer.innerHTML = content;
// Execute scripts from cache
const ewcJavascript = document.getElementById("ewc-content").parentNode.querySelectorAll(':scope > script');
ewcJavascript.forEach(function (script) {
var scriptTag = document.createElement("script");
scriptTag.innerHTML = script.innerHTML;
document.body.appendChild(scriptTag);
});
if (typeof window.uex === 'function') {
window.uex('ld', 'ewc-loaded-from-cache', {wb: 1});
}
} else if (window.ue && window.ue.count && typeof window.ue.count === 'function') {
var currentFailure = window.ue.count("ewc-slow-cache") || 0;
window.ue.count("ewc-slow-cache", currentFailure + 1);
}
}
} else {
cache.removeCache(CACHE_VALUE);
cache.removeCache(CACHE_KEY);
cache.removeCache(CACHE_EXPIRY);
}
}
}
function delayBy(delayTime) {
if (delayTime) {
window.setTimeout(function() {
loadFromCache();
}, delayTime)
} else {
loadFromCache();
}
}
if(config.delayRenderingTillATF) {
(window.AmazonUIPageJS ? AmazonUIPageJS : P).when('atf').execute("EverywhereCartLoadFromCacheOnAtf", function () {
delayBy(config.loadFromCacheWithDelay);
});
} else {
delayBy(config.loadFromCacheWithDelay);
}
}()));
uet('x2', 'ewc', {wb: 1});
}
ue.tag('ewc');
ue.tag('ewc:unrec');
ue.tag('ewc:cartsize:0');
ue.tag('ewc:aui');
} else {
ue.tag('ewc:noAui');
}
}
}());
// ============================================================================= // Function Class: Show/Hide product promotions & special offers link // =============================================================================
function showElement(id) { var elm = document.getElementById(id); if (elm) { elm.style.visibility = 'visible'; if (elm.getAttribute('name') == 'heroQuickPromoDiv') { elm.style.display = 'block'; } } } function hideElement(id) { var elm = document.getElementById(id); if (elm) { elm.style.visibility = 'hidden'; if (elm.getAttribute('name') == 'heroQuickPromoDiv') { elm.style.display = 'none'; } } } function showHideElement(h_id, div_id) { var hiddenTag = document.getElementById(h_id); if (hiddenTag) { showElement(div_id); } else { hideElement(div_id); } }
if(typeof P === 'object' && typeof P.when === 'function'){ P.register("isLazyLoadWeblabEnabled", function(){ var isWeblabEnabled = 1; return isWeblabEnabled; }); }
window.isBowserFeatureCleanup = 0;
var touchDeviceDetected = false;
P.now('sp.load.js').execute(function(jsObj){ if(!jsObj){ P.declare('sp.load.js', {}); if (window.ue && ue.count){ ue.count("jsLoadedAtStartMarkerCount", 1); } } });
var CSMReqs={af:{c:2,p:'atf'},cf:{c:2,p:'cf'},x1:{c:1,p:'x1'},x2:{c:1,p:'x2'}}; var prioritizeCriticalModules = true; function setCSMReq(a){ a=a.toLowerCase(); var b=CSMReqs[a]; if(b&&--b.c==0){ if(typeof uet=='function'){uet(a); (a == 'af') && (typeof replaceImg === 'function') && replaceImg();};
if (a == 'af' && prioritizeCriticalModules){
var featureElements = document.getElementsByClassName('dp-cif');
if(featureElements.length){
var priorityModuleList = ["A","jQuery"];
var moduleMap = {
'A' : 1,
'jQuery' : 1
};
for (var i = 0; i
P.when("p-detect").execute(function() { var h = document.documentElement; h.className = h.className.replace(/(^|b)a-touch(b|$)/g,""); });
window.weblabs = {}; window.weblabs['booksUDP'] = 1;
if(typeof P !== "undefined" && typeof P.when === "function"){ P.when('cf').execute(function() { P.when('navbarJS-jQuery').execute(function(){}); P.when('finderFitsJS').execute(function(){}); P.when('twister').execute(function(){}); P.when('swfjs').execute(function(){});
}); }
');
doc.close();
}
}
this.iframeload = function () {
var iframe = document.getElementById(iframeId);
iframe.style.display = '';
setTimeout(function () {
setIframeHeight(initialResizeCallback);
}, 20);
}
function getDocHeight(doc) {
var contentDiv = doc.getElementById("iframeContent");
var docHeight = 0;
if(contentDiv){
docHeight = Math.max(
contentDiv.scrollHeight,
contentDiv.offsetHeight,
contentDiv.clientHeight
);
}
return docHeight;
}
function setIframeHeight(resizeCallback) {
var iframeDoc, iframe = document.getElementById(iframeId);
iframeDoc = ((iframe.contentWindow && iframe.contentWindow.document) || iframe.contentDocument);
if (iframeDoc) {
var h = getDocHeight(iframeDoc);
if (h && h != 0) {
iframe.style.height = parseInt(h) + 'px';
if(typeof resizeCallback == "function") {
resizeCallback(iframeId);
}
} else if (nTries < MAX_TRIES) {
nTries++;
setTimeout(function () {
setIframeHeight(resizeCallback);
}, 50);
}
}
}
this.resizeIframe = function(resizeCallback) {
nTries = 0;
setIframeHeight(resizeCallback);
}
}
return DynamicIframe;
});