Skip to content

Commit 2209bd3

Browse files
committed
Bring playpen.js up to date with @rust-lang/rustbe203ac25836
- Copied playpen.js from rust/src/librustdoc/html/static/
1 parent e19eebb commit 2209bd3

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

librustdoc/html/static/playpen.js

+43-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,46 @@
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+
'use strict';
16+
17+
if (!window.playgroundUrl) {
18+
return;
2619
}
27-
}());
20+
21+
var featureRegexp = new RegExp('^\s*#!\\[feature\\(\.*?\\)\\]');
22+
var elements = document.querySelectorAll('pre.rust-example-rendered');
23+
24+
Array.prototype.forEach.call(elements, function(el) {
25+
el.onmouseover = function(e) {
26+
if (el.contains(e.relatedTarget)) {
27+
return;
28+
}
29+
30+
var a = document.createElement('a');
31+
a.setAttribute('class', 'test-arrow');
32+
a.textContent = 'Run';
33+
34+
var code = el.previousElementSibling.textContent;
35+
36+
var channel = '';
37+
if (featureRegexp.test(code)) {
38+
channel = '&version=nightly';
39+
}
40+
41+
a.setAttribute('href', window.playgroundUrl + '?code=' +
42+
encodeURIComponent(code) + channel);
43+
a.setAttribute('target', '_blank');
44+
45+
el.appendChild(a);
46+
};
47+
48+
el.onmouseout = function(e) {
49+
if (el.contains(e.relatedTarget)) {
50+
return;
51+
}
52+
53+
el.removeChild(el.querySelectorAll('a.test-arrow')[0]);
54+
};
55+
});
56+
});

0 commit comments

Comments
 (0)