1/* @license GPL-2.0-or-later https://www.drupal.org/licensing/faq */ 2(function(Drupal){Drupal.behaviors.legalitasModalContrata={attach:function(context,settings){jQuery(document).ajaxComplete(function(){document.querySelectorAll('.modal-contrata-container__top').forEach((element)=>{const height=element.getAttribute('data-height');const mdHeight=element.getAttribute('data-mdheight');const lgHeight=element.getAttribute('data-lgheight');if(height)element.style.setProperty('--data-height',height);if(mdHeight)element.style.setProperty('--data-mdheight',mdHeight);if(lgHeight)element.style.setProperty('--data-lgheight',lgHeight);});document.querySelectorAll('.modal-contrata-container').forEach((container)=>{const dialog=container.closest('.ui-dialog');let width;if(window.innerWidth<300)width=`${window.innerWidth}px`;else if(window.innerWidth<450)width=`${window.innerWidth}px`;else width='auto';if(dialog)dialog.style.setProperty('--modal-width',width);});});jQuery(document).ready(function(){if(window.location.pathname.startsWith('/actualidad/'))document.querySelectorAll('.modal-contrata-container__top').forEach((element)=>{const height=element.getAttribute('data-height');const mdHeight=element.getAttribute('data-mdheight');const lgHeight=element.getAttribute('data-lgheight');if(height)element.style.setProperty('--data-height',height);if(mdHeight)element.style.setProperty('--data-mdheight',mdHeight);if(lgHeight)element.style.setProperty('--data-lgheight',lgHeight);if(window.innerWidth<=1025){const proportion=element.getAttribute('data-proportion');if(proportion){const calculatedHeight=(parseFloat(proportion)*element.offsetWidth);element.setAttribute('data-height',`${calculatedHeight}px`);element.style.setProperty('--data-height',`${calculatedHeight}px`);element.setAttribute('data-mdheight',`${calculatedHeight}px`);element.style.setProperty('--data-mdheight',`${calculatedHeight}px`);element.setAttribute('data-lgheight',`${calculatedHeight}px`);element.style.setProperty('--data-lgheight',`${calculatedHeight}px`);}}});});}};})(Drupal);; 3(function(Drupal,once){'use strict';const exampleTypingSpeed=52;const exampleDeletingSpeed=26;const examplePauseDelay=1600;const exampleRestartDelay=280;function launchChatIaEvent(eventName,subCategory,text){if(typeof Drupal.legalitas==='undefined'||typeof Drupal.legalitas.launch!=='function')return;const utils=Drupal.legalitas;const payload={event:eventName,category:'chat_ia',pageURL:utils.getUrl(),subCategory,text:utils.normalizeGtmText(text||''),pageSection:utils.getPageSectionFromUrl()};utils.cleanEmptyValues(payload);utils.launch(payload);}function appendMessage(messages,text,type){const item=document.createElement('div');item.className='legalitas-ai-chat__message legalitas-ai-chat__message--'+type;if(type==='assistant'){const avatar=document.createElement('span');avatar.className='legalitas-ai-chat__avatar';avatar.setAttribute('aria-hidden','true');item.appendChild(avatar);}const bubble=document.createElement('div');bubble.className='legalitas-ai-chat__bubble';bubble.textContent=text;item.appendChild(bubble);messages.appendChild(item);messages.scrollTop=messages.scrollHeight;return item;}function appendTyping(messages){const item=document.createElement('div');item.className='legalitas-ai-chat__message legalitas-ai-chat__message--assistant legalitas-ai-chat__message--typing';item.setAttribute('aria-label',Drupal.t('El asistente está escribiendo'));const avatar=document.createElement('span');avatar.className='legalitas-ai-chat__avatar';avatar.setAttribute('aria-hidden','true');const bubble=document.createElement('div');bubble.className='legalitas-ai-chat__bubble';bubble.innerHTML='<span></span><span></span><span></span>';item.appendChild(avatar);item.appendChild(bubble);messages.appendChild(item);messages.scrollTop=messages.scrollHeight;return item;}function setFormDisabled(chat,disabled){const form=chat.querySelector('[data-ai-message-form]');form.querySelector('input').disabled=disabled;form.querySelector('button').disabled=disabled;chat.dataset.busy=disabled?'true':'';}function scrollMessages(messages){messages.scrollTop=messages.scrollHeight;}function syncChatViewport(chat){if(chat.getAttribute('aria-hidden')==='true')return;
3const viewport=window.visualViewport;const width=viewport?viewport.width:window.innerWidth;const height=viewport?viewport.height:window.innerHeight;const offsetTop=viewport?viewport.offsetTop:0;const offsetLeft=viewport?viewport.offsetLeft:0;chat.style.setProperty('--legalitas-ai-viewport-width',Math.round(width)+'px');chat.style.setProperty('--legalitas-ai-viewport-height',Math.round(height)+'px');chat.style.setProperty('--legalitas-ai-viewport-top',Math.round(offsetTop)+'px');chat.style.setProperty('--legalitas-ai-viewport-left',Math.round(offsetLeft)+'px');window.requestAnimationFrame(function(){scrollMessages(chat.querySelector('[data-ai-messages]'));});}function initChatViewport(chat){let frameId=0;const scheduleSync=function(){if(frameId)window.cancelAnimationFrame(frameId);frameId=window.requestAnimationFrame(function(){frameId=0;syncChatViewport(chat);});};const input=chat.querySelector('[data-ai-message-form] input');input.addEventListener('focus',function(){scheduleSync();window.setTimeout(scheduleSync,150);window.setTimeout(scheduleSync,350);});input.addEventListener('blur',scheduleSync);window.addEventListener('orientationchange',scheduleSync);if(window.visualViewport){window.visualViewport.addEventListener('resize',scheduleSync);window.visualViewport.addEventListener('scroll',scheduleSync);}}function appendInputRequest(messages,event,onSelect){if(!event.requestId||!Array.isArray(event.options)||!event.options.length)throw {message:Drupal.t('El asistente ha solicitado una respuesta que no podemos mostrar.')};const item=appendMessage(messages,event.message||Drupal.t('Selecciona una opción:'),'assistant');const actions=document.createElement('div');actions.className='legalitas-ai-chat__actions';event.options.forEach(function(option){if(!option.optionId||!option.label)return;const button=document.createElement('button');button.type='button';button.className='legalitas-ai-chat__option';button.textContent=option.label;button.addEventListener('click',function(){actions.querySelectorAll('button').forEach(function(candidate){candidate.disabled=true;});onSelect(event.requestId,option.optionId,option.label,actions);});actions.appendChild(button);});if(!actions.children.length){item.remove();throw {message:Drupal.t('El asistente ha solicitado una respuesta que no podemos mostrar.')};}item.querySelector('.legalitas-ai-chat__bubble').appendChild(actions);scrollMessages(messages);}function parseExamples(value){if(!value)return [];try{const parsed=JSON.parse(value);if(!Array.isArray(parsed))return [];return parsed.filter(function(item){return typeof item==='string'&&item.trim()!=='';});}catch(error){return [];}}function trackFloatingIaOnFirstInput(input){function onFirstInput(){if(input.value.trim()==='')return;input.removeEventListener('input',onFirstInput);launchChatIaEvent('floating_ia','floating','ia');}input.addEventListener('input',onFirstInput);}function initConsultExamples(block){const input=block.querySelector('[data-ai-consult-input]');if(!input)return;trackFloatingIaOnFirstInput(input);const fallbackPlaceholder=input.dataset.consultPlaceholder||input.getAttribute('placeholder')||'';const examplesEnabled=input.dataset.consultExamplesEnabled==='1';const examples=parseExamples(input.dataset.consultExamples);input.setAttribute('placeholder',fallbackPlaceholder);if(!examplesEnabled||!examples.length)return;let timerId=0;let exampleIndex=0;let charIndex=0;let deleting=false;function clearExampleTimer(){if(timerId){window.clearTimeout(timerId);timerId=0;}}function shouldPauseAnimation(){return document.activeElement===input||input.value.trim()!=='';}function schedule(delay){clearExampleTimer();timerId=window.setTimeout(tick,delay);}function setText(value){input.setAttribute('placeholder',value);}function tick(){if(shouldPauseAnimation()){clearExampleTimer();setText(fallbackPlaceholder);return;}const currentExample=examples[exampleIndex]||fallbackPlaceholder;if(!deleting){charIndex+=1;setText(currentExample.slice(0,charIndex));if(charIndex<currentExample.length){schedule(exampleTypingSpeed);return;}deleting=true;schedule(examplePauseDelay);return;}charIndex-=1;setText(currentExample.slice(0,Math.max(charIndex,0)));if(charIndex>0){schedule(exampleDeletingSpeed);return;}deleting=false;exampleIndex=(exampleIndex+1)%examples.length;schedule(exampleRestartDelay);}function restartIfIdle(){if(shouldPauseAnimation())return;charIndex=0;deleting=false;setText('');schedule(exampleRestartDelay);}input.addEventListener('focus',function(){clearExampleTimer();setText(fallbackPlaceholder);});input.addEventListener('blur',function(){restartIfIdle();});input.addEventListener('input',function(){if(input.value.trim()!==''){clearExampleTimer();setText(fallbackPlaceholder);return;}restartIfIdle();});restartIfIdle();}function openChat(chat,initialMessage){const messages=chat.querySelector('[data-ai-messages]');const input=chat.querySelector('[data-ai-message-form] input');chat.setAttribute('aria-hidden','false');document.documentElement.classList.add('legalitas-ai-chat-open');syncChatViewport(chat);if(!chat.dataset.started){appendMessage(messages,chat.dataset.welcomeMessage||'','assistant');chat.dataset.started='true';}
3if(initialMessage)sendMessage(chat,initialMessage,false);window.setTimeout(function(){input.focus();},50);}function closeChat(chat){const closeButton=chat.querySelector('[data-ai-close]');chat.querySelector('[data-ai-message-form] input').blur();chat.setAttribute('aria-hidden','true');document.documentElement.classList.remove('legalitas-ai-chat-open');launchChatIaEvent('legalitas_ai_close','',closeButton?closeButton.getAttribute('aria-label'):'');}function sendTurn(chat,payload){if(chat.dataset.busy==='true')return;const form=chat.querySelector('[data-ai-message-form]');const input=form.querySelector('input');const messages=chat.querySelector('[data-ai-messages]');const endpoint=chat.dataset.chatEndpoint;const typing=appendTyping(messages);let terminalEvent='';let assistantItem=null;let assistantBubble=null;let pendingText='';let frameId=0;let delayedMessageTimer=0;const isFirstMessage=!chat.dataset.firstMessageSent&&Object.prototype.hasOwnProperty.call(payload,'message');if(isFirstMessage)chat.dataset.firstMessageSent='true';setFormDisabled(chat,true);function clearDelayedMessageTimer(){if(delayedMessageTimer){window.clearTimeout(delayedMessageTimer);delayedMessageTimer=0;}}function showDelayedMessage(){if(!typing.parentNode)return;const bubble=typing.querySelector('.legalitas-ai-chat__bubble');bubble.textContent=chat.dataset.delayedMessage||'';typing.classList.add('legalitas-ai-chat__message--delayed');scrollMessages(messages);}if(isFirstMessage&&chat.dataset.delayedMessageEnabled==='1'&&chat.dataset.delayedMessage){const delaySeconds=Math.max(1,parseInt(chat.dataset.delayedMessageSeconds||'8',10));delayedMessageTimer=window.setTimeout(showDelayedMessage,delaySeconds*1000);}function ensureAssistantBubble(){if(!assistantItem){typing.remove();assistantItem=appendMessage(messages,'','assistant');assistantBubble=assistantItem.querySelector('.legalitas-ai-chat__bubble');}return assistantBubble;}function flushPendingText(){frameId=0;if(!pendingText)return;const bubble=ensureAssistantBubble();bubble.textContent+=pendingText;pendingText='';scrollMessages(messages);}function queueDelta(delta){if(!delta)return;pendingText+=delta;if(!frameId)frameId=window.requestAnimationFrame(flushPendingText);}function handleEvent(event){if(!event||typeof event.type!=='string')return;if(event.type==='session.accepted'){chat.dataset.conversationId=event.conversationId||chat.dataset.conversationId||'';return;}if(event.type==='turn.started'){chat.dataset.lastTurnId=event.turnId||'';return;}if(event.type==='message.delta'){clearDelayedMessageTimer();queueDelta(event.delta||'');return;}if(event.type==='message.completed'){clearDelayedMessageTimer();if(frameId)window.cancelAnimationFrame(frameId);flushPendingText();ensureAssistantBubble().textContent=event.message||'';scrollMessages(messages);return;}if(event.type==='input.requested'){clearDelayedMessageTimer();if(frameId)window.cancelAnimationFrame(frameId);flushPendingText();typing.remove();terminalEvent='input.requested';chat.dataset.busy='';appendInputRequest(messages,event,function(requestId,optionId,label,actions){actions.remove();appendMessage(messages,label,'user');sendTurn(chat,{inputResponses:[{requestId,optionId}]});});return;}if(event.type==='session.waiting'){clearDelayedMessageTimer();if(terminalEvent==='input.requested')return;terminalEvent='session.waiting';chat.dataset.conversationId=event.conversationId||chat.dataset.conversationId||'';return;}if(event.type==='error'){clearDelayedMessageTimer();chat.dataset.conversationId=event.conversationId||chat.dataset.conversationId||'';throw event;}}fetch(endpoint,{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json','Accept':'application/x-ndjson, application/json','X-Requested-With':'XMLHttpRequest'},body:JSON.stringify(Object.assign({},payload,{conversationId:chat.dataset.conversationId||'',lastTurnId:chat.dataset.lastTurnId||'',source:window.location.href}))}).then(function(response){if(!response.ok)return response.json().catch(function(){return {};}).then(function(error){throw error;});if(!response.body||typeof response.body.getReader!=='function')throw {message:chat.dataset.errorMessage||''};const reader=response.body.getReader();const decoder=new TextDecoder();let buffer='';function processBuffer(complete){const lines=buffer.split('\n');buffer=complete?'':lines.pop();
3lines.forEach(function(line){if(!line.trim())return;try{handleEvent(JSON.parse(line));}catch(error){if(error&&error.type==='error')throw error;throw {message:chat.dataset.errorMessage||''};}});}function read(){return reader.read().then(function(result){buffer+=decoder.decode(result.value||new Uint8Array(),{stream:!result.done});processBuffer(result.done);if(!result.done)return read();});}return read();}).then(function(){if(!terminalEvent)throw {message:chat.dataset.errorMessage||''};}).catch(function(error){clearDelayedMessageTimer();if(frameId)window.cancelAnimationFrame(frameId);flushPendingText();typing.remove();if(!assistantItem||!assistantBubble.textContent)appendMessage(messages,error.message||chat.dataset.errorMessage||'','assistant');terminalEvent='error';}).finally(function(){if(terminalEvent!=='input.requested'){setFormDisabled(chat,false);input.focus();}});}function sendMessage(chat,message,trackAnalytics){const cleanMessage=(message||'').trim();if(!cleanMessage||chat.dataset.busy==='true')return;const form=chat.querySelector('[data-ai-message-form]');const button=form.querySelector('button');appendMessage(chat.querySelector('[data-ai-messages]'),cleanMessage,'user');form.querySelector('input').value='';if(trackAnalytics!==false)launchChatIaEvent('interactions_chat_ia','enviar_mensaje',button.textContent||button.value||'');sendTurn(chat,{message:cleanMessage});}Drupal.behaviors.legalitasAi={attach:function(context){once('legalitas-ai','.legalitas-ai',context).forEach(function(block){const consultForm=block.querySelector('[data-ai-consult-form]');const chat=block.querySelector('[data-ai-chat]');const closeButton=block.querySelector('[data-ai-close]');const messageForm=block.querySelector('[data-ai-message-form]');const getSubmitterText=function(event,form){const submitter=event&&event.submitter?event.submitter:null;if(submitter)return submitter.textContent||submitter.value||'';const button=form.querySelector('button[type="submit"], input[type="submit"]');return button?(button.textContent||button.value||''):'';};initConsultExamples(block);initChatViewport(chat);consultForm.addEventListener('submit',function(event){event.preventDefault();const input=consultForm.querySelector('input');const clickedText=getSubmitterText(event,consultForm);const skipStartAnalytics=consultForm.getAttribute('data-skip-start-analytics')==='1';if(skipStartAnalytics)consultForm.removeAttribute('data-skip-start-analytics');if(!skipStartAnalytics)launchChatIaEvent('interactions_chat_ia','iniciar_conversacion_ia',clickedText);openChat(chat,input.value);input.value='';});closeButton.addEventListener('click',function(){closeChat(chat);});chat.addEventListener('click',function(event){if(event.target===chat)closeChat(chat);});messageForm.addEventListener('submit',function(event){event.preventDefault();sendMessage(chat,messageForm.querySelector('input').value);});block.addEventListener('keydown',function(event){if(event.key==='Escape'&&chat.getAttribute('aria-hidden')==='false')closeChat(chat);});});}};})(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.