Local fallback for jquery #46

This commit is contained in:
Mathieu David 2015-09-13 19:16:11 +02:00
parent 754773f857
commit 95dfff008c
5 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1 @@
# Contributors

View File

@ -156,6 +156,10 @@ impl Renderer for HtmlHandlebars {
let mut css_file = try!(File::create(book.get_dest().join("book.css")));
try!(css_file.write_all(&theme.css));
// JQuery
let mut jquery = try!(File::create(book.get_dest().join("jquery.js")));
try!(jquery.write_all(&theme.jquery));
// syntax highlighting
let mut highlight_css = try!(File::create(book.get_dest().join("highlight.css")));
try!(highlight_css.write_all(&theme.highlight_css));

View File

@ -71,7 +71,14 @@
</div>
<!-- Fetch JQuery from CDN but have a local fallback -->
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='jquery.js'%3E%3C/script%3E"));
}
</script>
<script src="highlight.js"></script>
<script src="book.js"></script>
</body>

4
src/theme/jquery-2.1.4.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,7 @@ pub static CSS: &'static [u8] = include_bytes!("book.css");
pub static JS: &'static [u8] = include_bytes!("book.js");
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
pub static HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
pub static JQUERY: &'static [u8] = include_bytes!("jquery-2.1.4.min.js");
/// The `Theme` struct should be used instead of the static variables because the `new()` method
/// 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 {
pub js: Vec<u8>,
pub highlight_css: Vec<u8>,
pub highlight_js: Vec<u8>,
pub jquery: Vec<u8>,
}
impl Theme {
@ -34,6 +36,7 @@ impl Theme {
js: JS.to_owned(),
highlight_css: HIGHLIGHT_CSS.to_owned(),
highlight_js: HIGHLIGHT_JS.to_owned(),
jquery: JQUERY.to_owned(),
};
// Check if the given path exists