Combine dois scripts jQuery semelhantes em um script if / then
Estou tentando combinar dois loops jQuery, com base no código das perguntas respondidasaqui, que remove imagens e iframes das postagens do WordPress e os move para novas divs ou para novas listas. Minhas perguntas anteriores procuraram atingir cada um desses resultados de forma independente, mas agora preciso combiná-los em uma única página, selecionando qual deles usar com base no contêiner pai.
Especificamente, quero que o primeiro script seja executado em todos<section>
recipientes além daquele com o#clients
EU IRIA. Esse deve usar o segundo script.
Eu imagino que provavelmente precise de algum tipo de lógica if / then que execute o código apropriado para o seletor, mas estou tendo dificuldades para conseguir isso. Atualmente, um script está quebrando o outro.
Aqui estão os dois scripts - observe o comentário entre parênteses na linha 4:
jQuery("document").ready (function($){
// Elements you want to match
var matchesEl = "img, iframe"
// For each section [I have added a 'not-#clients' selector, which doesn't work but gives an idea of the logic I'm attempting], get its index number and do the following:
$('section !#clients').each(function(index){
//If there is a matched element (for each section),
if ($(this).find(matchesEl).length > 0) {
// create a div.royalSlider and prepend to this section
$('<div>', {'class': 'royalSlider'}).prependTo(this)
// For each matched element into this section (we don't need to get index number here),
$(this).find(matchesEl).each(function() {
// add .rsImg class to this element and insert on the div.royalSlider,
// not any div.royaSlider, but that one with equivalent index given before
$(this).addClass('rsImg').appendTo($('section .royalSlider').eq(index));
});
}
});
});
jQuery("document").ready (function($){
var matchesEl = "img, iframe"
$('section #clients').each(function(index){
if ($(this).find(matchesEl).length > 0) {
$('<ul>').appendTo($('section');
$(this).find(matchesEl).each(function() {
//The line code under will only works if all your <section>s always have at least one matched element.
//$("<li>").append($(this)).appendTo($('section ul').eq(index));
//So the right code is:
$("<li>").append($(this)).appendTo($('section').eq(index).children('ul'));
});
}
$('p').filter(function () { return $.trim(this.innerHTML) == "" }).remove();
});
});
Em vez de executar dois scripts que se chocam, preciso desenvolver um script que seja executado seletivamente com base no seletor jQuery.
Eu tentaria escrever esse script unificado e publicá-lo aqui, em vez de mostrar os dois, mas atualmente o segundo script (que tenta criar<ul>
elementos) não funciona, e não tenho certeza de como fazê-lo funcionar sozinho, o que parece ser um pré-requisito para combiná-los.
Se ajudar, o site em que estou trabalhando pode ser visualizado (em estágios de desenvolvimento!)aqui.
Muito obrigado antecipadamente por qualquer ajuda com isso.