Skip to content

Commit dcb3e39

Browse files
committed
demo: move boilerplate code to lib/squeak.js
1 parent 01ccec4 commit dcb3e39

File tree

10 files changed

+82
-158
lines changed

10 files changed

+82
-158
lines changed

benchmark/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
TARGET=../gh-pages/benchmark
77
MANIFEST=$(TARGET)/offline.appcache
8-
FILES=../vm.js benchmark.html benchmark.css benchmark.js benchmark.image \
8+
FILES=../lib/squeak.js ../vm.js benchmark.html benchmark.css benchmark.js benchmark.image \
99
../lib/lz-string.js
1010
EXTRA=
1111

benchmark/benchmark.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
<link rel="stylesheet" href="benchmark.css">
2727
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
2828
<script src="../lib/lz-string.js"></script>
29-
<script src="benchmark.js"></script>
29+
<script src="../lib/squeak.js"></script>
3030
<script src="../vm.js"></script>
31+
<script src="benchmark.js"></script>
3132

3233
</head>
3334
<body>

benchmark/benchmark.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,6 @@
2020
* THE SOFTWARE.
2121
*/
2222

23-
24-
//////////////////////////////////////////////////////////////////////////////
25-
// these functions fake the Lively module and class system
26-
// just enough so the loading of vm.js succeeds
27-
//////////////////////////////////////////////////////////////////////////////
28-
29-
module = function(dottedPath) {
30-
if (dottedPath == "") return window;
31-
var path = dottedPath.split("."),
32-
name = path.pop(),
33-
parent = module(path.join("."));
34-
if (!parent[name]) parent[name] = {
35-
requires: function(ignored) { return this; },
36-
toRun: function(code) { code(); }
37-
};
38-
return parent[name];
39-
};
40-
41-
Object.subclass = function(classPath /* + more args */ ) {
42-
var path = classPath.split("."),
43-
className = path.pop();
44-
var newClass = function() {
45-
if (this.initialize) this.initialize.apply(this, arguments);
46-
return this;
47-
};
48-
// skip arg 0, copy properties of other args to class proto
49-
for (var i = 1; i < arguments.length; i++)
50-
for (name in arguments[i])
51-
newClass.prototype[name] = arguments[i][name];
52-
module(path.join('.'))[className] = newClass;
53-
};
54-
55-
Object.extend = function(obj /* + more args */ ) {
56-
// skip arg 0, copy properties of other args to obj
57-
for (var i = 1; i < arguments.length; i++)
58-
for (name in arguments[i])
59-
obj[name] = arguments[i][name];
60-
};
61-
62-
//////////////////////////////////////////////////////////////////////////////
63-
// now for the good stuff
64-
//////////////////////////////////////////////////////////////////////////////
65-
6623
window.stopVM = false;
6724

6825
window.onload = function() {
@@ -141,12 +98,3 @@ window.onload = function() {
14198
};
14299
loadAndRunImage('benchmark.image');
143100
};
144-
145-
if (window.applicationCache) {
146-
applicationCache.addEventListener('updateready', function() {
147-
applicationCache.swapCache();
148-
if (confirm('SqueakJS has been updated. Restart now?')) {
149-
window.location.reload();
150-
}
151-
});
152-
}

demo/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
TARGET=../gh-pages/demo
77
MANIFEST=$(TARGET)/offline.appcache
8-
FILES=../vm.js simple.html simple.css simple.js SimplePlugin.js mini.image icon.png \
8+
FILES=../lib/squeak.js ../vm.js simple.html simple.css simple.js SimplePlugin.js mini.image icon.png \
99
../lib/lz-string.js ../lib/addtohomescreen.css ../lib/addtohomescreen.js ../lib/gh-fork-ribbon.css
1010
EXTRA=
1111

demo/simple.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
<link rel="stylesheet" href="simple.css">
3535
<script src="../lib/lz-string.js"></script>
36-
<script src="simple.js"></script>
36+
<script src="../lib/squeak.js"></script>
3737
<script src="../vm.js"></script>
38+
<script src="simple.js"></script>
3839
<script src="SimplePlugin.js"></script>
3940

4041
</head>

demo/simple.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,6 @@
2121
*/
2222

2323

24-
//////////////////////////////////////////////////////////////////////////////
25-
// these functions fake the Lively module and class system
26-
// just enough so the loading of vm.js succeeds
27-
//////////////////////////////////////////////////////////////////////////////
28-
29-
module = function(dottedPath) {
30-
if (dottedPath == "") return window;
31-
var path = dottedPath.split("."),
32-
name = path.pop(),
33-
parent = module(path.join("."));
34-
if (!parent[name]) parent[name] = {
35-
requires: function(ignored) { return this; },
36-
toRun: function(code) { code(); }
37-
};
38-
return parent[name];
39-
};
40-
41-
Object.subclass = function(classPath /* + more args */ ) {
42-
var path = classPath.split("."),
43-
className = path.pop();
44-
var newClass = function() {
45-
if (this.initialize) this.initialize.apply(this, arguments);
46-
return this;
47-
};
48-
// skip arg 0, copy properties of other args to class proto
49-
for (var i = 1; i < arguments.length; i++)
50-
for (name in arguments[i])
51-
newClass.prototype[name] = arguments[i][name];
52-
module(path.join('.'))[className] = newClass;
53-
};
54-
55-
Object.extend = function(obj /* + more args */ ) {
56-
// skip arg 0, copy properties of other args to obj
57-
for (var i = 1; i < arguments.length; i++)
58-
for (name in arguments[i])
59-
obj[name] = arguments[i][name];
60-
};
61-
62-
//////////////////////////////////////////////////////////////////////////////
63-
// now for the good stuff
64-
//////////////////////////////////////////////////////////////////////////////
65-
6624
var fullscreen = navigator.standalone;
6725

