about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-22 05:23:50 +0000
committerbors <bors@rust-lang.org>2015-06-22 05:23:50 +0000
commit2287b4b628cb6f4d66578e1298cd9f34e9ef77db (patch)
treee5112db295dcdd87cc2dc26775a56421a223fdbc
parentba7f79e9f8f2da008796ae0f8006c5cf3a24434e (diff)
parent95dc32dde61c379b913fdd47b97181f31c49597f (diff)
downloadrust-2287b4b628cb6f4d66578e1298cd9f34e9ef77db.tar.gz
rust-2287b4b628cb6f4d66578e1298cd9f34e9ef77db.zip
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.
-rw-r--r--src/doc/footer.inc1
-rw-r--r--src/librustdoc/html/static/playpen.js48
-rw-r--r--src/rustbook/build.rs7
-rw-r--r--src/rustbook/javascript.rs1
4 files changed, 36 insertions, 21 deletions
diff --git a/src/doc/footer.inc b/src/doc/footer.inc
index f32f2fd443f..b5eb589eb53 100644
--- a/src/doc/footer.inc
+++ b/src/doc/footer.inc
@@ -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>
diff --git a/src/librustdoc/html/static/playpen.js b/src/librustdoc/html/static/playpen.js
index 06b3c4e42d6..ff947d93fca 100644
--- a/src/librustdoc/html/static/playpen.js
+++ b/src/librustdoc/html/static/playpen.js
@@ -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.
 //
@@ -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]);
+        };
+    });
+});
diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs
index 5ffb9b007d0..a7a6ed3bfe7 100644
--- a/src/rustbook/build.rs
+++ b/src/rustbook/build.rs
@@ -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.
 //
@@ -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));
diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs
index 26303d13b6c..f33b79cc188 100644
--- a/src/rustbook/javascript.rs
+++ b/src/rustbook/javascript.rs
@@ -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>
 "#;