forked from scratchblocks/scratchblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.html
172 lines (148 loc) · 4.65 KB
/
tester.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>[scratchblocks]</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="scratchblocks2.css">
<script type="text/javascript" src="scratchblocks2.js"></script>
<style type="text/css">
h1 {
font-family: monospace;
}
a {
text-decoration: none;
color: #22f;
}
a:hover {
text-decoration: underline;
}
body {
margin: 1em;
font-family: sans-serif;
}
input, button {
font-size: 1em;
font-family: inherit;
}
textarea {
font-size: 1em;
margin-bottom: 1em;
min-width: 30em;
min-height: 15em;
}
button {
display: block;
font-size: 1.25em;
margin-bottom: 1em;
border: 1px solid #444;
background: #ccc;
box-shadow: 0 1px 1px #888;
}
a:active, button:active {
position: relative;
top: 1px;
box-shadow: none;
}
#preview {
margin: 1em;
}
#link-url {
width: auto;
min-width: 40em;
cursor: text;
}
label {
font-weight: bold;
cursor: pointer;
}
#footer {
text-align: right;
padding: 1em;
background: rgba(255, 255, 255, 0.5);
z-index: 60000;
}
#footer a {
color: black;
}
#me {
font-weight: bold;
}
</style>
</head>
<body>
<h1>[scratchblocks]</h1>
<p>
Test <code>[scratchblocks]</code>...<code>[/scratchblocks]</code> code for the
<a href="http://scratch.mit.edu/forums/viewtopic.php?id=90403">Scratch Forums</a>
or <code><scratchblocks></code>...<code></scratchblocks></code> code for the
<a href="http://wiki.scratch.mit.edu/wiki/Block_Plugin">Scratch Wiki</a>.
</p>
<p>
To generate the code: <a href="http://scratch.mit.edu/forums/viewtopic.php?id=102175">Squeak plugin</a> | <a href="http://github.com/blob8108/kurt#decompiler">Python script</a>
</p>
<textarea id="code"></textarea>
<button id="render">Render</button>
<div id="link">
<label for="link-url" id="link-url-label">Link:</label>
<input type="text" id="link-url" readonly>
</div>
<pre id="preview" class="blocks"></pre>
<div id="footer"><a id="me"
href="http://scratch.mit.edu/users/blob8108">~blob8108</a></div>
<script type="text/javascript">
if(typeof(String.prototype.trim) === "undefined") {
String.prototype.trim = function() {
return String(this).replace(/^\s+|\s+$/g, '');
};
}
code = document.getElementById('code');
preview = document.getElementById('preview');
link_url = document.getElementById('link-url');
link_url_label = document.getElementById('link-url-label');
var oldHash;
function refresh () {
script = code.value;
script = script.replace(/\[\/?scratchblocks\]/gi, ''); // Scratch Forums
script = script.replace(/<\/?scratchblocks>/gi, ''); // Scratch Wiki
script = script.replace(/^position\:[0-9\., ]+/i, ''); // Kurt
script = script.trim();
location.hash = '#'+encodeURIComponent(script);
oldHash = location.hash;
link_url.value = location;
script = script.replace(/&/g, '&');
script = script.replace(/</g, '<');
script = script.replace(/>/g, '>');
script = script.replace(/"/g, '"');
preview.innerHTML = script;
scratchblocks2.parse("pre.blocks");
}
function checkHash() {
if (oldHash != location.hash) {
code.value = decodeURIComponent((location.href.split("#")[1] || ""));
refresh();
}
window.setTimeout(checkHash, 1000);
}
code.value = decodeURIComponent((location.href.split("#")[1] || ""));
checkHash();
document.getElementById('render').onmousedown = refresh;
code.onkeyup = refresh;
code.onblur = refresh;
code.oncopy = code.onpaste = function(e) {
window.setTimeout(refresh, 100);
}
link_url.onclick = link_url.onfocus = link_url_label.onclick = function(e) {
link_url.focus();
link_url.select();
// Work around Chrome's little problem
link_url.onmouseup = function() {
// Prevent further mouseup intervention
link_url.onmouseup = null;
return false;
};
}
refresh();
</script>
</body>
</html>