Created
May 26, 2010 03:07
-
-
Save willbailey/414008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cart = (function(){ | |
return { | |
// windows to update | |
windowsToUpdate : function(){ | |
var windowsToUpdate = [window]; | |
if (window.opener) windowsToUpdate.push(window.opener); | |
return jQuery(windowsToUpdate); | |
}, | |
// start a timer to update the cart icon periodically | |
init : function(){ | |
var me = this; | |
clearInterval(this.updater); | |
this.updater = setInterval(function(){ | |
me.updateCartIcon(); | |
}, 200); | |
}, | |
// calculate the total items in the current cart | |
totalItems : function(){ | |
var total = 0; | |
jQuery('.product.quantity input').each(function(i, elem){ | |
total = total + parseInt(elem.value,10); | |
}); | |
return total; | |
}, | |
// update the cart icon on this window and the opener if applicable | |
updateCartIcon : function(){ | |
var totalItems = this.totalItems(); | |
if (isNaN(totalItems)) return; | |
this.windowsToUpdate().each(function(i, win){ | |
var cartElem = win.jQuery('.header-item.right-divide')[4]; | |
if (cartElem) { | |
cartElem.innerHTML = '<a href="/en/Revlon-Home/Revlon-General/View-Cart.aspx">' + | |
totalItems + ' ' + | |
'<img src="http://images.revlon.com/%7E/media/Images/Revlon/cart-icon.ashx"' + | |
'alt="Cart" height="16" width="20"></a>'; | |
} | |
}); | |
} | |
} | |
})(); | |
cart.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment