PageSourceSearch

https://www.samaterials.es/js/header-language.js?v=1789002534

js samaterials.es collected 2026-10-02 20:45:18 UTC 7,420 bytes, 258 lines download raw bytes

1(function () {
2  'use strict'
3
4  var PC_MIN_WIDTH = 1026
5  var TRIGGER_LEAVE_DELAY = 180
6  var root = document.getElementById('main-sam-header')
7  if (!root) return
8
9  var pcLangZone = document.querySelector('.sam-lang--pc')
10  var pcTrigger = document.getElementById('sam-lang-pc-trigger')
11  var overlay = document.getElementById('sam-lang-overlay')
12  var panel = document.getElementById('sam-lang-panel')
13  var mobileEntryWrap = document.querySelector('.sam-lang-mobile-entry-wrap')
14  var mobileEntry = document.getElementById('sam-lang-mobile-entry')
15  var mobilePanel = document.getElementById('sam-lang-mobile-panel')
16  var mobileBack = document.getElementById('sam-lang-mobile-back')
17  var mobileClose = document.getElementById('sam-lang-mobile-close')
18  var mobileNav = document.querySelector('.oc-main-sam-header-nav-mobile')
19  var pcHeader = document.querySelector('.oc-main-sam-header-pc')
20
21  var pcOpen = false
22  var closeTimer = null
23  var mobileOpen = false
24
25  function isPcViewport () {
26    return window.matchMedia('(min-width: ' + PC_MIN_WIDTH + 'px)').matches
27  }
28
29  function updatePanelOffset () {
30    if (!pcHeader) return
31    var bottom = pcHeader.getBoundingClientRect().bottom
32    root.style.setProperty('--sam-lang-panel-top', bottom + 'px')
33  }
34
35  var offsetRaf = null
36  var offsetUntil = 0
37
38  function stopPanelOffsetSync () {
39    offsetUntil = 0
40    if (offsetRaf) {
41      cancelAnimationFrame(offsetRaf)
42      offsetRaf = null
43    }
44  }
45
46  function tickPanelOffsetSync () {
47    offsetRaf = null
48    if (!pcOpen) return
49    updatePanelOffset()
50    if (Date.now() < offsetUntil) {
51      offsetRaf = requestAnimationFrame(tickPanelOffsetSync)
52    }
53  }
54
55  function startPanelOffsetSync (durationMs) {
56    if (!pcOpen) return
57    offsetUntil = Date.now() + (durationMs || 320)
58    if (!offsetRaf) {
59      offsetRaf = requestAnimationFrame(tickPanelOffsetSync)
60    }
61  }
62
63  function clearCloseTimer () {
64    if (closeTimer) {
65      clearTimeout(closeTimer)
66      closeTimer = null
67    }
68  }
69
70  function scheduleClose (delay) {
71    clearCloseTimer()
72    closeTimer = setTimeout(function () {
73      setPcOpen(false)
74    }, delay)
75  }
76
77  function isMovingToPanelArea (relatedTarget) {
78    if (!relatedTarget) return false
79    return (panel && panel.contains(relatedTarget)) ||
80      (overlay && overlay.contains(relatedTarget))
81  }
82
83  function setPcOpen (open) {
84    if (!pcTrigger || !overlay || !panel) return
85
86    if (open) {
87      updatePanelOffset()
88    }
89
90    pcOpen = open
91    pcTrigger.classList.toggle('is-active', open)
92    pcTrigger.setAttribute('aria-expanded', open ? 'true' : 'false')
93    overlay.hidden = !open
94    overlay.setAttribute('aria-hidden', open ? 'false' : 'true')
95    panel.hidden = !open
96    panel.setAttribute('aria-hidden', open ? 'false' : 'true')
97
98    if (!open) {
99      clearCloseTimer()
100      stopPanelOffsetSync()
101    }
102  }
103
104  function initPcFlyoutHover () {
105    if (pcLangZone) {
106      pcLangZone.addEventListener('mouseenter', function () {
107        if (!isPcViewport()) return
108        clearCloseTimer()
109        setPcOpen(true)
110      })
111
112      pcLangZone.addEventListener('mouseleave', function (event) {
113        if (!isPcViewport()) return
114        if (isMovingToPanelArea(event.relatedTarget)) return
115        scheduleClose(TRIGGER_LEAVE_DELAY)
116      })
117    }
118
119    if (panel) {
120      panel.addEventListener('mouseenter', function () {
121        if (!isPcViewport()) return
122        clearCloseTimer()
123      })
124
125      panel.addEventListener('mouseleave', function () {
126        if (!isPcViewport()) return
127        setPcOpen(false)
128      })
129    }
130
131    // Product/nav mega menu sits under the language overlay; close language when using nav.
132    var pcNav = document.querySelector('.oc-main-sam-header-pc .oc-main-sam-header-nav')
133    if (pcNav) {
134      pcNav.addEventListener('mouseenter', function () {
135        if (!isPcViewport()) return
136        setPcOpen(false)
137      })
138    }
139  }
140
141  function closeMobilePanel () {
142    if (!mobilePanel) return
143    mobileOpen = false
144    mobilePanel.classList.remove('is-open')
145    mobilePanel.setAttribute('aria-hidden', 'true')
146    if (mobileEntry) mobileEntry.setAttribute('aria-expanded', 'false')
147    if (mobileNav) mobileNav.classList.remove('is-lang-open')
148  }
149
150  function openMobilePanel () {
151    if (!mobilePanel) return
152    mobileOpen = true
153    mobilePanel.classList.add('is-open')
154    mobilePanel.setAttribute('aria-hidden', 'false')
155    if (mobileEntry) mobileEntry.setAttribute('aria-expanded', 'true')
156    if (mobileNav) mobileNav.classList.add('is-lang-open')
157  }
158
159  function closeMobileNav () {
160    closeMobilePanel()
161    if (!mobileNav) return
162    if (window.jQuery) {
163      window.jQuery(mobileNav).slideUp('fast')
164    } else {
165      mobileNav.style.display = 'none'
166    }
167    document.body.style.overflow = ''
168  }
169
170  if (pcTrigger) {
171    pcTrigger.addEventListener('click', function (event) {
172      event.preventDefault()
173      event.stopPropagation()
174      if (!isPcViewport()) return
175      clearCloseTimer()
176      setPcOpen(!pcOpen)
177    })
178  }
179
180  if (overlay) {
181    overlay.addEventListener('click', function () {
182      setPcOpen(false)
183    })
184  }
185
186  if (mobileEntryWrap) {
187    mobileEntryWrap.addEventListener('click', function (event) {
188      event.preventDefault()
189      openMobilePanel()
190    })
191  } else if (mobileEntry) {
192    mobileEntry.addEventListener('click', function (event) {
193      event.preventDefault()
194      openMobilePanel()
195    })
196  }
197
198  if (mobileBack) {
199    mobileBack.addEventListener('click', function (event) {
200      event.preventDefault()
201      closeMobilePanel()
202    })
203  }
204
205  if (mobileClose) {
206    mobileClose.addEventListener('click', function (event) {
207      event.preventDefault()
208      closeMobileNav()
209    })
210  }
211
212  var mainNavClose = document.querySelector('.oc-main-sam-header-nav-mobile .close-icon-wrapper')
213  if (mainNavClose) {
214    mainNavClose.addEventListener('click', function () {
215      closeMobilePanel()
216    })
217  }
218
219  root.querySelectorAll('.sam-lang-accordion-trigger').forEach(function (trigger) {
220    trigger.addEventListener('click', function () {
221      var item = trigger.closest('.sam-lang-accordion-item')
222      if (!item) return
223      var willOpen = !item.classList.contains('is-open')
224      item.classList.toggle('is-open', willOpen)
225      trigger.setAttribute('aria-expanded', willOpen ? 'true' : 'false')
226    })
227  })
228
229  document.addEventListener('keydown', function (event) {
230    if (event.key !== 'Escape') return
231    if (pcOpen) setPcOpen(false)
232    if (mobileOpen) closeMobilePanel()
233  })
234
235  window.addEventListener('resize', function () {
236    if (pcOpen) {
237      updatePanelOffset()
238    }
239    if (!isPcViewport() && pcOpen) {
240      setPcOpen(false)
241    }
242  })
243
244  window.addEventListener('scroll', function () {
245    if (!pcOpen || !isPcViewport()) return
246    startPanelOffsetSync(320)
247  }, { passive: true })
248
249  if (pcHeader && window.MutationObserver) {
250    new MutationObserver(function () {
251      if (!pcOpen || !isPcViewport()) return
252      startPanelOffsetSync(320)
253    }).observe(pcHeader, { attributes: true, attributeFilter: ['class'] })
254  }
255
256  updatePanelOffset()
257  initPcFlyoutHover()
258})()

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.