PageSourceSearch

https://braga25.pt/wp-content/themes/braga25/assets/scripts/welcome.js?ver=1790694769

js braga25.pt collected 2026-10-01 15:53:39 UTC 3,049 bytes, 115 lines download raw bytes

1(function ($) {
2  'use strict';
3
4  function prefersReducedMotion() {
5    return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
6  }
7
8  function waitForAssets(container) {
9    var fontsReady = document.fonts && document.fonts.ready
10      ? document.fonts.ready.catch(function () {})
11      : Promise.resolve();
12
13    var images = Array.prototype.slice.call(container.querySelectorAll('img'));
14    var imagesReady = Promise.all(
15      images.map(function (img) {
16        if (img.complete) {
17          return Promise.resolve();
18        }
19
20        return new Promise(function (resolve) {
21          img.addEventListener('load', resolve, { once: true });
22          img.addEventListener('error', resolve, { once: true });
23        });
24      })
25    );
26
27    return Promise.all([fontsReady, imagesReady]);
28  }
29
30  // Palavras em inline-block para poderem subir (transform); espaços ficam texto
31  function wrapChunkWords(chunk) {
32    var text = chunk.textContent;
33    var parts = text.split(/(\s+)/);
34
35    chunk.textContent = '';
36
37    parts.forEach(function (part) {
38      if (!part) {
39        return;
40      }
41
42      if (/^\s+$/.test(part)) {
43        chunk.appendChild(document.createTextNode(part));
44        return;
45      }
46
47      var word = document.createElement('span');
48      word.className = 'welcome-word';
49      word.textContent = part;
50      chunk.appendChild(word);
51    });
52  }
53
54  function prepareWelcomeText(el) {
55    var items = [];
56    var children = Array.prototype.slice.call(el.children);
57
58    // Sem :scope — falha em alguns WebKit mobile e só as pills animavam
59    children.forEach(function (child) {
60      if (child.classList.contains('welcome-chunk')) {
61        wrapChunkWords(child);
62        Array.prototype.push.apply(items, child.querySelectorAll('.welcome-word'));
63      } else if (child.classList.contains('pill-link')) {
64        items.push(child);
65      }
66    });
67
68    items.forEach(function (item, i) {
69      var delay = (0.35 + i * 0.06) + 's';
70      item.style.animationDelay = delay;
71      item.style.webkitAnimationDelay = delay;
72    });
73
74    return items;
75  }
76
77  function initWelcome() {
78    var el = document.querySelector('.welcome-text');
79
80    if (!el) {
81      return;
82    }
83
84    if (!el.getAttribute('data-original-html')) {
85      el.setAttribute('data-original-html', el.innerHTML);
86    } else {
87      el.innerHTML = el.getAttribute('data-original-html');
88    }
89
90    el.classList.remove('is-ready', 'is-animated', 'is-gsap');
91
92    if (prefersReducedMotion()) {
93      el.classList.add('is-ready', 'is-animated');
94      return;
95    }
96
97    prepareWelcomeText(el);
98
99    waitForAssets(el).then(function () {
100      el.classList.add('is-ready');
101
102      // Reflow — necessário p/ keyframes dispararem no iOS
103      void el.offsetWidth;
104
105      window.requestAnimationFrame(function () {
106        window.requestAnimationFrame(function () {
107          el.classList.add('is-animated');
108        });
109      });
110    });
111  }
112
113  $(initWelcome);
114  $(document).on('b25:page-view', initWelcome);
115})(jQuery);

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.