git @ Cat's Eye Technologies Wierd / 599ba3f
Sketching and refactoring. And a start script! Chris Pressey 10 years ago
4 changed file(s) with 69 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
1111 "cursor.js",
1212 "stack.js",
1313 "element-factory.js",
14 "preset-manager.js"
14 "preset-manager.js",
15 "source-manager.js"
1516 ];
1617 var loaded = 0;
1718 for (var i = 0; i < deps.length; i++) {
7373 this.speed = undefined;
7474 this.controls = {};
7575
76 /*
77 * This is not a public method.
78 */
79 this._makeEventHandler = function(control, action) {
80 if (this['click_' + action] !== undefined) {
76 var _makeEventHandler = function(controller, control, action) {
77 if (controller['click_' + action] !== undefined) {
8178 action = 'click_' + action;
8279 }
83 var $this = this;
8480 return function(e) {
85 $this[action](control);
81 controller[action](control);
8682 };
8783 };
8884
121117 value = document.getElementById(value);
122118 }
123119 if (value) {
124 value.onclick = this._makeEventHandler(value, key);
120 value.onclick = _makeEventHandler(this, value, key);
125121 this.controls[key] = value;
126122 }
127123 }
332328 var $this = this;
333329 var makeButton = function(action) {
334330 var button = document.createElement('button');
335 button.innerHTML = action; // TODO: capitalize
331 button.innerHTML = action.charAt(0).toUpperCase() + action.slice(1);
336332 button.style.width = "5em";
337333 buttonPanel.appendChild(button);
338 button.onclick = $this._makeEventHandler(button, action);
334 button.onclick = _makeEventHandler($this, button, action);
339335 $this.controls[action] = button;
340336 return button;
341337 };
2121 this.init = function(cfg) {
2222 this.editor = cfg.editor;
2323 this.display = cfg.display;
24 this.controls = {};
2425 this.panel = this.makePanel();
26 if (cfg.panelContainer) {
27 cfg.panelContainer.appendChild(this.panel);
28 }
2529 return this;
2630 };
2731
28 this.makeEditButton = function(container) {
29 var button = document.createElement('button');
30 button.innerHTML = "Edit";
31 button.style.width = "5em";
32 if (container) {
33 container.appendChild(button);
32 this.makePanel = function() {
33 var panel = document.createElement('div');
34 var $this = this;
35 var keys = ["edit", "done", "load", "save", "export"];
36 for (var i = 0; i < keys.length; i++) {
37 var action = keys[i];
38 var button = document.createElement('button');
39 var upperAction = action.charAt(0).toUpperCase() + action.slice(1);
40 button.innerHTML = upperAction;
41 button.style.width = "5em";
42 panel.appendChild(button);
43 button.onclick = function(e) {
44 var method = $this['click' + upperAction];
45 if (method) { method(); }
46 }
47 $this.controls[action] = button;
48 return button;
3449 }
35 button.onclick = function(e) {
36 // heck I dunno
37 this.editor.style.display = 'block';
38 this.display.style.display = 'none';
39 };
40 return button;
50 return panel;
51 };
52
53 this.onClickEdit = function() {
54 this.editor.style.display = 'block';
55 this.display.style.display = 'none';
56 this.controls.edit.style.disabled = true;
57 var keys = ["done", "load", "save", "export"];
58 for (var i = 0; i < keys.length; i++) {
59 this.controls[keys[i]].style.disabled = false;
60 }
61 this.onEdit();
62 };
63
64 this.onClickDone = function() {
65 this.editor.style.display = 'none';
66 this.display.style.display = 'block';
67 this.controls.edit.style.disabled = true;
68 var keys = ["done", "load", "save", "export"];
69 for (var i = 0; i < keys.length; i++) {
70 this.controls[keys[i]].style.disabled = false;
71 }
72 this.onDone();
73 };
74
75 this.onEdit = function() {
76 };
77
78 /*
79 * Override this to load it into the controller
80 */
81 this.onDone = function() {
4182 };
4283
4384 /*
119160 //alert(localStorage.length);
120161 }
121162 };
122
123 this.makeButtonPanel = function(container) {
124 var buttonPanel = document.createElement('div');
125 container.appendChild(buttonPanel);
126 var $this = this;
127 var makeButton = function(action) {
128 var button = document.createElement('button');
129 button.innerHTML = action; // TODO: capitalize
130 button.style.width = "5em";
131 buttonPanel.appendChild(button);
132 button.onclick = $this._makeEventHandler(button, action);
133 $this.controls[action] = button;
134 return button;
135 };
136 var keys = ["start", "stop", "step", "load", "edit", "reset"];
137 for (var i = 0; i < keys.length; i++) {
138 makeButton(keys[i]);
139 }
140 return buttonPanel;
141 };
142163 };
0 #!/bin/sh
1
2 THIS=`realpath $0`
3 DIR=`dirname $THIS`
4 cd $DIR
5 python -m SimpleHTTPServer &
6 sleep 1
7 python -m webbrowser -t "http://127.0.0.1:8000/impl/wierd.js/demo/wierd.html"