]> git.lizzy.rs Git - rust.git/commitdiff
Convert playpen.js to plain JS.
authorNick Howell <howellnick@gmail.com>
Fri, 5 Jun 2015 17:09:45 +0000 (13:09 -0400)
committerNick Howell <howellnick@gmail.com>
Fri, 12 Jun 2015 20:26:07 +0000 (16:26 -0400)
It is still compatible with IE9+.

This removes the jQuery dependency from the "Book" entirely.

src/doc/footer.inc
src/librustdoc/html/static/playpen.js
src/rustbook/build.rs
src/rustbook/javascript.rs

index f32f2fd443f8e71bff708a5d6d349e461ac1375b..b5eb589eb53983ed9a5134021f1e6e6fbc97b761 100644 (file)
@@ -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>
index 06b3c4e42d6334c3f7e962dd6aa12de0c1ff1198..ff947d93fca16786e56fff3a4dd5ce22316439b6 100644 (file)
@@ -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.
 //
 /*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]);
+        };
+    });
+});
index 5ffb9b007d041394789b684228afeada4c46116c..a7a6ed3bfe749503cbe5a8b1cb618c8dca3c1b6a 100644 (file)
@@ -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));
index 26303d13b6cfcb61542d1d46ff45d29186a405a1..f33b79cc1888f770c5bfe861b0072e18979516bb 100644 (file)
@@ -71,6 +71,5 @@
 
 });
 </script>
-<script type="text/javascript" src="jquery.js"></script>
 <script type="text/javascript" src="playpen.js"></script>
 "#;