0

我陷入了一个 JavaScript 问题,我不知道如何解决。

我在博客中有一个联系模式:http ://www.northernvirginiapaintingcontractor.com/blog 点击“发送页面”

当您单击它时,您将看到问题。联系模式不会一直打开。

将其与父应用程序上功能正常的相同“发送页面”按钮进行比较。http://www.northernvirginiapaintingcontractor.com

这利用了 Eric Martin 的 Simple Modal 的修改版本。

修改了 Contact.js 以启用动态高度,以及与同一脚本一起使用的几种不同的联系模式。

其他 3 个 .js 文件包括:actual.js jquery-easing-1.3.pack.js jquery-easing-compatibility.1.2.pack.js

这是有问题的contact.js:我没有丝毫线索,如果其他人这样做会很棒。

jQuery(function ($) {
var contact = {
    message: null,
    init: function () {
        $('#contact-form input.contact, a.contact').click(function (e) {
            e.preventDefault();

            // Create the 1stModal dialog with the data

            $('#modal-contact-form').modal({
                closeHTML: "<a href='#' title='Close' class='modal-close'>Close Pager Modal</a>",
                //maxHeight: 62,
                //maxWidth: 62,
                //minHeight: 62,
                //minWidth: 62,
                position: [98, 377],
                //autoPosition: false,
                autoResize: true,
                //overlayId: 'contact-overlay',
                containerId: 'contact-container',
                containerCss: { 'width': '350px'},
                onOpen: contact.open,
                onShow: contact.show,
                onClose: contact.close
            });
        });

        $('#contact-form input.suportecontacto, a.suportecontacto').click(function (e) {
            e.preventDefault();

            // Create the 2nd Modal dialog with the data

            $('#modal-soporte-form').modal({
                closeHTML: "<a href='#' title='Close' class='modal-close'>Close Ticket Modal</a>",
                //maxHeight: 62,
                //maxWidth: 62,
                //minHeight: 62,
                //minWidth: 62,
                position: [98, 377],
                //autoPosition: false,
                autoResize: true,
                //overlayId: 'contact-overlay',
                containerId: 'contact-container',
                containerCss: { 'width': '350px' },
                onOpen: contact.open,
                onShow: contact.show,
                onClose: contact.close
            });
        });

        $('#contact-indivform input.indivcontacto, a.indivcontacto').click(function (e) {
            e.preventDefault();

            // Create the 3rd Modal dialog with the data

            $('#modal-indivcontact-form').modal({
                closeHTML: "<a href='#' title='Close' class='modal-close'>Close Contacto Modal</a>",
                //maxHeight: 62,
                //maxWidth: 62,
                //minHeight: 62,
                //minWidth: 62,
                position: [98, 377],
                //autoPosition: false,
                autoResize: true,
                //overlayId: 'contact-overlay',
                containerId: 'contact-container',
                containerCss: { 'width': '350px' },
                onOpen: contact.open,
                onShow: contact.show,
                onClose: contact.close
            });
        });

        $('#HeadLogin').click(function (e) {
            e.preventDefault();

            // Create the Login modal

            $('#login_form').modal({
                closeHTML: "<a href='#' title='Cerrar' class='modal-close' style='padding-right:15px'>Cerrar Login Modal</a>",
                //maxHeight: 62,
                //maxWidth: 62,
                //minHeight: 62,
                //minWidth: 62,
                position: [110, 364],
                //autoPosition: false,
                autoResize: true,
                //overlayId: 'contact-overlay',
                containerId: 'contact-container',
                containerCss: { 'width': '310px' },
                onOpen: contact.open,
                onShow: contact.login,
                onClose: contact.close
            });
        });
    },
    open: function (dialog) {
        $('#ajax_loading').hide();
        $('.simplemodal-wrap').css('overflow-x', 'visible').css('overflow-y', 'visible');
        // add padding to the buttons in firefox/mozilla
        if ($.browser.mozilla) {
            $('#contact-container .contact-button').css({
                'padding-bottom': '2px'
            });
        }
        // input field font size
        if ($.browser.safari) {
            $('#contact-container .contact-input').css({
                'font-size': '.9em'
            });
        }

        // Dynamically determine Modal Height

        //var h = 280;
        //var h = 220;
        //if ($('#contact-subject').length) {
        //    h += 26;
        //}
        //if ($('#contact-cc').length) {
        //    h += 22;
        //}

        var h = $('#contact-container form').actual('outerHeight') + 30;

        var title = $('#contact-container .contact-title').html();
        $('#contact-container .contact-title').html('Loading...');
        dialog.overlay.fadeIn(200, function () {
            dialog.container.fadeIn(200, function () {
                dialog.data.fadeIn(200, function () {
                    $('#contact-container .contact-content').animate({
                        height: h
                    }, function () {
                        $('#contact-container .contact-title').html(title);
                        $('#contact-container form').fadeIn(200, function () {
                            $('#contact-container #contact-name').focus();

                            $('#contact-container .contact-cc').click(function () {
                                var cc = $('#contact-container #contact-cc');
                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                            });

                            // fix png's for IE 6
                            if ($.browser.msie && $.browser.version < 7) {
                                $('#contact-container .contact-button').each(function () {
                                    if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                        var src = RegExp.$1;
                                        $(this).css({
                                            backgroundImage: 'none',
                                            filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")'
                                        });
                                    }
                                });
                            }
                        });
                    });
                });
            });
        });
    },
    login: function() {
    $('#contact-container .contact-send').click(function (e) {
            e.preventDefault();
        // Hide 'Submit' Button
     if (contact.validateLogin()) {
        $('.contact-send').hide();
        $('.contact-cancel').hide();

        // Show Gif Spinning Rotator
        $('#ajax_loading').show();

        // 'this' refers to the current submitted form  
        var url ='';
        var str = $('#frmlogin').serialize();
        var path = window.location.pathname;
        var sub = 'Account';


        if(path.toUpperCase().indexOf(sub.toUpperCase()) != -1) {
            url = 'Login.aspx';
            var image = $('#ajax_loading img');
            image.attr('src','../images/spinner.gif');
        }
        else {
            url = 'Account/Login.aspx';
        }

        // -- Start AJAX Call --
        var form = $('#status form');
        $.ajax({
            type: "POST",
            //url: form[0].action,
            url: url,
            data: str,
            success: function (msg) {


            $("#status").ajaxComplete(function (event, request, settings) {

                // Show 'Submit' Button
                $('.contact-send').show();
                $('.contact-cancel').show();
                // Hide Gif Spinning Rotator
                $('#ajax_loading').hide();

                if (msg != 'False') // LOGIN OK?
                {
                    var login_response = '<div style="color:green; margin: 1px; float: right; width: 300px;">Ya Estás Conectado!<br />Por favor, espera mientras estas redirigido...</div>';
                    $('.contact-title').hide();

                    $('a.modalCloseImg').hide();
                    $('#frmlogin').hide();

                    $('#simplemodal-container').css("width", "500px");
                    $('#simplemodal-container').css("height", "140px");

                    $('#login_form .contact-message').html(login_response).show();      // Refers to 'status'

                    // After 1 second redirect the Logged-in User 
                    setTimeout(contact.redirect, 500);
                }
                else // ERROR?
                {
                    $('#login_form .contact-content').css("height", "150px");

                    $('#login_form .contact-message').html("Login failed!").css('color','red').show();
                }

            });

        }

    });
    }
    // -- End AJAX Call --

    else {
                if ($('#login_form .contact-message:visible').length > 0) {
                    var msg = $('#login_form .contact-message div');
                    msg.fadeOut(200, function () {
                        msg.empty();
                        contact.showError();
                        msg.fadeIn(200);
                    });
                }
                else {
                    $('#login_form .contact-message').animate({
                        height: '30px'
                    }, contact.showError);
                }

            }
    });


    },
    redirect: function() {
        window.location = '/'; // Members Area
    },
    show: function (dialog) {
        $('#contact-container .contact-send').click(function (e) {
            e.preventDefault();

            var form = $('#contact-container form');

            // validate form
            if (contact.validate()) {
                var msg = $('#contact-container .contact-message');
                msg.fadeOut(function () {
                    msg.removeClass('contact-error').empty();
                });
                $('#contact-container .contact-title').html('Sending...');
                $('#contact-container form').fadeOut(200);

                $('#contact-container .contact-content').animate({
                    height: '80px'
                }, function () {

                    var uname = $('#contact-container #contact-name').val();
                    var email = $('#contact-container #contact-email').val();
                    var cntx = $('#contact-container #contact-message').val();

                    var docc = "false";
                    if ($('#contact-container #contact-cc').is(':checked')) {
                        docc = "true";
                    }

                    $.ajax({
                      url: "blog/api/Blogs.asmx/SendMail",
                      data: "{'uname':'" + uname + "', 'email':'" + email + "','cntx':'" + cntx + "','docc':'" + docc + "'}",
                      type: "POST",
                      contentType: "application/json",
                      success: function (msg) {
                         //contact.close(dialog);
                         $('#contact-container .contact-loading').fadeOut(200, function () {
                            $('#contact-container .contact-title').html('Thank you!');
                            msg.html(data).fadeIn(200);
                            setTimeout(function () {
                                contact.close(dialog);
                            }, 1500);
                        });
                      }
                   });

                    contact.close(dialog);
                });
            }
            else {
                if ($('#contact-container .contact-message:visible').length > 0) {
                    var msg = $('#contact-container .contact-message div');
                    msg.fadeOut(200, function () {
                        msg.empty();
                        contact.showError();
                        msg.fadeIn(200);
                    });
                }
                else {
                    $('#contact-container .contact-message').animate({
                        height: '30px'
                    }, contact.showError);
                }
            }
        });
    },


    close: function (dialog) {

        $('#contact-container .contact-message').fadeOut();
        $('#contact-container .contact-title').html('Closing...');
        $('#contact-container form').fadeOut(200);

        $('#contact-container .contact-content').animate({
            height: 40
        }, function () {
            dialog.data.fadeOut(200, function () {
                dialog.container.fadeOut(200, function () {
                    dialog.overlay.fadeOut(200, function () {
                        $.modal.close();
                    });
                });
            });
        });
    },
    error: function (xhr) {
        alert(xhr.statusText);
    },
    validateLogin: function () {
        contact.message = '';

        if (!$('#username').val()) {

             contact.message += 'User name is required. ';
        }

        var pass = $('#password').val();
        if (!pass) {

            contact.message += 'Password is required. ';
        }
        if (contact.message.length > 0) {
            return false;
        }
        else {
            return true;
        }

    },
    validate: function () {
        contact.message = '';
        if (!$('#contact-container input[name="name"]').val()) {
            contact.message += 'Name is required. ';
        }

        var email = $('#contact-container input[name="email"]').val();
        if (!email) {
            contact.message += 'Email is required. ';
        }
        else {
            if (!contact.validateEmail(email)) {
                contact.message += 'Email is invalid. ';
            }
        }

        if (!$('#contact-container textarea[name="message"]').val()) {
            contact.message += 'Message is required.';
        }

        if (contact.message.length > 0) {
            return false;
        }
        else {
            return true;
        }
    },
    validateEmail: function (email) {
        var at = email.lastIndexOf("@");

        // Make sure the at (@) sybmol exists and  
        // it is not the first or last character
        if (at < 1 || (at + 1) === email.length)
            return false;

        // Make sure there aren't multiple periods together
        if (/(\.{2,})/.test(email))
            return false;

        // Break up the local and domain portions
        var local = email.substring(0, at);
        var domain = email.substring(at + 1);

        // Check lengths
        if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
            return false;

        // Make sure local and domain don't start with or end with a period
        if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
            return false;

        // Check for quoted-string addresses
        // Since almost anything is allowed in a quoted-string address,
        // we're just going to let them go through
        if (!/^"(.+)"$/.test(local)) {
            // It's a dot-string address...check for valid characters
            if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
                return false;
        }

        // Make sure domain contains only valid characters and at least one period
        if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
            return false;

        return true;
    },
    showError: function () {
        $('#contact-container .contact-message')
            .html($('<div class="contact-error"></div>').append(contact.message))
            .fadeIn(200);
    }
};

contact.init();

});
4

2 回答 2

0

这:

$('.contact-send').hide();
$('.contact-cancel').hide();

添加的显示:无;到这些元素,当您调用“打开”时它们不会被删除

于 2013-02-05T18:35:41.703 回答
0

simpleModal 插件以编程方式为 .simplemodal-wrap 类分配 100% 的高度,但 jquery.actual 插件因此在页面调整大小期间无法找到模态表单的正确高度。作为一种解决方法,我将最小高度重新设置为无论如何都显示完整形式的值。

.simplemodal-wrap { 最小高度:350px; 高度:自动!重要;/* IE6 及以下需要/ height: 350px; / IE6 及以下需要 */ }

网站.cshtml:

第 129 行的元素:具有内联样式 == "display: none;"。这没有被更改为 display: block; 当联系人模式打开时。我选择删除内联样式,因为其中一个祖先元素已经具有 display: none; 指定以及何时打开正确更改的模式。

于 2013-02-08T23:15:56.760 回答