1

I want to optimized some codes (I use jQuery UI):

$(function() {
    $('.click-login-modal').click(function() {
        $('.login-modal').dialog('open');
        return false;
    })

    $('.login-modal').dialog({
        autoOpen: false,
        width: 500,
        height:300,
        modal: true,
        resizable: false,
    })
    $('.click-register-modal').click(function() {
        $('.register-modal').dialog('open');
        return false;
    })

    $('.register-modal').dialog({
        autoOpen: false,
        width: 500,
        height:300,
        modal: true,
        resizable: false,
    })
})

It's possible? I have two deferential modals. (Dialog Popup)

2 Answers 2

3
var options = {
        autoOpen: false,
        width: 500,
        height:300,
        modal: true,
        resizable: false
    };

$(".register-modal").dialog(options);
$(".login-modal").dialog(options);

$('.click-register-modal, .click-login-modal').click(function() {
    $(this).dialog('open');
    return false;
});
Sign up to request clarification or add additional context in comments.

6 Comments

ie will have a fit with the closing comma!
thanks, I think $('.register-modal').dialog('open'); should be $('.login-modal, .register-modal').dialog('open');
@Mini - actually, it should be $(this).dialog('open');. Updated.
Opps. the optimized open two modals in the same time. why?
Argh! I guess they have to be bound one at a time.
|
0

I would use the tabs approach, where the href would point to the element ID, so you can change your modal classes to IDs and then use:

var options = {
        autoOpen: false,
        width: 500,
        height:300,
        modal: true,
        resizable: false
    };

$(".register-modal").dialog(options);
$(".login-modal").dialog(options);

$('.click-register-modal, .click-login-modal').click(function() {
    $($(this).attr('href')).dialog('open');
    return false;
});

Or if you need to use classes then replace the hash # with a dot . also if you are not using LINKS you may use the rel attribute to point to your dialogs or even jquery data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.