Tests celcat
Jquery pour supprimer les doublons et formater par jour et heure
by toubia95
HTML
<module id="02738">
<day>2</day>
<rawweeks>NNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN</rawweeks>
<start><item>10:30</item></start>
<staff><item>GERARD MAJAX</item></staff>
<content><item>Cours de magie Première année</item></content>
</module>
<module id="02739">
<day>2</day>
<rawweeks>NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN</rawweeks>
<start><item>10:30</item></start>
<staff><item>GERARD MAJAX</item></staff>
<content><item>Cours de magie Première année</item></content>
</module>
<module id="02740">
<day>2</day>
<rawweeks>NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN</rawweeks>
<start><item>10:30</item></start>
<staff><item>GERARD MAJAX</item></staff>
<content><item>Cours de magie Première année</item></content>
</module>
CSS
module {
display: block;
}
module:after {
content:attr(id);
}
JavaScript
// fonction stripTags() à utiliser éventuellement
jQuery.fn.stripTags = function() { return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') ); };
// supprimer les doublons HTML avec des ID différents
var seen = {};
$('module').each(function() {
var txt = $(this).remove('id').text();
if (seen[txt])
$(this).remove();
else
seen[txt] = true;
});
// enlever des balises inutiles
$('module').find('rawweeks').remove();
// enlever les retours à la ligne et sauts de page dans l'html
// utilisation : $('#widget').cleanWhitespace();
jQuery.fn.cleanWhitespace = function() {
textNodes = this.contents().filter(
function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
.remove();
return this;
}