Skip to content

Commit 4780e46

Browse files
author
Jake Bell
committed
Adding code blocks to embed display type (then hiding with javascript).
1 parent ec28ff1 commit 4780e46

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

gist_filter.module

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function gist_filter_filter_tips($filter, $format, $long = FALSE) {
7979
function theme_gist_filter_code($vars) {
8080
$file = $vars['file'];
8181

82-
return '<div class="github-file"><code>' . check_plain($file['content']) . '</code></div>';
82+
return '<div class="drupal-gist-file"><pre type="' . strtolower($file['language']) . '">' . check_plain($file['content']) . '</pre></div>';
8383
}
8484

8585
/**
@@ -117,7 +117,15 @@ function _gist_display_code($matches) {
117117
function _gist_display_embed($matches) {
118118
$gist_url = 'http://gist.github.com/' . $matches[1];
119119
$gist_url = isset($matches[2]) && !empty($matches[2]) ? $gist_url . '.js?file=' . $matches[2] : $gist_url . '.js';
120-
return '<script src="' . $gist_url . '"></script>';
120+
121+
// Also grab the content and display it in code tags (in case the user does not have JS).
122+
// TODO: 1. there is some caching going on here. 2. this is expensive.
123+
drupal_add_js(drupal_get_path('module', 'gist_filter') . '/js/gist-filter-hide-code.js');
124+
$code = _gist_display_code($matches);
125+
126+
$output = $code;
127+
$output .= '<script src="' . $gist_url . '"></script>';
128+
return $output;
121129
}
122130

123131
/**

js/gist-filter-hide-code.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function ($) {
2+
3+
Drupal.behaviors.gistFilterHideCode = {
4+
attach: function (context, settings) {
5+
// Just hide the code tags if JS is enabled.
6+
$('.drupal-gist-file', context).hide();
7+
}
8+
};
9+
10+
}(jQuery));

0 commit comments

Comments
 (0)