1jQuery.expr[":"].icontains = (a, i, m) => { 2 return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; 3}; 4 5var Tengolf = { 6 ajax_url : "/wp-admin/admin-ajax.php", 7 cart_url : null, 8 desktop : true, 9 mobile : false, 10 igualar_alturas_columnas : false, 11 isHorizontal : (jQuery(window).width() >= jQuery(window).height()), 12 isVertical : (jQuery(window).height() > jQuery(window).width()), 13 keyCodes : { 14 'RETURN' : 13 15 }, 16 idioma : 'es', 17 windowHeight : null, 18 windowWidth : null, 19 menu_fijo : true, 20 postSlug : "", 21 scroll_menu_fijo : 241, 22 v_politica_cookies : 1, 23 24 showSidebars : function() { 25 jQuery(".sidebar-tengolf").css({ 26 background: "#f00", 27 border: "5px solid #f00", 28 minHeight: "50px" 29 }); 30 }, 31 32 showGoogleSlotsForAds : function(only_empty) { 33 window.setTimeout(() => { 34 var selector; 35 var slots = googletag.pubads().getSlots(); 36 var _ = {}; 37 38 for(var i=0; i<slots.length; i++) { 39 console.log(slots[i].getAttributeKeys()); 40 var id = slots[i].getSlotElementId(); 41 _[id] = { 42 path : slots[i].getAdUnitPath().replace(/\/\d+\//, ""), 43 }; 44 } 45 46 only_empty = only_empty ?? false; 47 48 if (!only_empty) { 49 selector = "div[id^='div-gpt-ad']"; 50 } else { 51 selector = "div[id^='div-gpt-ad']:not(:visible)"; 52 } 53 54 jQuery(selector).each(function(i, e) { 55 var $e = jQuery(e); 56 var id = $e.attr("id"); 57 var path = typeof _[id] !== "undefined" ? _[id].path : null; 58 59 if (path === null) { 60 return; 61 } 62 63 $e.css({ 64 background : "#0a0", 65 display : "block", 66 minHeight : "100px", 67 position : "relative" 68 }); 69 70 $e.html("<div style=\"align-items: center; background: #0a0; display: flex; height: 100%; justify-content: center; " + 71 "padding: 5px 10px; position: absolute; top: 50%; left: 50%; " + 72 "color: #fff; transform: translate3d(-50%, -50%, 0); width: 100%; z-index: 9999999;\">" + path + "</div>"); 73 }); 74 }, 5e3); 75 }, 76 77 initGT : function(activar_interstitial) { 78 var _this = this; 79 console.log("initGT"); 80 81 activar_interstitial = activar_interstitial ?? 0; 82 83 let gg = document.location.hash.match(/\#google\-slots(\-empty)?/); 84 let sd = document.location.hash.match(/\#sidebars/); 85 86 if (gg !== null) { 87 _this.showGoogleSlotsForAds((typeof gg[1] !== "undefined")); 88 return; 89 } 90 91 if (sd !== null) { 92 _this.showSidebars(); 93 return; 94 } 95 96 if (document.location.hash.match(/\#window\-size/) !== null) { 97 console.log(jQuery(window).width() + "x" + jQuery(window).height()); 98 return; 99 } 100 101 _this.initFlotanteDerechaAd(); 102 _this.initLiveResultsAd(); 103 // NOTE Descomentar para activar el insterstitial 104 if (activar_interstitial == 1) { 105 _this.initInterstitialAd(); 106 } 107 _this.InitBottomAd(); 108 _this.InitHeaderAd(); 109 }, 110 111 init : function() { 112 var _this = this; 113 114 jQuery(".cmplz-btn.cmplz-accept").on("click", function(e) { 115 window.setTimeout(() => { 116 window.top.location.href = window.top.location.href; 117 }, 1e3); 118 }); 119 120 // NOTE Intentamos eliminar la publicidad que sea más baja de 10px 121 console.log("Autoeliminando bloques de publicidad <= 10px"); 122 jQuery(".publicidad").filter((i, e) => { return jQuery(e).height() <= 10 }).remove(); 123 124 _this.windowHeight = jQuery(window).height(); 125 _this.windowWidth = jQuery(window).width(); 126 127 if (_this.desktop) { // Desktop 128 jQuery(".banner img[data-src]").each(function(i,e) { 129 var $e = jQuery(e); 130 $e.attr("src", $e.attr("data-src")); 131 }); 132 } else { // Mobile 133 jQuery(".banner img[data-src-movil]").each(function(i,e) { 134 var $e = jQuery(e); 135 $e.attr("src", $e.attr("data-src-movil")); 136 }); 137 } 138 139 if (_this.desktop) { // Desktop 140 if (_this.igualar_alturas_columnas) { 141 jQuery("body.device-computer.home .fila").each(function(i, e) { 142 var $e = jQuery(e); 143 var maxHeight = 0; 144 var $columnas_hijas = $e.children(".columna"); 145 146 if ($columnas_hijas.length <= 1) { 147 return; 148 } 149 150 $columnas_hijas.each(function(j, f) { 151 var $f = jQuery(f); 152 var h = $f.height(); 153 154 if (h > maxHeight) { 155 maxHeight = h; 156 } 157 }); 158 159 $columnas_hijas.height(maxHeight); 160 }); 161 } 162 } else { // Mobile 163 // TODO 164 } 165 166 jQuery(window).on("scroll", function() { 167 var st = jQuery(this).scrollTop(); 168 var ww = jQuery(window).width(); 169 170 if (_this.menu_fijo || _this.mobile) { 171 if (st >= _this.scroll_menu_fijo && ww >= 1024) { 172 _this.setMenuFijo(true); 173 } else { 174 _this.setMenuFijo(false); 175 } 176 } 177 }); 178 179 jQuery(window).scroll(); 180 181 if (jQuery(".tengolf-tour-clasificacion").length !== 0) { 182 if (jQuery("a[name='" + document.location.hash.replace(/^\#/, "") + "']").length !== 0) { 183 var $c = jQuery("a[name='" + document.location.hash.replace(/^\#/, "") + "']"); 184 var $torneo = $c.parents(".torneo"); 185 var $holder = $torneo.find(".clasificacion-holder"); 186 var fichero = $holder.attr("data-fichero"); 187 var $torneo_clasificacion = $torneo.find(".torneo-clasificacion"); 188 189 _this.scrollTo($c); 190 191 $torneo_clasificacion.slideDown(); 192 193 // Cambiamos el icono 194 $torneo.find("span.fa.fa-chevron-up").css({ 195 top : "calc(50% - 8px)", 196 transform : "rotate(180deg)" 197 }); 198 } 199 200 jQuery(".tengolf-tour-clasificacion .torneo-nombre > a").on("click", function(e) { 201 e.preventDefault(); 202 203 var $torneo = jQuery(this).parents(".torneo"); 204 var $holder = $torneo.find(".clasificacion-holder"); 205 var fichero = $holder.attr("data-fichero"); 206 var $torneo_clasificacion = $torneo.find(".torneo-clasificacion"); 207 208 if ($torneo_clasificacion.is(":visible")) { // No hacemos nada 209 jQuery(".tengolf-tour-clasificacion .torneo .torneo-clasificacion").slide
209Up(); 210 // Ponemos el icono como estaba 211 $torneo.find("span.fa.fa-chevron-up").get(0).style.cssText = ""; 212 return; 213 } 214 215 $torneo_clasificacion.slideDown(); 216 217 // Cambiamos el icono 218 $torneo.find("span.fa.fa-chevron-up").css({ 219 top : "calc(50% - 8px)", 220 transform : "rotate(180deg)" 221 }); 222 }); 223 224 // Desplegamos el último que haya 225 jQuery(".tengolf-tour-clasificacion .torneo").last().find("a[data-fichero]").click(); 226 } 227 228 // Si el sidebar no tiene altura lo ocultamos 229 /*window.setTimeout(function() { 230 jQuery("div[class^='sidebar-tengolf']").each(function(i, e) { 231 var $e = jQuery(e); 232 233 if ($e.hasClass("sidebar-tengolf-sidebar-publicidad-cabecera") 234 || $e.hasClass("sidebar-tengolf-sidebar-logo-cabecera-derecha")) { 235 return; 236 } 237 238 if ($e.height() === 0) { 239 $e.hide(); 240 } 241 }); 242 }, 500);*/ 243 244 jQuery(".card-update > a#update-card-details").on("click", function(e) { 245 e.preventDefault(); 246 247 jQuery.post(_this.ajax_url, { 248 action : "tengolf_update_card_details", 249 }, function(data) { 250 if (typeof data.redirect !== "undefined" && data.redirect !== null) { 251 window.top.document.location.href = data.redirect; 252 } 253 254 return; 255 }, "json"); 256 }); 257 258 _this.initImagesFigures(); 259 _this.initOnResize(); 260 _this.initBuscadorCabecera(); 261 _this.initBuscadorPagina(); 262 _this.initCompartir(); 263 _this.initArticulosRelacionados(); 264 _this.initComentariosArticulo(); 265 _this.initWoocommerce(); 266 267 var $live_iframe = jQuery("iframe[src*='liveblog']"); 268 269 if ($live_iframe.length !== 0) { 270 $live_iframe.css({ 271 overflow : "hidden" 272 }); 273 window.setInterval(function() { 274 $live_iframe.height(jQuery($live_iframe.get(0).contentWindow.document.body).height() + 50); 275 }, 1000); 276 } 277 }, 278 279 initReady : function() { 280 var _this = this; 281 282 _this.windowHeight = jQuery(window).height(); 283 _this.windowWidth = jQuery(window).width(); 284 285 if (_this.desktop) { // Desktop 286 jQuery(".only-desktop").show(); 287 jQuery(".only-mobile").hide(); 288 } else { // Mobile 289 jQuery(".only-desktop").hide(); 290 jQuery(".only-mobile").show(); 291 } 292 293 _this.organizarAdsPortadaMobile(); 294 _this.initElGolpeDelDia(); 295 _this.initElGimnasioDelPirata(); 296 _this.initPaywallLoginBar(); 297 298 jQuery("form[name='loginform'] #rememberme").prop("checked", true); 299 300 jQuery("a.enlace-banner").on("click", function(e) { 301 if (typeof gtag === "undefined" || gtag === null) { 302 return; 303 } 304 305 e.preventDefault(); 306 let href = jQuery(this).attr("href"); 307 let target = jQuery(this).attr("target"); 308 309 let default_link = window.setTimeout(() => { 310 if (target == "_blank") { 311 window.open(href); 312 } else { 313 window.top.location.href = href; 314 } 315 }, 2e3); 316 317 console.log("Sending enlace_banner event"); 318 gtag("event", "enlace_banner", { 319 enlace_banner_url : href, 320 event_callback : () => { 321 console.log("Event enlace_banner sent"); 322 window.clearTimeout(default_link); 323 if (target == "_blank") { 324 window.open(href); 325 } else { 326 window.top.location.href = href; 327 } 328 } 329 }); 330 }); 331 }, 332 333 initInterstitialAd : function(debug, width, height) { 334 var _this = this; 335 let cookie_expires = null; // Number (float) of days or null for session cookie 336 337 debug = debug ?? false; 338 height = height ?? null; 339 width = width ?? null; 340
341 let shown_before = (Cookies.get("interstitial_ad") === "1"); 342 343 if (shown_before && !debug) { 344 console.log("Not showing interstitial ad"); 345 return; 346 } 347 348 console.log("Will show interstitial"); 349 350 jQuery("body").on("click", ".interstitial-ad #interstitial-ad-slot a.close", function(e) { 351 e.preventDefault(); 352 353 if (_this.desktop) { 354 interstitial_ad.fadeOut({ 355 complete : () => { 356 if (cookie_expires !== null) { 357 Cookies.set("interstitial_ad", "1", { expires : cookie_expires }); 358 } else { 359 Cookies.set("interstitial_ad", "1"); 360 } 361 362 interstitial_ad.remove(); 363 } 364 }); 365 } else { 366 interstitial_ad.remove(); 367 } 368 }); 369 370 let interstitial_ad = jQuery("<div>").addClass("interstitial-ad"); 371 372 if (_this.mobile) { 373 interstitial_ad.addClass("interstitial-ad-slot-mobile"); 374 } 375 376 interstitial_ad.appendTo(jQuery("body")); 377 378 interstitial_ad.html("<div id=\"interstitial-ad-slot\"></div>"); 379 380 if (!debug) { 381 googletag.pubads().refresh(); 382 383 googletag.pubads().addEventListener("slotRenderEnded", function(e) { 384 let slot = e.slot; 385 let path = slot.getAdUnitPath(); 386 387 if (path == "/126012366/tengolf-intersticial") { 388 if (!e.isEmpty) { 389 console.log("Interstitial ad defined"); 390 391 if (cookie_expires !== null) { 392 Cookies.set("interstitial_ad", "1", { expires : co
392okie_expires }); 393 } else { 394 Cookies.set("interstitial_ad", "1"); 395 } 396 397 jQuery(".interstitial-ad").addClass("ready"); 398 let ad_slot = jQuery(".interstitial-ad #interstitial-ad-slot > div,.interstitial-ad #interstitial-ad-slot > img"); 399 jQuery(".interstitial-ad #interstitial-ad-slot").css({ 400 height : ad_slot.height() + "px", 401 width : ad_slot.width() + "px" 402 }); 403 404 window.setTimeout(() => { 405 interstitial_ad.find("a.close").trigger("click"); 406 }, 15e3); 407 408 jQuery(".interstitial-ad #interstitial-ad-slot").append("<a href=\"#\" class=\"close\">â</a>"); 409 410 if (jQuery(window).height() <= ad_slot.height()) { 411 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 412 top : (25 + Math.abs(jQuery(window).height() - ad_slot.height()) / 2) + "px", 413 }); 414 } 415 416 if (jQuery(window).width() <= ad_slot.width()) { 417 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 418 right : (25 + Math.abs(jQuery(window).width() - ad_slot.width()) / 2) + "px" 419 }); 420 } 421 422 jQuery(window).on("resize", function() { 423 if (jQuery(window).height() <= ad_slot.height()) { 424 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 425 top : (25 + Math.abs(jQuery(window).height() - ad_slot.height()) / 2) + "px" 426 }); 427 } else { 428 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 429 top : "" 430 }); 431 } 432 433 if (jQuery(window).width() <= ad_slot.width()) { 434 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 435 right : (25 + Math.abs(jQuery(window).width() - ad_slot.width()) / 2) + "px" 436 }); 437 } else { 438 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 439 right : "" 440 }); 441 } 442 }); 443 } else { 444 console.log("No interstitial ad defined, removing DIV"); 445 interstitial_ad.remove(); 446 } 447 448 return; 449 } 450 }); 451 452 googletag.pubads().setCentering(true); 453 454 if (_this.desktop) { // Desktop 455 console.log("Desktop interstitial"); 456 457 if (_this.isHorizontal) { 458 googletag.pubads().display("/126012366/tengolf-intersticial", [[1920, 1080],[1024, 768]], 'interstitial-ad-slot'); 459 } else { 460 googletag.pubads().display("/126012366/tengolf-intersticial", [[1080, 1920],[768, 1024]], 'interstitial-ad-slot'); 461 } 462 } else { // Mobile 463 console.log("Mobile interstitial"); 464 465 if (_this.isVertical) { 466 googletag.pubads().display("/126012366/tengolf-intersticial", [[720, 1334], [320, 480]], 'interstitial-ad-slot'); 467 } else { 468 googletag.pubads().display("/126012366/tengolf-intersticial", [[1334, 720], [480, 320]], 'interstitial-ad-slot'); 469 } 470 } 471 } else { 472 let image = new Image(); 473 474 jQuery(image).on("load", function() { 475 jQuery("#interstitial-ad-slot").append(jQuery(image)); 476 477 jQuery(".interstitial-ad").addClass("ready"); 478 jQuery(".interstitial-ad #interstitial-ad-slot").css({ 479 height : jQuery("#interstitial-ad-slot > img").height() + "px", 480 width : jQuery("#interstitial-ad-slot > img").width() + "px" 481 }); 482 483 jQuery(".interstitial-ad #interstitial-ad-slot").append("<a href=\"#\" class=\"close\">â</a>"); 484 485 if (jQuery(window).height() <= jQuery("#interstitial-ad-slot > img").height()) { 486 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 487 top : (25 + Math.abs(jQuery(window).height() - jQuery("#interstitial-ad-slot > img").height()) / 2) + "px", 488 }); 489 } 490 491 if (jQuery(window).width() <= jQuery("#interstitial-ad-slot > img").width()) { 492 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 493 right : (25 + Math.abs(jQuery(window).width() - jQuery("#interstitial-ad-slot > img").width()) / 2) + "px" 494 }); 495 } 496 497 jQuery(window).on("resize", function() { 498 if (jQuery(window).height() <= jQuery("#interstitial-ad-slot > img").height()) { 499 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 500 top : (25 + Math.abs(jQuery(window).height() - jQuery("#interstitial-ad-slot > img").height()) / 2) + "px" 501 }); 502 } else { 503 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 504 top : "" 505 }); 506 } 507 508 if (jQuery(window).width() <= jQuery("#interstitial-ad-slot > img").width()) { 509 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 510 right : (25 + Math.abs(jQuery(window).width() - jQuery("#interstitial-ad-slot > img").width()) / 2) + "px" 511 }); 512 } else { 513 jQuery(".interstitial-ad #interstitial-ad-slot a.close").css({ 514 right : "" 515 }); 516 } 517 }); 518 }); 519 520 if (_this.desktop) { 521 height = height === null ? 768 : height; 522 width = width === null ? 1024 : width; 523 image.src = "https://picsum.photos/" + width + "/" + height; 524 } else { 525 height = height === null ? 480 : height; 526 width = width === null ? 320 : width; 527 image.src = "https://picsum.photos/" + width + "/" + height; 528 } 529 } 530 }, 531 532 initLiveResultsAd : function() { 533 var _this = this; 534 535 if(jQuery(".live-results-ad").length == 0) { 536 return; 537 } 538 539 let slot; 540 let path; 541 542 if (this.desktop) { 543 googletag.pubads().addEventListener("slotRenderEnded", function(e) { 544 slot = e.slot; 545 path = slot.getAdUnitPath(); 546 547 if (path == "/126012366/live-results") { 548 if (!e.isEmpty) { 549 if (jQuery(".columna.columna-derecha-portada").length != 0) { 550 jQuery("a#live-results").css({ 551 display : "block", 552 margin : "17px 0 15px" 553 }).prependTo(jQuery(".columna.columna-derecha-portada")); 554 } else if (jQuery(".columna.columna-derecha").length != 0) { 555 jQuery("a#live-results").css({ 556 display : "block", 557 margin : "17px 0 15px" 558 }).prependTo(jQuery(".columna.columna-derecha")); 559 } else { 560 jQuery("a#live-results").attr("style", "all: initial; display : none !important"); 561 } 562 563 jQuery(".live-results-ad").addClass("ready"); 564 } else { 565 jQuery("a#live-results").css({ display : "initial" }); 566 jQuery(".live-results-ad").remove(); 567 } 568 } 569 }); 570 571 googletag.pubads().display("/126012366/live-results", [[240, 52]], "live-results-ad-slot"); 572 } else if (this.mobile) { 573 googletag.pubads().addEventListener("slotRenderEnded", function(e) { 574 slot = e.slot; 575 path = slot.getAdUnitPath(); 576 577 if (path == "/126012366/live-results") { 578 if (!e.isEmpty) { 579 jQuery(".live-results-ad").addClass("ready"); 580 } else { 581 jQuery(".live-results-ad").remove(); 582 } 583 } 584 }); 585 586 googletag.pubads().display("/126012366/live-results", [[320, 100], [240, 52]], "live-results-ad-slot"); 587 } 588 }, 589 590 initFlotanteDerechaAd : function() { 591 var _this = this; 592 593 if (this.mobile) { 594 return; 595 } 596 597 if(jQuery(".flotante-derecha-ad").length == 0) { 598 return; 599 } 600 601 jQuery(".flotante-derecha-ad a.close").on("click", function(e) { 602 e.preventDefault(); 603 e.stopPropagation(); 604 605 jQuery(".flotante-derecha-ad").removeClass("ready"); 606 window.setTimeout(() => { 607 jQuery(".flotante-derecha-ad").remove(); 608 }, 4e2); 609 }); 610 611 googletag.pubads().addEventListener("slotRenderEnded", function(e) { 612 let slot = e.slot; 613 let path = slot.getAdUnitPath(); 614 615 if (path == "/126012366/flotante-derecha") { 616 if (!e.isEmpty) { 617 jQuery(".flotante-derecha-ad").addClass("ready"); 618 } else { 619 jQuery(".flotante-derecha-ad").remove(); 620 } 621 } 622 }); 623 624 googletag.pubads().display('/126012366/flotante-derecha', [[320, 100], [320, 60], [320, 50], [320, 120]], "flotante-derecha-ad-slot"); 625 }, 626 627 InitBottomAd : function() { 628 var _this = this; 629 630 if(jQuery(".bottom-ad").length == 0 631 || jQuery(".bottom-ad.ready").length != 0) { 632 return; 633 } 634 635 jQuery(".bottom-ad a.close").on("click", function(e) { 636 e.preventDefault(); 637 jQuery(".bottom-ad").removeClass("ready"); 638 window.setTimeout(() => { 639 jQuery(".bottom-ad").remove(); 640 }, 4e2); 641 }); 642 643 googletag.pubads().refresh(); 644 645 googletag.pubads().addEventListener("slotRenderEnded", function(e) { 646 let slot = e.slot; 647 let path = slot.getAdUnitPath(); 648 649 if (path == '/126012366/movil-pie-intersticial') { 650 if (!e.isEmpty) { 651 jQuery(".bottom-ad").addClass("ready"); 652 let style = "<style>.st-placement.inScreen {display: none !important; opacity: 0 !important; z-index: -99999; }</style>"; 653 jQuery("body").append(style); 654 window.setTimeout(() => { 655 jQuery(".st-placement.inScreen").remove(); 656 }, 500); 657 } else { 658 jQuery(".bottom-ad").remove(); 659 } 660 } 661 }); 662 663 if (!this.mobile) { // Desktop 664 googletag.pubads().display('/126012366/movil-pie-intersticial', [[990, 250], [990, 90]], 'bottom-ad-slot'); 665 } else { // Mobile 666 googletag.pubads().display('/126012366/movil-pie-intersticial', [[320, 100], [320, 60], [320, 50]], 'bottom-ad-slot'); 667 } 668 }, 669 670 InitHeaderAd : function() { 671 var _this = this; 672 673 if(jQuery(".header-ad").length == 0) { 674 return; 675 } 676 677 jQuery(".header-ad a.close").on("click", function(e) { 678 e.preventDefault(); 679 jQuery(".header-ad").removeClass("ready"); 680 window.setTimeout(() => { 681 jQuery(".header-ad").remove(); 682 }, 4e2); 683 }); 684 685 googletag.pubads().refresh(); 686 687 googletag.pubads().addEventListener("slotRenderEnded", function(e) { 688 let slot = e.slot; 689 let path = slot.getAdUnitPath(); 690 691 if (path == '/126012366/movil-cabecera-intersticial') { 692 if (!e.isEmpty) { 693 jQuery(".header-ad").addClass("ready"); 694 } else { 695 jQuery(".header-ad").remove(); 696 } 697 } 698 }); 699 700 googletag.pubads().display('/126012366/movil-cabecera-intersticial', [[320, 100], [320, 60], [320, 50]], 'header-ad-slot'); 701 }, 702 703 initPaywallLoginBar : function() { 704 var _this = this; 705 706 jQuery.post(_this.ajax_url, { 707 action : "tengolf_paywall_login_bar", 708 current_url : document.location.href, 709 mobile : _this.mobile ? 1 : 0 710 }, function(html) { 711 jQuery("li.paywall-user-data").remove(); 712 if (jQuery.trim(html) != "" && html != 0) { 713 if (_this.desktop) { 714 jQuery("#header-login-info").html(html); 715 } else { 716 jQuery(".menu-top-container > ul").prepend(html); 717 } 718 719 if (jQuery("span#comments-logged-in").length != 0) { 720 let user_shown_name = jQuery(html).find("#user-shown-name").text(); 721 jQuery("span#comments-logged-in").html(user_shown_name); 722 } 723 } 724 }); 725 }, 726 727 initWoocommerce : function() { 728 var _this = this; 729 730 jQuery(".product button[type='submit'].single_add_to_cart_button").html("Comprar").fadeIn(); 731 732 jQuery(".product select#talla > option[value='']").remove(); 733 jQuery(".product select#color > option[value='']").remove(); 734 735 jQuery(".product .images > a[class!='image']").remove(); 736 737 jQuery(".product .images > a.image").on("mouseenter", function() { 738 let image = jQuery(this).attr("data-image"); 739 let product = jQuery(this).parents(".product"); 740 product.find("a.woocommerce-LoopProduct-link").attr("data-hover", image).css({
741 "--image" : "url(" + image + ")" 742 }); 743 }); 744 745 // NOTE No mouseleave for here 746 747 jQuery(".product .images > a.image:first-of-type").trigger("mouseenter"); 748 }, 749 750 initArticulosRelacionados : function() { 751 var _this = this; 752 753 function actualizar_pagina_relacionados(post_id, pagina) { 754 jQuery.post(_this.ajax_url, { 755 action : "tengolf_articulos_relacionados", 756 post_id : post_id, 757 pagina : pagina 758 }, function(respuesta) { 759 jQuery("body.single div.relacionados .noticia-relacionada").animate({ 760 opacity : 0 761 }, { 762 complete : function() { 763 jQuery("body.single div.relacionados").html(respuesta); 764 jQuery("body.single div.relacionados .noticia-relacionada").animate({ 765 opacity : 1 766 }); 767 } 768 }); 769 }); 770 } 771 772 jQuery("body.single").on("click", "div.relacionados .paginador a", function(e) { 773 e.preventDefault(); 774 775 var post_id = parseInt(jQuery(this).parents("[data-post-id]").attr("data-post-id")); 776 var pagina = parseInt(jQuery(this).parents("[data-pagina]").attr("data-pagina")); 777 var total_paginas = parseInt(jQuery(this).parents("[data-total-paginas]").attr("data-total-paginas")); 778 779 var avanzar = jQuery(e.currentTarget).hasClass("avanzar"); 780 781 if (avanzar && pagina < total_paginas) { 782 actualizar_pagina_relacionados(post_id, pagina + 1); 783 } else if (!avanzar && pagina > 1) { 784 actualizar_pagina_relacionados(post_id, pagina - 1); 785 } 786 }); 787 }, 788 789 initBuscadorCabecera : function() { 790 var _this = this; 791 792 jQuery("input[name='q']").on("keypress", function(e) { 793 var code = (e.which || e.charCode || e.keyCode || 0); 794 if (code === _this.keyCodes.RETURN) { 795 document.location.href = '/' + _this.idioma + '/search/' + (jQuery(this).val().trim()); 796 } 797 }); 798 799 jQuery("input[name='q']").on("blur", function(e) { 800 jQuery("span.contenedor-q").removeClass("abierto"); 801 }); 802 803 jQuery("span.contenedor-q").on("click", function(e) { 804 if (e.target == this) { 805 jQuery(this).toggleClass("abierto"); 806 jQuery("input[name='q']").val(""); 807 jQuery("input[name='q']").focus(); 808 } 809 }); 810 }, 811 812 initBuscadorPagina : function() { 813 var _this = this; 814 815 jQuery("#formulario-buscador input[type='submit']").on("click", function(e) { 816 e.preventDefault(); 817 var q = jQuery("#formulario-buscador input[type='text']").val(); 818 document.location.href = '/' + _this.idioma + '/search/' + (q.trim()); 819 }); 820 }, 821 822 initComentariosArticulo : function() { 823 var abrirCerrar = jQuery("<a>").addClass("abrir-cerrar-comentarios").attr("data-abierto", "0"); 824 abrirCerrar.appendTo(jQuery("#comments h3#reply-title")); 825 826 jQuery("h3#reply-title").has("a.abrir-cerrar-comentarios").on("click", function(e) { 827 e.stopPropagation(); 828 if (jQuery("h3#reply-title > a.abrir-cerrar-comentarios").attr("data-abierto") == "0") { 829 jQuery(this).next("form.comment-form").slideDown(); 830 jQuery("h3#reply-title > a.abrir-cerrar-comentarios").attr("data-abierto", "1"); 831 } else { 832 jQuery(this).next("form.comment-form").slideUp(); 833 jQuery("h3#reply-title > a.abrir-cerrar-comentarios").attr("data-abierto", "0"); 834 } 835 }); 836 837 jQuery("body").on("click", "li.comment article a.comment-reply-link", function() { 838 jQuery("h3#reply-title").has("a.abrir-cerrar-comentarios").next("form.comment-form").slideDown(); 839 jQuery("h3#reply-title > a.abrir-cerrar-comentarios").attr("data-abierto", "1"); 840 }); 841 }, 842
843 initCompartir : function() { 844 var openSharerWindow = function(url) { 845 var a = function() { 846 if (!window.open(url, 'sharer', 'toolbar=0, status=0, resizable=1, width=626, height=436')) { 847 document.location.href = url; 848 } 849 }; 850 851 window.setTimeout(a, 0); 852 }; 853 854 jQuery("body").on("click", ".compartir a.facebook", function(e) { 855 e.preventDefault(); 856 var url = jQuery(this).parents(".compartir").attr("data-url"); 857 var f = 'http://www.facebook.com/sharer.php?&i=' + ((new Date()).getTime()) + '&u=' + encodeURIComponent(url); 858 openSharerWindow(f); 859 }); 860 861 jQuery("body").on("click", ".compartir a.twitter", function(e) { 862 e.preventDefault(); 863 var url = jQuery(this).parents(".compartir").attr("data-url"); 864 var t = 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(url) + '&via=Tengolf'; 865 openSharerWindow(t); 866 }); 867 }, 868 869 initElGolpeDelDia : function() { 870 if (jQuery(".td-container.td-category-container.el-golpe-del-dia").length != 0) { 871 var capa = jQuery(".columna.articulo").first(); 872 var imagen_post = capa.find(".imagen-post"); 873 imagen_post.css({ 874 position : "relative" 875 }); 876 capa.addClass("el-golpe-del-dia"); 877 878 jQuery("<div>").addClass("marca-el-golpe-del-dia").appendTo(imagen_post); 879 } 880 881 }, 882 883 initElGimnasioDelPirata : function() { 884 if (jQuery(".td-container.td-category-container.el-gimnasio-del-pirata").length != 0) { 885 var capa = jQuery(".columna.articulo").first(); 886 var imagen_post = capa.find(".imagen-post"); 887 imagen_post.css({ 888 position : "relative" 889 }); 890 capa.addClass("el-gimnasio-del-pirata"); 891 892 jQuery("<div>").addClass("marca-el-gimnasio-del-pirata").appendTo(imagen_post); 893 } 894 895 }, 896 897 initImagesFigures : function() { 898 var fc = jQuery("figure:has(img) figcaption"); 899 900 if (fc.length !== 0) { 901 var img = fc.parent("figure").find("img"); 902 fc.css({ 903 opacity : 1, 904 width : img.width() + "px" 905 }); 906 } 907 }, 908 909 initOnResize : function() { 910 var _this = this; 911 var _changeBanner = function() { 912 if (_this.desktop) { // Desktop 913 jQuery(".banner img[data-src]").each(function(i,e) { 914 var $e = jQuery(e); 915 $e.attr("src", $e.attr("data-src")); 916 }); 917 } else { // Mobile 918 jQuery(".banner img[data-src-movil]").each(function(i,e) { 919 var $e = jQuery(e); 920 $e.attr("src", $e.attr("data-src-movil")); 921 }); 922 } 923 924 jQuery("div.banner img").show(); 925 }; 926 927 jQuery(window).on("resize", function() { 928 _this.windowHeight = jQuery(window).height(); 929 _this.windowWidth = jQuery(window).width(); 930 931 if (_this.desktop) { // Desktop 932 jQuery(".only-desktop").show(); 933 jQuery(".only-mobile").hide(); 934 } else { // Mobile 935 jQuery(".only-desktop").hide(); 936 jQuery(".only-mobile").show(); 937 } 938 939 _changeBanner(); 940 }); 941 }, 942 943 initScrollViewHorizontal : function(desactivar) { 944 let _this = this; 945 desactivar = desactivar ?? false; 946 947 if (_this.mobile || (jQuery(".hscrollview").length != 0 && !desactivar)) { 948 return; 949 } 950 951 _hscrollview = () => { 952 const windowHeight = window.innerHeight; 953 const fullHeight = document.body.scrollHeight; 954 const scrolled = window.scrollY; 955 const position = scrolled / (fullHeight - windowHeight); 956 957 jQuery(".hscrollview").css({ 958 "--pc" : (position * 100 + "%") 959 }); 960 } 961 962 if (!desactivar) { 963 let div = jQuery(".menu-top-container").parent(); 964 div.append("<div class=\"hscrollview\"></div>"); 965 966 jQuery(window).on("scroll.hscrollview", _hscrollview); 967 _hscrollview(); 968 } else { 969 jQuery(window).off("scroll.hscrollview"); 970 jQuery(".hscrollview").remove(); 971 } 972 }, 973 974 abrirCapa : function(id) { 975 var _this = this; 976 var capa = jQuery("#" + id); 977
978 clon = capa.clone(); 979 capa.remove(); 980 981 jQuery("body").append(clon); 982 983 var h = 375; 984 var w = 375; 985 986 clon.css({ 987 background : "transparent", 988 height : h + "px", 989 left : "calc(50% - " + w + "px / 2)", 990 padding : 0, 991 position : "fixed", 992 top : "calc(50% - " + h + "px / 2)", 993 width : w + "px", 994 zIndex: 999999 995 }).fadeIn(); 996 997 _this.opaca(function() { 998 clon.fadeOut(); 999 }); 1000 }, 1001 1002 categoriaId : function(nivel) { 1003 var path = document.getElementsByTagName("body")[0].getAttribute("data-path-with-ids"); 1004 1005 if (typeof nivel !== "undefined" && nivel !== null) { 1006 path = path.replace(/(^\/|\/$)/g, "").split("/"); 1007 nivel = parseInt(nivel); 1008 var tmp = "/"; 1009 1010 for(var i=0; i<nivel; i++) { 1011 if (typeof path[i] !== "undefined") { 1012 tmp += path[i] + "/"; 1013 } else { 1014 break; 1015 } 1016 } 1017 1018 return tmp; 1019 } 1020 1021 return path; 1022 }, 1023 1024 categoriaPath : function(nivel) { 1025 var path = document.getElementsByTagName("body")[0].getAttribute("class").match(/single/) !== null ? document.location.href.replace(/https?\:\/\/[^\/]+\/(es|en)(?:\/categoria)?/, "").replace(/[^\/]+\/?$/, "") : document.location.href.replace(/https?\:\/\/[^\/]+\/(es|en)(?:\/categoria)?/, ""); 1026 1027 if (typeof nivel !== "undefined" && nivel !== null) { 1028 path = path.replace(/(^\/|\/$)/g, "").split("/"); 1029 nivel = parseInt(nivel); 1030 var tmp = "/"; 1031 1032 for(var i=0; i<nivel; i++) { 1033 if (typeof path[i] !== "undefined") { 1034 tmp += path[i] + "/"; 1035 } else { 1036 break; 1037 } 1038 } 1039 1040 return tmp; 1041 } 1042 1043 return path; 1044 }, 1045 1046 checkEmail : function(email) { 1047 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 1048 return re.test(email); 1049 }, 1050 1051 /** 1052 * Devuelve un aleatorio entre 1 y total (ambos inclusive) 1053 */ 1054 clienteRand : function(total) { 1055 total = total ?? 2; 1056 return (Math.ceil(Math.random() * total)).toString(); 1057 }, 1058 1059 country : function() { 1060 let node = document.childNodes[1]; 1061 1062 if (node.nodeName == "#comment") { 1063 let nodeValue = jQuery.trim(node.nodeValue); 1064 let country = nodeValue.match(/\@country\s([a-z]{2})/i); 1065 return country !== null ? country[1] : null; 1066 } 1067 1068 return null; 1069 }, 1070 1071 getCurrentPagePostID : function() { 1072 let body = jQuery("body"); 1073 let classes = body.attr("class"); 1074 let id = classes.match(/(?:page\-id|postid)\-(\d+)/); 1075 1076 if (id !== null) { 1077 return "" + id[1]; 1078 } 1079 1080 return null; 1081 }, 1082 1083 getCurrentUrl : function(vars, with_search, short) { 1084 with_search = with_search ?? true; 1085 short = short ?? false; 1086 var search = ""; 1087 1088 var protocol = document.location.protocol; 1089 var host = document.location.host; 1090 var pathname = document.location.pathname; 1091 1092 if (with_search) { 1093 search = document.location.search.replace(/^\?/, ""); 1094 } 1095 1096 if (typeof vars == "undefined" || vars === null) { 1097 if (search !== "") { 1098 return (!short ? (protocol + "//" + host) : "") + pathname + "?" + search; 1099 } else { 1100 return (!short ? (protocol + "//" + host) : "") + pathname; 1101 } 1102 } 1103 1104 var aSearch = search.split("&"); 1105 var query = {}; 1106 1107 if (typeof aSearch[0] != "undefined" && aSearch[0] !== null && aSearch[0] !== "") { 1108 for (var i=0; i<aSearch.length; i++) { 1109 var f = jQuery.trim(aSearch[i]); 1110 var m = f.match(/^([^\=]*)(?:\=(.*))?/); 1111 1112 if (typeof m[1] != "undefined" && m[1] !== null) { 1113 query[m[1]] = ""; 1114 1115 if (typeof m[2] != "undefined" && m[2] !== null) { 1116 query[m[1]] = m[2]; 1117 } 1118 } 1119 } 1120 } 1121 1122 for(var key in vars) { 1123 if (vars[key] !== null && jQuery.trim(vars[key]) !== "") { 1124 query[key] = vars[key]; 1125 } else { 1126 delete query[key]; 1127 } 1128 } 1129 1130 if (!jQuery.isEmptyObject(query)) { 1131 return (!short ? (protocol + "//" + host) : "") + pathname + "?" + jQuery.param(query); 1132 } else { 1133 return (!short ? (protocol + "//" + host) : "") + pathname; 1134 } 1135 }, 1136 1137 getCurrentLanguage : function() { 1138 let m = document.location.href.match(/\/(en|es)\//); 1139 1140 if (m !== null) { 1141 return m[1]; 1142 } 1143 1144 return ''; 1145 }, 1146 1147 /** 1148 * Devuelve true si la etiqueta tag existe en el post 1149 * @param {string} tag 1150 * @returns {boolean} 1151 */ 1152 hasTag : function(tag) { 1153 var a = jQuery("body.single-post ul.td-tags > li > a:icontains(" + tag + ")"); 1154 return (a.length != 0 && a.text().toUpperCase() == tag.toUpperCase()); 1155 }, 1156 1157 tags : function() { 1158 var tags = []; 1159 1160 jQuery("body.single-post ul.td-tags > li > a").each((i, e) => { 1161 tags.push(jQuery(e).text()); 1162 }); 1163 1164 return tags; 1165 }, 1166 1167 opaca : function(clickCallback) { 1168 var o = jQuery("<div>").attr("id", "opaca").css({ 1169 background : "rgba(0,0,0,0.7)", 1170 height : "100vh", 1171 left : 0, 1172 position : "fixed", 1173 top : 0, 1174 width : "100vw", 1175 zIndex : 10000 1176 }).appendTo(jQuery("body")); 1177 1178 o.on("click", function(e) { 1179 e.preventDefault(); 1180 1181 jQuery(this).remove(); 1182 1183 if (typeof clickCallback == "function") { 1184 clickCallback(); 1185 } 1186 }); 1187 }, 1188 1189 organizarAdsPortadaMobile : function() { 1190 var _this = this; 1191 1192 if (_this.desktop || jQuery("body.home").length == 0) { 1193 return; 1194 } 1195 1196 var ads = jQuery("[data-zona='2'] > .columna:nth-child(2) [id^='div-gpt-ad']"); 1197 var noticias = jQuery("[data-zona='2'] > .columna:nth-child(1) .columna.articulo:nth-child(2n), .shortcode-johndoe-rules"); 1198 1199 noticias.each((i, e) => { 1200 if (typeof ads[i] !== "undefined" && ads[i] !== null) { 1201 var ad = jQuery(ads[i]); 1202 console.log("id=" + ad.attr("id") + " " + ad.is(":visible")); 1203 if (ad.is(":visible")) { 1204 jQuery(e).after(ad.parents(".widget_text").addClass("publicidad").detach()); 1205 } 1206 } 1207 }); 1208 }, 1209 1210 prettyTime : s => { 1211 var horas = Math.floor(s / 3600); 1212 var minutosRestantes = Math.floor((s % 3600) / 60); 1213 var segundosRestantes = s % 60; 1214 1215 // Función para agregar un cero delante de los valores menores de 10 1216 let _zeroPad = valor => { 1217 return valor < 10 ? "0" + valor : valor; 1218 } 1219 1220 let prettyTime = ""; 1221 1222 if (horas > 0) { 1223 prettyTime += _zeroPad(horas) + "h"; 1224 } 1225 1226 if (minutosRestantes > 0) { 1227 prettyTime += _zeroPad(minutosRestantes) + "m"; 1228 } 1229 1230 prettyTime += _zeroPad(segundosRestantes) + "s"; 1231 1232 return prettyTime; 1233 }, 1234 1235 /** 1236 * Rewrites browser url without loading the page 1237 * @param strin url 1238 */ 1239 rewriteURL : function(url) { 1240 window.history.pushState(null, "", url); 1241 return url; 1242 }, 1243 1244 scrollTo : function($e, offset) { 1245 offset = offset ?? 0; 1246 1247 jQuery('html, body').animate({ 1248 scrollTop : $e.offset().top + offset 1249 }, 1000); 1250 }, 1251 1252 setMenuFijo : function(activar) { 1253 var _this = this; 1254 activar = activar ?? true; 1255 1256 if (activar) { 1257 if (jQuery("li#logo-menu-fijo").length === 0) { 1258 var imgLogoMenuFijo = jQuery("<img>").attr({ 1259 src : "/wp-content/themes/tengolf-child/images/logo-menu.webp" 1260 }).css({ 1261 filter : "drop-shadow(1px 1px 1px #666)" 1262 }); 1263 1264 var liLogoMenuFijo = jQuery("<li>").attr({ 1265 id : "logo-menu-fijo" 1266 }).css({ 1267 cursor : "pointer", 1268 margin : "0 5px 0 0", 1269 verticalAlign : "top" 1270 }).on("click", function() { 1271 document.location.href = "/"; 1272 }); 1273
1274 imgLogoMenuFijo.appendTo(liLogoMenuFijo); 1275 liLogoMenuFijo.prependTo(jQuery("ul.top-header-menu")); 1276 } 1277 1278 jQuery(".td-header-container,body").addClass("posicion-fija"); 1279 1280 if (_this.menu_fijo === false) { 1281 jQuery("body.posicion-fija .td-outer-container").css({ 1282 paddingTop : "10px" 1283 }); 1284 } 1285 1286 _this.initScrollViewHorizontal(); 1287 } else { 1288 _this.initScrollViewHorizontal(true); 1289 jQuery("li#logo-menu-fijo").remove(); 1290 jQuery(".td-header-container,body").removeClass("posicion-fija"); 1291 } 1292 }, 1293 1294 setPushToken : function(token) { 1295 var _this = this; 1296 1297 if (typeof token !== "undefined" && token !== null && jQuery.trim(token) !== "") { 1298 jQuery.post(_this.ajax_url, { 1299 action : "tengolf_set_push_token", 1300 token : token 1301 }, function(data) { 1302 // No hacemoa nada 1303 }, "json"); 1304 } 1305 1306 // NOTE We do not care if returns ok or not 1307 }, 1308 1309 showWidths : function(max) { 1310 var ww = jQuery(window).width(); 1311 max = max ?? ww; 1312 1313 jQuery("*").each(function(i, e) { 1314 var $e = jQuery(e); 1315 var ew = $e.width(); 1316 1317 if (ew >= max) { 1318 console.log("classname='" + e.className + "' - id='" + e.id + "' - width=" + ew + "px", $e.get(0)); 1319 } 1320 }); 1321 }, 1322 1323 simpleHash : function(s) { 1324 return s.split("").reduce(function(a, b) { 1325 a = ((a<<5) - a) + b.charCodeAt(0); 1326 return a&a; 1327 }, 0); 1328 }, 1329 1330 UTF8_2_B64 : function(str) { 1331 return window.btoa(unescape(encodeURIComponent(str))); 1332 }, 1333 1334 B64_2_UTF8 : function(str) { 1335 return decodeURIComponent(escape(window.atob(str))); 1336 } 1337}; 1338 1339jQuery(window).on("load", function() { 1340 Tengolf.init(); 1341}); 1342 1343jQuery(document).on("ready", function() { 1344 Tengolf.initReady(); 1345});
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.