1/*1790294980000*/ 2Liferay.on('allPortletsReady', function () { 3 const listSize = 10; 4 5 const getRanges = (page, numOfPages) => { 6 page = Math.max(1, Math.min(page, numOfPages)); 7 let start = Math.max(1, page - Math.floor(listSize / 2)); 8 let end = Math.min(numOfPages, start + listSize - 1); 9 10 if (end - start < listSize - 1) { 11 start = Math.max(1, end - listSize + 1); 12 } 13 14 return [start, end]; 15 }; 16 17 const extractBaseUrl = (sampleUrl) => { 18 try { 19 // Para Asset Publisher, o padrão é _cur=NUMERO 20 const curMatch = sampleUrl.match(/^(.+_cur=)\d+(.*)$/); 21 if (curMatch) { 22 return { 23 base: curMatch[1], 24 suffix: curMatch[2] || '' 25 }; 26 } 27 28 // Suporte a start=NUMERO 29 const startMatch = sampleUrl.match(/^(.+[?&]start=)\d+(.*)$/); 30 if (startMatch) { 31 return { 32 base: startMatch[1], 33 suffix: startMatch[2] || '' 34 }; 35 } 36 37 // Outros padrões 38 const patterns = [ 39 /^(.+[?&]cur=)\d+(.*)$/, 40 /^(.+[?&]page=)\d+(.*)$/, 41 /^(.+\/)\d+\/?$/, 42 /^(.+)\d+(.*)$/ 43 ]; 44 45 for (let pattern of patterns) { 46 const match = sampleUrl.match(pattern); 47 if (match) { 48 return { 49 base: match[1], 50 suffix: match[2] || '' 51 }; 52 } 53 } 54 55 return null; 56 } catch (e) { 57 console.error('Erro ao extrair URL base:', e); 58 return null; 59 } 60 }; 61 62 const buildPageUrl = (urlInfo, pageNumber) => { 63 if (!urlInfo) return 'javascript:;'; 64 return urlInfo.base + pageNumber + urlInfo.suffix; 65 }; 66 67 // Função para extrair informações de paginação de múltiplas fontes 68 const extractPaginationInfo = (bottomBar, dropdownElement) => { 69 let curPage = 1; 70 let numOfPages = 1; 71 72 // PRIORIDADE 1: Analisa a URL atual PRIMEIRO para pegar a página correta 73 var currentUrl = window.location.href; 74 var curMatch = currentUrl.match(/_cur=(\d+)/); 75 if (curMatch) { 76 curPage = parseInt(curMatch[1], 10); 77 console.log("Página extraÃda da URL (_cur):", curPage); 78 } else { 79 var startMatch = currentUrl.match(/[?&]start=(\d+)/); 80 if (startMatch) { 81 curPage = parseInt(startMatch[1], 10); 82 console.log("Página extraÃda da URL (start):", curPage); 83 } 84 } 85 86 // PRIORIDADE 2: Tenta extrair do title do dropdown (só numOfPages) 87 var paginationText = $(dropdownElement).attr("title"); 88 89 if (paginationText) { 90 const patterns = [ 91 /Página\s+(\d+)\s+de\s+(\d+)/i, 92 /Page\s+(\d+)\s+of\s+(\d+)/i, 93 /(\d+)\s+de\s+(\d+)/i, 94 /(\d+)\s+of\s+(\d+)/i, 95 /(\d+)\s*\/\s*(\d+)/i 96 ]; 97 98 for (let pattern of patterns) { 99 const matches = paginationText.match(pattern); 100 if (matches) { 101 if (!curMatch) { 102 curPage = parseInt(matches[1], 10); 103 } 104 numOfPages = parseInt(matches[2], 10); 105 console.log("Info extraÃda do title:", matches[1], "de", matches[2]); 106 break; 107 } 108 } 109 } 110 111 // PRIORIDADE 3: Se não funcionou, tenta extrair do texto do dropdown 112 var dropdownText = $(dropdownElement).text().trim(); 113 114 if ((numOfPages === 1 || isNaN(numOfPages)) && dropdownText) { 115 const patterns = [ 116 /(\d+)\s+de\s+(\d+)/i, 117 /(\d+)\s+of\s+(\d+)/i, 118 /(\d+)\s*\/\s*(\d+)/i 119 ]; 120 121 for (let pattern of patterns) { 122 const matches = dropdownText.match(pattern); 123 if (matches) { 124 if (!curMatch) { 125 curPage = parseInt(matches[1], 10); 126 } 127 numOfPages = parseInt(matches[2], 10); 128 console.log("Info extraÃda do texto dropdown:", matches[1], "de", matches[2]); 129 break; 130 } 131 } 132 } 133 134 // PRIORIDADE 4: Tenta calcular baseado nos links disponÃveis 135 if (numOfPages === 1 || isNaN(numOfPages)) { 136 var allLinks = $(bottomBar).find(".pagination li a, .dropdown-menu li a, .lfr-menu-list li a"); 137 var maxPage = 1; 138 139 allLinks.each(function() { 140 var href = $(this).attr("href"); 141 var text = $(this).text().trim(); 142 143 // Tenta extrair número da página do link (_cur=) 144 if (href) { 145 var linkCurMatch = href.match(/_cur=(\d+)/); 146 var linkStartMatch = href.match(/[?&]start=(\d+)/); 147 if (linkCurMatch) { 148 maxPage = Math.max(maxPage, parseInt(linkCurMatch[1], 10)); 149 } else if (linkStartMatch) { 150 maxPage = Math.max(maxPage, parseInt(linkStartMatch[1], 10)); 151 } 152 } 153 154 // Tenta extrair do texto do link (número puro ou "Página N") 155 if (text && /^\d+$/.test(text)) { 156 maxPage = Math.max(maxPage, parseInt(text, 10)); 157 } 158 var pageTextMatch = text.match(/[Pp][áa]gina\s+(\d+)/); 159 if (pageTextMatch) { 160 maxPage = Math.max(maxPage, parseInt(pageTextMatch[1], 10)); 161 } 162 }); 163 164 if (maxPage > 1) { 165 numOfPages = maxPage; 166 console.log("Total de páginas calculado dos links:", maxPage); 167 } 168 } 169 170 // Se ainda não temos numOfPages e temos curPage da URL, usa curPage como mÃnimo 171 if ((numOfPages === 1 || isNaN(numOfPages)) && curPage > 1) { 172 numOfPages = curPage; 173 console.log("Assumindo numOfPages baseado em curPage:", curPage); 174 } 175 176 var result = { 177 curPage: Math.max(1, curPage), 178 numOfPages: Math.max(1, numOfPages) 179 }; 180 181 console.log("Resultado final - Página:", result.curPage, "de", result.numOfPages); 182 183 return result; 184 }; 185 186 const getIcon = (name) => { 187 if (name === "chevron-left") { 188 return ` 189 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-left" viewBox="0 0 16 16"> 190 <path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0"/> 191 </svg>`; 192 } else if (name === "chevron-right") { 193 return ` 194 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-right" viewBox="0 0 16 16"> 195 <path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708"/> 196 </svg>`; 197 } 198 return ''; 199 }; 200 201 // BUSCA POR AMBAS AS OPÃÃES 202 const paginationContainers = $(".taglib-page-iterator, .pagination-bar"); 203 204 if (paginationContainers.length === 0) { 205 console.warn("No pagination iterator found."); 206 return; 207 } 208 209 console.log("Encontrados " + paginationContainers.length + " containers de paginação"); 210 211 paginationContainers.each(function () { 212 var bottomBar = $(this); 213 214 // Verifica se já foi processado 215 if (bottomBar.hasClass("custom-pagination-processed")) { 216 console.log("âContainer já processado, pulando..."); 217 return; 218 } 219 220 // Marca como processado 221 bottomBar.addClass("custom-pagination-processed"); 222 223 var containerType = bottomBar.hasClass("taglib-page-iterator") ? "taglib-page-iterator" : "pagination-bar"; 224 console.log("Processando paginador do tipo:", containerType); 225 226 // Busca o primeiro dropdown dentro deste container 227 var dropdownElement = bottomBar.find(".dropdown-toggle").first(); 228 229 if (dropdownElement.length === 0) { 230 console.warn("Nenhum dropdown encontrado neste container"); 231 return; 232 } 233 234 if (!bottomBar.hasClass("d-block")) { 235 bottomBar.addClass("d-block"); 236 } 237 238 var botoes = bottomBar.find(".pagination li a, .dropdown-menu li a, .lfr-menu-list li a"); 239 if (botoes.length === 0) { 240 console.warn("Nenhum botão encontrado"); 241 return; 242 } 243 244 // Oculta a paginação original 245 bottomBar.find(".pagination, .lfr-pagination").first().hide(); 246 247 // Extrai informações de paginação 248 var paginationInfo = extractPaginationInfo(bottomBar, dropdownElement); 249 var curPage = paginationInfo.curPage; 250 var numOfPages = paginationInfo.numOfPages; 251 252 console.log("Página atual final:", curPage); 253 console.log("Total de páginas final:", numOfPages); 254 255 // Validação 256 if (isNaN(curPage) || isNaN(numOfPages) || curPage < 1 || numOfPages < 1) { 257 console.warn("Informações inválidas"); 258 return; 259 } 260 261 var botaoWithLink = botoes.filter(function () { 262 var href = $(this).attr("href"); 263 return href && href !== "javascript:;" && href.trim() !== ""; 264 }); 265 266 if (botaoWithLink.length === 0) { 267 console.warn("Nenhum link válido"); 268 return; 269 } 270 271 // Prioriza links com start= para montar a URL base 272 var linkParaPagina = botaoWithLink.filter(function() { 273 var href = $(this).attr("href"); 274 return href && /[?&]start=\d+/.test(href); 275 }); 276 277 var urlBase = linkParaPagina.length > 0 ? linkParaPagina[0].href : botaoWithLink[0].href; 278 var urlInfo = extractBaseUrl(urlBase); 279 280 if (!urlInfo) { 281 console.warn("URL base não extraÃda"); 282 return; 283 } 284 285 var range = getRanges(curPage, numOfPages); 286 console.log("Range:", range); 287 288 var canGoPrev = curPage > 1; 289 var canGoNext = curPage < numOfPages; 290 291 var prevPage = canGoPrev ? curPage - 1 : 1; 292 var nextPage = canGoNext ? curPage + 1 : numOfPages; 293 294 var navHtml = `<ul class="pagination mt-5 mb-4 custom-pagination">`; 295 296 // Botão anterior 297 navHtml += ` 298 <li class="page-item ${!canGoPrev ? 'disabled' : ''}"> 299 <a data-senna-off="true" href="${canGoPrev ? buildPageUrl(urlInfo, prevPage) : 'javascript:;'}" class="page-link page-chevron"> 300 ${getIcon("chevron-left")} 301 </a> 302 </li> 303 `; 304 305 // Páginas do range atual 306 for (let i = range[0]; i <= range[1]; i++) { 307 navHtml += ` 308 <li class="${i === curPage ? 'page-item active' : 'page-item'}"> 309 <a data-senna-off="true" href="${buildPageUrl(urlInfo, i)}" class="page-link">${i}</a> 310 </li> 311 `; 312 } 313 314 // Botão próximo 315 navHtml += ` 316 <li class="page-item ${!canGoNext ? 'disabled' : ''}"> 317 <a data-senna-off="true" href="${canGoNext ? buildPageUrl(urlInfo, nextPage) : 'javascript:;'}" class="page-link page-chevron"> 318 ${getIcon("chevron-right")} 319 </a> 320 </li> 321 `; 322 323 navHtml += ` 324 </ul> 325 <style> 326 .custom-pagination .page-chevron {
327 background-color: #e0e0e0 !important; 328 border: 2px solid #f1f1f1 !important; 329 color: #767676 !important; 330 font-size: 18px !important; 331 font-weight: bold !important; 332 height: auto !important; 333 font-family: "Titillium Web", sans-serif !important; 334 display: block !important; 335 -moz-transition: all 0.3s linear !important; 336 -o-transition: all 0.3s linear !important; 337 transition: all 0.3s linear !important; 338 } 339 .custom-pagination .page-item.disabled .page-chevron { 340 background-color: #e0e0e0 !important; 341 border: 2px solid #f1f1f1 !important; 342 color: #767676 !important; 343 opacity: 0.6; 344 cursor: not-allowed; 345 } 346 .custom-pagination .page-chevron:hover { 347 background-color: #d0d0d0 !important; 348 border: 2px solid #e1e1e1 !important; 349 color: #565656 !important; 350 } 351 .custom-pagination .page-item.disabled .page-chevron:hover { 352 background-color: #e0e0e0 !important; 353 border: 2px solid #f1f1f1 !important; 354 color: #767676 !important; 355 opacity: 0.6; 356 } 357 </style> 358 `; 359 360 bottomBar.append(navHtml); 361 console.log("Paginação criada!"); 362 }); 363});
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.