1
NodeList.prototype.array = function() {
2
return Array.prototype.slice.call(this);
6
return document.querySelectorAll(qs).array();
12
var list = find("figure script[type='text/beziercode']");
13
list.forEach(function(e, idx) {
14
var figure = e.parentNode;
15
var code = e.textContent.substring(1).split("\n");
16
e.parentNode.removeChild(e);
18
code[0].replace(/^(\s+)/, function(a,b) { indent = b; });
19
var len = code.length;
20
code = "var curve = " + code.map(function(l) { return l.replace(indent,''); }).join("\n");
22
var content = code + "\n draw();";
23
content = content + "\n handleInteraction(getCanvas(), curve).onupdate = function() { reset(); draw(); }";
24
content = "\n with(Math) { " + content + "\n }";
25
content = "\n with(drawfunctions) { " + content + "\n }";
26
content = "(function(drawfunctions) { " + content + "\n} (bindDrawFunctions( " + idx + " )) );\n";
28
var codearea = document.createElement("div");
29
codearea.classList.add("textarea");
30
codearea.textContent = code;
31
codearea.setAttribute("style", "height: " + (16*(len-1)) + "px!important;");
32
figure.appendChild(codearea);
33
var button = document.createElement("button");
34
button.textContent = "view source";
35
figure.appendChild(button);
37
button.onclick = function(evt) {
38
if(open && open!==codearea) { open.classList.remove("showcode"); }
39
if(codearea.classList.contains("showcode")) {
40
codearea.classList.remove("showcode");
42
codearea.classList.add("showcode");
45
evt.stopPropagation();
48
document.addEventListener("click", function() {
49
if(codearea.classList.contains("showcode")) {
50
codearea.classList.remove("showcode");
54
var ns = document.createElement("script");
55
ns.textContent = content;
56
document.querySelector("head").appendChild(ns);
60
document.addEventListener("DOMContentLoaded", loadAll);