xref: /OK3568_Linux_fs/buildroot/docs/website/js/buildroot.js (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1function load_activity(feedurl, divid) {
2    let container = document.getElementById(divid);
3    $.ajax({
4      url: "https://cors-anywhere.herokuapp.com/" + feedurl
5    })
6    .done(function(data){
7        let x2js = new X2JS();
8        let result = x2js.xml_str2json(data.documentElement.outerHTML);
9        let loaded = 0;
10        let nb_display = 8;
11        if (result==null) return;
12        for (let i = 0; i < result.feed.entry.length; i++) {
13            let entry = result.feed.entry[i];
14            if (entry.title.indexOf("git commit") !== -1)
15                continue;
16            loaded += 1;
17            if (loaded > nb_display)
18                break;
19            let div = document.createElement("p");
20            let link = document.createElement("a");
21            let d = new Date(entry.published);
22            let data = '[' + d.toLocaleDateString() + '] ' + entry.title;
23            let text = document.createTextNode(data);
24            link.appendChild(text);
25            link.title = entry.title;
26            link.href = entry.link._href;
27            div.appendChild(link);
28            container.appendChild(div);
29        }
30        let empty = nb_display - loaded;
31        for (let i = 0; i < empty; i++) {
32            container.appendChild(document.createElement("p"));
33        }
34    });
35}
36
37function google_analytics() {
38    let _gaq = _gaq || [];
39    _gaq.push(['_setAccount', 'UA-21761074-1']);
40    _gaq.push(['_setDomainName', 'none']);
41    _gaq.push(['_setAllowLinker', true]);
42    _gaq.push(['_trackPageview']);
43
44    let ga = document.createElement('script');
45    ga.type = 'text/javascript';
46    ga.async = true;
47    ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
48    let s = document.getElementsByTagName('script')[0];
49    s.parentNode.insertBefore(ga, s);
50}
51
52function showTooltip(elem, msg) {
53    elem.setAttribute('class', 'btn tooltipped tooltipped-s');
54    elem.setAttribute('aria-label', msg);
55}
56
57let clipboard = new Clipboard('.btn');
58
59$(function () {
60  $('[data-toggle="tooltip"]').tooltip()
61});
62
63clipboard.on('success', function(e) {
64    e.clearSelection();
65    $(e.trigger).tooltip('show');
66});
67
68$(function() {
69  $('a[href*=\\#]:not([href=\\#])').click(function() {
70    if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
71        let target = $(this.hash);
72      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
73      if (target.length) {
74        $('html,body').animate({
75          scrollTop: target.offset().top
76        }, 1000);
77        return false;
78      }
79    }
80  });
81});
82
83jQuery(document).ready(function($) {
84    let url = window.location.href;
85    // Get the basename of the URL
86    url = url.split(/[\\/]/).pop();
87    $('.nav a[href="/' + url + '"]').parent().addClass('active');
88
89    load_activity("http://buildroot-busybox.2317881.n4.nabble.com/Buildroot-busybox-ft2.xml", "mailing-list-activity");
90    load_activity("http://git.buildroot.org/buildroot/atom/?h=master", "commit-activity");
91
92    $('#slides').html('<iframe src="https://docs.google.com/gview?url=http://bootlin.com/doc/training/buildroot/buildroot-slides.pdf&embedded=true" style="position:absolute; width:100%; height:100%; top:0; left:0;" frameborder="0"></iframe>')
93});
94