1(function ($, Drupal, once) { 2 Drupal.behaviors.loadBlocksAjax = { 3 attach: function (context, settings) { 4 var pageBlocks = $.makeArray($('div[data-dynamic="true"]').map( 5 function () { 6 return { 7 nid: $(this).data('nid'), 8 uuid: $(this).data('uuid'), 9 loaded: false 10 }; 11 })); 12 13 var attempt = 0; 14 var maxAttempts = 50; 15 var get_blocks = null; 16 var get_blocks_id = setInterval(function () { 17 get_blocks = getCookie('dmp-get-blocks'); 18 if (get_blocks !== null && get_blocks === '1') { 19 var loader = function () { 20 var container = $(this); 21 var container_nid = container.data('nid') || $(".hic-customization-data").data("nid"); 22 var containerUUID = container.data('uuid'); 23 24 if (!containerUUID) { 25 console.error('Container UUID is undefined'); 26 return; 27 } 28 29 container.addClass('ph-loading'); 30 31 // Ensure container exists before appending 32 if (container.length > 0) { 33 container.append('<div class="spinner"><div class="dot1"></div><div class="dot2"></div></div>'); 34 $.post({ 35 url: Drupal.url('hic-md-loader'), 36 data: JSON.stringify({ 37 nid: container_nid, 38 uuid: containerUUID 39 }), 40 contentType: 'application/json', 41 success: function (data) { 42 container.append(data); 43 container.find('.spinner').remove(); 44 container.removeClass('ph-loading'); 45 pageBlocks.filter(function (block) { 46 return block.uuid === containerUUID; 47 }).shift().loaded = true; 48 Drupal.attachBehaviors(container.get(0)); // Attach behaviors to the newly added content 49 }, 50 error: function (error) { 51 console.error('Error in post hic-md-loader.js request:', error); 52 container.find('.spinner').remove(); 53 container.removeClass('ph-loading'); 54 } 55 }); 56 } else { 57 console.error('Container is empty or undefined'); 58 } 59 }; 60 61 // Select the div elements with data-dynamic attribute 62 once('data-dynamic-true', 'div[data-dynamic="true"]', context).forEach(function (element) { 63 const blocNumItemsElement = element.querySelector('#bloc_num_items'); 64 65 // Ensure that blocNumItemsElement exists before accessing its dataset 66 if (blocNumItemsElement) { 67 const numItems = blocNumItemsElement.dataset.num_items; 68 69 // Check if num_items is defined and apply class if necessary 70 if (typeof numItems !== 'undefined' && numItems == 0) { 71 element.classList.add('no-content'); 72 } 73 74 // Check if element is visible (assuming a visible function is defined or use a library) 75 if ($(element).visible(true)) { 76 loader.call(element); // Call the loader function 77 } 78 } 79 }); 80 81 var scrollFilter = function (block) { 82 return block.loaded === false && $('div[data-uuid="' + block.uuid + '"]').visible(true); 83 }; 84 85 // Attach the scroll event listener 86 window.addEventListener('scroll', function () { 87 const filteredBlocks = pageBlocks.filter(scrollFilter); 88 89 filteredBlocks.map(function (block) { 90 return document.querySelector('div[data-uuid="' + block.uuid + '"]'); 91 }).filter(Boolean).forEach(function (element) { 92 once('loaded-block', element).forEach(function () { 93 loader.call(element); 94 }); 95 }); 96 }); 97 98 99 clearInterval(get_blocks_id); 100 } else { 101 // Meter aquà la aceptación de cookies 102 var cookie_agreed = getCookie('cookie-agreed'); 103 if (cookie_agreed == '2') { 104 var cookie_agreed_categories = getCookie('cookie-agreed-categories'); 105 if (attempt < maxAttempts) { 106 attempt++; 107 } else { 108 // the execution goes on but we have not got a new campaign... 109 clearInterval(get_blocks_id); 110 } 111 } 112 } 113 }, 50); 114 } 115 }; 116 117 function getCookie(name) { 118 var nameEQ = name + "="; 119 var ca = document.cookie.split(';'); 120 for (var i = 0; i < ca.length; i++) { 121 var c = ca[i]; 122 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 123 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 124 } 125 return null; 126 } 127})(jQuery, Drupal, once);
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.