Skip to content

Commit 2287b4b

Browse files
committed
Auto merge of #26037 - nhowell:plain_js_playpen, r=steveklabnik
Since the "Book" already avoids jQuery in its inline script tags and playpen.js is tiny, I figured I would convert it to plain old JS as well. Side note: This is a separate issue, but another thing I noticed in my testing is that the "⇱" character doesn't display correctly in Chrome on Windows 7. (Firefox and IE work fine; other browsers not tested) r? @steveklabnik Edit: Github didn't like the "script" tag above Edit 2: Actually, now IE seems to render "⇱" fine for me. Odd.
2 parents ba7f79e + 95dc32d commit 2287b4b

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

src/doc/footer.inc

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ or the <a href="http://opensource.org/licenses/MIT">MIT license</a>, at your opt
55
</p><p>
66
This file may not be copied, modified, or distributed except according to those terms.
77
</p></footer>
8-
<script type="text/javascript" src="jquery.js"></script>
98
<script type="text/javascript" src="playpen.js"></script>

src/librustdoc/html/static/playpen.js

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -11,17 +11,37 @@
1111
/*jslint browser: true, es5: true */
1212
/*globals $: true, rootPath: true */
1313

14-
(function() {
15-
if (window.playgroundUrl) {
16-
$('pre.rust').hover(function() {
17-
var a = $('<a>').text('⇱').attr('class', 'test-arrow');
18-
var code = $(this).prev(".rusttest").text();
19-
a.attr('href', window.playgroundUrl + '?code=' +
20-
encodeURIComponent(code));
21-
a.attr('target', '_blank');
22-
$(this).append(a);
23-
}, function() {
24-
$(this).find('a.test-arrow').remove();
25-
});
14+
document.addEventListener('DOMContentLoaded', function() {
15+
if (!window.playgroundUrl) {
16+
return;
2617
}
27-
}());
18+
19+
var elements = document.querySelectorAll('pre.rust');
20+
21+
Array.prototype.forEach.call(elements, function(el) {
22+
el.onmouseover = function(e) {
23+
if (el.contains(e.relatedTarget)) {
24+
return;
25+
}
26+
27+
var a = document.createElement('a');
28+
a.textContent = '⇱';
29+
a.setAttribute('class', 'test-arrow');
30+
31+
var code = el.previousElementSibling.textContent;
32+
a.setAttribute('href', window.playgroundUrl + '?code=' +
33+
encodeURIComponent(code));
34+
a.setAttribute('target', '_blank');
35+
36+
el.appendChild(a);
37+
};
38+
39+
el.onmouseout = function(e) {
40+
if (el.contains(e.relatedTarget)) {
41+
return;
42+
}
43+
44+
el.removeChild(el.querySelectorAll('a.test-arrow')[0]);
45+
};
46+
});
47+
});

src/rustbook/build.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -158,10 +158,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
158158
// create index.html from the root README
159159
try!(fs::copy(&tgt.join("README.html"), &tgt.join("index.html")));
160160

161-
// Copy some js for playpen
162-
let mut jquery = try!(File::create(tgt.join("jquery.js")));
163-
let js = include_bytes!("../librustdoc/html/static/jquery-2.1.0.min.js");
164-
try!(jquery.write_all(js));
161+
// Copy js for playpen
165162
let mut playpen = try!(File::create(tgt.join("playpen.js")));
166163
let js = include_bytes!("../librustdoc/html/static/playpen.js");
167164
try!(playpen.write_all(js));

src/rustbook/javascript.rs

-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ document.addEventListener("DOMContentLoaded", function(event) {
7171
7272
});
7373
</script>
74-
<script type="text/javascript" src="jquery.js"></script>
7574
<script type="text/javascript" src="playpen.js"></script>
7675
"#;

0 commit comments

Comments
 (0)