OSDN Git Service

タグを打ち忘れていたついでに、html版ドキュメントを追加しました。
[ring-lang-081/ring.git] / docs / ja-jp / build / html / _static / copybutton.js
1 $(document).ready(function() {
2     /* Add a [>>>] button on the top-right corner of code samples to hide
3      * the >>> and ... prompts and the output and thus make the code
4      * copyable. */
5     var div = $('.highlight-python .highlight,' +
6                 '.highlight-python3 .highlight,' +
7                 '.highlight-default .highlight')
8     var pre = div.find('pre');
9
10     // get the styles from the current theme
11     pre.parent().parent().css('position', 'relative');
12     var hide_text = 'Hide the prompts and output';
13     var show_text = 'Show the prompts and output';
14     var border_width = pre.css('border-top-width');
15     var border_style = pre.css('border-top-style');
16     var border_color = pre.css('border-top-color');
17     var button_styles = {
18         'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0',
19         'border-color': border_color, 'border-style': border_style,
20         'border-width': border_width, 'color': border_color, 'text-size': '75%',
21         'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em',
22         'border-radius': '0 3px 0 0'
23     }
24
25     // create and add the button to all the code blocks that contain >>>
26     div.each(function(index) {
27         var jthis = $(this);
28         if (jthis.find('.gp').length > 0) {
29             var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
30             button.css(button_styles)
31             button.attr('title', hide_text);
32             button.data('hidden', 'false');
33             jthis.prepend(button);
34         }
35         // tracebacks (.gt) contain bare text elements that need to be
36         // wrapped in a span to work with .nextUntil() (see later)
37         jthis.find('pre:has(.gt)').contents().filter(function() {
38             return ((this.nodeType == 3) && (this.data.trim().length > 0));
39         }).wrap('<span>');
40     });
41
42     // define the behavior of the button when it's clicked
43     $('.copybutton').click(function(e){
44         e.preventDefault();
45         var button = $(this);
46         if (button.data('hidden') === 'false') {
47             // hide the code output
48             button.parent().find('.go, .gp, .gt').hide();
49             button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
50             button.css('text-decoration', 'line-through');
51             button.attr('title', show_text);
52             button.data('hidden', 'true');
53         } else {
54             // show the code output
55             button.parent().find('.go, .gp, .gt').show();
56             button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
57             button.css('text-decoration', 'none');
58             button.attr('title', hide_text);
59             button.data('hidden', 'false');
60         }
61     });
62 });
63