Skip to content

Instantly share code, notes, and snippets.

@adautoneto
Last active December 19, 2015 15:28
Show Gist options
  • Save adautoneto/5976437 to your computer and use it in GitHub Desktop.
Save adautoneto/5976437 to your computer and use it in GitHub Desktop.
$(function() {
$("[data-plan]").each(function(i, item) {
var $item = $(item),
table = $item.parents("table"),
tableRows = table.find("tr"),
templateRow = tableRows.last().clone(),
columnIndex = $item.siblings().andSelf().index($item),
currentRowIndex = tableRows.index($item.parents("tr")) + 1;
var produtos = conteudo[ $item.data("plan") ];
for(var produto in produtos) {
if (currentRowIndex >= tableRows.length - 1) {
table.append(templateRow.clone());
tableRows = table.find("tr");
}
tableRows.eq(currentRowIndex).find("td:eq(" + columnIndex + ")").html(produtos[produto]);
currentRowIndex++;
}
});
$("table:has([data-plan])").each(function(i, item) {
$(item).find("tr").last().remove();
});
});
<p>&nbsp;</p>
<br />
<h2 class="headingA01">SHOP MUSIC TEO</h2>
<p>AV SINDONIO OTONI, 640 - MG<br /> TEOFILO OTONI</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="10" width="100%">
<tbody>
<tr>
<td colspan="4">Instrumentos Musicais</td>
</tr>
<tr>
<td width="25%" bgcolor="#CCCCCC" data-plan="teclado"><strong>Teclado e Piano Port&aacute;til</strong></td>
<td width="25%" bgcolor="#CCCCCC"><strong>Guitarra, Contrabaixo e Amplificador</strong></td>
<td width="25%" bgcolor="#CCCCCC"><strong>Bateria Eletr&ocirc;nica DTX</strong></td>
<td width="25%" bgcolor="#CCCCCC" data-plan="sopro"><strong>Sopros</strong></td>
</tr>
<tr>
<td width="25%"></td>
<td width="25%"></td>
<td width="25%"></td>
<td width="25%"></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="10" width="50%">
<tbody>
<tr>
<td colspan="2">Standard &Aacute;udio</td>
</tr>
<tr>
<td width="25%" bgcolor="#CCCCCC"><strong>Digital Mixer</strong></td>
<td width="25%" bgcolor="#CCCCCC" data-plan="mixer"><strong>MG/MGP Mixer</strong></td>
</tr>
<tr>
<td width="25%"></td>
<td width="25%"></td>
</tr>
</tbody>
</table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="plans.js"></script>
<script src="contentLoader.js"></script>
var conteudo = {
teclado: [ "PSR-E243", "PSR-E423" ],
sopro: [ "YSL-354", "YSL-3335", "YTR-2330", "YFL-211" ],
mixer: [ "MG82CX", "MG102C / C-R", "MG124CX-R", "MG166C / USB", "MG166CX / USB", "MG206C / USB", "MG24/14FX", "MG32/14FX", "MGP12X", "MGP16X", "MGP24X", "MGP32X", "Serie EMX", "Serie STAGEPAS"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment