PageSourceSearch

https://kubernetes.io/js/legacy-script.js

js kubernetes.io collected 2026-09-24 06:13:03 UTC 15,276 bytes, 507 lines download raw bytes

1//modal close button
2(function(){
3    //π.modalCloseButton = function(closingFunction){
4    //	return π.button('pi-modal-close-button', null, null, closingFunction);
5    //};
6})();
7
8// globals
9var body;
10
11//helper functions
12function booleanAttributeValue(element, attribute, defaultValue){
13    // returns true if an attribute is present with no value
14    // e.g. booleanAttributeValue(element, 'data-modal', false);
15    if (element.hasAttribute(attribute)) {
16        var value = element.getAttribute(attribute);
17        if (value === '' || value === 'true') {
18            return true;
19        } else if (value === 'false') {
20            return false;
21        }
22    }
23
24    return defaultValue;
25}
26
27function classOnCondition(element, className, condition) {
28    if (condition)
29        $(element).addClass(className);
30    else
31        $(element).removeClass(className);
32}
33
34function highestZ() {
35    var Z = 1000;
36
37    $("*").each(function(){
38        var thisZ = $(this).css('z-index');
39
40        if (thisZ != "auto" && thisZ > Z) Z = ++thisZ;
41    });
42
43    return Z;
44}
45
46function newDOMElement(tag, className, id){
47    var el = document.createElement(tag);
48
49    if (className) el.className = className;
50    if (id) el.id = id;
51
52    return el;
53}
54
55function px(n){
56    return n + 'px';
57}
58
59var kub = (function () {
60    var HEADER_HEIGHT;
61    var html, header, mainNav, quickstartButton, hero, encyclopedia, footer, headlineWrapper;
62
63    $(document).ready(function () {
64        html = $('html');
65        body = $('body');
66        header = $('header');
67        mainNav = $('#mainNav');
68        quickstartButton = $('#quickstartButton');
69        hero = $('#hero');
70        encyclopedia = $('#encyclopedia');
71        footer = $('footer');
72        headlineWrapper = $('#headlineWrapper');
73        HEADER_HEIGHT = header.outerHeight();
74
75        resetTheView();
76
77        window.addEventListener('resize', resetTheView);
78        window.addEventListener('scroll', resetTheView);
79        window.addEventListener('keydown', handleKeystrokes);
80
81        document.onunload = function(){
82            window.removeEventListener('resize', resetTheView);
83            window.removeEventListener('scroll', resetTheView);
84            window.removeEventListener('keydown', handleKeystrokes);
85        };
86
87        setInterval(setFooterType, 10);
88    });
89
90    function setFooterType() {
91        var windowHeight = window.innerHeight;
92        var bodyHeight;
93
94        switch (html[0].id) {
95            case 'docs': {
96                bodyHeight = hero.outerHeight() + encyclopedia.outerHeight();
97                break;
98            }
99
100            case 'home':
101            // case 'caseStudies':
102                bodyHeight = windowHeight;
103                break;
104            case 'blog':
105                bodyHeight = windowHeight;
106            case 'caseStudies':
107            case 'partners':
108                bodyHeight = windowHeight * 2;
109                break;
110
111            default: {
112                bodyHeight = hero.outerHeight() + $('#mainContent').outerHeight();
113            }
114        }
115
116        var footerHeight = footer.outerHeight();
117        classOnCondition(body, 'fixed', windowHeight - footerHeight > bodyHeight);
118    }
119
120    function resetTheView() {
121        if (html.hasClass('open-nav')) {
122            toggleMenu();
123        } else {
124            HEADER_HEIGHT = header.outerHeight();
125        }
126
127        if (html.hasClass('open-toc')) {
128            toggleToc();
129        }
130
131        if (html[0].id == 'home') {
132            setHomeHeaderStyles();
133        }
134    }
135
136    function setHomeHeaderStyles() {
137        if (!quickstartButton[0]) {
138            return;
139        }
140        var Y = window.pageYOffset;
141        var quickstartBottom = quickstartButton[0].getBoundingClientRect().bottom;
142
143        classOnCondition(html[0], 'y-enough', Y > quickstartBottom);
144    }
145
146    function toggleMenu() {
147        // Clickable for Bootstrap "lg" and narrower
148        if (window.innerWidth < 992) {
149            pushmenu.show('primary');
150        }
151
152        else {
153            var newHeight = HEADER_HEIGHT;
154
155            if (!html.hasClass('open-nav')) {
156                newHeight = mainNav.outerHeight();
157            }
158
159            header.css({height: px(newHeight)});
160            html.toggleClass('open-nav');
161        }
162    }
163
164    function handleKeystrokes(e) {
165        switch (e.which) {
166            case 27: {
167                if (html.hasClass('open-nav')) {
168                    toggleMenu();
169                }
170                break;
171            }
172        }
173    }
174
175    function showVideo() {
176        $('body').css({overflow: 'hidden'});
177
178        var videoPlayer = $("#videoPlayer");
179        var videoIframe = videoPlayer.find("iframe")[0];
180        videoIframe.src = videoIframe.getAttribute("data-url");
181        videoPlayer.css({zIndex: highestZ()});
182        videoPlayer.fadeIn(300);
183        videoPlayer.click(function(){
184            $('body').css({overflow: 'auto'});
185
186            videoPlayer.fadeOut(300, function(){
187                videoIframe.src = '';
188            });
189        });
190    }
191
192    function tocWasClicked(e) {
193        var target = $(e.target);
194        var docsToc = $("#docsToc");
195        return (target[0] === docsToc[0] || target.parents("#docsToc").length > 0);
196    }
197
198    function listenForTocClick(e) {
199        if (!tocWasClicked(e)) toggleToc();
200    }
201
202    function toggleToc() {
203        html.toggleClass('open-toc');
204
205        setTimeout(function () {
206            if (html.hasClass('open-toc')) {
207                window.addEventListener('click', listenForTocClick);
208            } else {
209                window.removeEventListener('click', listenForTocClick);
210            }
211        }, 100);
212    }
213
214    return {
215        toggleToc: toggleToc,
216        toggleMenu: toggleMenu,
217        showVideo: showVideo
218    };
219})();
220
221
222// accordion
223(function(){
224    var yah = true;
225    var moving = false;
226    var CSS_BROWSER_HACK_DELAY = 25;
227
228    $(document).ready(function(){
229        // Safari chokes on the animation here, so...
230        if (navigator.userAgent.indexOf('Chrome') == -1 && navigator.userAgent.indexOf('Safari') != -1){
231            var hackStyle = newDOMElement('style');
232            hackStyle.innerHTML = '.pi-accordion .wrapper{transition: none}';
233            body.append(hackStyle);
234        }
235        // Gross.
236
237        $('.pi-accordion').each(function () {
238            var accordion = this;
239            var content = this.innerHTML;
240            var container = newDOMElement('div', 'container');
241            container.innerHTML = content;
242            $(accordion).empty();
243            accordion.appendChild(container);
244            CollapseBox($(container));
245        });
246
247        setYAH();
248
249        setTimeout(function () {
250            yah = false;
251        }, 500);
252    });
253
254    function CollapseBox(container){
255        container.children('.item').each(function(){
256            // build the TOC DOM
257            // the animated open/close is enabled by having each item's content exist in the flow, at its natural height,
258            // enclosed in a wrapper with height = 0 when closed, and height = contentHeight when open.
259            var item = this;
260
261            // only add content wrappers to containers, not to links
262            var isContainer = item.tagName === 'DIV';
263
264            var titleText = item.getAttribute('data-title');
265            var title = newDOMElement('div', 'title');
266            title.innerHTML = titleText;
267
268            var wrapper, content;
269
270            if (isContainer) {
271                wrapper = newDOMElement('div', 'wrapper');
272                content = newDOMElement('div', 'content');
273                content.innerHTML = item.innerHTML;
274                wrapper.appendChild(content);
275            }
276
277            item.innerHTML = '';
278            item.appendChild(title);
279
280            if (wrapper) {
281                item.appendChild(wrapper);
282                $(wrapper).css({height: 0});
283            }
284
285
286            $(title).click(function(){
287                if (!yah) {
288                    if (moving) return;
289                    moving = true;
290                }
291
292                if (container[0].getAttribute('data-single')) {
293                    var openSiblings = item.siblings().filter(function(sib){return sib.hasClass('on');});
294                    openSiblings.forEach(function(sibling){
295                        toggleItem(sibling);
296                    });
297                }
298
299                setTimeout(function(){
300                    if (!isContainer) {
301                        moving = false;
302                        return;
303                    }
304                    toggleItem(item);
305                }, CSS_BROWSER_HACK_DELAY);
306            });
307
308            function toggleItem(thisItem){
309                var thisWrapper = $(thisItem).find('.wrapper').eq(0);
310
311                if (!thisWrapper) return;
312
313                var contentHeight = thisWrapper.find('.content').eq(0).innerHeight() + 'px';
314
315                if ($(thisItem).hasClass('on')) {
316                    thisWrapper.css({height: contentHeight});
317                    $(thisItem).removeClass('on');
318
319                    setTimeout(function(){
320                        thisWrapper.css({height: 0});
321                        moving = false;
322                    }, CSS_BROWSER_HACK_DELAY);
323                } else {
324                    $(item).addClass('on');
325                    thisWrapper.css({height: contentHeight});
326
327                    var duration = parseFloat(getComputedStyle(thisWrapper[0]).transitionDuration) * 1000;
328
329                    setTimeout(function(){
330                        thisWrapper.css({height: ''});
331                        moving = false;
332                    }, duration);
333                }
334            }
335
336            if (content) {
337                var innerContainers = $(content).children('.container');
338                if (innerContainers.length > 0) {
339                    innerContainers.each(function(){
340                        CollapseBox($(this));
341                    });
342                }
343            }
344        });
345    }
346
347    function setYAH() {
348        var pathname = location.href.split('#')[0]; // on page load, make sure the page is YAH even if there's a hash
349        var currentLinks = [];
350
351        $('.pi-accordion a').each(function () {
352            if (pathname === this.href) currentLinks.push(this);
353        });
354
355        currentLinks.forEach(function (yahLink) {
356            $(yahLink).parents('.item').each(function(){
357                $(this).addClass('on');
358                $(this).find('.wrapper').eq(0).css({height: 'auto'});
359                $(this).find('.content').eq(0).css({opacity: 1});
360            });
361
362            $(yahLink).addClass('yah');
363            yahLink.onclick = function(e){e.preventDefault();};
364        });
365    }
366})();
367
368
369var pushmenu = (function(){
370    var allPushMenus = {};
371
372    $(document).ready(function(){
373        $('[data-auto-burger]').each(function(){
374            var container = this;
375            var id = container.getAttribute('data-auto-burger');
376
377            var autoBurger = document.getElementById(id) || newDOMElement('div', 'pi-pushmenu', id);
378            var ul = autoBurger.querySelector('ul') || newDOMElement('ul');
379
380            $(container).find('a[href], button').each(function () {
381                if (!booleanAttributeValue(this, 'data-auto-burger-exclude', false)) {
382                    var clone = this.cloneNode(true);
383                    clone.id = '';
384
385                    if (clone.tagName == "BUTTON") {
386                        var aTag = newDOMElement('a');
387                        aTag.href = '';
388                        aTag.innerHTML = clone.innerHTML;
389                        aTag.onclick = clone.onclick;
390                        // Preserve data-* attributes (e.g. data-bs-theme-value) so cloned controls can be identified.
391                        for (var i = 0; i < clone.attributes.length; i++) {
392                            var attr = clone.attributes[i];
393                            if (attr.name.indexOf('data-') === 0) {
394                                aTag.setAttribute(attr.name, attr.value);
395                            }
396                        }
397                        clone = aTag;
398                    }
399                    var li = newDOMElement('li');
400                    li.appendChild(clone);
401                    ul.appendChild(li);
402                }
403            });
404
405            autoBurger.appendChild(ul);
406            body.append(autoBurger);
407        });
408
409        $(".pi-pushmenu").each(function(){
410            allPushMenus[this.id] = PushMenu(this);
411        });
412
413        // Cloned theme buttons lose Docsy's addEventListener bindings; forward clicks to the original.
414        // Capture-phase listener runs before sled.onclick's stopPropagation kills the bubble.
415        document.addEventListener('click', function (e) {
416            var target = e.target.closest('.pi-pushmenu [data-bs-theme-value]');
417            if (!target) return;
418            e.preventDefault();
419            var theme = target.getAttribute('data-bs-theme-value');
420            var original = document.querySelector('#bd-theme ~ ul [data-bs-theme-value="' + theme + '"]');
421            if (original) {
422                original.click();
423            }
424            var pushmenuEl = target.closest('.pi-pushmenu');
425            if (pushmenuEl) {
426                pushmenuEl.classList.remove('on');
427                setTimeout(function () { pushmenuEl.style.display = 'none'; }, 300);
428            }
429        }, true);
430    });
431
432    function show(objId) {
433        allPushMenus[objId].expose();
434    }
435
436    function PushMenu(el) {
437        var html = document.querySelector('html');
438
439        var overlay = newDOMElement('div', 'overlay');
440        var content = newDOMElement('div', 'content');
441        content.appendChild(el.querySelector('*'));
442
443        var side = el.getAttribute("data-side") || "right";
444
445        var sled = newDOMElement('div', 'sled');
446        $(sled).css(side, 0);
447
448        sled.appendChild(content);
449
450        var closeButton = newDOMElement('button', 'btn fa fa-times');
451        closeButton.onclick = closeMe;
452
453        sled.appendChild(closeButton);
454
455        overlay.appendChild(sled);
456        el.innerHTML = '';
457        el.appendChild(overlay);
458
459        sled.onclick = function(e){
460            e.stopPropagation();
461        };
462
463        overlay.onclick = closeMe;
464
465        window.addEventListener('resize', closeMe);
466
467        function closeMe(e) {
468            if (e.target == sled) return;
469
470            $(el).removeClass('on');
471            setTimeout(function(){
472                $(el).css({display: 'none'});
473            }, 300);
474        }
475
476        function exposeMe(){
477            $(el).css({
478                display: 'block',
479                zIndex: highestZ()
480            });
481
482            setTimeout(function(){
483                $(el).addClass('on');
484            }, 10);
485        }
486
487        return {
488            expose: exposeMe
489        };
490    }
491
492    return {
493        show: show
494    };
495})();
496
497$(function() {
498    // If vendor strip doesn't exist add className
499    if ( !$('#vendorStrip').length > 0 ) {
500        $('.header-hero').addClass('bot-bar');
501    }
502
503    // If is not homepage add class to hero section
504    if (!$('.td-home').length > 0 ) {
505        $('.header-hero').addClass('no-sub');
506    }
507});

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.