Skip to content

Commit 95dfff0

Browse files
committed
Local fallback for jquery #46
1 parent 754773f commit 95dfff0

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

book-example/src/misc/contributors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Contributors

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ impl Renderer for HtmlHandlebars {
156156
let mut css_file = try!(File::create(book.get_dest().join("book.css")));
157157
try!(css_file.write_all(&theme.css));
158158

159+
// JQuery
160+
let mut jquery = try!(File::create(book.get_dest().join("jquery.js")));
161+
try!(jquery.write_all(&theme.jquery));
162+
159163
// syntax highlighting
160164
let mut highlight_css = try!(File::create(book.get_dest().join("highlight.css")));
161165
try!(highlight_css.write_all(&theme.highlight_css));

src/theme/index.hbs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@
7171

7272
</div>
7373

74+
<!-- Fetch JQuery from CDN but have a local fallback -->
7475
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
76+
<script>
77+
if (typeof jQuery == 'undefined') {
78+
document.write(unescape("%3Cscript src='jquery.js'%3E%3C/script%3E"));
79+
}
80+
</script>
81+
7582
<script src="highlight.js"></script>
7683
<script src="book.js"></script>
7784
</body>

src/theme/jquery-2.1.4.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/theme/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub static CSS: &'static [u8] = include_bytes!("book.css");
99
pub static JS: &'static [u8] = include_bytes!("book.js");
1010
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
1111
pub static HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
12+
pub static JQUERY: &'static [u8] = include_bytes!("jquery-2.1.4.min.js");
1213

1314
/// The `Theme` struct should be used instead of the static variables because the `new()` method
1415
/// will look if the user has a theme directory in his source folder and use the users theme instead
@@ -22,6 +23,7 @@ pub struct Theme {
2223
pub js: Vec<u8>,
2324
pub highlight_css: Vec<u8>,
2425
pub highlight_js: Vec<u8>,
26+
pub jquery: Vec<u8>,
2527
}
2628

2729
impl Theme {
@@ -34,6 +36,7 @@ impl Theme {
3436
js: JS.to_owned(),
3537
highlight_css: HIGHLIGHT_CSS.to_owned(),
3638
highlight_js: HIGHLIGHT_JS.to_owned(),
39+
jquery: JQUERY.to_owned(),
3740
};
3841

3942
// Check if the given path exists

0 commit comments

Comments
 (0)