PageSourceSearch

https://fastercapital.com/assets/2017/js/quality-fixes.js?v=1788447400

js fastercapital.com collected 2026-09-24 08:29:07 UTC 15,506 bytes, 367 lines download raw bytes

1(function () {
2    'use strict';
3
4    var qualityFixesScriptUrl = document.currentScript && document.currentScript.src ? document.currentScript.src : '';
5
6    function onReady(callback) {
7        if (document.readyState === 'loading') {
8            document.addEventListener('DOMContentLoaded', callback);
9        } else {
10            callback();
11        }
12    }
13
14    function makeIdsUnique() {
15        var seen = Object.create(null);
16        var nodes = document.querySelectorAll('[id]');
17        Array.prototype.forEach.call(nodes, function (node) {
18            var original = node.id;
19            if (!original) {
20                node.removeAttribute('id');
21                return;
22            }
23            if (!seen[original]) {
24                seen[original] = 1;
25                return;
26            }
27            seen[original] += 1;
28            node.id = original + '--' + seen[original];
29            var parentLabel = node.closest ? node.closest('label') : null;
30            if (parentLabel && parentLabel.getAttribute('for') === original) {
31                parentLabel.setAttribute('for', node.id);
32            }
33        });
34    }
35
36    function supportsExpanded(node) {
37        return node.matches('button, a, summary, input, [role="button"], [role="tab"], [role="combobox"]');
38    }
39
40    function repairExpanded(root) {
41        var scope = root && root.querySelectorAll ? root : document;
42        var nodes = scope.querySelectorAll('[aria-expanded]');
43        Array.prototype.forEach.call(nodes, function (node) {
44            if (!supportsExpanded(node)) {
45                node.removeAttribute('aria-expanded');
46            }
47        });
48        if (root && root.nodeType === 1 && root.hasAttribute('aria-expanded') && !supportsExpanded(root)) {
49            root.removeAttribute('aria-expanded');
50        }
51    }
52
53    function improveMedia() {
54        var priorityImage = document.querySelector('#header .header-logo img, .home-intro img, #main-content > section:first-of-type img');
55        Array.prototype.forEach.call(document.querySelectorAll('iframe'), function (frame) {
56            if (!frame.hasAttribute('loading')) {
57                frame.setAttribute('loading', 'lazy');
58            }
59            if (!frame.getAttribute('title')) {
60                frame.setAttribute('title', 'Embedded media');
61            }
62        });
63        Array.prototype.forEach.call(document.querySelectorAll('img'), function (image) {
64            if (!image.hasAttribute('decoding')) {
65                image.setAttribute('decoding', 'async');
66            }
67            if (image === priorityImage || (image.closest && image.closest('#header'))) {
68                image.setAttribute('loading', 'eager');
69                image.setAttribute('fetchpriority', 'high');
70            } else if (!image.hasAttribute('loading')) {
71                image.setAttribute('loading', 'lazy');
72            }
73            if (image.closest && image.closest('.fc-video-testimonials .thumb-info-wrapper')) {
74                image.setAttribute('width', '500');
75                image.setAttribute('height', '281');
76            }
77        });
78    }
79
80    function youtubeVideoId(href) {
81        if (!href) {
82            return '';
83        }
84        try {
85            var url = new URL(href, document.baseURI);
86            if (url.hostname.indexOf('youtu.be') !== -1) {
87                return (url.pathname.split('/').filter(Boolean)[0] || '').substring(0, 11);
88            }
89            if (url.hostname.indexOf('youtube.com') !== -1) {
90                return (url.searchParams.get('v') || '').substring(0, 11);
91            }
92        } catch (error) {
93            return '';
94        }
95        return '';
96    }
97
98    function localYoutubeThumbnail(videoId) {
99        var url;
100        try {
101            url = new URL(qualityFixesScriptUrl || document.baseURI, document.baseURI);
102            var markerIndex = url.pathname.indexOf('/assets/');
103            if (markerIndex !== -1) {
104                url.pathname = url.pathname.substring(0, markerIndex) + '/images/service/video/youtube/' + videoId + '.webp';
105            } else {
106                url = new URL('images/service/video/youtube/' + videoId + '.webp', document.baseURI);
107            }
108            url.search = '';
109            url.hash = '';
110            return url.href;
111        } catch (error) {
112            return '';
113        }
114    }
115
116    function improveYoutubeThumbnails() {
117        var links = document.querySelectorAll('.video-section a.popup-youtube, .fc-video-testimonials a.popup-youtube');
118        Array.prototype.forEach.call(links, function (link) {
119            var videoId = youtubeVideoId(link.href);
120            var image = link.querySelector('img');
121            if (!videoId || !image) {
122                return;
123            }
124            var thumbnail = localYoutubeThumbnail(videoId);
125            if (!thumbnail) {
126                return;
127            }
128            var originalSrc = image.getAttribute('src');
129            var originalDataSrc = image.getAttribute('data-src');
130            var restoreOriginal = function () {
131                image.removeEventListener('error', restoreOriginal);
132                image.classList.remove('fc-actual-youtube-thumbnail');
133                if (originalSrc) {
134                    image.setAttribute('src', originalSrc);
135                } else {
136                    image.removeAttribute('src');
137                }
138                if (originalDataSrc) {
139                    image.setAttribute('data-src', originalDataSrc);
140                } else {
141                    image.removeAttribute('data-src');
142                }
143            };
144            image.addEventListener('error', restoreOriginal);
145            image.setAttribute('src', thumbnail);
146            image.setAttribute('data-src', thumbnail);
147            image.setAttribute('width', '640');
148            image.setAttribute('height', '360');
149            image.setAttribute('loading', link.closest('.video-section') ? 'eager' : 'lazy');
150            image.setAttribute('decoding', 'async');
151            image.classList.add('fc-actual-youtube-thumbnail');
152        });
153    }
154
155    function improveNavigation() {
156        var collapseButton = document.querySelector('.header-btn-collapse-nav');
157        var navigation = document.querySelector('.header-nav-main');
158        if (collapseButton && navigation) {
159            var syncNavigationState = function () {
160                collapseButton.setAttribute('aria-expanded', navigation.classList.contains('in') ? 'true' : 'false');
161            };
162            collapseButton.setAttribute('aria-controls', navigation.id || 'main-navigation');
163            if (!navigation.id) {
164                navigation.id = 'main-navigation';
165            }
166            syncNavigationState();
167            collapseButton.addEventListener('click', function () {
168                window.setTimeout(syncNavigationState, 400);
169            });
170            if (window.jQuery) {
171                window.jQuery(navigation)
172                    .on('shown.bs.collapse', syncNavigationState)
173                    .on('hidden.bs.collapse', syncNavigationState);
174            }
175        }
176
177        Array.prototype.forEach.call(document.querySelectorAll('#mainNav .dropdown > a, #mainNav .dropdown-submenu > a'), function (toggle) {
178            toggle.setAttribute('aria-haspopup', 'true');
179            toggle.setAttribute('aria-expanded', 'false');
180            toggle.addEventListener('click', function () {
181                window.setTimeout(function () {
182                    toggle.setAttribute('aria-expanded', toggle.parentNode.classList.contains('open') ? 'true' : 'false');
183                }, 0);
184            });
185            toggle.addEventListener('keydown', function (event) {
186                var menu = toggle.parentNode.querySelector('.dropdown-menu');
187                if ((event.key === 'ArrowDown' || event.keyCode === 40) && menu) {
188                    event.preventDefault();
189                    toggle.parentNode.classList.add('open');
190                    toggle.setAttribute('aria-expanded', 'true');
191                    var firstLink = menu.querySelector('a');
192                    if (firstLink) {
193                        firstLink.focus();
194                    }
195                }
196                if (event.key === 'Escape' || event.keyCode === 27) {
197                    toggle.parentNode.classList.remove('open');
198                    toggle.setAttribute('aria-expanded', 'false');
199                    toggle.focus();
200                }
201            });
202        });
203
204        document.addEventListener('keydown', function (event) {
205            if (event.key !== 'Escape' && event.keyCode !== 27) {
206                return;
207            }
208            Array.prototype.forEach.call(document.querySelectorAll('#mainNav .dropdown.open, #mainNav .dropdown-submenu.open'), function (item) {
209                item.classList.remove('open');
210                var toggle = item.querySelector('a[aria-expanded]');
211                if (toggle) {
212                    toggle.setAttribute('aria-expanded', 'false');
213                }
214            });
215            if (collapseButton && navigation && navigation.classList.contains('in')) {
216                if (window.jQuery && window.jQuery.fn && window.jQuery.fn.collapse) {
217                    window.jQuery(navigation).collapse('hide');
218                } else {
219                    navigation.classList.remove('in');
220                    collapseButton.setAttribute('aria-expanded', 'false');
221                }
222                collapseButton.focus();
223            }
224        });
225    }
226
227    function improveLinksAndCarousels() {
228        Array.prototype.forEach.call(document.querySelectorAll('a[target="_blank"], a[target="blank"]'), function (link) {
229            var rel = (link.getAttribute('rel') || '').split(/\s+/).filter(Boolean);
230            ['noopener', 'noreferrer'].forEach(function (value) {
231                if (rel.indexOf(value) === -1) {
232                    rel.push(value);
233                }
234            });
235            link.setAttribute('rel', rel.join(' '));
236        });
237
238        Array.prototype.forEach.call(document.querySelectorAll('.owl-carousel'), function (carousel, index) {
239            if (!carousel.getAttribute('aria-label')) {
240                carousel.setAttribute('aria-label', 'Content carousel ' + (index + 1));
241            }
242            carousel.setAttribute('role', 'region');
243            ['focusin', 'mouseenter'].forEach(function (eventName) {
244                carousel.addEventListener(eventName, function () {
245                    if (window.jQuery) {
246                        window.jQuery(carousel).trigger('stop.owl.autoplay');
247                    }
248                });
249            });
250            carousel.addEventListener('mouseleave', function () {
251                if (window.jQuery) {
252                    window.jQuery(carousel).trigger('play.owl.autoplay');
253                }
254            });
255        });
256    }
257
258    function improveForms() {
259        var sequence = 0;
260        var autocomplete = {
261            name: 'name',
262            name_field: 'name',
263            full_name: 'name',
264            email: 'email',
265            email2: 'email',
266            phone: 'tel',
267            whatsapp: 'tel',
268            country: 'country-name',
269            company: 'organization',
270            company_name: 'organization',
271            startup_name: 'organization',
272            linkedin: 'url'
273        };
274
275        Array.prototype.forEach.call(document.querySelectorAll('form input, form select, form textarea'), function (control) {
276            if (control.type === 'hidden') {
277                return;
278            }
279            var name = (control.name || '').toLowerCase().replace(/[^a-z0-9_]/g, '_');
280            if (!control.id) {
281                sequence += 1;
282                control.id = 'fc-form-field-' + sequence;
283            }
284            if (control.required) {
285                control.setAttribute('aria-required', 'true');
286            }
287            if (!control.getAttribute('autocomplete') && autocomplete[name]) {
288                control.setAttribute('autocomplete', autocomplete[name]);
289            }
290            var wrapper = control.closest('.input__wrapper, .form-group, [class*="col-"]');
291            var label = wrapper ? wrapper.querySelector('label:not(.error)') : null;
292            if (label && !label.getAttribute('for') && !label.querySelector('input, select, textarea')) {
293                label.setAttribute('for', control.id);
294            }
295        });
296    }
297
298    function improveFoldableForms() {
299        Array.prototype.forEach.call(document.querySelectorAll('#Btn_2'), function (button) {
300            var panel = document.getElementById('more_2');
301            if (!panel) {
302                return;
303            }
304            button.setAttribute('role', 'button');
305            button.setAttribute('aria-controls', panel.id);
306            button.classList.add('fc-application-toggle');
307
308            var syncState = function () {
309                var expanded = window.getComputedStyle(panel).display !== 'none';
310                button.setAttribute('aria-expanded', expanded ? 'true' : 'false');
311            };
312            syncState();
313            button.addEventListener('click', function () {
314                window.setTimeout(syncState, 0);
315            });
316        });
317    }
318
319    onReady(function () {
320        makeIdsUnique();
321        repairExpanded(document);
322        improveYoutubeThumbnails();
323        improveMedia();
324        improveForms();
325        improveFoldableForms();
326        improveNavigation();
327        improveLinksAndCarousels();
328
329        if ('MutationObserver' in window) {
330            var observer = new MutationObserver(function (mutations) {
331                mutations.forEach(function (mutation) {
332                    if (mutation.type === 'attributes') {
333                        repairExpanded(mutation.target);
334                    } else {
335                        Array.prototype.forEach.call(mutation.addedNodes, function (node) {
336                            repairExpanded(node);
337                            if (node.nodeType === 1) {
338                                if (node.matches && node.matches('iframe')) {
339                                    if (!node.hasAttribute('loading')) {
340                                        node.setAttribute('loading', 'lazy');
341                                    }
342                                    if (!node.getAttribute('title')) {
343                                        node.setAttribute('title', 'Embedded media');
344                                    }
345                                }
346                                Array.prototype.forEach.call(node.querySelectorAll ? node.querySelectorAll('iframe') : [], function (frame) {
347                                    if (!frame.hasAttribute('loading')) {
348                                        frame.setAttribute('loading', 'lazy');
349                                    }
350                                    if (!frame.getAttribute('title')) {
351                                        frame.setAttribute('title', 'Embedded media');
352                                    }
353                                });
354                            }
355                        });
356                    }
357                });
358            });
359            observer.observe(document.body, {
360                subtree: true,
361                childList: true,
362                attributes: true,
363                attributeFilter: ['aria-expanded']
364            });
365        }
366    });
367}());

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.