6826
window.onload = function() {
@@ -169,14 +127,6 @@ window.onload = function() {
169127
};
170128
run();
171129
};
172-
if (window.applicationCache) {
173-
applicationCache.addEventListener('updateready', function() {
174-
applicationCache.swapCache();
175-
if (confirm('SqueakJS has been updated. Restart now?')) {
176-
window.location.reload();
177-
}
178-
});
179-
}
180130
document.body.addEventListener('dragover', function(evt) {
181131
evt.stopPropagation();
182132
evt.preventDefault();

etoys/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
TARGET=../gh-pages/etoys
77
MANIFEST=$(TARGET)/offline.appcache
8-
FILES=../vm.js index.html etoys.css etoys.js etoys.png \
8+
FILES=../lib/squeak.js ../vm.js index.html etoys.css etoys.js etoys.png \
99
../lib/lz-string.js ../lib/addtohomescreen.css ../lib/addtohomescreen.js ../lib/gh-fork-ribbon.css
1010
EXTRA=http://freudenbergs.de/bert/squeakjs/etoys.image
1111

etoys/etoys.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,6 @@
2121
*/
2222

2323

24-
//////////////////////////////////////////////////////////////////////////////
25-
// these functions fake the Lively module and class system
26-
// just enough so the loading of vm.js succeeds
27-
//////////////////////////////////////////////////////////////////////////////
28-
29-
module = function(dottedPath) {
30-
if (dottedPath == "") return window;
31-
var path = dottedPath.split("."),
32-
name = path.pop(),
33-
parent = module(path.join("."));
34-
if (!parent[name]) parent[name] = {
35-
requires: function(ignored) { return this; },
36-
toRun: function(code) { code(); }
37-
};
38-
return parent[name];
39-
};
40-
41-
Object.subclass = function(classPath /* + more args */ ) {
42-
var path = classPath.split("."),
43-
className = path.pop();
44-
var newClass = function() {
45-
if (this.initialize) this.initialize.apply(this, arguments);
46-
return this;
47-
};
48-
// skip arg 0, copy properties of other args to class proto
49-
for (var i = 1; i < arguments.length; i++)
50-
for (name in arguments[i])
51-
newClass.prototype[name] = arguments[i][name];
52-
module(path.join('.'))[className] = newClass;
53-
};
54-
55-
Object.extend = function(obj /* + more args */ ) {
56-
// skip arg 0, copy properties of other args to obj
57-
for (var i = 1; i < arguments.length; i++)
58-
for (name in arguments[i])
59-
obj[name] = arguments[i][name];
60-
};
61-
62-
//////////////////////////////////////////////////////////////////////////////
63-
// now for the good stuff
64-
//////////////////////////////////////////////////////////////////////////////
65-
6624
var fullscreen = navigator.standalone;
6725

6826
window.onload = function() {
@@ -159,14 +117,6 @@ window.onload = function() {
159117
};
160118
return display;
161119
};
162-
if (window.applicationCache) {
163-
applicationCache.addEventListener('updateready', function() {
164-
applicationCache.swapCache();
165-
if (confirm('SqueakJS has been updated. Restart now?')) {
166-
window.location.reload();
167-
}
168-
});
169-
}
170120
function loadAndRunImage(url) {
171121
var imageName = Squeak.splitFilePath(url).basename;
172122
canvas.showBanner("Downloading " + imageName);

etoys/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
<link rel="stylesheet" href="etoys.css">
3535
<script src="../lib/lz-string.js"></script>
36-
<script src="etoys.js"></script>
36+
<script src="../lib/squeak.js"></script>
3737
<script src="../vm.js"></script>
38+
<script src="etoys.js"></script>
3839

3940
</head>
4041
<body>

lib/squeak.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2013,2014 Bert Freudenberg
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
24+
//////////////////////////////////////////////////////////////////////////////
25+
// these functions fake the Lively module and class system
26+
// just enough so the loading of vm.js succeeds
27+
//////////////////////////////////////////////////////////////////////////////
28+
29+
module = function(dottedPath) {
30+
if (dottedPath == "") return window;
31+
var path = dottedPath.split("."),
32+
name = path.pop(),
33+
parent = module(path.join("."));
34+
if (!parent[name]) parent[name] = {
35+
requires: function(ignored) { return this; },
36+
toRun: function(code) { code(); }
37+
};
38+
return parent[name];
39+
};
40+
41+
Object.subclass = function(classPath /* + more args */ ) {
42+
var path = classPath.split("."),
43+
className = path.pop();
44+
var newClass = function() {
45+
if (this.initialize) this.initialize.apply(this, arguments);
46+
return this;
47+
};
48+
// skip arg 0, copy properties of other args to class proto
49+
for (var i = 1; i < arguments.length; i++)
50+
for (name in arguments[i])
51+
newClass.prototype[name] = arguments[i][name];
52+
module(path.join('.'))[className] = newClass;
53+
};
54+
55+
Object.extend = function(obj /* + more args */ ) {
56+
// skip arg 0, copy properties of other args to obj
57+
for (var i = 1; i < arguments.length; i++)
58+
for (name in arguments[i])
59+
obj[name] = arguments[i][name];
60+
};
61+
62+
//////////////////////////////////////////////////////////////////////////////
63+
// browser stuff
64+
//////////////////////////////////////////////////////////////////////////////
65+
66+
if (window.applicationCache) {
67+
applicationCache.addEventListener('updateready', function() {
68+
applicationCache.swapCache();
69+
if (confirm('SqueakJS has been updated. Restart now?')) {
70+
window.location.reload();
71+
}
72+
});
73+
}

0 commit comments

Comments
 (0)