]>
Commit | Line | Data |
---|---|---|
62682a34 | 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT |
1a4d82fc JJ |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | /*jslint browser: true, es5: true */ | |
12 | /*globals $: true, rootPath: true */ | |
13 | ||
62682a34 | 14 | document.addEventListener('DOMContentLoaded', function() { |
b039eaaf SL |
15 | 'use strict'; |
16 | ||
62682a34 SL |
17 | if (!window.playgroundUrl) { |
18 | return; | |
1a4d82fc | 19 | } |
62682a34 | 20 | |
c1a9b12d SL |
21 | var featureRegexp = new RegExp('^\s*#!\\[feature\\(\.*?\\)\\]'); |
22 | var elements = document.querySelectorAll('pre.rust-example-rendered'); | |
62682a34 SL |
23 | |
24 | Array.prototype.forEach.call(elements, function(el) { | |
25 | el.onmouseover = function(e) { | |
26 | if (el.contains(e.relatedTarget)) { | |
27 | return; | |
28 | } | |
29 | ||
9e0c209e | 30 | var a = el.querySelectorAll('a.test-arrow')[0]; |
62682a34 SL |
31 | |
32 | var code = el.previousElementSibling.textContent; | |
c1a9b12d SL |
33 | |
34 | var channel = ''; | |
35 | if (featureRegexp.test(code)) { | |
36 | channel = '&version=nightly'; | |
37 | } | |
38 | ||
62682a34 | 39 | a.setAttribute('href', window.playgroundUrl + '?code=' + |
c1a9b12d | 40 | encodeURIComponent(code) + channel); |
62682a34 SL |
41 | }; |
42 | }); | |
43 | }); |