From 64106c4d3d4ddba8c7bc2af75376e6d3d3d75601 Mon Sep 17 00:00:00 2001 From: Date: Mon, 29 Jun 2015 20:16:15 +0000 Subject: Update documentation --- playpen.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 playpen.js (limited to 'playpen.js') diff --git a/playpen.js b/playpen.js new file mode 100644 index 0000000..ff947d9 --- /dev/null +++ b/playpen.js @@ -0,0 +1,47 @@ +// 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. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*jslint browser: true, es5: true */ +/*globals $: true, rootPath: true */ + +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]); + }; + }); +}); -- cgit v1.2.3