Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert playpen.js to plain JS #26037

Merged
merged 1 commit into from
Jun 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/doc/footer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ or the <a href="http://opensource.org/licenses/MIT">MIT license</a>, at your opt
</p><p>
This file may not be copied, modified, or distributed except according to those terms.
</p></footer>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="playpen.js"></script>
48 changes: 34 additions & 14 deletions src/librustdoc/html/static/playpen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -11,17 +11,37 @@
/*jslint browser: true, es5: true */
/*globals $: true, rootPath: true */

(function() {
if (window.playgroundUrl) {
$('pre.rust').hover(function() {
var a = $('<a>').text('⇱').attr('class', 'test-arrow');
var code = $(this).prev(".rusttest").text();
a.attr('href', window.playgroundUrl + '?code=' +
encodeURIComponent(code));
a.attr('target', '_blank');
$(this).append(a);
}, function() {
$(this).find('a.test-arrow').remove();
});
document.addEventListener('DOMContentLoaded', function() {
if (!window.playgroundUrl) {
return;
}
}());

var elements = document.querySelectorAll('pre.rust');

Array.prototype.forEach.call(elements, function(el) {
el.onmouseover = function(e) {
if (el.contains(e.relatedTarget)) {
return;
}

var a = document.createElement('a');
a.textContent = '⇱';
a.setAttribute('class', 'test-arrow');

var code = el.previousElementSibling.textContent;
a.setAttribute('href', window.playgroundUrl + '?code=' +
encodeURIComponent(code));
a.setAttribute('target', '_blank');

el.appendChild(a);
};

el.onmouseout = function(e) {
if (el.contains(e.relatedTarget)) {
return;
}

el.removeChild(el.querySelectorAll('a.test-arrow')[0]);
};
});
});
7 changes: 2 additions & 5 deletions src/rustbook/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -158,10 +158,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
// create index.html from the root README
try!(fs::copy(&tgt.join("README.html"), &tgt.join("index.html")));

// Copy some js for playpen
let mut jquery = try!(File::create(tgt.join("jquery.js")));
let js = include_bytes!("../librustdoc/html/static/jquery-2.1.0.min.js");
try!(jquery.write_all(js));
// Copy js for playpen
let mut playpen = try!(File::create(tgt.join("playpen.js")));
let js = include_bytes!("../librustdoc/html/static/playpen.js");
try!(playpen.write_all(js));
Expand Down
1 change: 0 additions & 1 deletion src/rustbook/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,5 @@ document.addEventListener("DOMContentLoaded", function(event) {

});
</script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="playpen.js"></script>
"#;