Skip to content

Commit 42cf1a8

Browse files
committed
manipulate existing elements rather than cloning
1 parent 16e20c6 commit 42cf1a8

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

source/javascripts/codebuttons.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,20 @@ $(function() {
4343

4444
$(".expandcode").click(function() {
4545
var codeId = $(this).attr("id").replace('expand_','');
46-
var codeblock = $('#code_' + codeId).clone();
46+
var codeblock = $('#wrapper_' + codeId + " figure.code")
4747
codeblock.addClass('expanded');
4848

49-
codeblock.appendTo(document.body);
50-
51-
var overlay = $('<div id="overlay"> </div>');
49+
var overlay = $('<div id="overlay"></div>');
5250
overlay.appendTo(document.body);
5351

5452
//prevent the body from scrolling
5553
$(document.body).css("overflow", "hidden");
5654

5755
innerblock = codeblock.find('.highlight');
56+
innerblock.css("overflow", "scroll");
5857
innerblock.css("height", $(window).height() - 100 + "px");
5958
innerblock.css("width", $(window).width() - 80 + "px");
60-
61-
codeblock.css("width", $(window).width() - 80 + "px");
62-
63-
innerblock.css("overflow", "scroll");
64-
59+
6560
//move all of this into a css class and toggle it
6661
//append a button that closes the window
6762
button = $('<a class="close-btn btn btn-large btn-danger"><i class="icon-remove"></i> Close</a>');
@@ -70,13 +65,20 @@ $(function() {
7065
button.css("top","20px");
7166
button.css("right","40px");
7267
innerblock.append(button);
68+
7369
button.click(function() {
7470
$(document.body).css("overflow", "auto");
7571
$('#overlay').remove();
7672

77-
var code = $(this).closest("figure.code")
78-
code.removeClass('expanded');
79-
code.css("width","auto");
73+
var codeblock = $(this).closest("figure.code")
74+
codeblock.removeClass('expanded');
75+
codeblock.css("width","auto");
76+
77+
innerblock = codeblock.find('.highlight');
78+
innerblock.css("width","auto");
79+
innerblock.css("height","auto");
80+
innerblock.css("overflow", "auto");
81+
8082
$(this).remove();
8183
});
8284
});

0 commit comments

Comments
 (0)