[ADD] doc: new documentation, with training tutorials, and new scaffolding
[odoo/odoo.git] / doc / _themes / odoodoc / static / app.js
1 $(function () {
2     var $body = $(document.body);
3     $body.scrollspy({ target: '.sphinxsidebarwrapper' });
4     $(window).on('load', function () {
5         $body.scrollspy('refresh');
6     });
7
8     // Sidenav affixing
9     setTimeout(function () {
10         var $sideBar = $('.sphinxsidebarwrapper');
11
12         $sideBar.affix({
13             offset: {
14                 top: function () {
15                     var offsetTop = $sideBar.offset().top;
16                     var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10);
17                     var navOuterHeight = $('.docs-nav').height();
18
19                     return (this.top = offsetTop - navOuterHeight - sideBarMargin);
20                 },
21                 bottom: function () {
22                     return (this.bottom = $('div.footer').outerHeight(true));
23                 }
24             }
25         });
26     }, 100);
27
28     // Config ZeroClipboard
29     ZeroClipboard.config({
30         moviePath: '_static/ZeroClipboard.swf',
31         hoverClass: 'btn-clipboard-hover'
32     });
33
34     // Insert copy to clipboard button before .highlight or .example
35     $('.highlight-html, .highlight-scss').each(function () {
36         var highlight = $(this);
37         var previous = highlight.prev();
38         var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>';
39
40         if (previous.hasClass('example')) {
41             previous.before(btnHtml.replace(/btn-clipboard/, 'btn-clipboard with-example'));
42         } else {
43             highlight.before(btnHtml);
44         }
45     });
46     var zeroClipboard = new ZeroClipboard($('.btn-clipboard'));
47     var htmlBridge = $('#global-zeroclipboard-html-bridge');
48
49     // Handlers for ZeroClipboard
50     zeroClipboard.on('load', function () {
51         htmlBridge
52             .data('placement', 'top')
53             .attr('title', 'Copy to clipboard')
54             .tooltip();
55     });
56
57     // Copy to clipboard
58     zeroClipboard.on('dataRequested', function (client) {
59         var highlight = $(this).parent().nextAll('.highlight').first();
60         client.setText(highlight.text());
61     });
62
63     // Notify copy success and reset tooltip title
64     zeroClipboard.on('complete', function () {
65         htmlBridge
66             .attr('title', 'Copied!')
67             .tooltip('fixTitle')
68             .tooltip('show')
69             .attr('title', 'Copy to clipboard')
70             .tooltip('fixTitle');
71     });
72
73     // Notify copy failure
74     zeroClipboard.on('noflash wrongflash', function () {
75         htmlBridge.attr('title', 'Flash required')
76             .tooltip('fixTitle')
77             .tooltip('show');
78     });
79 });