olie480
05-30-11, 08:02 PM
Hey all, we are using the Ajaxcart order form in the new WHMCS 4.5 system, and we just modified a little bit of code to automatically scroll the page to the next input when the continue button is pressed. We did this because the way we listed our products had a pretty long height to it. So basically here are the modifications we did. BE SURE TO BACK UP YOUR AJAXCART DIRECTORY.
(add this to your template header.tpl underneath the jQuery link)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
{literal}
<script type="text/javascript">
function scrollTo(selector) {
var targetOffset = $(selector).offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1500, 'swing');
}
{/literal}
(orderforms/ajaxcart/configureproductdomain.tpl)
Change:
function completedomain() {
jQuery("#loading2").slideDown();
jQuery.post("cart.php", 'ajax=1&a=add&pid={/literal}{$pid}{literal}&'+jQuery("#domainfrm").serialize(),
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer2").html(data);
jQuery("#configcontainer2").slideDown();
jQuery("#loading2").slideUp();
}
});
}
to
function completedomain() {
jQuery("#loading2").slideDown();
jQuery.post("cart.php", 'ajax=1&a=add&pid={/literal}{$pid}{literal}&'+jQuery("#domainfrm").serialize(),
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer2").html(data);
jQuery("#configcontainer2").slideDown();
scrollTo('#configcontainer2');
jQuery("#loading2").slideUp();
}
});
}
(orderforms/ajaxcart/js/main.js)
change
function signupstep() {
jQuery.post("cart.php", 'a=checkout&ajax=1',
function(data){
jQuery("#signupcontainer").html(data);
jQuery("#signupcontainer").slideDown();
jQuery("#prodconfloading").slideUp();
jQuery("#domainconfloading").slideUp();
});
}
to
function signupstep() {
jQuery.post("cart.php", 'a=checkout&ajax=1',
function(data){
jQuery("#signupcontainer").html(data);
jQuery("#signupcontainer").slideDown();
scrollTo('#signupcontainer');
jQuery("#prodconfloading").slideUp();
jQuery("#domainconfloading").slideUp();
});
}
and change
function selectproduct(pid) {
jQuery("#loading1").slideDown();
jQuery("#configcontainer1").fadeOut();
jQuery("#configcontainer2").fadeOut();
jQuery("#configcontainer3").fadeOut();
jQuery("#signupcontainer").fadeOut();
jQuery.post("cart.php", 'ajax=1&a=add&pid='+pid,
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer1").html(data);
jQuery("#configcontainer1").slideDown();
}
jQuery("#loading1").slideUp();
recalcsummary();
});
}
to
function selectproduct(pid) {
jQuery("#loading1").slideDown();
jQuery("#configcontainer1").fadeOut();
jQuery("#configcontainer2").fadeOut();
jQuery("#configcontainer3").fadeOut();
jQuery("#signupcontainer").fadeOut();
jQuery.post("cart.php", 'ajax=1&a=add&pid='+pid,
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer1").html(data);
jQuery("#configcontainer1").slideDown();
scrollTo('#configcontainer1');
}
jQuery("#loading1").slideUp();
recalcsummary();
});
}
Now if your screen resolution is high enough, you won't see the change, but if you look at your page on a laptop, or actually change your resolution to let's say 800 x 600, then you'll see the difference. If you have any questions, let me know! Hope this helps out some people, just a nice useful effect.
(add this to your template header.tpl underneath the jQuery link)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
{literal}
<script type="text/javascript">
function scrollTo(selector) {
var targetOffset = $(selector).offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1500, 'swing');
}
{/literal}
(orderforms/ajaxcart/configureproductdomain.tpl)
Change:
function completedomain() {
jQuery("#loading2").slideDown();
jQuery.post("cart.php", 'ajax=1&a=add&pid={/literal}{$pid}{literal}&'+jQuery("#domainfrm").serialize(),
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer2").html(data);
jQuery("#configcontainer2").slideDown();
jQuery("#loading2").slideUp();
}
});
}
to
function completedomain() {
jQuery("#loading2").slideDown();
jQuery.post("cart.php", 'ajax=1&a=add&pid={/literal}{$pid}{literal}&'+jQuery("#domainfrm").serialize(),
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer2").html(data);
jQuery("#configcontainer2").slideDown();
scrollTo('#configcontainer2');
jQuery("#loading2").slideUp();
}
});
}
(orderforms/ajaxcart/js/main.js)
change
function signupstep() {
jQuery.post("cart.php", 'a=checkout&ajax=1',
function(data){
jQuery("#signupcontainer").html(data);
jQuery("#signupcontainer").slideDown();
jQuery("#prodconfloading").slideUp();
jQuery("#domainconfloading").slideUp();
});
}
to
function signupstep() {
jQuery.post("cart.php", 'a=checkout&ajax=1',
function(data){
jQuery("#signupcontainer").html(data);
jQuery("#signupcontainer").slideDown();
scrollTo('#signupcontainer');
jQuery("#prodconfloading").slideUp();
jQuery("#domainconfloading").slideUp();
});
}
and change
function selectproduct(pid) {
jQuery("#loading1").slideDown();
jQuery("#configcontainer1").fadeOut();
jQuery("#configcontainer2").fadeOut();
jQuery("#configcontainer3").fadeOut();
jQuery("#signupcontainer").fadeOut();
jQuery.post("cart.php", 'ajax=1&a=add&pid='+pid,
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer1").html(data);
jQuery("#configcontainer1").slideDown();
}
jQuery("#loading1").slideUp();
recalcsummary();
});
}
to
function selectproduct(pid) {
jQuery("#loading1").slideDown();
jQuery("#configcontainer1").fadeOut();
jQuery("#configcontainer2").fadeOut();
jQuery("#configcontainer3").fadeOut();
jQuery("#signupcontainer").fadeOut();
jQuery.post("cart.php", 'ajax=1&a=add&pid='+pid,
function(data){
if (data=='') {
signupstep();
} else {
jQuery("#configcontainer1").html(data);
jQuery("#configcontainer1").slideDown();
scrollTo('#configcontainer1');
}
jQuery("#loading1").slideUp();
recalcsummary();
});
}
Now if your screen resolution is high enough, you won't see the change, but if you look at your page on a laptop, or actually change your resolution to let's say 800 x 600, then you'll see the difference. If you have any questions, let me know! Hope this helps out some people, just a nice useful effect.