añadida pestaña de traducido
This commit is contained in:
parent
a9c1e16bdd
commit
0bfeb610a9
4 changed files with 179 additions and 121 deletions
|
|
@ -1,56 +1,89 @@
|
|||
<ul class="noticias-list">
|
||||
{% for noticia in noticias %}
|
||||
<li class="noticia-item">
|
||||
{% if noticia.imagen_url %}
|
||||
<div class="noticia-imagen">
|
||||
<a href="{{ noticia.url }}" target="_blank" rel="noopener noreferrer">
|
||||
<img src="{{ noticia.imagen_url }}" alt="Imagen para {{ noticia.titulo }}" loading="lazy">
|
||||
</a>
|
||||
</div>
|
||||
{% for n in noticias %}
|
||||
<li class="noticia-item" data-item>
|
||||
{% if n.imagen_url %}
|
||||
<div class="noticia-imagen">
|
||||
<a href="{{ n.url }}" target="_blank" rel="noopener noreferrer">
|
||||
<img src="{{ n.imagen_url }}" alt="Imagen para {{ n.titulo }}" loading="lazy">
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="noticia-texto">
|
||||
<h3 style="margin:0 0 6px 0;">
|
||||
<a href="{{ noticia.url }}" target="_blank" rel="noopener noreferrer">{{ noticia.titulo }}</a>
|
||||
{% if use_tr %}
|
||||
{% if noticia.usa_tr %}
|
||||
<span class="badge" title="Mostrando traducción">Traducido</span>
|
||||
{% else %}
|
||||
<span class="badge" title="Mostrando original">Original</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
<div class="tabs">
|
||||
<div class="tabs-header" role="tablist">
|
||||
<button class="tab-btn {% if use_tr and n.tiene_traduccion %}active{% endif %}" data-tab="trad" {% if not n.tiene_traduccion %}disabled{% endif %}>
|
||||
Traducido
|
||||
</button>
|
||||
<button class="tab-btn {% if not (use_tr and n.tiene_traduccion) %}active{% endif %}" data-tab="orig">
|
||||
Original
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="noticia-meta">
|
||||
<span>
|
||||
<i class="far fa-calendar-alt"></i>
|
||||
{% if noticia.fecha %}
|
||||
{% if noticia.fecha is string %}
|
||||
{{ noticia.fecha }}
|
||||
{% else %}
|
||||
{{ noticia.fecha.strftime('%d-%m-%Y %H:%M') }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
N/D
|
||||
{% endif %}
|
||||
</span>
|
||||
{% if noticia.fuente_nombre %}
|
||||
| <span><i class="fas fa-newspaper"></i> <strong>{{ noticia.fuente_nombre }}</strong></span>
|
||||
{% endif %}
|
||||
{% if noticia.categoria %}
|
||||
| <span><i class="fas fa-tag"></i> {{ noticia.categoria }}</span>
|
||||
{% endif %}
|
||||
{% if noticia.pais %}
|
||||
| <span><i class="fas fa-globe-americas"></i> {{ noticia.pais }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tabs-body">
|
||||
<div class="tab-panel {% if use_tr and n.tiene_traduccion %}active{% endif %}" data-panel="trad">
|
||||
<h3 class="m0">
|
||||
<a href="{{ n.url }}" target="_blank" rel="noopener noreferrer">
|
||||
{{ n.titulo_traducido or n.titulo }}
|
||||
</a>
|
||||
{% if n.tiene_traduccion %}
|
||||
<span class="badge" title="Mostrando traducción">ES</span>
|
||||
{% if n.traduccion_id %}
|
||||
<a class="mini-link" href="{{ url_for('noticia', tr_id=n.traduccion_id) }}">ver detalle</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
||||
<div class="resumen-container">
|
||||
{% set resumen_txt = noticia.resumen | safe_html %}
|
||||
<div class="resumen clamp">{{ resumen_txt }}</div>
|
||||
{% if noticia.resumen and noticia.resumen|length > 280 %}
|
||||
<button class="ver-mas-btn" type="button">Ver más</button>
|
||||
{% endif %}
|
||||
<div class="noticia-meta">
|
||||
<span><i class="far fa-calendar-alt"></i>
|
||||
{% if n.fecha %}
|
||||
{% if n.fecha is string %}{{ n.fecha }}{% else %}{{ n.fecha.strftime('%d-%m-%Y %H:%M') }}{% endif %}
|
||||
{% else %}N/D{% endif %}
|
||||
</span>
|
||||
{% if n.fuente_nombre %} | <span><i class="fas fa-newspaper"></i> <strong>{{ n.fuente_nombre }}</strong></span>{% endif %}
|
||||
{% if n.categoria %} | <span><i class="fas fa-tag"></i> {{ n.categoria }}</span>{% endif %}
|
||||
{% if n.pais %} | <span><i class="fas fa-globe-americas"></i> {{ n.pais }}</span>{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="resumen-container">
|
||||
{% set resumen_txt = (n.resumen_traducido or n.resumen) | safe_html %}
|
||||
<div class="resumen-corto">{{ resumen_txt | truncate(280, True) }}</div>
|
||||
<div class="resumen-completo" style="display:none;">{{ resumen_txt }}</div>
|
||||
{% if (n.resumen_traducido or n.resumen) and (n.resumen_traducido or n.resumen)|length > 280 %}
|
||||
<button class="ver-mas-btn" type="button">Ver más</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-panel {% if not (use_tr and n.tiene_traduccion) %}active{% endif %}" data-panel="orig">
|
||||
<h3 class="m0">
|
||||
<a href="{{ n.url }}" target="_blank" rel="noopener noreferrer">
|
||||
{{ n.titulo_original or n.titulo }}
|
||||
</a>
|
||||
<span class="badge badge-secondary">ORIG</span>
|
||||
</h3>
|
||||
|
||||
<div class="noticia-meta">
|
||||
<span><i class="far fa-calendar-alt"></i>
|
||||
{% if n.fecha %}
|
||||
{% if n.fecha is string %}{{ n.fecha }}{% else %}{{ n.fecha.strftime('%d-%m-%Y %H:%M') }}{% endif %}
|
||||
{% else %}N/D{% endif %}
|
||||
</span>
|
||||
{% if n.fuente_nombre %} | <span><i class="fas fa-newspaper"></i> <strong>{{ n.fuente_nombre }}</strong></span>{% endif %}
|
||||
{% if n.categoria %} | <span><i class="fas fa-tag"></i> {{ n.categoria }}</span>{% endif %}
|
||||
{% if n.pais %} | <span><i class="fas fa-globe-americas"></i> {{ n.pais }}</span>{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="resumen-container">
|
||||
{% set resumen_orig = (n.resumen_original or n.resumen) | safe_html %}
|
||||
<div class="resumen-corto">{{ resumen_orig | truncate(280, True) }}</div>
|
||||
<div class="resumen-completo" style="display:none;">{{ resumen_orig }}</div>
|
||||
{% if (n.resumen_original or n.resumen) and (n.resumen_original or n.resumen)|length > 280 %}
|
||||
<button class="ver-mas-btn" type="button">Ver más</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
|
@ -72,62 +105,75 @@
|
|||
{% if total_pages and total_pages > 1 %}
|
||||
<nav class="pagination" aria-label="Paginación de noticias" style="margin-top:15px;">
|
||||
{% set current = page %}
|
||||
|
||||
{% if current > 1 %}
|
||||
<a href="#" class="page-link" data-page="{{ current - 1 }}">« Anterior</a>
|
||||
{% endif %}
|
||||
|
||||
{% if current > 1 %}<a href="#" class="page-link" data-page="{{ current - 1 }}">« Anterior</a>{% endif %}
|
||||
{% set start = 1 if current - 2 < 1 else current - 2 %}
|
||||
{% set end = total_pages if current + 2 > total_pages else current + 2 %}
|
||||
|
||||
{% if start > 1 %}
|
||||
<a href="#" class="page-link" data-page="1">1</a>
|
||||
{% if start > 2 %}<span class="page-link">…</span>{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% for p in range(start, end + 1) %}
|
||||
{% if p == current %}
|
||||
<span class="page-link active">{{ p }}</span>
|
||||
{% else %}
|
||||
<a href="#" class="page-link" data-page="{{ p }}">{{ p }}</a>
|
||||
{% endif %}
|
||||
{% if p == current %}<span class="page-link active">{{ p }}</span>
|
||||
{% else %}<a href="#" class="page-link" data-page="{{ p }}">{{ p }}</a>{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if end < total_pages %}
|
||||
{% if end < total_pages - 1 %}<span class="page-link">…</span>{% endif %}
|
||||
<a href="#" class="page-link" data-page="{{ total_pages }}">{{ total_pages }}</a>
|
||||
{% endif %}
|
||||
|
||||
{% if current < total_pages %}
|
||||
<a href="#" class="page-link" data-page="{{ current + 1 }}">Siguiente »</a>
|
||||
{% endif %}
|
||||
{% if current < total_pages %}<a href="#" class="page-link" data-page="{{ current + 1 }}">Siguiente »</a>{% endif %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
if (window.__noticiasToggleBound) return;
|
||||
window.__noticiasToggleBound = true;
|
||||
if (window.__noticiasHandlersBound) return;
|
||||
window.__noticiasHandlersBound = true;
|
||||
|
||||
const container = document.getElementById('noticias-container') || document;
|
||||
const root = document.getElementById('noticias-container') || document;
|
||||
|
||||
container.addEventListener('click', function (e) {
|
||||
const btn = e.target.closest('.ver-mas-btn');
|
||||
if (!btn) return;
|
||||
root.addEventListener('click', function(e){
|
||||
const t = e.target;
|
||||
|
||||
const wrap = btn.closest('.resumen-container');
|
||||
if (!wrap) return;
|
||||
// Ver más / Ver menos
|
||||
const verMasBtn = t.closest('.ver-mas-btn');
|
||||
if (verMasBtn) {
|
||||
const wrap = verMasBtn.closest('.resumen-container');
|
||||
if (!wrap) return;
|
||||
const corto = wrap.querySelector('.resumen-corto');
|
||||
const completo = wrap.querySelector('.resumen-completo');
|
||||
const expanded = completo.style.display === 'block';
|
||||
completo.style.display = expanded ? 'none' : 'block';
|
||||
corto.style.display = expanded ? 'block' : 'none';
|
||||
verMasBtn.textContent = expanded ? 'Ver más' : 'Ver menos';
|
||||
return;
|
||||
}
|
||||
|
||||
const resumen = wrap.querySelector('.resumen.clamp');
|
||||
if (!resumen) return;
|
||||
// Pestañas
|
||||
const tabBtn = t.closest('.tab-btn');
|
||||
if (tabBtn && !tabBtn.disabled) {
|
||||
const li = tabBtn.closest('[data-item]');
|
||||
const header = tabBtn.parentElement;
|
||||
header.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
tabBtn.classList.add('active');
|
||||
|
||||
const isExpanded = resumen.classList.contains('expanded');
|
||||
if (isExpanded) {
|
||||
resumen.classList.remove('expanded');
|
||||
btn.textContent = 'Ver más';
|
||||
} else {
|
||||
resumen.classList.add('expanded');
|
||||
btn.textContent = 'Ver menos';
|
||||
const wanted = tabBtn.getAttribute('data-tab');
|
||||
li.querySelectorAll('.tab-panel').forEach(p => {
|
||||
p.classList.toggle('active', p.getAttribute('data-panel') === wanted);
|
||||
});
|
||||
}
|
||||
|
||||
// Paginación (AJAX)
|
||||
const pageLink = t.closest('.page-link[data-page]');
|
||||
if (pageLink) {
|
||||
e.preventDefault();
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('page', pageLink.dataset.page);
|
||||
fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' }})
|
||||
.then(r => r.text())
|
||||
.then(html => {
|
||||
(document.getElementById('noticias-container') || document).innerHTML = html;
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue