git @ Cat's Eye Technologies ZOWIE / 969b885
Fix indentation, add a missing `var` and a missing semicolon Chris Pressey 2 years ago
1 changed file(s) with 76 addition(s) and 82 deletion(s). Raw diff Collapse all Expand all
1818 }
1919
2020 PresetManager = function() {
21 this.init = function(cfg) {
22 this.selectElem = cfg.selectElem;
23 if (cfg.setPreset) {
24 this.setPreset = cfg.setPreset;
25 }
26 this.clear();
27 var $this = this;
28 this.selectElem.onchange = function() {
29 $this._select(this.options[this.selectedIndex].value);
30 }
21 this.init = function(cfg) {
22 this.selectElem = cfg.selectElem;
23 this.clear();
24 var $this = this;
25 this.selectElem.onchange = function() {
26 $this._select(this.options[this.selectedIndex].value);
27 };
28 return this;
29 };
30
31 this.clear = function() {
32 this.reactTo = {};
33 while (this.selectElem.firstChild) {
34 this.selectElem.removeChild(this.selectElem.firstChild);
35 }
36 this.add('(select one...)', function() {});
37 return this;
38 };
39
40 this.add = function(id, callback) {
41 var opt = document.createElement("option");
42 opt.text = id;
43 opt.value = id;
44 this.selectElem.options.add(opt);
45 var $this = this;
46 this.reactTo[id] = callback;
47 return this;
48 };
49
50 this._select = function(id) {
51 this.reactTo[id](id);
52 if (this.onselect) {
53 this.onselect(id);
54 }
55 };
56
57 this.select = function(id) {
58 var i = 0;
59 var opt = this.selectElem.options[i];
60 while (opt) {
61 if (opt.value === id) {
62 this.selectElem.selectedIndex = i;
63 this._select(id);
3164 return this;
32 };
33
34 this.clear = function() {
35 this.reactTo = {};
36 while (this.selectElem.firstChild) {
37 this.selectElem.removeChild(this.selectElem.firstChild);
38 }
39 this.add('(select one...)', function() {});
40 return this;
41 };
42
43 this.add = function(id, callback) {
44 var opt = document.createElement("option");
45 opt.text = id;
46 opt.value = id;
47 this.selectElem.options.add(opt);
48 var $this = this;
49 this.reactTo[id] = callback || this.setPreset;
50 return this;
51 };
52
53 this.setPreset = function(id) {
54 throw new Error("No default setPreset callback configured");
55 };
56
57 this._select = function(id) {
58 this.reactTo[id](id);
59 if (this.onselect) {
60 this.onselect(id);
61 }
62 };
63
64 this.select = function(id) {
65 var i = 0;
66 var opt = this.selectElem.options[i];
67 while (opt) {
68 if (opt.value === id) {
69 this.selectElem.selectedIndex = i;
70 this._select(id);
71 return this;
72 }
73 i++;
74 opt = this.selectElem.options[i];
75 }
76 // if not found, select the "(select one...)" option
77 this.selectElem.selectedIndex = 0;
78 return this;
79 };
65 }
66 i++;
67 opt = this.selectElem.options[i];
68 }
69 // if not found, select the "(select one...)" option
70 this.selectElem.selectedIndex = 0;
71 return this;
72 };
8073 };
8174
8275 function launch(prefix, container, config) {
114107 });
115108
116109 document.getElementById("run").onclick = function() {
117 var esoprog = document.getElementById("editor").value;
118 var mypre = document.getElementById("output");
119 mypre.innerHTML = '';
120 Sk.canvas = "mycanvas";
121 Sk.pre = "output";
122 Sk.configure({
123 output: function(text) {
124 var mypre = document.getElementById("output");
125 mypre.innerHTML = mypre.innerHTML + text.replace(/\n$/, "");
126 },
127 read: function(x) {
128 if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined) {
129 throw "File not found: '" + x + "'";
130 }
131 return Sk.builtinFiles["files"][x];
132 }
133 });
134 prog = zowie_interpreter + "\n";
135 prog += 'p = Processor()\n';
136 prog += 'p.load_string("""\n';
137 prog += esoprog;
138 prog += '""")\n';
139 prog += 'p.run()\n';
140 eval(Sk.importMainWithBody("<stdin>", false, prog));
110 var esoprog = document.getElementById("editor").value;
111 var mypre = document.getElementById("output");
112 mypre.innerHTML = '';
113 // Sk is the Skulpt object, which we assume has been loaded first
114 Sk.canvas = "mycanvas";
115 Sk.pre = "output";
116 Sk.configure({
117 output: function(text) {
118 var mypre = document.getElementById("output");
119 mypre.innerHTML = mypre.innerHTML + text.replace(/\n$/, "");
120 },
121 read: function(x) {
122 if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined) {
123 throw "File not found: '" + x + "'";
124 }
125 return Sk.builtinFiles["files"][x];
126 }
127 });
128 var prog = zowie_interpreter + "\n";
129 prog += 'p = Processor()\n';
130 prog += 'p.load_string("""\n';
131 prog += esoprog;
132 prog += '""")\n';
133 prog += 'p.run()\n';
134 eval(Sk.importMainWithBody("<stdin>", false, prog));
141135 };
142136 }