4
I am refactoring the CSS of a system function and to treat the CSS property and not a string I switched this line of code: (1st way was working properly)
var ultimaMensagem = $("#box-confirm:not([style*='display: none;']),#box-erro:not([style*='display: none;'])").last();
for this:
var ultimaMensagem = $('#box-confirm:not(:visible),#box-erro:not(:visible)').last();
And so the code pad went like this:
GerenciadorModais.prototype.FecharModal = function () {
var ultimaModal = $(".modalJanela").last(); //Pegar a ultima Modal que será fechada
//var ultimoBlock = $(".modal:not([style='display: none;'])").last(); //Maneira antiga
var ultimoBlock = $(".modal:not(:visible)").last(); //Pegar a ultima div que será somente escondida
//var ultimaMensagem = $("#box-confirm:not([style*='display: none;']),#box-erro:not([style*='display: none;'])").last(); //Maneira antiga
var ultimaMensagem = $('#box-confirm:not(:visible),#box-erro:not(:visible)').last(); //Pegar a ultima div de mensagem que será somente escondida
if (ultimoBlock.length > 0) { // Deixar invisivel essa div
ultimoBlock.css('display', 'none');
} else
if (ultimaMensagem.length > 0) { // Deixar invisivel essa div
ultimaMensagem.css('display', 'none');
} else { // fechar essa modal
ultimaModal.remove();
$(".block").last().remove();
this.nivelModal--;
}
if (!$(".modalJanela").length > 0) //Fechar a layer escura
$('#btn-center-dialog').fadeOut();
};
I took into consideration what is written in this post: https://stackoverflow.com/questions/17425543/difference-between-hidden-and-notvisible-in-jquery
But I’m not sure it won’t bring future problems. Basically I need to get all the #box-confirm and #box-error that are invisible somehow on the screen.
So my doubts are:
1) Why does this change not work?
Note: I am doing some tests and noticed that what is not working is the last else
that really closes a modal, but this is probably happening because it is trying to close one of the Divs and not the modal.
2) Is there any possibility that he won’t pick the last selector that’s invisible on the screen?
3) Is there any better way to do it or is this already the best solution?
I changed it, but it’s going wrong. I’m writing it right?
Uncaught Error: Syntax error, unrecognized expression: .modal(:visible)
orUncaught Error: Syntax error, unrecognized expression: .modal:(:visible)
– Andrey Hartung
I think it makes it easier to understand:
var ultimoBlock = $(".modal(:visible)").last();
This is wrong, I would know the right way?– Andrey Hartung
Try
.modal:visible
.– falsarella
\Õ/ this way you posted it worked in modal o/ Thanks! Now just missing I check if it is ok in the other 2 cases
– Andrey Hartung
It worked in all cases! Thank you!
– Andrey Hartung
You’re right, lack of attention my +1
– Guilherme Nascimento
@Good! I hope you understand why! Good studies! =)
– falsarella