/** * This file holds javscript functions that are used by the templates in the Theme * */ // AJAX FUNCTIONS function loadNewPage( el, url ) { var theEl = $(el); var callback = { success : function(responseText) { theEl.innerHTML = responseText; if( Lightbox ) Lightbox.init(); } } var opt = { // Use POST method: `get`, // Handle successful response onComplete: callback.success } new Ajax( url + `&only_page=1`, opt ).request(); } function handleGoToCart() { document.location = live_site + `/index.php?option=com_virtuemart&page=shop.cart&product_id=` + formCartAdd.product_id.value ; } var flyingSpeed = 10; var shopping_cart_id = `vmCartModule`; var shopping_cart_div = false; var flyingDiv = false; var currentProductDiv = false; var shopping_cart_x = false; var shopping_cart_y = false; var slide_xFactor = false; var slide_yFactor = false; var diffX = false; var diffY = false; var currentXPos = false; var currentYPos = false; function shoppingCart_getTopPos(inputObj) { var returnValue = inputObj.offsetTop; while((inputObj = inputObj.offsetParent) != null){ if(inputObj.tagName!=`HTML`)returnValue += inputObj.offsetTop; } return returnValue; } function shoppingCart_getLeftPos(inputObj) { var returnValue = inputObj.offsetLeft; while((inputObj = inputObj.offsetParent) != null){ if(inputObj.tagName!=`HTML`)returnValue += inputObj.offsetLeft; } return returnValue; } function addToBasket(product_id) //productId - id of html element to move to cart { productId = `vm_pic`+product_id; if(!shopping_cart_div) shopping_cart_div = document.getElementById(shopping_cart_id); // id of cart if(!flyingDiv){ flyingDiv = document.createElement(`DIV`); flyingDiv.style.position = `absolute`; document.body.appendChild(flyingDiv); } shopping_cart_x = shoppingCart_getLeftPos(shopping_cart_div); shopping_cart_y = shoppingCart_getTopPos(shopping_cart_div); currentProductDiv = document.getElementById(productId); //currentProductDiv = document.getElementById(productId).parentNode.parentNode; currentXPos = shoppingCart_getLeftPos(currentProductDiv); currentYPos = shoppingCart_getTopPos(currentProductDiv); diffX = shopping_cart_x - currentXPos; diffY = shopping_cart_y - currentYPos; var shoppingContentCopy = currentProductDiv.cloneNode(true); shoppingContentCopy.id=``; flyingDiv.innerHTML = ``; flyingDiv.style.left = currentXPos + `px`; flyingDiv.style.top = currentYPos + `px`; flyingDiv.appendChild(shoppingContentCopy); flyingDiv.style.display=`block`; flyingDiv.style.width = currentProductDiv.offsetWidth + `px`; flyToBasket(); } function flyToBasket() { var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY)); var moveX = (diffX / maxDiff) * flyingSpeed; var moveY = (diffY / maxDiff) * flyingSpeed; currentXPos = currentXPos + moveX; currentYPos = currentYPos + moveY; flyingDiv.style.left = Math.round(currentXPos) + `px`; flyingDiv.style.top = Math.round(currentYPos) + `px`; if(moveX>0 && currentXPos > shopping_cart_x){ flyingDiv.style.display=`none`; } if(moveX<0 && currentXPos < shopping_cart_x){ flyingDiv.style.display=`none`; } if(flyingDiv.style.display==`block`) setTimeout(`flyToBasket()`,10); else flyingDiv.innerHTML = ``; } function handleAddToCart( formId, product_id) { formCartAdd = document.getElementById( formId ); addToBasket(product_id); var callback = function(responseText) { updateMiniCarts(); // close an existing mooPrompt box first, before attempting to create a new one (thanks wellsie!) if (document.boxB) { document.boxB.close(); } } var opt = { // Use POST method: `post`, // Send this lovely data data: $(formId), // Handle successful response onComplete: callback, evalScripts: true } new Ajax(formCartAdd.action, opt).request(); } /** * This function searches for all elements with the class name "vmCartModule" and * updates them with the contents of the page "shop.basket_short" after a cart modification event */ function updateMiniCarts() { var callbackCart = function(responseText) { carts = $$( `.
Copyright 2010 - All rights reserved Your Company name
Related Posts
Many Tags
May 2, 2008Readability Test
May 1, 2008Many Tags
May 2, 2008Readability Test
May 1, 2008