| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
$.fn.clicktoggle = function(a, b) { |
| 6 |
return this.each(function() { |
| 7 |
var clicked = false; |
| 8 |
$(this).click(function() { |
| 9 |
if (clicked) { |
| 10 |
clicked = false; |
| 11 |
return b.apply(this, arguments); |
| 12 |
} |
| 13 |
clicked = true; |
| 14 |
return a.apply(this, arguments); |
| 15 |
}); |
| 16 |
}); |
| 17 |
}; |
| 18 |
|
| 19 |
$(document).ready(function() { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
var div = $('.highlight-default .highlight,' + |
| 24 |
'.highlight-python .highlight' + |
| 25 |
'.highlight-python3 .highlight') |
| 26 |
var pre = div.find('pre'); |
| 27 |
|
| 28 |
|
| 29 |
pre.parent().parent().css('position', 'relative'); |
| 30 |
var hide_text = 'Hide the prompts and output'; |
| 31 |
var show_text = 'Show the prompts and output'; |
| 32 |
var border_width = pre.css('border-top-width'); |
| 33 |
var border_style = pre.css('border-top-style'); |
| 34 |
var border_color = pre.css('border-top-color'); |
| 35 |
var button_styles = { |
| 36 |
'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0', |
| 37 |
'border-color': border_color, 'border-style': border_style, |
| 38 |
'border-width': border_width, 'color': border_color, 'text-size': '75%', |
| 39 |
'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em', |
| 40 |
'border-radius': '0 3px 0 0' |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
div.each(function(index) { |
| 45 |
var jthis = $(this); |
| 46 |
if (jthis.find('.gp').length > 0) { |
| 47 |
var button = $('<span class="copybutton">>>></span>'); |
| 48 |
button.css(button_styles); |
| 49 |
button.attr('title', hide_text); |
| 50 |
jthis.prepend(button); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
jthis.find('pre:has(.gt)').contents().filter(function() { |
| 55 |
return ((this.nodeType == 3) && (this.data.trim().length > 0)); |
| 56 |
}).wrap('<span>'); |
| 57 |
}); |
| 58 |
|
| 59 |
|
| 60 |
$('.copybutton').clicktoggle( |
| 61 |
function() { |
| 62 |
var button = $(this); |
| 63 |
button.parent().find('.go, .gp, .gt').hide(); |
| 64 |
button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden'); |
| 65 |
button.css('text-decoration', 'line-through'); |
| 66 |
button.attr('title', show_text); |
| 67 |
}, |
| 68 |
function() { |
| 69 |
var button = $(this); |
| 70 |
button.parent().find('.go, .gp, .gt').show(); |
| 71 |
button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible'); |
| 72 |
button.css('text-decoration', 'none'); |
| 73 |
button.attr('title', hide_text); |
| 74 |
}); |
| 75 |
}); |
| 76 |
|