/**
* Rich Cart Widget
* This widget provides the main rich cart functionality.
* Created by Jim Barraud, 10/11/06
* Reworked by James Wiltshire, 01/17/2007
*
* Updated to Dojo 1.0
*/
dojo.provide("atg.store.widget.RichCartSummary");
// dojo.require("dojo.fx");
// dojo.require("dijit._Widget");
// dojo.require("dijit._Templated");
// dojo.require("dijit._Container");
//dojo.require("atg.store.widget.RichCartSummaryItem");
dojo.declare(
"atg.store.widget.RichCartSummary",
[dijit._Widget, dijit._Templated, dijit._Container],
{
// Define all global variables for the widget.
// templateString: dojo.cache("dijit", contextPath + "/javascript/widget/template/richCartSummary.html"),
// dojo.uri.dojoUri(contextPath+"/javascript/widget/template/richCartSummary.html"),
templateString: '
',
// Widget properties
triggerWidget: null, // Reference to trigger widget
data: null, // Cart data - should be set with initial widget initialisation properties
quantityNodeId: null, // DOM ID of the node to contain the cart quantity - i.e. "Show Cart (3)"
hijackClassName: null, // CSS class used to signify forms/anchors to hijack
highlightColor: null, // Color used to highlight newly added items
firstPlacementDone: false,
cartAnimationInProgress: false,
duration:{
// Durations in ms of animation elements
highlight: 3000,
scroll:500,
wipe: 280,
autoHide:5000
},
/**
* Initialize the widget
*/
afterStartup: function(){
console.debug("Initializing RichCartSummary widget");
// Load any initial data into the widget
if (this.data!==null){
this.setAllCartData(this.data);
}
// Hook up event handling
var _this=this;
dojo.connect(window, "onresize", this, "placeCart");
dojo.connect(window, "onscroll", this, "placeCart");
dojo.connect(document.body, "onclick", function(evt){
// If body is clicked and cart is showing, hide it.
var type=evt.target.nodeName;
//Ignore clicks on links or submit buttons as they'll be perfoming an action themselves.
//if (_this.isShowing && type!="A" && type!="INPUT" && type!="BUTTON"){
_this.hide();
//}
});
dojo.connect(this.domNode, "onclick", function(evt){
// Prevent body from handling click within the cart
evt.stopPropagation();
});
this.triggerWidget=dijit.byId("richCartTrigger");
if (this.doHijack===true){
this.hijackAllAddToCartNodes();
}
},
/*
* Replace postCreate with startup. postCreate removed from dojo 0.9
*/
startup: function(){
console.debug("Startup RichCartSummary widget");
var _this=this;
dojo.addOnLoad(function(){
// Prepare for first show animation - hide the element's domNode and call the
// hide animation. Set a callback to change the visibility when hide is complete.
_this.domNode.style.visibility="hidden";
_this.attachToContainer();
_this.hide(function(){
_this.domNode.style.visibility="visible";
});
});
this.afterStartup();
},
/**
* Set the rich cart to display all of the passed in data. This function will be
* called whenever the rich cart widget is initialised (i.e. on page load) and
* also whenever an item has been added to the cart and a JSON XHR response
* is received containing the new cart contents.
*/
setAllCartData: function(pData){
console.debug("Setting all cart data");
// console.debug(pData);
this.data=pData;
this.clearCartItems();
this.setCartSummaryData();
if (pData.items){
// Create CartSummaryItem widget for each line item and add to this parent widget
for (var i=0; i 0) ? cartLeft : 0;
// Top position is directly under the trigger link
triggerHeight = dojo._getMarginBox(node.parentNode).h;
scrollOffsetHeight=dijit.getViewport().t;
console.debug('scrollOffsetHeight' + scrollOffsetHeight);
cartTop = pos.y;
cartTop = (cartTop-scrollOffsetHeight > 0) ? cartTop : scrollOffsetHeight;
console.debug("Placing cart @ "+cartLeft+", "+cartTop);
this.domNode.style.left=cartLeft+"px";
this.domNode.style.top=cartTop+"px";
this.domNode.style.zIndex="1000";
// If we have a bgIframe for IE6, resize it so it's positioned directly under the cart
if (this.bgIframe){
this.bgIframe.size(this.domNode);
}
},
/**
* Show the Rich Cart
*/
show: function(callback) {
console.debug('show cart');
if (this.isShowing){
// If we've been passed a callback function, then call it even if we're showing. It's
// most likely that a new item has been added, and the callback is the highlight
if (callback){
callback();
}
return;
}
if (this.cartAnimationInProgress===true){
return;
}
this.cartAnimationInProgress=true;
this.placeCart();
var _this=this;
console.debug('show:node: ' + this.domNode);
console.debug('show:duration: ' + this.duration.wipe);
var wipeAnimation=dojo.fx.wipeIn({
node: this.domNode,
duration: this.duration.wipe,
onEnd: function() {
_this.isShowing = true;
_this.cartAnimationInProgress=false;
// IE6 - prevent form elements from shining through cart with hidden bg iframe
if(dojo.isIE){
if(dojo.isIE < 6){
if(!_this.bgIframe){
_this.bgIframe = new dijit.BackgroundIframe();
_this.bgIframe.setZIndex(_this.domNode);
}
_this.bgIframe.size(_this.domNode);
_this.bgIframe.show();
}
}
if (callback && dojo.isFunction(callback)){
callback();
}
}
});
console.debug("after wipe animation");
var fadeAnimation=dojo.fadeIn({
node: this.domNode,
properties: {
opacity: {
start:0.3,
end:0.1
}},
duration: this.duration.wipe}
);
dojo.fx.combine([wipeAnimation,fadeAnimation]).play();
this.triggerWidget.updateTriggerDisplay();
},
/**
* Hide the Rich Cart
*/
hide: function(callback){
if (this.cartAnimationInProgress===true){
return;
}
this.cartAnimationInProgress=true;
var _this=this;
console.debug('hide:node: ' + this.domNode);
console.debug('hide:duration: ' + this.duration.wipe);
var wipeAnimation=dojo.fx.wipeOut({
node: this.domNode,
duration: this.duration.wipe,
onEnd: function(){
_this.isShowing = false;
_this.cartAnimationInProgress=false;
_this.triggerWidget.updateTriggerDisplay();
// IE6 - Prevent form element shine through - hide hidden iframe
if(_this.bgIframe){
_this.bgIframe.hide();
_this.bgIframe.size({left:0, top:0, width:0, height:0});
}
if (callback && dojo.isFunction(callback)){
callback();
}
}});
// var fadeAnimation=dojo.fadeIn(this.domNode, { start:1, end: 0.8 }, this.duration.wipe);
var fadeAnimation=dojo.fadeOut({node: this.domNode,
properties: {
opacity: {
start:1,
end:0.8
}},
duration: this.duration.wipe}
);
dojo.fx.combine([wipeAnimation,fadeAnimation]).play();
this.clearAutoHide();
},
/*
* Get an array of all items that have been flagged as 'modified. This will
* usually be just a single item - the item that has just been added to the cart.
*/
getChangedItemWidgets: function(){
var changedItems=[];
var item;
var children = this.getChildren();
for (var i=0; i0){
changedItems[0].scrollIntoView();
}
for (var i=0; i and tags that are submitted or clicked
* to add items to the cart. All of these nodes must be 'hijacked' so that the
* http request uses XHR so that the rich cart can operate.
*/
hijackAllAddToCartNodes: function(){
console.debug("Connecting RichCart to all elements with class ["+this.hijackClassName+"]");
var _this = this;
console.debug('class name: ' + this.hijackClassName);
dojo.query("*."+this.hijackClassName).forEach(function(node) {
_this.hijackNode(node);
});
},
/*
* Hijack a node. The node should be either a