Learn how to use jQuery at the Blog

Pasta Harvest « visit

  • Added 9 months ago
  • 214 Lines of Code shown
  • 4 Links of Interest
http://pastaharvest.com
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Pasta Harvest - http://pastaharvest.com

/* Page Ready */ 
var vmod;

$(document).ready(function() {
    $.preloadImages('/images/header/mainnav-sprite.gif', '/images/footer/footer-nav-sprite.png');

    $('#getmesomepasta').bind('click', function() {
        
        pageTracker._trackEvent('signup', 'open');

        $('#modal').modal({

            containerCss: {
                height: '450px',
                width: '500px',
                backgroundColor: '#e6d2b7',
                border: '15px solid #fff',
                color: 'Black',
                lineHeight: 'normal',
                padding: '5px 50px  5px 50px',
                overflow: 'auto',
                overflowX: 'hidden'
            },

            onOpen: function(dialog) {


                dialog.overlay.fadeIn('slow', function() {
                    $('#modal').fadeIn('slow');
                    dialog.container.slideDown('slow', function() {
                        //dialog.data.fadeIn('slow');

                    });
                });

                $('#simplemodal-overlay').bind('click', function() {
                    $.modal.close();
                });
            },


            onClose: function(dialog) {


                dialog.container.slideUp('slow', function() {
                    dialog.overlay.fadeOut('fast');
                    dialog.data.fadeOut('slow', function() {
                        $.modal.close();
                    });
                });

            },
            onShow: function(dialog) {
                $("#contactform").validate({
                    rules:
                                {
                                    fullname: {
                                        required: true
                                    },
                                    email: {
                                        email: true,
                                        required: true
                                    },
                                    address: {
                                        required: true
                                    },
                                    city: {
                                        required: true

                                    },
                                    stated: {

                                        required: true
                                    },
                                    zip: {
                                        required: true,
                                        minlength: 5,
                                        maxlength: 5
                                    }
                                },

                    messages: {
                        fullname: "required",
                        address: "required",

                        email: { required: "required",
                            email: "invalid"
                        }
                                        ,

                        address: "required",
                        city: "all required",
                        stated: { required: "all required"

                        },
                        zip: { required: "all required",
                            minlength: "all required",
                            maxlength: "all required",
                            digits: true
                        }
                    }

                   ,
                    errorPlacement: function(error, element) {
                        //alert(element.attr('id'));
                        // element.addClass('badboy');
                        if (element.attr('id') == 'stated' || element.attr('id') == 'city' || element.attr('id') == 'zip') {
                            element.nextAll('span:first').html(error);
                        } else {
                            error.appendTo(element.nextAll('span:first'));


                        }

                    }

                });


                $('#btnCancel').bind('click', function() {
                    pageTracker._trackEvent('signup', 'cancel');
                    $.modal.close();
                });

                $('#btnSend').bind('click', function() {
                    $('input').removeClass('badboy');
                    if ($('#contactform').valid()) {
                        if (PastaContest($.modal)) {
                            // $.modal.close();
                        } else {
                        }
                    } else {
                        $('#fixform').show('slow');
                        //$('#fixform').html('All fields are required. ');
                    }
                });
            }
        });
    });

});

function q(s) {
    return "'" + s + "'";
}


function PastaContest(m) {
    var validentry = 1;
    var fullname = q($('#fullname').val());
    var email = q($('#email').val());
    var address = q($('#address').val());
    var city = q($('#city').val());
    var state = q($('#stated').val());
    var zip = q($('#zip').val());

    var pdata = "{FullName:" + fullname + ",Email:" + email + ",Address:" + address + ",City: " + city + ",State:" + state + ",Zip:" + zip + "}";
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "res/webservices/PastaContest.asmx/Contest",
        data: pdata,
        beforeSend: function(XMLHttpRequest) {

            $('#fixform').html('<img src="res/images/waiting.gif" alt="" />');
        }

                ,
        dataType: "json",
        success: function(msg) {

            validentry = msg.d.success;

            if (msg.d.success == 0) {

                vmod = m;
                pageTracker._trackEvent('signup', 'success');
                $('.button').hide();
                $('#fixform').html('');
                $('#fixform').before('<span id="countertext">We have received your entry.  This window will close in </span><span id="counter"></span>');
                $('#counter').countdown({ seconds: 3, callback: 'closemodal()' });
                //m.close();
            } else {
                switch (msg.d.success) {
                    case 999:
                        $('#fixform').html('Only one entry per day.  Please try again tomorrow.');
                        break;
                    case 1000:
                        $('#fixform').html('All fields required.');
                        break;
                    default:
                        $('#fixform').html('General Error');
                }

            }

        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            // some kind of error
            $('#fixform').html('There was an error.  Please try again later');
            validentry = 1;



        }


    });
    return validentry == 0;
}

function closemodal() {
    vmod.close();
}