Skip to content

Commit 3faa827

Browse files
committed
export PicSVG and add playbox to pictcl page
1 parent 6adb8a4 commit 3faa827

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

diagram/pictcl.html

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,19 @@ <h2>Quick Example</h2>
120120
</section
121121
</article>
122122

123-
<aside>
124-
<textarea style="display:block;width:100%;margin:1em 0"></textarea>
125-
</aside>
123+
<section>
124+
<a name="playbox"></a>
125+
<aside>
126+
<svg id="pictcl-svg"></svg>
127+
<textarea id="pictcl-input" style="display:block;width:100%;min-height:7em;margin:1em 0">
128+
line
129+
box "PicTcl"
130+
arrow
131+
</textarea>
132+
<p>
133+
<button id="pictcl-trigger" type="button">Draw Diagram</button>
134+
</p>
135+
</aside>
126136

127137

128138
<pre>
@@ -131,11 +141,12 @@ <h2>Quick Example</h2>
131141
circle -down
132142
circle -padx 0
133143
</pre>
144+
</section>
134145

135146
</main>
136147

137148
<script type="module">
138-
import PicDiagram from './pictcl.js';
149+
import PicDiagram, {PicSVG} from './pictcl.js';
139150

140151
PicDiagram(document.querySelector("#demo-a1"));
141152
PicDiagram(document.querySelector("#demo-a2"));
@@ -148,4 +159,12 @@ <h2>Quick Example</h2>
148159

149160
PicDiagram("code.lang-pictcl");
150161

162+
document.querySelector("#pictcl-trigger").addEventListener('click', function(){
163+
var pictcl_code = document.querySelector("#pictcl-input");
164+
var pictcl_svg = pictcl_code.parentElement.querySelector("svg");
165+
var new_svg = PicSVG.createElement("svg");
166+
pictcl_svg.parentElement.replaceChild(new_svg, pictcl_svg);
167+
PicDiagram(new_svg, pictcl_code.value);
168+
});
169+
151170
</script>

diagram/pictcl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function PicDiagram(el, pictcl_code){
333333
figure.appendChild(newsvg);
334334
figure.appendChild(preNode);
335335
svg = newsvg;
336-
pictcl_code = el.textContent;
336+
pictcl_code = pictcl_code || el.textContent;
337337
preNode.style.display = 'none';
338338
svg.addEventListener('dblclick', function(){
339339
if(preNode.style.display == 'none'){
@@ -344,7 +344,7 @@ function PicDiagram(el, pictcl_code){
344344
});
345345
}else{
346346
svg = el;
347-
pictcl_code = el.parentElement.querySelector("script[type='text/pictcl']").text;
347+
pictcl_code = pictcl_code || el.parentElement.querySelector("script[type='text/pictcl']").text;
348348
}
349349

350350
svg.setAttribute("stroke", "black");
@@ -367,3 +367,4 @@ function PicDiagram(el, pictcl_code){
367367

368368

369369
export default PicDiagram;
370+
export {PicSVG};

diagram/tcl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function TclInterp () {
238238
var res = "";
239239
interp.inLoop = true;
240240
interp.code = interp.OK;
241-
for(i in list) {
241+
for(var i in list) {
242242
interp.setVar(args[1],interp.objectify(list[i]));
243243
interp.eval(body);
244244
if(interp.code == interp.BRK) break;
@@ -886,7 +886,7 @@ function TclParser(text) {
886886
return this.OK;
887887
}
888888
this.parseList = function () {
889-
level = 0;
889+
var level = 0;
890890
this.start = this.index;
891891
while (true) {
892892
if (this.len == 0) {

0 commit comments

Comments
 (0)