Skip to content

Commit 68379ad

Browse files
committed
Less JavaScript code
1 parent c6c60d2 commit 68379ad

File tree

6 files changed

+493
-3
lines changed

6 files changed

+493
-3
lines changed

mindmap/app/assets/javascripts/mindmap-generated.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,149 @@ var x12 = {'name' : x10,'vertices' : x11,'edges' : x9};
136136
return x12
137137
}
138138
;
139+
m['setupExploration'] = function(x0, x1, x2, x3) {
140+
var x4 = document.querySelector(".workspace");
141+
var x6 = document.querySelector("svg");
142+
if (x4 !== null) {
143+
var x5 = x4;
144+
var x11 = function(x12,x13,x14) {
145+
var x17 = x14;
146+
var x16 = x13;
147+
var x15 = x12;
148+
var x18 = x15 / 100.0;
149+
var x19 = "scale("+x18;
150+
var x20 = x19+") translate(";
151+
var x21 = x20+x16;
152+
var x22 = x21+" ";
153+
var x23 = x22+x17;
154+
var x24 = x23+")";
155+
var x25 = x5.setAttribute("transform", x24);
156+
var x28 = x3(x15,x16,x17);
157+
var x26 = {'s' : x15,'tx' : x16,'ty' : x17};
158+
var x29 = history.replaceState(x26, "", x28);
159+
return x29
160+
}
161+
if (x6 !== null) {
162+
var x7 = x6;
163+
var x8 = x0;
164+
var x9 = x1;
165+
var x10 = x2;
166+
var x48 = window.addEventListener('popstate', function (x31) {
167+
var x32 = x31.state;
168+
if (x32 !== null) {
169+
var x33 = x32;
170+
var x34 = x33.s;
171+
x8 = x34
172+
var x36 = x33.tx;
173+
x9 = x36
174+
var x38 = x33.ty;
175+
x10 = x38
176+
var x40 = x8;
177+
var x41 = x9;
178+
var x42 = x10;
179+
var x44 = x11(x40,x41,x42);
180+
}
181+
var x46 = undefined;
182+
}, false);
183+
var x83 = x7.addEventListener('mousewheel', function (x49) {
184+
var x50 = x8;
185+
var x51 = x49.wheelDeltaY;
186+
var x52 = x51 / 16.0;
187+
var x53 = x50 + x52;
188+
var x54 = Math.round(x53);
189+
var x55 = x54 > 0.0;
190+
var x81
191+
if (x55) {
192+
var x56 = x9;
193+
var x57 = x49.offsetX;
194+
var x58 = x57 * 100.0;
195+
var x59 = x58 / x50;
196+
var x60 = x56 - x59;
197+
var x61 = x58 / x54;
198+
var x62 = x60 + x61;
199+
var x63 = Math.round(x62);
200+
x9 = x63
201+
var x65 = x10;
202+
var x66 = x49.offsetY;
203+
var x67 = x66 * 100.0;
204+
var x68 = x67 / x50;
205+
var x69 = x65 - x68;
206+
var x70 = x67 / x54;
207+
var x71 = x69 + x70;
208+
var x72 = Math.round(x71);
209+
x10 = x72
210+
x8 = x54
211+
var x75 = x8;
212+
var x76 = x9;
213+
var x77 = x10;
214+
var x79 = x11(x75,x76,x77);
215+
x81=x79
216+
} else {
217+
x81=undefined
218+
}
219+
}, false);
220+
var x84 = false;
221+
var x85 = 0.0;
222+
var x86 = 0.0;
223+
var x100 = window.addEventListener('mousedown', function (x87) {
224+
var x88 = x87.target;
225+
var x89 = x88;
226+
var x90 = x89.tagName;
227+
var x91 = x90=="svg";
228+
var x98
229+
if (x91) {
230+
x84 = true
231+
var x93 = x87.offsetX;
232+
x85 = x93
233+
var x95 = x87.offsetY;
234+
x86 = x95
235+
x98=undefined
236+
} else {
237+
x98=undefined
238+
}
239+
}, false);
240+
var x131 = window.addEventListener('mousemove', function (x101) {
241+
var x102 = x84;
242+
var x129
243+
if (x102) {
244+
var x103 = x9;
245+
var x105 = x85;
246+
var x108 = x8;
247+
var x104 = x101.offsetX;
248+
var x106 = x104 - x105;
249+
var x107 = x106 * 100.0;
250+
var x109 = x107 / x108;
251+
var x110 = x103 + x109;
252+
var x111 = Math.round(x110);
253+
x9 = x111
254+
var x113 = x10;
255+
var x115 = x86;
256+
var x114 = x101.offsetY;
257+
var x116 = x114 - x115;
258+
var x117 = x116 * 100.0;
259+
var x118 = x117 / x108;
260+
var x119 = x113 + x118;
261+
var x120 = Math.round(x119);
262+
x10 = x120
263+
x85 = x104
264+
x86 = x114
265+
var x124 = x9;
266+
var x125 = x10;
267+
var x127 = x11(x108,x124,x125);
268+
x129=x127
269+
} else {
270+
x129=undefined
271+
}
272+
}, false);
273+
var x135 = window.addEventListener('mouseup', function (x132) {
274+
x84 = false
275+
}, false);
276+
}
277+
var x137 = undefined;
278+
}
279+
var x139 = undefined;
280+
return x139
281+
}
282+
;
139283
return m
140284
})(window.MindMap || {});

