0001
0002
0003
0004 $(document).ready(function() {
0005
0006
0007
0008 var div = $('.highlight-python .highlight,' +
0009 '.highlight-default .highlight,' +
0010 '.highlight-python3 .highlight')
0011 var pre = div.find('pre');
0012
0013
0014 pre.parent().parent().css('position', 'relative');
0015 var hide_text = 'Hide the prompts and output';
0016 var show_text = 'Show the prompts and output';
0017 var border_width = pre.css('border-top-width');
0018 var border_style = pre.css('border-top-style');
0019 var border_color = pre.css('border-top-color');
0020 var button_styles = {
0021 'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0',
0022 'border-color': border_color, 'border-style': border_style,
0023 'border-width': border_width, 'color': border_color, 'text-size': '75%',
0024 'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em',
0025 'border-radius': '0 3px 0 0'
0026 }
0027
0028
0029 div.each(function(index) {
0030 var jthis = $(this);
0031 if (jthis.find('.gp').length > 0) {
0032 var button = $('<span class="copybutton">>>></span>');
0033 button.css(button_styles)
0034 button.attr('title', hide_text);
0035 button.data('hidden', 'false');
0036 jthis.prepend(button);
0037 }
0038
0039
0040 jthis.find('pre:has(.gt)').contents().filter(function() {
0041 return ((this.nodeType == 3) && (this.data.trim().length > 0));
0042 }).wrap('<span>');
0043 });
0044
0045
0046 $('.copybutton').click(function(e){
0047 e.preventDefault();
0048 var button = $(this);
0049 if (button.data('hidden') === 'false') {
0050
0051 button.parent().find('.go, .gp, .gt').hide();
0052 button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
0053 button.css('text-decoration', 'line-through');
0054 button.attr('title', show_text);
0055 button.data('hidden', 'true');
0056 } else {
0057
0058 button.parent().find('.go, .gp, .gt').show();
0059 button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
0060 button.css('text-decoration', 'none');
0061 button.attr('title', hide_text);
0062 button.data('hidden', 'false');
0063 }
0064 });
0065 });
0066