1"use strict"; 2 3var Calendari = null; 4var CalendariId = null; 5var CalendariName = null; 6var CalendarType = 0; 7 8function isDesktop() { 9 if ($("body").width() < WIDTH_DESKTOPS) { 10 return true; 11 } else { 12 return false; 13 } 14} 15function isTablet() { 16 if ($("body").width() < WIDTH_TABLETS) { 17 return true; 18 } else { 19 return false; 20 } 21} 22function isSmartphone() { 23 if ($("body").width() < WIDTH_SMARTPHONES) { 24 return true; 25 } else { 26 return false; 27 } 28} 29function isPhone() { 30 if ($("body").width() < WIDTH_PHONES) { 31 return true; 32 } else { 33 return false; 34 } 35} 36function hideMsg() { 37 $(".messages").hide("slow"); 38 $(".messages").html(""); 39 $(".messages").show("fast"); 40} 41 42/** 43 * Normalize 'pag' query parameter in the URL without reloading the page. 44 * Ensures 'pag' is between 1 and 1000 and replaces the URL via history.replaceState. 45 */ 46function normalizeSearchPag() { 47 try { 48 if (typeof URL === 'undefined') { return; } 49 var u = new URL(window.location); 50 var orig = u.searchParams.get('pag'); 51 if (orig === null) { return; } 52 var pag = parseInt(orig, 10); 53 var san = Number.isInteger(pag) ? Math.max(1, Math.min(1000, pag)) : 1; 54 if (String(san) !== orig) { 55 u.searchParams.set('pag', san); 56 window.history.replaceState(null, '', u.toString()); 57 } 58 } catch(e) { 59 } 60} 61function getDateInfo(date, wantsClassName) { 62 var articleId = $(this)[0].id; 63 var as_number = Calendar.dateToInt(date); 64 return DATE_INFO[articleId][as_number]; 65} 66function initPestanyesTabs() { 67 $(".o-tabs").each(function () { 68 var $tabs = $(this); 69 if ($tabs.data("pestanyes-init")) { 70 return; 71 } 72 $tabs.data("pestanyes-init", true); 73 var $buttons = $tabs.find("> .o-tabs__nav .o-tabs__tab"); 74 var $panels = $tabs.find("> .o-tabs__panels > .o-tabs__panel"); 75 76 function activate($btn) { 77 var targetSel = $btn.attr("data-tab-target"); 78 $buttons.removeClass("is-active").attr("aria-selected", "false").attr("tabindex", "-1"); 79 $buttons.parent().removeClass("is-active"); 80 $panels.removeClass("is-active").attr("hidden", "hidden"); 81 $btn.addClass("is-active").attr("aria-selected", "true").attr("tabindex", "0"); 82 $btn.parent().addClass("is-active"); 83 $tabs.find(targetSel).addClass("is-active").removeAttr("hidden"); 84 } 85 86 $buttons.on("click", function (e) { 87 e.preventDefault(); 88 activate($(this)); 89 }); 90 $buttons.on("keydown", function (e) { 91 var idx = $buttons.index(this); 92 var newIdx = null; 93 if (e.key === "ArrowRight" || e.keyCode === 39) { 94 newIdx = (idx + 1) % $buttons.length; 95 } else if (e.key === "ArrowLeft" || e.keyCode === 37) { 96 newIdx = (idx - 1 + $buttons.length) % $buttons.length; 97 } else if (e.key === "Home" || e.keyCode === 36) { 98 newIdx = 0; 99 } else if (e.key === "End" || e.keyCode === 35) { 100 newIdx = $buttons.length - 1; 101 } 102 if (newIdx !== null) { 103 e.preventDefault(); 104 var $next = $buttons.eq(newIdx); 105 activate($next); 106 $next.trigger("focus"); 107 } 108 }); 109 }); 110} 111 112function start() { 113 // show menu if resize from table width 114 window.addEventListener("resize", resizeMainMenu); 115 116 // Inicialitzar pestanyes dels contenidors 117 initPestanyesTabs(); 118 119 // resize columns 120 setEqualContentColumns(); 121 window.addEventListener("resize", setEqualContentColumns); 122 123 // resize logo 124 checkResizeLogo(); 125 window.addEventListener("resize", checkResizeLogo); 126 127 // resize footer Sitemap 128 resizeFooterSitemap(); 129 window.addEventListener("resize", resizeFooterSitemap); 130 131 var watchMasonryGroup = []; 132 window.addEventListener("resize", function () { 133 resizeMasonry(watchMasonryGroup); 134 setTimeout(function () { 135 resizeMasonry(watchMasonryGroup); 136 }, 100); 137 setTimeout(function () { 138 resizeMasonry(watchMasonryGroup); 139 }, 500); 140 }); 141 142 // Footer featureds slider 143 $(".highlights .bxslider, .o-widget--footer .highlights .bxslider").bxSlider({ 144 infiniteLoop: false, 145 adaptiveHeight: true, 146 hideControlOnEnd: true, 147 minSlides: 1, 148 maxSlides: 7, 149 slideWidth: 130, 150 slideMargin: 0, 151 preventDefaultSwipeY: true, 152 nextText: "Següent", 153 prevText: "Anterior", 154 onSliderLoad: function () { 155 $(".highlights .bxslider, .o-widget--footer .highlights .bxslider").css( 156 "display", 157 "block" 158 ); 159 }, 160 }); 161 162 // Meteocat slider 163 if ( 164 $("#cm_meteocat .bxslider, .o-widget--footer .highlights .bxslider") 165 .length !== 0 166 ) { 167 $( 168 "#cm_meteocat .bxslider, .o-widget--footer .highlights .bxslider" 169 ).bxSlider({ 170 infiniteLoop: false, 171 adaptiveHeight: true, 172 hideControlOnEnd: true, 173 preventDefaultSwipeY: true, 174 nextSelector: "#slider-next", 175 prevSelector: "#slider-prev", 176 nextText: "Següent", 177 prevText: "Anterior", 178 onSliderLoad: function () { 179 $( 180 "#cm_meteocat .bxslider, .o-widget--footer .highlights .bxslider" 181 ).css("display", "block"); 182 }, 183 });
184 } 185 186 // resize footer Plugins 187 resizeFooterPlugins(); 188 window.addEventListener("resize", resizeFooterPlugins); 189 190 /* Subscripció Newsletter (Butlletà Digital) */ 191 $('.NewsletterForm input:radio[name="group1"]').change(function () { 192 if ( 193 $(".NewsletterForm input:radio[name=group1]:checked").val() == "Totes" 194 ) { 195 $("#CategoryList:visible").slideUp("slow", function () { 196 setEqualContentColumns(); 197 }); 198 } else { 199 $("#CategoryList:hidden").slideDown("slow", function () { 200 setEqualContentColumns(); 201 }); 202 } 203 }); 204 $("INPUT[type='checkbox']").click(function () { 205 checkChildsNewsletterForm($(this).attr("id")); 206 checkParentsNewsletterForm($(this).parent().attr("id"), $(this).attr("id")); 207 }); 208 209 /* Filter for carrerer */ 210 if ($("body").hasClass("md_carrerer")) { 211 $(".conditional").click(function () { 212 var moduleFilterParent = $(this).closest("form#ModuleFilter"); 213 214 if (moduleFilterParent.length === 0) { 215 checkChildsFilterCategories($(this).attr("id")); 216 checkParentsFilterCategories( 217 $(this).parent().parent().parent().attr("id"), 218 $(this).attr("id") 219 ); 220 } 221 setEqualContentColumns(); 222 }); 223 } 224 225 /* Areas/Themes columnes */ 226 if ($("body").hasClass("theme")) { 227 setEqualContentThemes(); 228 window.addEventListener("resize", setEqualContentThemes); 229 } 230 231 /* External share buttons */ 232 shareTwitter(); 233 shareFacebook(); 234 235 // Filtres 236 if ($("#ContentFilter").length !== 0) { 237 $("#all_selection").click(function () { 238 $("#" + $(this).attr("rel") + " INPUT[type='checkbox']").attr( 239 "checked", 240 true 241 ); 242 return false; 243 }); 244 $("#none_selection").click(function () { 245 $("#" + $(this).attr("rel") + " INPUT[type='checkbox']").attr( 246 "checked", 247 false 248 ); 249 return false; 250 }); 251 $("#invert_selection").click(function () { 252 $("#" + $(this).attr("rel") + " INPUT[type='checkbox']").each( 253 function () { 254 $(this).attr("checked", !$(this).attr("checked")); 255 } 256 ); 257 return false; 258 }); 259 } 260 // Forms 261 $(document).on("submit", "form", function (e) { 262 $(this) 263 .find("input[type=checkbox]") 264 .each(function () { 265 var checkbox = $(this); 266 // Afegirem un camp ocult amb el mateix nom (y valor NO) davant 267 // del checkbox sense marcar per a que es passi el valor sempre 268 if (!checkbox.prop("checked")) { 269 checkbox 270 .clone() 271 .prop("type", "hidden") 272 .val("No") 273 .insertBefore(checkbox); 274 } 275 }); 276 }); 277 278 279 // Normalize search pagination parameter before initializing widgets 280 normalizeSearchPag(); 281 // Inicializa todos los sliders de widgets (incluido el de portada) 282 startWidgetSliders(); 283 resizeMasonry(watchMasonryGroup); 284 equalHeightIconTime(); 285 // 02-09-2021 - En el cas que es vulgui la mateixa alçada dels containers 286 //equalHeightWidgetContainerRow(); 287 $(".carousel").each(function () { 288 initCarousel($(this).attr("data-bs-id"), $(this).attr("data-bs-interval")); 289 }); 290} 291 292function reviewForm(formScope) { 293 // Limita la validació al formulari que fa submit; si no s'indica, valida tot el document. 294 var $scope = formScope && $(formScope).length ? $(formScope) : $(document); 295 var alertMessage = ""; 296 var returnReview = true; 297 var errorSubmit = $("#errorSubmit"); 298 $("#buttonSubmit").prop("disabled", true); 299 errorSubmit.empty(); 300 301 // Neteja marcadors d'error anteriors 302 $(".is-invalid").removeAttr("aria-invalid").removeAttr("aria-describedby").removeClass("is-invalid"); 303 $(".form-consent--invalid").removeClass("form-consent--invalid"); 304 $(".form-field-error").remove(); 305 306 // Construeix l'span d'error accessible (icona + role alert) i relaciona'l amb el camp via aria 307 function buildFieldError(field, message) { 308 var fieldId = field.attr("id"); 309 var errorId = fieldId ? fieldId + "-error" : ""; 310 field.attr("aria-invalid", "true"); 311 if (errorId) { 312 field.attr("aria-describedby", errorId); 313 } 314 return '<span' + (errorId ? ' id="' + errorId + '"' : '') + ' class="form-field-error" role="alert">
314' + 315 '<i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i> ' + message + '</span>'; 316 } 317 318 // Valida camps obligatoris â error inline per camp 319 $scope.find("[required]").each(function () { 320 var field = $(this); 321 var isEmpty = field.is("input[type=checkbox]") 322 ? !field.prop("checked") 323 : !field.val() || !field.val().trim(); 324 325 if (isEmpty) { 326 field.addClass("is-invalid"); 327 var errorMessage = buildFieldError(field, "Camp obligatori."); 328 var consent = field.closest(".form-consent"); 329 if (consent.length) { 330 consent.addClass("form-consent--invalid"); 331 consent.after(errorMessage); 332 } else { 333 field.after(errorMessage); 334 } 335 returnReview = false; 336 } 337 }); 338 339 // Valida format i confirmació d'emails â error inline per camp 340 $scope.find("input[type=email]").each(function () { 341 var field = $(this); 342 var nom = field.attr("name"); 343 var email = field.val().trim(); 344 var regexp = new RegExp("^copia_"); 345 346 if (!regexp.test(nom) && email !== "" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { 347 field.addClass("is-invalid"); 348 field.after(buildFieldError(field, "Adreça de correu electrònic no và lida.")); 349 returnReview = false; 350 } 351 352 if (regexp.test(nom)) { 353 var nombis = nom.replace("copia_", ""); 354 if ($scope.find("[name='" + nombis + "']").length > 0) { 355 if ($($scope.find("[name='" + nombis + "']").get(0)).val() !== $($scope.find("[name='" + nom + "']").get(0)).val()) { 356 field.addClass("is-invalid"); 357 field.after(buildFieldError(field, "Els correus electrònics no coincideixen.")); 358 returnReview = false; 359 } 360 } 361 } 362 }); 363 $scope 364 .find("input[type=checkbox]") 365 .each(function () { 366 var checkbox = $(this); 367 // Afegirem un camp ocult amb el mateix nom (y valor NO) davant 368 // del checkbox sense marcar per a que es passi el valor sempre 369 if (!checkbox.prop("checked")) { 370 checkbox 371 .clone() 372 .prop("type", "hidden") 373 .val("No") 374 .insertBefore(checkbox); 375 } 376 }); 377 378 var total = $("#total"); 379 if (total.length) { 380 var formTotal = calculaTotal(); 381 if (total.val() === 0 || formTotal === 0) { 382 alertMessage += "<li>El import de la compra ha de ser superior a 0.</li>"; 383 returnReview = false; 384 } 385 } 386 387 if (alertMessage !== "") { 388 errorSubmit.append( 389 '<div class="alert alert-danger">\n' + 390 ' <h4 id="submitError">Atenció!</h4> \n' + 391 " <ul>" + 392 alertMessage + 393 "</ul>" + 394 "</div>" 395 ); 396 // This prevents the page from scrolling down to where it was previously. 397 if ("scrollRestoration" in history) { 398 history.scrollRestoration = "manual"; 399 } 400 window.scrollTo(0, 0); 401 returnReview = false; 402 } 403 404 if (returnReview === false) { 405 $("#buttonSubmit").prop("disabled", false); 406 var firstInvalid = $(".is-invalid").first(); 407 if (firstInvalid.length) { 408 var stickyOffset = ($('#site-header').outerHeight() || 0) + 24; 409 $("html, body").animate({ scrollTop: firstInvalid.offset().top - stickyOffset }, 300); 410 firstInvalid.focus({ preventScroll: true }); 411 } 412 } 413 414 return returnReview; 415} 416 417function calculaTotal() { 418 var total = 0; 419 $("input[id$=_total]").each(function () { 420 let t; 421 const id_total = $(this).attr("id"); 422 const id = id_total.replace("_total", ""); 423 const id_quantitat = id_total.replace("_total", "_quantitat"); 424 const id_percentatge = id_total.replace("_total", "_percentatge"); 425 const id_preu = id_total.replace("_total", "_preu"); 426 const id_select = id_total.replace("_total", "_select_field"); 427 if ($("#" + id_quantitat).length) { 428 t = 429 parseFloat( 430 $("#" + id) 431 .val() 432 .replace(",", ".") 433 ) * 434 parseFloat( 435 $("#" + id_quantitat) 436 .val() 437 .replace(",", ".") 438 ); 439 } 440 if ($("#" + id_preu).length) { 441 t = 442 parseFloat( 443 $("#" + id) 444 .val() 445 .replace(",", ".") 446 ) * 447 parseFloat( 448 $("#" + id_preu) 449 .val() 450 .replace(",", ".") 451 ); 452 } 453 if ($("#" + id_percentatge).length) { 454 t = 455 (parseFloat( 456 $("#" + id) 457 .val() 458 .replace(",", ".") 459 ) * 460 parseFloat( 461 $("#" + id_percentatge) 462 .val() 463 .replace(",", ".") 464 )) / 465 100; 466 } 467 if ($("#" + id_select).length) { 468 t = parseFloat( 469 $("#" + id + "_total") 470 .val() 471 .replace(",", ".") 472 ); 473 } 474 if (!isNaN(t)) { 475 total += t; 476 } 477 }); 478 return total; 479} 480 481var currentRequest; 482var Calendari; 483var CalendariName; 484var CalendariId; 485var CalendarType; 486 487function buildCalendars() { 488 var item; 489 if (typeof calendars !== "undefined") { 490 for (var i = calendars.length - 1; i >= 0; i--) { 491 item = calendars[i]; 492 buildCalendar(item.id, item.data); 493 } 494 } 495} 496function buildCalendar(id, data, type = 0, day = "") { 497 if (typeof id === "undefined") return false; 498 499 var cutId = id.split("dv_calendar_"); 500 CalendariName = id; 501 CalendariId = cutId[1]; 502 CalendarType = type; 503 504 if (type === 0) { 505 CalendarType = $("#dv_calendar_" + id).attr("data-type"); 506 } 507 508 function getDateFromUrl() { 509 var params = new URLSearchParams(window.location.search); 510 var dateStr = params.get("date"); 511 if (dateStr) { 512 var parts = dateStr.split("-"); 513 return new Date(parts[0], parts[1] - 1, parts[2]); 514 } 515 return new Date(); 516 } 517 518 var getDateInfo = function (date, wantsClassName) { 519 var as_number = Calendar.dateToInt(date); 520 return data[as_number]; 521 }; 522 523 var cal = Calendar.setup({ 524 cont: id, 525 fdow: 1, 526 noScroll: true, 527 bottomBar: false, 528 animation: false, 529 titleFormat: "%B %Y", 530 dateInfo: getDateInfo, 531 date: getDateFromUrl(), 532 }); 533 534 Calendari = cal; 535 536 if (day !== "") { 537 cal.moveTo(day); 538 } 539 540 setEqualContentColumns(); 541 542 getDataCalendar(CalendariId); 543 544 if (CalendariId === "default") { 545 const idCalendar = CalendariId; 546 const category = $("#dv_calendar_" + idCalendar).attr("data-category"); 547 const dataToFind = new Date( 548 $("#dv_calendar_" + idCalendar + " .DynarchCalendar-month").attr( 549 "data-date" 550 ) 551 ); 552 ajaxCalendar(idCalendar, dataToFind, category); 553 } 554} 555 556function setDataCalendar(id, calendar, type, selected = 0) { 557 var cutId = id.split("dv_calendar_"); 558 CalendariName = id; 559 CalendariId = cutId[1]; 560 CalendarType = type; 561 if (selected !== 0) { 562 Calendari.moveTo(selected); 563 } 564} 565 566function getInternalCalendar(id) { 567 var cutId = id.split("dv_calendar_"); 568 Calendari = Calendar.refresh();
569 CalendariName = id; 570 CalendariId = cutId[1]; 571 572 getDataCalendar(CalendariId); 573} 574 575function getParameterByName(name) { 576 name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); 577 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 578 results = regex.exec(location.search); 579 return results === null 580 ? "" 581 : decodeURIComponent(results[1].replace(/\+/g, " ")); 582} 583 584function getDataCalendar(id) { 585 var monthDown = $( 586 "#dv_calendar_" + 587 id + 588 " div.DynarchCalendar-prevMonth.DynarchCalendar-navBtn" 589 ); 590 var monthUp = $( 591 "#dv_calendar_" + 592 id + 593 " div.DynarchCalendar-nextMonth.DynarchCalendar-navBtn" 594 ); 595 var dia = $("#dv_calendar_" + id + " div.DynarchCalendar-day.dia_marcat a"); 596 var diaLliure = $( 597 "#dv_calendar_" + id + " div.DynarchCalendar-day.dia_lliure a" 598 ); 599 var diaOcupat = $( 600 "#dv_calendar_" + id + " div.DynarchCalendar-day.dia_ocupat a" 601 ); 602 603 dia 604 .add(diaLliure) 605 .add(diaOcupat) 606 .on("click", function () { 607 console.log("ð DÃa clicado:", $(this).data("day")); 608 }); 609 610 monthDown.attr({ "data-id": id, role: "button", tabindex: "0", "aria-label": "Mes anterior" }); 611 monthUp.attr({ "data-id": id, role: "button", tabindex: "0", "aria-label": "Mes següent" }); 612 613 monthDown.on("mousedown", function (e) { 614 var id = $(this).attr("data-id"); 615 var category = $("#dv_calendar_" + id).attr("data-category"); 616 setTimeout(function () { 617 var data = new Date( 618 $("#dv_calendar_" + id + " .DynarchCalendar-month").attr("data-date") 619 ); 620 ajaxCalendar(id, data, category); 621 }, 0); 622 }); 623 624 monthDown.on("keydown", function (e) { 625 if (e.key === "Enter" || e.key === " ") { 626 e.preventDefault(); 627 this.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true })); 628 } 629 }); 630 631 monthUp.on("mousedown", function (e) { 632 var id = $(this).attr("data-id"); 633 var category = $("#dv_calendar_" + id).attr("data-category"); 634 setTimeout(function () { 635 var data = new Date( 636 $("#dv_calendar_" + id + " .DynarchCalendar-month").attr("data-date") 637 ); 638 ajaxCalendar(id, data, category); 639 }, 0); 640 }); 641 642 monthUp.on("keydown", function (e) { 643 if (e.key === "Enter" || e.key === " ") { 644 e.preventDefault(); 645 this.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true })); 646 } 647 }); 648} 649 650function ajaxCalendar(id, cal, cat = 0) { 651 var month = (cal.getMonth() + 1).toString().padStart(2, "0"); 652 var ajaxData; 653 654 if (id === "slot") { 655 ajaxData = { 656 id: $(".select2")[1].value, 657 params: cal.getFullYear() + "-" + month + "-01", 658 type: "slots", 659 }; 660 } else { 661 ajaxData = { 662 id: id, 663 params: cal.getFullYear() + "-" + month + "-01", 664 type: $("#dv_calendar_" + id).attr("data-type"), 665 category: cat, 666 }; 667 } 668 669 // Cancelar petición anterior 670 if (currentRequest) { 671 currentRequest.abort(); 672 } 673 674 currentRequest = $.ajax({ 675 cache: false, 676 type: "POST", 677 url: "/calendar", 678 data: ajaxData, 679 success: function (result) { 680 // console.log("Mes solicitado:", ajaxData.params); 681 682 if (result !== "") { 683 var obj = JSON.parse(result); 684 685 // Eliminar comprobación que ignora el mes por la primera clave 686 var requestedMonth = ajaxData.params.substring(0, 7).replace("-", ""); 687 688 if (id === "slot") { 689 clearCalendar(); 690 } 691 692 for (var k in obj) { 693 // Solo pintar los dÃas del mes solicitado 694 if (k.substring(0, 6) !== requestedMonth) continue; 695 696 if (obj[k] instanceof Object) { 697 var calendarDay = $( 698 "#dv_calendar_" + 699 id + 700 ' .DynarchCalendar-day[dyc-date="' + 701 k + 702 '"]' 703 ); 704 if (!calendarDay.length) continue; 705 706 calendarDay.removeAttr("dyc-type"); 707 calendarDay.attr("orioldyc-type", "date"); 708 calendarDay.addClass(obj[k]["klass"]); 709 calendarDay.html(""); 710 711 var attributeData = ""; 712 var onclick = ""; 713 var link = ""; 714 var diaMes = obj[k]["day"]; 715 716 if (id === "slot") { 717 link = "javascript:void(0)"; 718 attributeData = data; 719 onclick = 'onclick="showTimeSlots(' + k + ')"'; 720 } else { 721 link = obj[k]["lin"]; 722 } 723 724 calendarDay.append( 725 '<a href="' + 726 link + 727 '" class="day" data-selected ="' + 728 attributeData + 729 '" data-day="' + 730 k + 731 '" ' + 732 onclick + 733 ">" + 734 diaMes + 735 "</a>" 736 ); 737 } 738 } 739 } 740 }, 741 error: function (xhr, status, error) { 742 if (status !== "abort") { 743 console.error("â Error AJAX:", status, error); 744 } 745 }, 746 }); 747} 748 749function gotolink(url) { 750 window.location = url; 751} 752 753// Els SDK de tercers no es poden carregar sense consentiment: s'insereixen 754// bloquejats (type="text/plain" + data-name) i és Klaro qui els activa. 755function appendKlaroScript(id, service, src) { 756 if (document.getElementById(id)) { 757 return; 758 } 759 var js = document.createElement("script"); 760 js.id = id; 761 js.type = "text/plain"; 762 js.setAttribute("data-type", "text/javascript"); 763 js.setAttribute("data-name", service); 764 js.setAttribute("data-src", src); 765 document.body.appendChild(js); 766 applyKlaroConsentsToNewContent(); 767} 768 769function shareTwitter() { 770 if (!TWITTER || $("body").hasClass("home")) { 771 return; 772 } 773 appendKlaroScript("twitter-wjs", "twitter", "https://platform.twitter.com/widgets.js"); 774} 775 776function shareFacebook() { 777 if (!FACEBOOK || $("body").hasClass("home")) { 778 return; 779 } 780 appendKlaroScript("facebook-jssdk", "facebook", "https://connect.facebook.net/ca_ES/all.js#xfbml=1"); 781} 782 783function resizeMainMenu() { 784 if (!isTablet()) { 785 $("#Principal").css("display", "block"); 786 } else { 787 $("#Principal").css("display", "none"); 788 } 789} 790function checkResizeLogo() { 791 var finalWidth; 792 if (isTablet() && $("#mainLogo").attr("width") > 250) { 793 finalWidth = 250; 794 } else { 795 finalWidth = $("#mainLogo").attr("width"); 796 } 797 if (finalWidth != $("#mainLogo").width()) { 798 resizeLogo(finalWidth);
799 } 800} 801function resizeLogo(finalWidth) { 802 var currentWidth = $("#mainLogo").attr("width"); 803 var currentHeight = $("#mainLogo").attr("height"); 804 var ratio = finalWidth / currentWidth; 805 $("#mainLogo").width(currentWidth * ratio); 806 $("#mainLogo").height(currentHeight * ratio); 807} 808function openBlock(id) { 809 event.preventDefault(); 810 $("#" + id).slideDown("fold", function () { 811 setEqualContentColumns(); 812 }); 813} 814function closeBlock(id) { 815 event.preventDefault(); 816 $("#" + id).slideUp("fold", function () { 817 setEqualContentColumns(); 818 }); 819} 820function setEqualContentColumns() { 821 setEqualHeight($(".content .container > div.col")); 822} 823function setEqualContentThemes() { 824 setEqualHeight($(".content .container div.themeColumns > div.col")); 825} 826function setEqualHeight(columns) { 827 if (!isDesktop()) { 828 var currentHeight; 829 var tallestcolumn = 0; 830 columns.height("auto"); 831 columns.each(function () { 832 currentHeight = $(this).outerHeight(); 833 if (currentHeight > tallestcolumn) { 834 tallestcolumn = currentHeight; 835 } 836 }); 837 columns.each(function () { 838 if ($(this).hasClass("responsiveHeight") && isTablet()) { 839 $(this).height("auto"); 840 } else { 841 $(this).height(tallestcolumn); 842 } 843 }); 844 } else { 845 columns.height("auto"); 846 } 847} 848function removeBlankColumns() { 849 var columns = []; 850 var totalColumns = 0; 851 $(".content .columns > .col:visible").each(function (index) { 852 var html = $(this).html().replace(/\s/g, "").replace(" ", ""); 853 if (html == "") { 854 $(this).remove(); 855 } else { 856 if ($(this).hasClass("double")) { 857 columns[index] = 2; 858 totalColumns = totalColumns + 2; 859 } else if ($(this).hasClass("triple")) { 860 columns[index] = 3; 861 totalColumns = totalColumns + 3; 862 } else { 863 columns[index] = 1; 864 totalColumns = totalColumns + 1; 865 } 866 } 867 }); 868} 869function startClock(servertime) { 870 var localtime = new Date().getTime(); 871 localtime = Math.floor(localtime / 1000); 872 var dif = servertime - localtime; 873 updateClock(dif); 874} 875function updateClock(dif) { 876 var today = new Date(); 877 if (dif > 0 || dif < 0) { 878 today.setSeconds(today.getSeconds() + dif); 879 } 880 var Y = today.getFullYear(); 881 var M = today.getMonth() + 1; 882 var D = today.getDate(); 883 var h = today.getHours(); 884 var m = today.getMinutes(); 885 h = checkTime(h); 886 m = checkTime(m); 887 M = checkTime(M); 888 D = checkTime(D); 889 $("#clock").html(D + "." + M + "." + Y + " | " + h + ":" + m); 890 var t = setTimeout(function () { 891 updateClock(dif); 892 }, 10000); 893} 894function checkTime(i) { 895 if (i < 10) { 896 i = "0" + i; 897 } // add zero in front of numbers < 10 898 return i; 899} 900function removeFocus(level) { 901 // Remove focus attribute of current level and childs 902 $("." + level).removeAttr("focus"); 903 $("." + level + " *").removeAttr("focus"); 904} 905function addFocus(object) { 906 // Add focus attribute of current level and parent 907 $(object).parents("li").attr("focus", true); 908 $(object).focus(); 909} 910function setFocus(object) { 911 var classes = $(object).parent().attr("class"); 912 var level = getLevelFromClasses(classes); 913 removeFocus(level); 914 addFocus(object); 915 return object; 916} 917function getLevelFromClasses(string) { 918 var level; 919 $.each(string.split(" "), function (key, value) { 920 if (value.substring(0, 5) == "level") { 921 level = value; 922 } 923 }); 924 return level; 925} 926function ssl_check_and_redirect(url) { 927 $.ajax({ 928 url: url, 929 dataType: "script", 930 success: function () { 931 window.location.replace(url); 932 }, 933 }); 934} 935function redirect(url, target) { 936 if (target === "_blank") { 937 window.open(url, "_blank"); 938 } else { 939 window.location = url; 940 } 941} 942function checkParentsNewsletterForm(id, current) { 943 if (typeof id !== "undefined" && id != "CategoryList") { 944 var match = 0; 945 var total = 0; 946 $("#" + id) 947 .children("input[type='checkbox']") 948 .each(function (index) { 949 total = total + 1; 950 if (!$(this).is(":checked")) { 951 match = match + 1; 952 } 953 }); 954 var parent_input = id.split("-"); 955 if (match == total) { 956 $("#" + parent_input[1]).attr("checked", true); 957 } else { 958 $("#" + parent_input[1]).attr("checked", false); 959 } 960 checkParentsNewsletterForm( 961 $("#" + parent_input[1]) 962 .parent() 963 .attr("id"), 964 $("#" + parent_input[1]).attr("id") 965 ); 966 } 967} 968function checkChildsNewsletterForm(id) { 969 if (!$("#" + id).is(":checked")) { 970 $("#childs-" + id + " input[type='checkbox']").each(function (index) { 971 if ($(this).is("input[type='checkbox']")) { 972 $(this).attr("checked", false); 973 } 974 });
975 } else { 976 $("#childs-" + id + " input[type='checkbox']").each(function (index) { 977 if ($(this).is("input[type='checkbox']")) { 978 $(this).attr("checked", true); 979 } 980 }); 981 } 982} 983function switchFilter(id) { 984 var obj = document.getElementById(id); 985 if (obj.className == "detallHide") { 986 obj.className = ""; 987 } else { 988 obj.className = "detallHide"; 989 } 990} 991function checkParentsFilterCategories(id, current) { 992 if ($("#" + current).is(":checked")) { 993 var match = 0; 994 $("#" + id + " input[type='checkbox']").each(function (index) { 995 if (!$(this).is(":checked")) { 996 match = match + 1; 997 } 998 }); 999 var parent_input = id.split("-"); 1000 if (match > 0) { 1001 $("#" + parent_input[1]).attr("checked", true); 1002 } else { 1003 $("#" + parent_input[1]).attr("checked", false); 1004 } 1005 checkParentsFilterCategories( 1006 $("#" + parent_input[1]) 1007 .parent() 1008 .parent() 1009 .attr("id"), 1010 $("#" + parent_input[1]).attr("id") 1011 ); 1012 } 1013} 1014function checkChildsFilterCategories(id) { 1015 if (!$("#" + id).is(":checked")) { 1016 $("#childs-" + id + " input[type='checkbox']").each(function (index) { 1017 if ($(this).is("input[type='checkbox']")) { 1018 $(this).attr("checked", false); 1019 } 1020 }); 1021 $("#childs-" + id + "").hide(); 1022 setEqualContentColumns(); 1023 } else { 1024 $("#childs-" + id + " input[type='checkbox']").each(function (index) { 1025 if ($(this).is("input[type='checkbox']")) { 1026 $(this).attr("checked", true); 1027 } 1028 }); 1029 $("#childs-" + id + "").show(); 1030 } 1031} 1032// Klaro processa el DOM al carregar la pà gina, quan els widgets ajax encara no 1033// existeixen. Cal repassar-lo després d'inserir-los o els embeds amb data-name 1034// (xarxes socials, vÃdeos...) es queden sense desbloquejar i sense avÃs de 1035// consentiment: l'usuari només hi veu un buit. 1036function applyKlaroConsentsToNewContent() { 1037 if (!window.klaro) { 1038 return; 1039 } 1040 1041 try { 1042 if (getCookie("klaro-v2") && typeof window.klaro.getManager === "function") { 1043 var manager = window.klaro.getManager(); 1044 if (manager && typeof manager.applyConsents === "function") { 1045 manager.applyConsents(); 1046 } 1047 } 1048 1049 if (typeof window.klaro.render === "function" && window.klaroConfig) { 1050 window.klaro.render(window.klaroConfig, {}); 1051 } 1052 } catch (e) {} 1053} 1054 1055function loadAjaxWidgets() { 1056 $(".js-widget[data-load='ajax']").each(function () { 1057 var id = $(this).attr("data-id"); 1058 var idPage = $(this).attr("data-page") ?? 0; 1059 var widget = $(this); 1060 var widgetContent = widget.find(".js-widget__content"); 1061 loadAjaxWidget(id, idPage, widget, widgetContent); 1062 }); 1063} 1064function loadAjaxWidget(id, idPage, widget, widgetContent) { 1065 $.ajax({ 1066 cache: false, 1067 type: "POST", 1068 url: "/widget", 1069 data: { 1070 id: id, 1071 idpage: idPage, 1072 }, 1073 success: function (result) { 1074 if (result.trim().length) { 1075 widget.show(); 1076 widgetContent.html(result); 1077 reloadWidgetFunctionalities(); 1078 } else { 1079 widget.hide(); 1080 } 1081 }, 1082 }); 1083} 1084 1085function reloadWidgetFunctionalities() { 1086 $(".js-widget__content img").each(function () { 1087 if (typeof this.load !== "undefined") { 1088 this.load(); 1089 } 1090 }); 1091 1092 applyKlaroConsentsToNewContent(); 1093 1094 if ($("#cm_meteocat ul.bxslider").length !== 0) { 1095 $("#cm_meteocat .bxslider").bxSlider({ 1096 infiniteLoop: false, 1097 adaptiveHeight: true, 1098 hideControlOnEnd: true, 1099 preventDefaultSwipeY: true, 1100 nextSelector: "#slider-next", 1101 prevSelector: "#slider-prev", 1102 nextText: "Següent", 1103 prevText: "Anterior", 1104 onSliderLoad: function () { 1105 $("#cm_meteocat .bxslider").css("display", "block"); 1106 }, 1107 }); 1108 } 1109} 1110function hideEmptyWidgets() { 1111 // Amagar widgets 1112 $(".o-widget > .o-widget-wrapper > .o-widget__content").each(function () { 1113 if (!$(this).html().trim()) { 1114 var currentWidgetElement = $(this).closest(".o-widget"); 1115 1116 $(currentWidgetElement).hide(); 1117 if (!$(currentWidgetElement).hasClass("empty-widget")) { 1118 $(this).closest(".o-widget").addClass("empty-widget"); 1119 } 1120 } 1121 }); 1122 1123 // Amagar contenidors 1124 $(".o-widget.o-widget-contenidor").each(function () { 1125 var currentContainer = $(this); 1126 var childWidgets = $(this).find(".o-widget"); 1127 var totalChildWidgets = childWidgets.length; 1128 var hiddenWidgets = 0; 1129 1130 $(childWidgets).each(function () { 1131 if ($(this).hasClass("empty-widget")) { 1132 hiddenWidgets++; 1133 if (hiddenWidgets >= totalChildWidgets) { 1134 $(currentContainer).hide(); 1135 1136 if (!$(currentContainer).hasClass("empty-widget")) { 1137 $(currentContainer).addClass("empty-widget"); 1138 } 1139 } 1140 } 1141 });
1142 }); 1143} 1144function checkPasswordStrength() { 1145 var accpetedStrengths = ["medium", "strong"]; 1146 var passwordStrength = $("div[data-meter='password1']").attr("class"); 1147 return $.inArray(passwordStrength, accpetedStrengths); 1148} 1149function readCookie(name) { 1150 var nameEQ = name + "="; 1151 var ca = document.cookie.split(";"); 1152 for (var i = 0; i < ca.length; i++) { 1153 var c = ca[i]; 1154 while (c.charAt(0) == " ") c = c.substring(1, c.length); 1155 if (c.indexOf(nameEQ) == 0) { 1156 return decodeURIComponent(c.substring(nameEQ.length, c.length)); 1157 } 1158 } 1159 return null; 1160} 1161 1162function onBlurSelect(option) { 1163 window.open($("#code_" + option).data("url"), "_self"); 1164} 1165 1166function handleSelect(element) { 1167 var isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1; 1168 if ($("#code_" + element.value).is(":selected")) { 1169 if ($("#code_" + element.value).data("auto") === "auto") { 1170 if (isFirefox) { 1171 window.location = $("#code_" + element.value).data("url"); 1172 } else { 1173 window.open($("#code_" + element.value).data("url"), "_self"); 1174 } 1175 } else { 1176 window.location = $("#code_" + element.value).data("url"); 1177 } 1178 } 1179} 1180function formGetParams() { 1181 $(".tplFilter form") 1182 .find(":input[type=text]") 1183 .filter(function () { 1184 if (this.value == "") { 1185 return true; 1186 } 1187 }) 1188 .attr("disabled", "disabled"); 1189 $(".tplFilter form") 1190 .find(":input[type=checkbox]") 1191 .filter(function () { 1192 if (this.checked == false) { 1193 return true; 1194 } 1195 }) 1196 .attr("disabled", "disabled"); 1197 $(".tplFilter form") 1198 .find("select") 1199 .filter(function () { 1200 if (this.value == -1) { 1201 return true; 1202 } 1203 }) 1204 .attr("disabled", "disabled"); 1205} 1206function startWidgetSliders() { 1207 if (isTablet) { 1208 $(".dinamic > .tplSliderBig .bxslider").css("display", "block"); 1209 $(".dinamic > .tplSliderSmall .bxslider").css("display", "block"); 1210 } 1211 var interval = parseInt( 1212 $(".dinamic > .tplSliderBig .bxslider").attr("data-interval") 1213 ); 1214 1215 $(".dinamic > .tplSliderBig .bxslider").each(function () { 1216 var interval = $(this).data("interval"); 1217 $(this).bxSlider({ 1218 infiniteLoop: true, 1219 adaptiveHeight: true, 1220 hideControlOnEnd: true, 1221 preventDefaultSwipeX: true, 1222 auto: true, 1223 autoStart: true, 1224 pause: interval, 1225 nextText: "Següent", 1226 prevText: "Anterior", 1227 onSliderLoad: function () { 1228 $(".dinamic > .tplSliderBig .bxslider").css("display", "block"); 1229 }, 1230 }); 1231 }); 1232 1233 $(".dinamic > .tplSliderSmall .bxslider").bxSlider({ 1234 infiniteLoop: false, 1235 adaptiveHeight: true, 1236 hideControlOnEnd: true, 1237 minSlides: 1, 1238 maxSlides: 7, 1239 slideWidth: 130, 1240 slideMargin: 0, 1241 preventDefaultSwipeY: true, 1242 nextText: "Següent", 1243 prevText: "Anterior", 1244 onSliderLoad: function () { 1245 $(".dinamic > .tplSliderSmall .bxslider").css("display", "block"); 1246 }, 1247 }); 1248} 1249function equalizeHeights(parent, className) { 1250 $(parent).each(function () { 1251 var maximum = 0; 1252 $(this) 1253 .find(className) 1254 .each(function () { 1255 var value = parseFloat($(this).height()); 1256 maximum = value > maximum ? value : maximum; 1257 }); 1258 $(this).find(className).height(maximum); 1259 }); 1260} 1261function resizeMasonry(clsGroup) { 1262 for (var clsI in clsGroup) { 1263 var cls = clsGroup[clsI]; 1264 var clsCap = cls.charAt(0).toUpperCase() + cls.slice(1); 1265 if ($("." + cls).length) { 1266 $("." + cls).masonry({ 1267 gutter: 10, 1268 stagger: 100, 1269 resize: false, 1270 horizontalOrder: true, 1271 percentPosition: false, 1272 itemSelector: ".tpl" + clsCap, 1273 columnWidth: ".tpl" + clsCap, 1274 }); 1275 } 1276 } 1277} 1278function toggleRendiment() { 1279 $.ajax({ 1280 cache: false, 1281 url: "/rendiment", 1282 complete: function () { 1283 location.reload(); 1284 }, 1285 }); 1286} 1287function amagarBarra() { 1288 $(".topAlert").hide(); 1289 document.cookie = 1290 "PHPSESSID=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"; 1291} 1292 1293/** 1294 * Fucionalitat pels modals de Imatges, Videos i PDF's per visor 1295 */ 1296 1297// Imatge principal 1298function modalsImage() { 1299 // Get the modal Images 1300 // Get the image and insert it inside the modal - use its 'alt' text as a caption 1301 var img = $("#imageItem"); 1302 img.on("click", function () { 1303 openGallery(0); 1304 }); 1305} 1306 1307// Obrir modal per Id imatge 1308function openGallery(id) { 1309 id = String(id); 1310 1311 var $img; 1312 if (id === '0') { 1313 $img = $('#imgItem0'); 1314 if (!$img || !$img.length) $img = $('#imageItem0').find('img').first(); 1315 } else { 1316 $img = $('#imageGallery' + id); 1317 } 1318 1319 if (!$img || !$img.length) { 1320 console.warn('openGallery: imagen no encontrada para id', id); 1321 var $dl = $('#DownloadPrettyLink'); 1322 if ($dl && $dl.length && $dl.attr('href')) { 1323 var srcDl = $dl.attr('href'); 1324 $('#downloadImage').empty().append("<a id='DownloadPrettyLink' href='" + srcDl + "' download>Descarrega la imatge</a>"); 1325 if ($('#imageCarousel0').length) $('#imageCarousel0').attr('src', srcDl); 1326 $('#ImageModal').modal('show'); 1327 $('#closeModal').off('click.openGallery').on('click.openGallery', function () { $('#ImageModal').modal('hide'); }); 1328 } 1329 return; 1330 } 1331 1332 // Leer atributos 1333 var src = $img.attr('src') || $img.attr('data-src') || $img.attr('data-action') || $img.attr('href') || ''; 1334 var alt = $img.attr('alt') || ''; 1335 var text = $img.attr('data-content') || $img.attr('data-title') || ''; 1336 1337 // Actualizar UI 1338 $('#imageText').html(text || ''); 1339 $('#downloadImage').empty().append("<a id='DownloadPrettyLink' href='" + src + "' download>Descarrega la imatge</a>"); 1340 1341 // Mostrar modal 1342 $('#ImageModal').modal('show'); 1343 1344 // Si hay carrusel, mover al slide que tenga la misma src 1345 var carouselEl = document.querySelector('#carouselControls'); 1346 if (carouselEl) { 1347 var slides = carouselEl.querySelectorAll('.carousel-item img'); 1348 var targetIndex = -1; 1349 for (var i = 0; i < slides.length; i++) { 1350 var slideSrc = slides[i].getAttribute('src') || ''; 1351 if (slideSrc === src || (src && slideSrc && (slideSrc.endsWith(src) || src.endsWith(slideSrc)))) { 1352 targetIndex = i; 1353 break; 1354 } 1355 }
1356 var carousel = bootstrap.Carousel.getInstance(carouselEl) || new bootstrap.Carousel(carouselEl, { interval: false }); 1357 if (targetIndex >= 0) { 1358 carousel.to(targetIndex); 1359 // Actualizar texto y enlace de descarga según el slide seleccionado 1360 try { 1361 var slideImg = slides[targetIndex]; 1362 var newSrc = slideImg.getAttribute('src') || slideImg.getAttribute('data-src') || ''; 1363 var newText = slideImg.getAttribute('data-title') || slideImg.getAttribute('data-content') || ''; 1364 $('#imageText').html(newText); 1365 $('#downloadImage').empty().append("<a id='DownloadPrettyLink' href='" + newSrc + "' download>Descarrega la imatge</a>"); 1366 } catch(e) { } 1367 } else { 1368 var activeImg = carouselEl.querySelector('.carousel-item.active img'); 1369 if (activeImg) { 1370 activeImg.setAttribute('src', src); 1371 activeImg.setAttribute('alt', alt || ''); 1372 $('#imageText').html(text || ''); 1373 $('#downloadImage').empty().append("<a id='DownloadPrettyLink' href='" + src + "' download>Descarrega la imatge</a>"); 1374 } 1375 } 1376 } else { 1377 if ($('#imageCarousel0').length) $('#imageCarousel0').attr('src', src).attr('alt', alt || ''); 1378 } 1379 1380 // Evitar handlers duplicados 1381 $('#closeModal').off('click.openGallery').on('click.openGallery', function () { $('#ImageModal').modal('hide'); }); 1382 // Actualizar texto y enlace cuando se cambia de slide dentro del modal 1383 $('#carouselControls').off('slide.bs.carousel.openGallery').on('slide.bs.carousel.openGallery', function (e) { 1384 var idSlide = e.to; 1385 var imgEl = document.querySelector('#imageGalleryModal' + idSlide) || document.querySelector('#photoImageGalleryModal' + idSlide) || document.querySelector('#imageGalleryModal' + idSlide); 1386 if (imgEl) { 1387 var title = imgEl.getAttribute('data-title') || imgEl.getAttribute('data-content') || ''; 1388 var href = imgEl.getAttribute('src') || imgEl.getAttribute('data-src') || ''; 1389 // No rellenar con filename ni con atributos del artÃculo â dejar en blanco si no hay tÃtulo explÃcito 1390 $('#imageText').empty().append(title); 1391 $('#downloadImage').empty().append("<a id='DownloadPrettyLink' href='" + href + "' download>Descarrega la imatge</a>"); 1392 } 1393 }); 1394} 1395 1396 1397// Obrir modal per Id imatge 1398function openPhotoGallery(id) { 1399 var imgGallery = 1400 id === 0 1401 ? typeof $("#photoImageCarousel")[0] != "undefined" 1402 ? $("#photoImageCarousel")[0] 1403 : typeof $("#photoImageCarousel" + id)[0].src != "undefined" 1404 ? $("#photoImageCarousel" + id)[0] 1405 : $("#photoImageCarousel" + id) 1406 : typeof $("#photoImageCarousel" + id)[0].src != "undefined" 1407 ? $("#photoImageCarousel" + id)[0] 1408 : $("#photoImageCarousel" + id); 1409 var imgCarouselGallery = $("#photoImageCarousel" + id); 1410 var modalImgGallery = $("#photoImageModal"); 1411 var sourceImage = $("#sourceImage"); 1412 var close = $("#closeModalGallery"); 1413 //var titleImg = $('.title-head'); 1414 var download = $("#downloadImage"); 1415 var imageText = $("#imageText"); 1416 var $indicatorsGallery = $(".carousel-inner.gallery"); 1417 if (id === 0) { 1418 imgCarouselGallery.attr("src", imgGallery.src); 1419 } else if (!imgCarouselGallery.hasOwnProperty("src")) { 1420 var imgCarousel = $("#photoImageCarousel0"); 1421 imgCarouselGallery.attr("src", imgGallery.src); 1422 } 1423 $indicatorsGallery.find(".active").removeClass("active"); 1424 sourceImage.attr("src", id === 0 ? imgGallery.src : imgGallery.src); 1425 download.empty(); 1426 download.append( 1427 "<a id='DownloadPrettyLink' href='" + 1428 (id === 0 ? imgGallery.src : imgGallery.src) + 1429 "' download>Descarrega la imatge</a>" 1430 ); 1431 imageText.empty(); 1432 imageText.append(imgGallery.getAttribute("data-content")); 1433 //titleImg.append((id === 0) ? imgGallery.getAttribute('data-title') : imgGallery.getAttribute('data-title'));
1434 $("#imageText").empty(); 1435 $("#imageText").append(imgGallery.getAttribute("alt")); 1436 imgCarouselGallery.attr("alt", imgGallery.getAttribute("alt")); 1437 $("#photoImageCarouselM" + id).addClass("active"); 1438 modalImgGallery.modal("show"); 1439 1440 close.on("click", function () { 1441 modalImgGallery.modal("hide"); 1442 }); 1443 1444 var myCarouselGallery = $("#carouselControls"); 1445 1446 myCarouselGallery.on("slide.bs.carousel", function (e) { 1447 var id = e.to; 1448 var imgEl = document.querySelector('#imageGalleryModal' + id) || document.querySelector('#photoImageGalleryModal' + id); 1449 if (imgEl) { 1450 var title = imgEl.getAttribute('data-title') || imgEl.getAttribute('alt') || ''; 1451 var href = imgEl.getAttribute('src') || imgEl.getAttribute('data-src') || ''; 1452 $("#imageText").empty().append(title); 1453 $("#downloadImage").empty().append("<a id='DownloadPrettyLink' href='" + href + "' download>Descarrega la imatge</a>"); 1454 } 1455 }); 1456} 1457 1458function openVideo(id) { 1459 var video = $("#videoItem" + id); 1460 if (!video.length) return; 1461 1462 var type = (video.attr("data-type") || "").toUpperCase(); 1463 var videoUrl = video.attr("data-src") || ""; 1464 var videoTitle = video.attr("data-text") || ""; 1465 var idVideo = video.attr("data-id") || ""; 1466 1467 var modalVideo = $("#videoModal"); 1468 var iframe = $("#iframeVideo"); 1469 var title = $(".title-head"); 1470 var titleVideo = $(".titleVideo"); 1471 var tiktok = $(".tiktok-div-embed"); 1472 var closeVideo = $("#closeModalVideo"); 1473 1474 closeVideo.off("click").on("click", function (e) { 1475 e.preventDefault(); 1476 modalVideo.modal("hide"); 1477 }); 1478 1479 modalVideo.off("hidden.bs.modal").on("hidden.bs.modal", function () { 1480 if (iframe.length) iframe.attr("src", ""); 1481 if (tiktok.length) tiktok.empty().hide(); 1482 }); 1483 1484 if (title.length) title.empty(); 1485 if (titleVideo.length) { 1486 titleVideo.empty(); 1487 titleVideo.text(videoTitle); 1488 } 1489 1490 if (iframe.length) iframe.attr("src", "").hide(); 1491 if (tiktok.length) tiktok.empty().hide(); 1492 1493 modalVideo.modal("show"); 1494 1495 if (type === "TIKTOK") { 1496 if (!idVideo) { 1497 if (tiktok.length) { 1498 tiktok.html('<a href="' + videoUrl + '" target="_blank" rel="noopener">Ver vÃdeo</a>').show(); 1499 } 1500 return; 1501 } 1502 $.ajax({
1503 cache: false, 1504 type: "POST", 1505 url: "/requestvideo", 1506 data: { id: idVideo }, 1507 success: function (result) { 1508 if (tiktok.length) { 1509 tiktok.empty(); 1510 if (result && String(result).trim().length) { 1511 tiktok.html(result); 1512 } 1513 tiktok.show(); 1514 } 1515 } 1516 }); 1517 } else { 1518 if (iframe.length) iframe.attr("src", videoUrl).show(); 1519 } 1520} 1521 1522function stopVideo(iframe, video) { 1523 iframe.attr("src", ""); 1524 iframe.hide(); 1525} 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561/** 1562 * Bloquea iframes "raw" (pegados en HTML) según KlaroConfig: 1563 * - Si el iframe pertenece a un servicio conocido por Klaro -> se gestiona por consentimiento. 1564 * - Si pertenece a un dominio no registrado (no existe servicio Klaro) -> se bloquea al 100%. 1565 * 1566 * Requiere: 1567 * - window.klaroConfig.services (array) 1568 * - window.klaro.getManager() (para lectura/escritura de consentimiento) 1569 */ 1570var __consentSnapshotLast = null; 1571var __consentSnapshotTimer = null; 1572function openPdf(value) { 1573 var pdfItem = $("#pdfItem" + value); 1574 var iframe = $("#iframePdf"); 1575 var modalPdf = $("#pdfModal"); 1576 var title = $(".title-head"); 1577 var titlePdf = $(".titlePdf"); 1578 var closePdf = $("#closeModalPDF"); 1579 1580 title.empty(); 1581 iframe.attr("src", pdfItem.attr("data-action")); 1582 titlePdf.empty(); 1583 titlePdf.append(pdfItem.attr("title")); 1584 modalPdf.modal("show"); 1585 1586 closePdf.on("click", function () { 1587 modalPdf.modal("hide"); 1588 }); 1589} 1590 1591function modalsPdf() { 1592 // Get the modal Pdf 1593 var pdfItem = $("#pdfItem"); 1594 var iframe = $("#iframePdf"); 1595 var modalPdf = $("#pdfModal"); 1596 var title = $(".title-head"); 1597 var titlePdf = $(".titlePdf"); 1598 var closePdf = $("#closeModalPDF"); 1599 1600 pdfItem.on("click", function () { 1601 title.empty(); 1602 iframe.attr("src", pdfItem.attr("data-action")); 1603 titlePdf.empty(); 1604 titlePdf.append(this.title); 1605 modalPdf.modal("show"); 1606 }); 1607 1608 closePdf.on("click", function () { 1609 modalPdf.modal("hide"); 1610 }); 1611} 1612 1613function toSlideImage(event) { 1614 var to = event.to; 1615 var download = $("#downloadImage"); 1616 var imgGallery = $("#imageGalleryModal" + to); 1617 1618 download.empty(); 1619 download.append( 1620 "<a id='DownloadPrettyLink' href='" + 1621 imgGallery.attr("src") + 1622 "' download>Descarrega la imatge</a>" 1623 ); 1624} 1625 1626/** 1627 * Funcionalitat de filtes a Hemeroteca 1628 * Data Dev : 27/08/2021 1629 */ 1630 1631function filterCategories( 1632 categoriesArray, 1633 selectedType = 0, 1634 selectedCategory = 0 1635) { 1636 var comboCategory = $("#archive_category"); 1637 var labelCategory = $("#label_archive_category"); 1638 labelCategory.hide(); 1639 comboCategory.hide(); 1640 if (selectedType !== 0) { 1641 var val = selectedType; 1642 1643 if (categoriesArray[val].length > 0) { 1644 comboCategory.empty(); 1645 comboCategory.append( 1646 $("<option></option>").val("").html("Tot") 1647 ); 1648 } 1649 $.each(categoriesArray[val], function (key, value) { 1650 comboCategory.append( 1651 $("<option></option>").val(value.category).html(value.name) 1652 ); 1653 if (selectedCategory === value.category) { 1654 comboCategory.val(value.category); 1655 } 1656 }); 1657 1658 if (categoriesArray[val].length > 0) { 1659 labelCategory.show(); 1660 comboCategory.show(); 1661 } else { 1662 labelCategory.hide(); 1663 comboCategory.hide(); 1664 } 1665 } 1666 1667 $("#archive_type").on("change", function (key, value) { 1668 var val = $("#archive_type").val(); 1669 if (categoriesArray[val].length > 0) { 1670 comboCategory.empty(); 1671 comboCategory.append( 1672 $("<option></option>").val("").html("Tot") 1673 ); 1674 } 1675 $.each(categoriesArray[val], function (key, value) { 1676 comboCategory.append( 1677 $("<option></option>").val(value.category).html(value.name) 1678 ); 1679 if (selectedCategory === value.category) { 1680 comboCategory.val(value.category); 1681 } 1682 }); 1683 1684 if (categoriesArray[val].length > 0) { 1685 labelCategory.show(); 1686 comboCategory.show(); 1687 } else { 1688 labelCategory.hide(); 1689 comboCategory.hide(); 1690 } 1691 }); 1692} 1693 1694function equalHeightIconTime() { 1695 //$('.iconTime').each(function() { 1696 // var maxHeight = 0; 1697 // $(this).find('.tplIconTime').height('auto'); 1698 // $(this).find('.tplIconTime').each(function (index) { 1699 // if ($(this).height() > maxHeight) 1700 // maxHeight = $(this).height(); 1701 // });
1702 // $(this).find('.tplIconTime').height(maxHeight); 1703 //}); 1704} 1705 1706function equalHeightWidgetContainerRow() { 1707 $(".o-widget-container.row").each(function () { 1708 var maxHeight = 0; 1709 $(this).find(".o-widget-wrapper").height("auto"); 1710 $(this) 1711 .find(".o-widget-wrapper") 1712 .each(function (index) { 1713 if ($(this).height() > maxHeight) maxHeight = $(this).height(); 1714 }); 1715 $(this).find(".backgroundColor-BX").height(maxHeight); 1716 }); 1717} 1718 1719// datepicker inicialització 1720function datepickerInit() { 1721 !(function (a) { 1722 a.fn.datepicker.dates.ca = { 1723 days: [ 1724 "Diumenge", 1725 "Dilluns", 1726 "Dimarts", 1727 "Dimecres", 1728 "Dijous", 1729 "Divendres", 1730 "Dissabte", 1731 ], 1732 daysShort: ["Diu", "Dil", "Dmt", "Dmc", "Dij", "Div", "Dis"], 1733 daysMin: ["dg", "dl", "dt", "dc", "dj", "dv", "ds"], 1734 months: [ 1735 "Gener", 1736 "Febrer", 1737 "Març", 1738 "Abril", 1739 "Maig", 1740 "Juny", 1741 "Juliol", 1742 "Agost", 1743 "Setembre", 1744 "Octubre", 1745 "Novembre", 1746 "Desembre", 1747 ], 1748 monthsShort: [ 1749 "Gen", 1750 "Feb", 1751 "Mar", 1752 "Abr", 1753 "Mai", 1754 "Jun", 1755 "Jul", 1756 "Ago", 1757 "Set", 1758 "Oct", 1759 "Nov", 1760 "Des", 1761 ], 1762 today: "Avui", 1763 monthsTitle: "Mesos", 1764 clear: "Esborrar", 1765 weekStart: 1, 1766 format: "dd-mm-yyyy", 1767 }; 1768 })(jQuery); 1769 1770 $.fn.datepicker.defaults.format = "dd-mm-yyyy"; 1771 $.fn.datepicker.defaults.autoclose = true; 1772 $.fn.datepicker.defaults.language = "ca"; 1773 $(function () { 1774 $(".datepicker").datepicker(); 1775 }); 1776 1777 $(".del-ini").on("click", function () { 1778 $(".inputdateini").datepicker("setDate", null); 1779 }); 1780 $(".del-fi").on("click", function () { 1781 $(".inputdatefi").datepicker("setDate", null); 1782 }); 1783} 1784 1785function toSlideImage(event) { 1786 var to = event.to; 1787 var download = $("#downloadImage"); 1788 var imgGallery = $("#imageGalleryModal" + to); 1789 var imageText = $("#imageText"); 1790 download.empty(); 1791 download.append( 1792 "<a id='DownloadPrettyLink' href='" + 1793 imgGallery.attr("src") + 1794 "' download>Descarrega la imatge</a>" 1795 ); 1796 imageText.empty(); 1797 imageText.append(imgGallery[0].getAttribute("data-title")); 1798} 1799 1800function carouselControlSmall() { 1801 $(".carousel-item.small").each(function () { 1802 var next = $(this).next(); 1803 if (!next.length) { 1804 next = $(this).siblings(":first"); 1805 } 1806 }); 1807 1808 $(".carousel-control-prev.w-auto").on("click", function () { 1809 var content = parseInt(this.getAttribute("data-content")); 1810 var itemActiu = $(".carousel-item.content-" + content + ".small.active"); 1811 var items = $(".carousel-item.content-" + content + ".small"); 1812 var total = parseInt(this.getAttribute("data-end")); 1813 var posicioActual = parseInt(itemActiu.attr("data-id")) - 1; 1814 var posicioNova = 1; 1815 if (posicioActual < 0) { 1816 posicioNova = total; 1817 } else if (posicioActual >= 0) { 1818 posicioNova = posicioActual; 1819 } 1820 itemActiu.removeClass("active"); 1821 items[posicioNova].classList.add("active"); 1822 }); 1823 $(".carousel-control-next.w-auto").on("click", function () { 1824 var content = parseInt(this.getAttribute("data-content")); 1825 var itemActiu = $(".carousel-item.content-" + content + ".small.active"); 1826 var items = $(".carousel-item.content-" + content + ".small"); 1827 var total = parseInt(this.getAttribute("data-end")); 1828 var posicioActual = parseInt(itemActiu.attr("data-id")) + 1; 1829 var posicioNova = 1; 1830 if (posicioActual > total) { 1831 posicioNova = 0; 1832 } else if (posicioActual <= total) { 1833 posicioNova = posicioActual; 1834 } 1835 itemActiu.removeClass("active"); 1836 items[posicioNova].classList.add("active"); 1837 }); 1838 1839 $(".carousel-control-prev-mobile.w-auto").on("click", function () { 1840 var content = parseInt(this.getAttribute("data-content")); 1841 var itemMobileActiu = $( 1842 ".carousel-item.content-mobile-" + content + ".small.active" 1843 );
1844 var itemsMobile = $(".carousel-item.content-mobile-" + content + ".small"); 1845 var total = parseInt(this.getAttribute("data-end")); 1846 var posicioMobileActual = parseInt(itemMobileActiu.attr("data-id")) - 1; 1847 var posicioNova = 1; 1848 if (posicioMobileActual < 0) { 1849 posicioNova = total; 1850 } else if (posicioMobileActual >= 0) { 1851 posicioNova = posicioMobileActual; 1852 } 1853 itemMobileActiu.removeClass("active"); 1854 itemsMobile[posicioNova].classList.add("active"); 1855 }); 1856 $(".carousel-control-next-mobile.w-auto").on("click", function () { 1857 var content = parseInt(this.getAttribute("data-content")); 1858 var itemMobileActiu = $( 1859 ".carousel-item.content-mobile-" + content + ".small.active" 1860 ); 1861 var itemsMobile = $(".carousel-item.content-mobile-" + content + ".small"); 1862 var total = parseInt(this.getAttribute("data-end")); 1863 var posicioMobileActual = parseInt(itemMobileActiu.attr("data-id")) + 1; 1864 var posicioMobileNova = 1; 1865 if (posicioMobileActual > total) { 1866 posicioMobileNova = 0; 1867 } else if (posicioMobileActual <= total) { 1868 posicioMobileNova = posicioMobileActual; 1869 } 1870 itemMobileActiu.removeClass("active"); 1871 itemsMobile[posicioMobileNova].classList.add("active"); 1872 }); 1873} 1874function getCookie(cname) { 1875 var name = cname + "="; 1876 var ca = document.cookie.split(";"); 1877 for (var i = 0; i < ca.length; i++) { 1878 var c = ca[i]; 1879 while (c.charAt(0) == " ") c = c.substring(1); 1880 if (c.indexOf(name) === 0) return c.substring(name.length, c.length); 1881 } 1882 return ""; 1883} 1884 1885// translate 1886function translateWeb() { 1887 var link = $(".link-language"); 1888 1889 link.on("click", function (value) { 1890 window.location = value.currentTarget.getAttribute("data-target"); 1891 }); 1892} 1893 1894function playCarousel(id) { 1895 var carousel = "#carousel" + id + ".carousel"; 1896 $("#carouselPause" + id).addClass("none"); 1897 $("#carouselPlay" + id).removeClass("none"); 1898 initCarousel(id, $(carousel).attr("data-bs-interval")); 1899} 1900 1901function pauseCarousel(id) { 1902 var carousel = "#carousel" + id + ".carousel"; 1903 $("#carouselPlay" + id).addClass("none"); 1904 $("#carouselPause" + id).removeClass("none"); 1905 $(carousel).carousel("pause"); 1906} 1907 1908function initCarousel(id, interval) { 1909 var carousel = "#carousel" + id + ".carousel"; 1910 $(carousel).carousel({ 1911 interval: parseInt(interval), 1912 cycle: true, 1913 }); 1914} 1915 1916function addAttributesDivVcards() { 1917 var divVcards = $(".articlelist.vcards"); 1918 var divVcards2 = $(".articlelist.vcards2"); 1919} 1920 1921function removeEmptyParameters() { 1922 // Select all input fields in the form with a name attribute 1923 const inputs = document.querySelectorAll("input,select,textarea"); 1924 1925 inputs.forEach((input) => { 1926 // If the field is empty, remove the name attribute (so it won't be sent) 1927 if (!input.classList.contains("datepicker")) { 1928 if (input.value.trim() === "" || input.value === "0") { 1929 input.removeAttribute("name"); 1930 } 1931 } 1932 }); 1933} 1934 1935
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.