1/* ========================================================================= 2 CD TERUEL â Lista de Partidos por equipo (partidos.html?e=<equipo>) 3 Estilo "fixture list": una fila por partido con competición + estadio a la 4 izquierda, escudo local · fecha/hora · escudo visitante en el centro, y un 5 botón PREVIA a la derecha. Muestra SOLO los partidos SIN resultado 6 (goles_local / goles_visitante en null), ordenados por fecha ascendente. 7 Datos en data/partidos.json[<equipo>].partidos 8 ========================================================================= */ 9(function () { 10 "use strict"; 11 12 var CDT_ESCUDO = "assets/img/escudo-cdt-web.webp"; 13 var CDT_NOMBRE = "CD Teruel"; 14 var FALLBACK = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ccircle cx='20' cy='20' r='18' fill='%23cfc9c1'/%3E%3C/svg%3E"; 15 16 var MES_NUM = { enero:0, febrero:1, marzo:2, abril:3, mayo:4, junio:5, 17 julio:6, agosto:7, septiembre:8, octubre:9, noviembre:10, diciembre:11 }; 18 var MES = { enero:"ENE", febrero:"FEB", marzo:"MAR", abril:"ABR", mayo:"MAY", junio:"JUN", 19 julio:"JUL", agosto:"AGO", septiembre:"SEP", octubre:"OCT", noviembre:"NOV", diciembre:"DIC" }; 20 var DIA = { 0:"DOM", 1:"LUN", 2:"MAR", 3:"MIÃ", 4:"JUE", 5:"VIE", 6:"SÃB" }; 21 22 var EQUIPO = { 23 "primer-equipo": { nombre: "Primer Equipo", foto: "assets/img/equipos/primer-equipo.jpg" }, 24 "femenino": { nombre: "Femenino", foto: "assets/img/equipos/femenino.jpg" }, 25 "juvenil": { nombre: "Juvenil", foto: "assets/img/equipos/juvenil.jpg" }, 26 "cadete": { nombre: "Cadete", foto: "assets/img/equipos/cadete.jpg" }, 27 "infantil": { nombre: "Infantil", foto: "assets/img/equipos/infantil.jpg" }, 28 "alevin": { nombre: "AlevÃn", foto: "assets/img/equipos/alevin.jpg" }, 29 "femenino-base": { nombre: "Femenino base", foto: "assets/img/equipos/femenino-base.jpg" } 30 }; 31 32 function esc(s) { return String(s == null ? "" : s).replace(/[&<>"]/g, function (c) { 33 return { "&": "&", "<": "<", ">": ">", '"': """ }[c]; }); } 34 function qp(name) { 35 var m = new RegExp("[?&]" + name + "=([^&]*)").exec(location.search); 36 return m ? decodeURIComponent(m[1]) : null; 37 } 38 function parseFecha(f) { 39 var m = String(f || "").toLowerCase().match(/(\d{1,2})\s+([a-záéÃóú]+)\s+(\d{4})/); 40 if (!m || MES_NUM[m[2]] == null) return null; 41 return new Date(parseInt(m[3], 10), MES_NUM[m[2]], parseInt(m[1], 10)); 42 } 43 // "MIÃ. 29 JUL." a partir de la fecha larga (usa el nombre de dÃa calculado) 44 function fechaCorta(f) { 45 var d = parseFecha(f); 46 var m = String(f || "").toLowerCase().match(/(\d{1,2})\s+([a-záéÃóú]+)/); 47 if (!m || !MES[m[2]]) return f; 48 var dia = d ? DIA[d.getDay()] + ". " : ""; 49 return dia + m[1] + " " + MES[m[2]] + "."; 50 } 51 function crest(src, alt) { 52 return '<span class="fl-crest"><img src="' + esc(src) + '" alt="' + esc(alt) + 53 '" loading="lazy" onerror="this.onerror=null;this.src=\'' + FALLBACK + '\'"></span>'; 54 } 55 56 // Una fila de partido (estilo Osasuna) 57 function fila(p, destacado) { 58 var local = !!p.local; 59 var homeName = local ? CDT_NOMBRE : p.rival; 60 var awayName = local ? p.rival : CDT_NOMBRE; 61 var homeCrest = local ? CDT_ESCUDO : p.escudo_rival; 62 var awayCrest = local ? p.escudo_rival : CDT_ESCUDO; 63 var homeCls = local ? "fl-cdt" : ""; 64 var awayCls = local ? "" : "fl-cdt"; 65 66 // Recuadro central: marcador si el partido está jugado, si no fecha + hora. 67 var centro; 68 if (p._jugado) { 69 var gHome = local ? p.goles_local : p.goles_visitante; 70 var gAway = local ? p.goles_visitante : p.goles_local; 71 centro = '<span class="fl-when fl-when--score">' + esc(gHome) + ' - ' + esc(gAway) + '</span>'; 72 } else { 73 centro = '<span class="fl-when">' + 74 '<span class="fl-day">' + esc(fechaCorta(p.fecha)) + '</span>' + 75 (p.hora ? '<span class="fl-time">' + esc(p.hora) + '</span>' : '') + 76 '</span>'; 77 } 78 79 // Botón: "Ver crónica" (a cronica.html) si jugado; "Ver previa" (a previa.html) si no. 80 var eqIdx = "?e=" + encodeURIComponent(p._equipo) + "&i=" + (p._oi != null ? p._oi : 0); 81 var url = (p._jugado ? "cronica" : "previa") + eqIdx; 82 var btnTxt = p._jugado ? "Ver crónica" : "Ver previa"; 83 84 var res = ""; 85 if (p._jugado) { var gT = +p.goles_local, gR = +p.goles_visitante; res = gT > gR ? " fl-row--v" : gT < gR ? " fl-row--d" : " fl-row--e"; } 86 return '<article class="fl-row' + (destacado ? " fl-row--next" : "") + res + '">' + 87 '<div class="fl-meta">' + 88 '<span class="fl-comp">' + esc(p.competicion) + '</span>' + 89 '<span class="fl-place">
89' + esc(p.estadio) + '</span>' + 90 '</div>' + 91 '<div class="fl-match">' + 92 '<span class="fl-team fl-team--home ' + homeCls + '">' + esc(homeName) + '</span>' + 93 crest(homeCrest, homeName) + 94 centro + 95 crest(awayCrest, awayName) + 96 '<span class="fl-team fl-team--away ' + awayCls + '">' + esc(awayName) + '</span>' + 97 '</div>' + 98 '<div class="fl-btns"><a class="fl-btn" href="' + url + '">' + btnTxt + '</a>' + 99 (p._jugado && p.resumen_video ? '<a class="fl-btn fl-btn--video" href="https://www.youtube.com/watch?v=' + esc(p.resumen_video) + '" data-video="' + esc(p.resumen_video) + '" target="_blank" rel="noopener">Ver resumen</a>' : "") + 100 '</div>' + 101 '</article>'; 102 } 103 104 function pintarCabecera(equipo) { 105 var info = EQUIPO[equipo] || EQUIPO["primer-equipo"]; 106 var h1 = document.querySelector("[data-team-title]"); 107 var secTitulo = h1 ? (h1.getAttribute("data-title-sec") || "") : ""; 108 if (h1) h1.textContent = secTitulo ? secTitulo + " â " + (info.nombre) : (info.nombre); 109 var img = document.querySelector("[data-team-photo]"); 110 if (img) { img.src = info.foto; img.alt = "El " + info.nombre + " del CD Teruel"; } 111 } 112 113 function init() { 114 var host = document.getElementById("partidos-lista"); 115 if (!host) return; 116 var equipo = qp("e") || host.getAttribute("data-equipo") || "primer-equipo"; 117 if (!EQUIPO[equipo]) equipo = "primer-equipo"; 118 // modo = "resultados" -> partidos jugados; cualquier otro -> próximos 119 var modo = host.getAttribute("data-modo") === "resultados" ? "resultados" : "proximos"; 120 pintarCabecera(equipo); 121 122 window.CDTFetchJSON("data/partidos.json") 123 .then(function (data) { 124 var lista = ((data[equipo] || {}).partidos || []) 125 .map(function (p, oi) { 126 p._d = parseFecha(p.fecha); p._equipo = equipo; p._oi = oi; 127 p._jugado = p.goles_local != null && p.goles_local !== "" && 128 p.goles_visitante != null && p.goles_visitante !== ""; 129 return p; 130 }); 131 132 if (modo === "resultados") { 133 // solo los jugados, el más reciente primero 134 lista = lista.filter(function (p) { return p._jugado; }) 135 .sort(function (a, b) { return (b._d || 0) - (a._d || 0); }); 136 } else { 137 // solo los que NO tienen resultado (aún por jugar), el más próximo primero 138 lista = lista.filter(function (p) { return !p._jugado; }) 139 .sort(function (a, b) { return (a._d || 0) - (b._d || 0); }); 140 } 141 142 var vacio = modo === "resultados" 143 ? "Aún no hay resultados esta temporada." 144 : "No hay partidos programados por el momento."; 145 host.innerHTML = lista.length 146 ? lista.map(function (p, i) { return fila(p, i === 0); }).join("") 147 : '<p class="fl-empty">' + vacio + '</p>'; 148 }) 149 .catch(function () { 150 host.innerHTML = '<p class="fl-empty">No se han podido cargar los partidos.</p>'; 151 }); 152 } 153 154 if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); 155 else init(); 156})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.