Skip to content

Commit 5e8c20e

Browse files
Jeremy GrelleJeremy Grelle
Jeremy Grelle
authored and
Jeremy Grelle
committed
Final polishing for JavaOne demo
1 parent 009e91b commit 5e8c20e

File tree

4 files changed

+29
-94
lines changed

4 files changed

+29
-94
lines changed

src/main/webapp/WEB-INF/layouts/html5-default.jspx

+22-52
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:spring="http://www.springframework.org/tags" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util">
1+
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:spring="http://www.springframework.org/tags" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" manifest="cache.manifest">
22

33
<jsp:output doctype-root-element="HTML" doctype-system="about:legacy-compat" />
44

@@ -19,34 +19,25 @@
1919
dojo.require("dijit.form.FilteringSelect");
2020
dojo.require("dijit.form.Form");
2121
dojo.addOnLoad(function(){
22-
dojo.declare("Model", null, {
23-
data : null,
24-
25-
constructor : function(url, callback) {
26-
var resultHandler = this.load;
27-
var onload = (!callback ? function(){} : callback);
28-
var deferred = dojo.xhrGet({
29-
url : url.match(/.*[^\?form]/)[0],
22+
23+
var controller = {
24+
basePath : location.protocol + "//" + location.host + "/" + (location.pathname.search(/spring-html5/) > -1 ? "spring-html5/" : ""),
3025

26+
getModel : function(url) {
27+
return dojo.xhrGet({
28+
url : url.match(/.*[^\?form]/)[0],
29+
3130
preventCache : true,
32-
31+
3332
handleAs : "json",
34-
33+
3534
headers : {
3635
"Content-Type": "application/json",
3736
"Accept": "application/json"
3837
}
3938
});
40-
var that = this;
41-
deferred.addCallback(function(result){
42-
that.data = result;
43-
onload();
44-
});
45-
}
46-
});
47-
48-
var controller = {
49-
basePath : location.protocol + "//" + location.host + "/" + (location.pathname.search(/spring-html5/) > -1 ? "spring-html5/" : ""),
39+
},
40+
5041
getView : function(url) {
5142
var view = { requiresModel : true };
5243
var hasIdentifier = false;
@@ -75,35 +66,11 @@
7566
view.template = template;
7667
return dojo.isFunction(view.template) ? view : null;
7768
},
69+
7870
renderView : function(view, url) {
79-
if (view.requiresModel) {
80-
var model = new Model(url, function(){
81-
var content = view.template.apply(window, [{model : model.data}]);
82-
dojo.html.set(main, content, {parseContent:true,
83-
onBegin: function(){
84-
var existing = dijit.byId("content");
85-
if (existing) {
86-
existing.destroyRecursive();
87-
}
88-
},
89-
onEnd: function(){
90-
this.inherited("onEnd", arguments);
91-
dojo.query("#content a").forEach(function(navItem) {
92-
dojo.connect(navItem, "onclick", function(e) {
93-
var main = dojo.byId("main");
94-
var view = controller.getView(navItem.href);
95-
if (view) {
96-
dojo.stopEvent(e);
97-
controller.renderView(view, navItem.href);
98-
}
99-
});
100-
});
101-
dijit.byId("content").toggle();
102-
}
103-
});
104-
});
105-
} else {
106-
var content = view.template.apply(window, [{}]);
71+
var model = view.requiresModel ? controller.getModel(url) : null;
72+
dojo.when(model, function(model){
73+
var content = view.template.apply(window, [{model : model}]);
10774
dojo.html.set(main, content, {parseContent:true,
10875
onBegin: function(){
10976
var existing = dijit.byId("content");
@@ -123,16 +90,18 @@
12390
}
12491
});
12592
});
93+
12694
dijit.byId("content").toggle();
12795
}
128-
12996
});
130-
}
97+
});
98+
13199
if(location.href != url) {
132-
history.pushState({}, "", url);
100+
history.pushState({}, "view", url);
133101
}
134102
}
135103
};
104+
136105
dojo.query("a.menuItem").forEach(function(menuItem) {
137106
dojo.connect(menuItem, "onclick", function(e) {
138107
var main = dojo.byId("main");
@@ -143,6 +112,7 @@
143112
}
144113
});
145114
});
115+
146116
dojo.connect(window, "onpopstate", function(e){
147117
if(location.href.search(/html5-index/) > -1) {
148118
location.reload();

src/main/webapp/activity/Activity.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
</STYLE>
5050
</HEAD>
5151
<BODY>
52-
<H1>activity</H1>
52+
<H1>Spring 3.0 SVN Commit Activity</H1>
5353
<CANVAS id="glow" width="1000" height="500"></CANVAS>
54-
<P id="date">Sun 21 Sep 2008<BR>11:38 AM
54+
<P id="date">
5555
</P>
56-
<P id="footer">Derived from an example created by <A
56+
<P id="footer">Derived from an <A href="">example</A> created by <A
5757
href="http://www.mattryall.net/">Matt Ryall</A> with <A
5858
href="http://ejohn.org/blog/processingjs/">Processing.js</A></P>
5959

src/main/webapp/activity/activity.js

+3-36
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Array.prototype.remove = function(from, to) {
88

99
jQuery(function($) {
1010
var el = document.getElementById("glow");
11-
var frameRate = 30;
11+
var frameRate = 45;
1212
//var speed = 5; // average # of messages per second
1313
var width = el.width;
1414
var height = el.height;
@@ -47,15 +47,15 @@ jQuery(function($) {
4747
}
4848
p.noStroke();
4949
whiteText("overall activity", 20, fontSize * 1.5);
50-
whiteText("module", width - font.width("module") * fontSize
50+
whiteText("author", width - font.width("author") * fontSize
5151
* 1.5, bottom + height / 10 + fontSize * 1.2);
5252
}
5353
}
5454
};
5555
components.push(new Axes());
5656

5757
var Circle = function Circle(height, author) {
58-
var maxAge = 100;
58+
var maxAge = 50;
5959
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.".split("");
6060
var x = 0;
6161
for ( var i = 0; i < 3; i++)
@@ -124,51 +124,18 @@ jQuery(function($) {
124124
return t;
125125
}
126126

127-
/*var Glow = function Glow(commits) {
128-
var mindate = commits[0].date.getTime();
129-
var maxdate = mindate + commits[commits.length - 1].date.getTime();
130-
var frames = commits.length * frameRate / speed;
131-
var datedelta = (maxdate - mindate) / frames;
132-
var frame = 0;
133-
return {
134-
update: function () {
135-
frame++;
136-
var d = mindate + frame * datedelta;
137-
var last = null;
138-
while (commits.length > 0 && commits[0].date.getTime() <= d) {
139-
var c = commits.shift();
140-
if (!last || last.module != c.module || last.date.getTime() != c.date.getTime()) {
141-
last = c;
142-
console.debug("Pushing circle for " + c.module + " at " + c.date.getTime());
143-
components.push(new Circle(components.length, c.module));
144-
}
145-
}
146-
if (frame % 5 == 0)
147-
$("#date").html(formatDate(new Date(d)) + "<br/>" + formatTime(new Date(d)));
148-
},
149-
draw: function () {
150-
p.background(0, 15);
151-
}
152-
};
153-
};*/
154-
155127
var Glow = function Glow() {
156128
return {
157129
update : function() {
158130
var c = commits.shift();
159131
if (c) {
160-
/*if (window.console) {
161-
console.debug("Pushing circle #"+c.order+" for " + c.module + " at "
162-
+ c.date.getTime());
163-
}*/
164132
components.push(new Circle(components.length, c.author));
165133
$("#date").html(
166134
formatDate(c.date) + "<br/>" + formatTime(c.date));
167135
}
168136
},
169137
draw : function() {
170138
p.background(0, 15);
171-
//p.background(0, 0, 0, 100);
172139
}
173140
};
174141
};

src/main/webapp/activity/commitProcessor.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function start(offline) {
1111
var connectionFailed = false;
1212
var messagesReceived = false;
1313
if (!self.WebSocket || offline) {
14+
postMessage("Reverting to cached data.js");
1415
importScripts("data.js");
1516
data.reverse();
1617
for ( var i = 0; i < data.length; i++) {
@@ -48,9 +49,6 @@ function start(offline) {
4849
}
4950
socket.onclose = function(event) {
5051
postMessage("Connection to "+messageChannelUrl+" was closed.");
51-
if (connectionFailed && !messagesReceived) {
52-
postMessage("Reverting to cached data.js");
53-
}
5452
start(true);
5553
}
5654
}

0 commit comments

Comments
 (0)