Optimizar funciones en jQueryUI

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)

preguntado el 09 de enero de 11 a las 10:01

2 Respuestas

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;
});

Respondido el 09 de enero de 11 a las 15:01

ie will have a fit with the closing comma! - cuadrado rojo

thanks, I think $('.register-modal').dialog('open'); debiera ser $('.login-modal, .register-modal').dialog('open'); - ¡Hasta la vista

@Mini - actually, it should be $(this).dialog('open');. Actualizado. - karim79

Opps. the optimized open two modals in the same time. why? - ¡Hasta la vista

Argh! I guess they have to be bound one at a time. - karim79

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.

Respondido el 09 de enero de 11 a las 19:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.