PageSourceSearch

https://opencensus.io/theme-flex/script.js

js opencensus.io collected 2026-10-01 10:28:30 UTC 9,628 bytes, 277 lines download raw bytes

1jQuery(document).ready(function() {
2    jQuery('.category-icon').on('click', function() {
3        $( this ).toggleClass("fa-angle-down fa-angle-right") ;
4        $( this ).parent().parent().children('ul').toggle() ;
5        return false;
6    });
7
8
9
10    // Images
11    // Execute actions on images generated from Markdown pages
12    var images = $("article .lightbox img").not(".inline");
13    // Wrap image inside a featherlight (to get a full size view in a popup)
14    images.wrap(function () {
15        var image = $(this);
16        if (!image.parent("a").length) {
17            return "<a href='" + image[0].src + "' data-featherlight='image'></a>";
18        }
19    });
20    // Change styles, depending on parameters set to the image
21    images.each(function (index) {
22        var image = $(this);
23        var o = getUrlParameter(image[0].src);
24        if (typeof o !== "undefined") {
25            var h = o["height"];
26            var w = o["width"];
27            var c = o["classes"];
28            image.css({
29                width: function () {
30                    if (typeof w !== "undefined") {
31                        return w;
32                    }
33                },
34                height: function () {
35                    if (typeof h !== "undefined") {
36                        return h;
37                    }
38                }
39            });
40            if (typeof c !== "undefined") {
41                var classes = c.split(',');
42                $.each(classes, function(i) {
43                    image.addClass(classes[i]);
44                });
45            }
46        }
47    });
48
49
50	// Clipboard
51	// Add link button for every
52    var text, clip = new Clipboard('.anchor');
53    $("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function (index, html) {
54        var element = $(this);
55        var url = document.location.origin + document.location.pathname;
56        var link = url + "#" + element[0].id;
57        return " <span class='anchor' data-clipboard-text='" + link + "'>" +
58            "<i class='fa fa-link fa-lg'></i>" +
59            "</span>";
60    });
61
62    $(".anchor").on('mouseleave', function (e) {
63        $(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
64    });
65
66    clip.on('success', function (e) {
67        e.clearSelection();
68        $(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
69    });
70
71
72    var ajax;
73    jQuery('[data-search-input]').on('input', function() {
74        var input = jQuery(this),
75            value = input.val(),
76            items = jQuery('[data-nav-id]');
77        items.removeClass('search-match');
78        if (!value.length) {
79            $('ul.menu').removeClass('searched');
80            items.css('display', 'block');
81            sessionStorage.removeItem('search-value');
82            $("article").unhighlight({ element: 'mark' })
83            return;
84        }
85
86        sessionStorage.setItem('search-value', value);
87        $("article").unhighlight({ element: 'mark' }).highlight(value, { element: 'mark' });
88
89        if (ajax && ajax.abort) ajax.abort();
90
91        jQuery('[data-search-clear]').on('click', function() {
92            jQuery('[data-search-input]').val('').trigger('input');
93            sessionStorage.removeItem('search-input');
94            $("article").unhighlight({ element: 'mark' })
95        });
96    });
97
98    $.expr[":"].contains = $.expr.createPseudo(function(arg) {
99        return function( elem ) {
100            return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
101        };
102    });
103
104    if (sessionStorage.getItem('search-value')) {
105        var searchValue = sessionStorage.getItem('search-value')
106        sessionStorage.removeItem('search-value');
107        var searchedElem = $('article').find(':contains(' + searchValue + ')').get(0);
108        searchedElem && searchedElem.scrollIntoView();
109        $("article").highlight(searchValue, { element: 'mark' });
110    }
111
112    // clipboard
113    var clipInit = false;
114    $('pre code').each(function() {
115        var code = $(this),
116            text = code.text();
117
118        if (text.length > 5) {
119            if (!clipInit) {
120                var text, clip = new Clipboard('.copy-to-clipboard', {
121                    text: function(trigger) {
122                        text = $(trigger).next('code').text();
123                        return text.replace(/^\$\s/gm, '');
124                    }
125                });
126
127                var inPre;
128                clip.on('success', function(e) {
129                    e.clearSelection();
130                    inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
131                    $(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
132                });
133
134                clip.on('error', function(e) {
135                    inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
136                    $(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
137                    $(document).one('copy', function(){
138                        $(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
139                    });
140                });
141
142                clipInit = true;
143            }
144
145            code.before('<span class="copy-to-clipboard" title="Copy to clipboard"><span class="fa fa-clipboard" aria-hidden="true"></span></span>');
146            $('.copy-to-clipboard').on('mouseleave', function() {
147                $(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
148            });
149        }
150    });
151
152    // allow keyboard control for prev/next links
153    jQuery(function() {
154        jQuery('.nav-prev').click(function(){
155            location.href = jQuery(this).attr('href');
156        });
157        jQuery('.nav-next').click(function() {
158            location.href = jQuery(this).attr('href');
159        });
160    });
161    jQuery(document).keydown(function(e) {
162      // prev links - left arrow key
163      if(e.which == '37') {
164        jQuery('.nav.nav-prev').click();
165      }
166      // next links - right arrow key
167      if(e.which == '39') {
168        jQuery('.nav.nav-next').click();
169      }
170    });
171
172    $('article a:not(:has(img)):not(.btn)').addClass('highlight');
173});
174
175$(function() {
176    $('a[rel="lightbox"]').featherlight({
177        root: 'article'
178    });
179});
180jQuery.extend({
181    highlight: function(node, re, nodeName, className) {
182        if (node.nodeType === 3) {
183            var match = node.data.match(re);
184            if (match && !$(node.parentNode).hasClass("mermaid")) {
185                var highlight = document.createElement(nodeName || 'span');
186                highlight.className = className || 'highlight';
187                var wordNode = node.splitText(match.index);
188                wordNode.splitText(match[0].length);
189                var wordClone = wordNode.cloneNode(true);
190                highlight.appendChild(wordClone);
191                wordNode.parentNode.replaceChild(highlight, wordNode);
192                return 1; //skip added node in parent
193            }
194        } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
195            !/(script|style)/i.test(node.tagName) && // ignore script and style nodes
196            !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
197            for (var i = 0; i < node.childNodes.length; i++) {
198                i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
199            }
200        }
201        return 0;
202    }
203});
204
205jQuery.fn.unhighlight = function(options) {
206    var settings = {
207        className: 'highlight',
208        element: 'span'
209    };
210    jQuery.extend(settings, options);
211
212    return this.find(settings.element + "." + settings.className).each(function() {
213        var parent = this.parentNode;
214        parent.replaceChild(this.firstChild, this);
215        parent.normalize();
216    }).end();
217};
218
219jQuery.fn.highlight = function(words, options) {
220    var settings = {
221        className: 'highlight',
222        element: 'span',
223        caseSensitive: false,
224        wordsOnly: false
225    };
226    jQuery.extend(settings, options);
227
228    if (!words) { return; }
229
230    if (words.constructor === String) {
231        words = [words];
232    }
233    words = jQuery.grep(words, function(word, i) {
234        return word != '';
235    });
236    words = jQuery.map(words, function(word, i) {
237        return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
238    });
239    if (words.length == 0) { return this; }
240    ;
241
242    var flag = settings.caseSensitive ? "" : "i";
243    var pattern = "(" + words.join("|") + ")";
244    if (settings.wordsOnly) {
245        pattern = "\\b" + pattern + "\\b";
246    }
247    var re = new RegExp(pattern, flag);
248
249    return this.each(function() {
250        jQuery.highlight(this, re, settings.element, settings.className);
251    });
252};
253
254
255// Get Parameters from some url
256var getUrlParameter = function getUrlParameter(sPageURL) {
257    var url = sPageURL.split('?');
258    var obj = {};
259    if (url.length == 2) {
260        var sURLVariables = url[1].split('&'),
261            sParameterName,
262            i;
263        for (i = 0; i < sURLVariables.length; i++) {
264            sParameterName = sURLVariables[i].split('=');
265            obj[sParameterName[0]] = sParameterName[1];
266        }
267        return obj;
268    } else {
269        return undefined;
270    }
271};
272
273// Burger icon click toggle header menu on small devices
274$('.burger').on('click', function(e){
275    $('#shortcuts').toggleClass("responsive") ;
276    e.preventDefault();
277});

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.