Skip to content

Commit d39391d

Browse files
committed
add button to codeblocks that expands them to size of viewport
1 parent 8bbba2b commit d39391d

3 files changed

Lines changed: 75 additions & 7 deletions

File tree

plugins/code_block.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ def render(context)
8787
source = '<div class="code-buttons">'
8888
source += '<ul class="nav nav-tabs">'
8989
source += '<li class="pull-right">'
90-
source += '<a class="copycode btn-mini" id="copy_' + digest + '">'
91-
source += '<i class="icon-file"></i> Copy</a></li></ul></div>'
90+
source += '<a class="copycode code-button btn-mini" id="copy_' + digest + '">'
91+
source += '<i class="icon-file"></i> Copy</a></li>'
92+
source += '<li class="pull-right">'
93+
source += '<a class="expandcode code-button btn-mini" id="expand_' + digest + '">'
94+
source += '<i class="icon-fullscreen"></i> Expand</a></li>'
95+
source += '</ul></div>'
9296
source += '<figure class="code" id="code_' + digest + '">'
9397
source += @caption if @caption
9498
if @filetype

source/javascripts/codebuttons.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,44 @@ $(function() {
4040
}else{
4141
$("body").addClass("no-flash");
4242
}
43+
44+
$(".expandcode").click(function() {
45+
var codeId = $(this).attr("id").replace('expand_','');
46+
var codeblock = $('#code_' + codeId).clone();
47+
codeblock.addClass('expanded');
48+
49+
codeblock.appendTo(document.body);
50+
51+
var overlay = $('<div id="overlay"> </div>');
52+
overlay.appendTo(document.body);
53+
54+
//prevent the body from scrolling
55+
$(document.body).css("overflow", "hidden");
56+
57+
innerblock = codeblock.find('.highlight');
58+
innerblock.css("height", $(window).height() - 100 + "px");
59+
innerblock.css("width", $(window).width() - 80 + "px");
60+
61+
codeblock.css("width", $(window).width() - 80 + "px");
62+
63+
innerblock.css("overflow", "scroll");
64+
65+
//move all of this into a css class and toggle it
66+
//append a button that closes the window
67+
button = $('<a class="close-btn btn btn-large btn-danger"><i class="icon-remove"></i> Close</a>');
68+
button.css("float","right");
69+
button.css("position","fixed");
70+
button.css("top","20px");
71+
button.css("right","40px");
72+
innerblock.append(button);
73+
button.click(function() {
74+
$(document.body).css("overflow", "auto");
75+
$('#overlay').remove();
76+
77+
var code = $(this).closest("figure.code")
78+
code.removeClass('expanded');
79+
code.css("width","auto");
80+
$(this).remove();
81+
});
82+
});
4383
});

source/stylesheets/style.css

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ blockquote { background-color: #FFFFED; }
6565
margin: 0 40px -19px;
6666
}
6767

68-
.code-buttons > .nav-tabs > li > .copycode {
68+
.code-buttons > .nav-tabs > li > .code-button {
6969
padding-top:2px;
7070
padding-bottom:2px;
7171
border:1px solid #EEE;
@@ -79,10 +79,11 @@ figure.code {
7979
margin: 0 40px 1.5em;
8080
}
8181

82-
.copycode.hover {
83-
border-color: #eee #eee #ddd;
84-
text-decoration: none;
85-
background-color: #eee;
82+
.code-button:hover {
83+
cursor: pointer;
84+
}
85+
.code-button.hover {
86+
cursor: pointer;
8687
}
8788

8889
.no-flash figure.code {
@@ -267,6 +268,29 @@ li.official {
267268
margin-left: -20px;
268269
}
269270

271+
#overlay {
272+
position: fixed;
273+
top: 0;
274+
left: 0;
275+
width: 100%;
276+
height: 100%;
277+
background-color: #000;
278+
filter:alpha(opacity=70);
279+
-moz-opacity:0.7;
280+
-khtml-opacity: 0.7;
281+
opacity: 0.7;
282+
z-index: 10000;
283+
}
284+
285+
figure.code.expanded {
286+
position: fixed;
287+
top:0;
288+
left:0;
289+
padding:60px 40px 40px 40px;
290+
margin: 0;
291+
z-index:100000;
292+
}
293+
270294
.video-container {
271295
position: relative;
272296
padding-bottom: 56.25%;

0 commit comments

Comments
 (0)