JavaScript调整高度问题

时间:2013-02-05 18:28:07

标签: javascript

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

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

当您点击它时,您将看到问题。 Contact Modal不会一直打开。

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

这是使用Eric Martin的Simple Modal的修改版本。

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

其他3个.js文件包括: actual.js jQuery的宽松,1.3.pack.js jQuery的宽松-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();

});

2 个答案:

答案 0 :(得分:0)

此:

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

add's display:none;对于那些元素,当你打电话给“开放”时它们不会被删除

答案 1 :(得分:0)

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

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

site.cshtml:

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