MediaWiki:Common.js: Difference between revisions
From MalveraWiki
No edit summary |
No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
if (!tablesStr) return; | if (!tablesStr) return; | ||
var | var $tooltip = $wrapper.find('.custom-tooltip').empty(); | ||
var $ | // --- Pobieramy obrazek i nazwę z wiersza tabeli --- | ||
var $tr = $wrapper.closest('tr'); | |||
var $imgCell = $tr.find('td:first-child img').first(); | |||
var $nameCell = $tr.find('td:nth-child(2)').first(); | |||
/ | if ($imgCell.length || $nameCell.length) { | ||
var $header = $('<div class="tooltip-header"></div>'); | |||
if ($imgCell.length) { | |||
var $imgClone = $imgCell.clone(); | |||
$header.append($('<div class="tooltip-item-image"></div>').append($imgClone)); | |||
} | |||
if ($nameCell.length) { | |||
var nameText = $nameCell.text().trim(); | |||
$header.append($('<div class="tooltip-item-name"></div>').text(nameText)); | |||
} | |||
$tooltip.append($header); | |||
} | } | ||
// --- Kontener tabel --- | |||
var $tablesContainer = $('<div class="tooltip-tables-container"></div>'); | |||
var tables = tablesStr.split('##'); | var tables = tablesStr.split('##'); | ||
| Line 41: | Line 51: | ||
var cols = row.split(','); | var cols = row.split(','); | ||
if (cols.length < 2) return; | if (cols.length < 2) return; | ||
var $ | var $trRow = $('<tr></tr>'); | ||
cols.forEach(function(c){ $ | cols.forEach(function(c){ $trRow.append('<td>'+c.trim()+'</td>'); }); | ||
$tbody.append($ | $tbody.append($trRow); | ||
}); | }); | ||
$table.append($tbody); | $table.append($tbody); | ||
$tableContainer.append($table); | $tableContainer.append($table); | ||
$ | $tablesContainer.append($tableContainer); | ||
}); | }); | ||
$tooltip.append($tablesContainer); | |||
}); | }); | ||
}); | }); | ||
Latest revision as of 21:22, 2 February 2026
mw.hook('wikipage.content').add(function ($content) {
$content.find('.tooltip-wrapper[data-tooltip-tables]').each(function () {
var $wrapper = $(this);
var tablesStr = $wrapper.data('tooltip-tables');
if (!tablesStr) return;
var $tooltip = $wrapper.find('.custom-tooltip').empty();
// --- Pobieramy obrazek i nazwę z wiersza tabeli ---
var $tr = $wrapper.closest('tr');
var $imgCell = $tr.find('td:first-child img').first();
var $nameCell = $tr.find('td:nth-child(2)').first();
if ($imgCell.length || $nameCell.length) {
var $header = $('<div class="tooltip-header"></div>');
if ($imgCell.length) {
var $imgClone = $imgCell.clone();
$header.append($('<div class="tooltip-item-image"></div>').append($imgClone));
}
if ($nameCell.length) {
var nameText = $nameCell.text().trim();
$header.append($('<div class="tooltip-item-name"></div>').text(nameText));
}
$tooltip.append($header);
}
// --- Kontener tabel ---
var $tablesContainer = $('<div class="tooltip-tables-container"></div>');
var tables = tablesStr.split('##');
tables.forEach(function(tableDef) {
var parts = tableDef.split('{{!}}');
if (parts.length < 2) return;
var header = parts[0].trim();
var rowsStr = parts[1].trim();
if (!rowsStr) return;
var rows = rowsStr.split(';');
var $tableContainer = $('<div class="tooltip-table-container"></div>');
if (header) {
$tableContainer.append('<div class="tooltip-table-header">'+header+'</div>');
}
var $table = $('<table class="wikitable sortable"></table>');
$table.append('<thead><tr><th>Amount</th><th>Chance</th></tr></thead>');
var $tbody = $('<tbody></tbody>');
rows.forEach(function(row) {
var cols = row.split(',');
if (cols.length < 2) return;
var $trRow = $('<tr></tr>');
cols.forEach(function(c){ $trRow.append('<td>'+c.trim()+'</td>'); });
$tbody.append($trRow);
});
$table.append($tbody);
$tableContainer.append($table);
$tablesContainer.append($tableContainer);
});
$tooltip.append($tablesContainer);
});
});
