$(document).ready(function() { /* Add a [>>>] button on the top-right corner of code samples to hide * the >>> and ... prompts and the output and thus make the code * copyable. */ var div = $('.highlight-python .highlight,' + '.highlight-python3 .highlight') var pre = div.find('pre'); // get the styles from the current theme pre.parent().parent().css('position', 'relative'); var hide_text = 'Hide the prompts and output'; var show_text = 'Show the prompts and output'; var border_width = pre.css('border-top-width'); var border_style = pre.css('border-top-style'); var border_color = pre.css('border-top-color'); var button_styles = { 'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0', 'border-color': border_color, 'border-style': border_style, 'border-width': border_width, 'color': border_color, 'text-size': '75%', 'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em' } // create and add the button to all the code blocks that contain >>> div.each(function(index) { var jthis = $(this); if (jthis.find('.gp').length > 0) { var button = $('<span class="copybutton">>>></span>'); button.css(button_styles) button.attr('title', hide_text); jthis.prepend(button); } // tracebacks (.gt) contain bare text elements that need to be // wrapped in a span to work with .nextUntil() (see later) jthis.find('pre:has(.gt)').contents().filter(function() { return ((this.nodeType == 3) && (this.data.trim().length > 0)); }).wrap('<span>'); }); // define the behavior of the button when it's clicked $('.copybutton').toggle( function() { var button = $(this); button.parent().find('.go, .gp, .gt').hide(); button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden'); button.css('text-decoration', 'line-through'); button.attr('title', show_text); }, function() { var button = $(this); button.parent().find('.go, .gp, .gt').show(); button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible'); button.css('text-decoration', 'none'); button.attr('title', hide_text); }); });
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
ajax-loader.gif | File | 673 B | 0644 |
|
basic.css | File | 6.77 KB | 0644 |
|
comment-bright.png | File | 3.42 KB | 0644 |
|
comment-close.png | File | 3.49 KB | 0644 |
|
comment.png | File | 3.36 KB | 0644 |
|
copybutton.js | File | 2.4 KB | 0644 |
|
default.css | File | 4.03 KB | 0644 |
|
doctools.js | File | 6.68 KB | 0644 |
|
down-pressed.png | File | 368 B | 0644 |
|
down.png | File | 363 B | 0644 |
|
file.png | File | 392 B | 0644 |
|
jquery.js | File | 70.48 KB | 0644 |
|
minus.png | File | 199 B | 0644 |
|
opensearch.xml | File | 569 B | 0644 |
|
plus.png | File | 199 B | 0644 |
|
py.png | File | 695 B | 0644 |
|
pygments.css | File | 3.84 KB | 0644 |
|
searchtools.js | File | 15.67 KB | 0644 |
|
sidebar.js | File | 4.63 KB | 0644 |
|
underscore.js | File | 8.37 KB | 0644 |
|
up-pressed.png | File | 372 B | 0644 |
|
up.png | File | 363 B | 0644 |
|
version_switch.js | File | 1.76 KB | 0644 |
|
websupport.js | File | 24.65 KB | 0644 |
|