mindmap/app/views/v2/show.scala.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
} {
66
<script src="@routes.Assets.at("javascripts/ajax.min.js")"></script>
7-
<script src="@routes.Assets.at("javascripts/mindmap-generated.min.js")"></script>
87
<script>
98
(function () {
109
Ajax.getJSON('@routes.Application.show(id, ViewSettings(None, None, None))', function (data) {

mindmap/app/views/v3/show.scala.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
@workspace(id, vs) {
88

99
} {
10-
<script src="@routes.Assets.at("javascripts/mindmap-generated.min.js")"></script>
1110
<script>
1211
(function () {
1312
var nodes = MindMap.showMap(MindMap.buildMap(@Html(play.api.cache.Cache.getOrElse("map_"+id+"_json", 60 * 60)(Json.toJson(map)).toString)));

mindmap/app/views/workspace.scala.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
routes.javascript.Application.index,
1818
routes.javascript.Application.show
1919
)
20+
<script src="@routes.Assets.at("javascripts/mindmap-generated.js")"></script>
2021
<script>
21-
// To be replaced with a Scala implementation
22+
MindMap.setupExploration(@vs.s.getOrElse(100), @vs.x.getOrElse(0), @vs.y.getOrElse(0), function (s, x, y) {
23+
return Routes.controllers.Application.show('@id', { s: s, x: x, y: y }).url
24+
});
25+
/* Hand-written JavaScript
2226
(function () {
2327
var state = { s: @vs.s.getOrElse(100), x: @vs.x.getOrElse(0), y: @vs.y.getOrElse(0) };
2428
var workspace = document.querySelector('.workspace');
@@ -67,6 +71,7 @@
6771
})();
6872
6973
})();
74+
*/
7075
</script>
7176
@scripts
7277
}

mindmap/aspects/src/main/scala/CodeGenerator.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ object CodeGenerator extends App {
99
val prog = new Prog with ForestPkgExp with ScalaOpsPkgExp with StructExp with TupledFunctionsExp { context = Nil }
1010
val templates = new prog.Templates {}
1111
val jsProg = new javascripts.BuildMap with models.Models with JSExp with ListOpsExp with StructExp { context = Nil }
12+
val jsProg2 = new javascripts.Exploration with JSExp with javascripts.ExtraJSExp { context = Nil }
1213

1314
val scalaGen = new ScalaGenForestPkg with ScalaCodeGenPkg with ScalaGenStruct { val IR: prog.type = prog; stream = null }
1415
val scalaOut = new java.io.PrintWriter("app/MindMap-generated.scala")
@@ -47,6 +48,7 @@ object CodeGenerator extends App {
4748
val IR: jsProg.type = jsProg; stream = null
4849
import IR._
4950
}
51+
val jsGen3 = new JSGen with javascripts.JSGenExtra { val IR: jsProg2.type = jsProg2; stream = null }
5052
val jsOut = new java.io.PrintWriter("app/assets/javascripts/mindmap-generated.js")
5153
jsOut.println(";window.MindMap = (function (m) {")
5254
jsOut.print("m['showMap'] = ")
@@ -58,6 +60,9 @@ object CodeGenerator extends App {
5860
jsOut.print("m['buildMap'] = ")
5961
jsGen2.emitSource(jsProg.buildMap, "", jsOut)
6062
jsOut.println(";")
63+
jsOut.print("m['setupExploration'] = ")
64+
jsGen3.emitSource4(jsProg2.setup, "", jsOut)
65+
jsOut.println(";")
6166
jsOut.println("return m")
6267
jsOut.println("})(window.MindMap || {});")
6368
jsOut.close()

0 commit comments

Comments
 (0)