Skip to content

Commit d9f6d82

Browse files
committed
Port Ajaxifier to modern JavaScript
- Remove dependency on jQuery - Remove dedicated code in render phase continuation
1 parent 7fcdcd6 commit d9f6d82

File tree

15 files changed

+100
-100
lines changed

15 files changed

+100
-100
lines changed

repository/BaselineOfSeaside3.package/BaselineOfSeaside3.class/instance/baselinejavascript..st

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ baselinejavascript: spec
77
package: 'Javascript-Core' with: [
88
spec requires: #('Seaside-Core' 'Seaside-Canvas' ) ];
99
package: 'Javascript-Tests-Core' with: [
10-
spec requires: #('Javascript-Core' 'Seaside-Tests-Core' ) ].
10+
spec requires: #('Javascript-Core' 'Seaside-Tests-Core' ) ];
11+
package: 'Seaside-Ajaxifier-Core' with: [
12+
spec requires: #('Seaside-Core') ].
1113
spec
1214
group: 'Javascript' with: #('Javascript-Core');
1315
group: 'Javascript Tests' with: #('Javascript-Tests-Core' );
14-
group: 'Tests' with: #( 'Javascript Tests' ) ].
16+
group: 'Tests' with: #( 'Javascript Tests' );
17+
group: 'Ajaxifier' with: #( 'Seaside-Ajaxifier-Core' ) ].
1518

1619
spec for: #squeak do: [
1720
spec
@@ -47,4 +50,4 @@ baselinejavascript: spec
4750
package: 'Javascript-Core'
4851
with: [ spec includes: #('Javascript-GemStone-Core') ];
4952
package: 'Javascript-GemStone-Core'
50-
with: [ spec requires: #('Javascript-Core') ] ].
53+
with: [ spec requires: #('Javascript-Core') ] ].

repository/BaselineOfSeaside3.package/BaselineOfSeaside3.class/instance/baselinejquery..st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ baselinejquery: spec
77
package: 'JQuery-Core' with: [
88
spec requires: #('Javascript-Core' ) ];
99
package: 'JQuery-Tests-Core' with: [
10-
spec requires: #('JQuery-Core' 'Javascript-Tests-Core' 'Seaside-Development' 'Seaside-Tests-Functional') ];
10+
spec requires: #('JQuery-Core' 'Javascript-Tests-Core' 'Seaside-Development' 'Seaside-Tests-Functional' 'Seaside-Ajaxifier-Core') ];
1111
package: 'JQuery-JSON' with: [
1212
spec requires: #('JQuery-Core' 'Seaside-JSON-Core') ];
1313
package: 'JQuery-Tests-JSON' with: [

repository/JQuery-Core.package/JQAjaxifierLibrary.class/instance/ajaxifierJs.st

Lines changed: 0 additions & 84 deletions
This file was deleted.

repository/JQuery-Tests-Core.package/JQAllFunctionalTests.class/class/initialize.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ initialize
1212
application
1313
preferenceAt: #sessionClass put: WAExpirySession;
1414
addLibrary: JQDeploymentLibrary;
15-
addLibrary: JQAjaxifierLibrary
15+
addLibrary: WAAjaxifierLibrary
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"separateMethodMetaAndSource" : false,
3+
"noMethodMetaData" : true,
4+
"useCypressPropertiesFile" : true
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I ajaxify a web application by turning full page requests into background AJAX requests.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
uploads
2+
ajaxifierJs
3+
^ '/* JavaScript based Ajaxifier
4+
* Copyright (c) 2008 Lukas Renggli, [email protected]
5+
* Copyright (c) 2022 Philippe Marschall, [email protected]
6+
*/
7+
8+
window.addEventListener("DOMContentLoaded", (loadEvent) => {
9+
10+
// variables
11+
let activeHash = "";
12+
13+
// ajax action
14+
function load(type, url, data, modifyHistory) {
15+
const xhr = new XMLHttpRequest();
16+
17+
xhr.responseType = "document"
18+
xhr.addEventListener("load", (event) => {
19+
if (xhr.status === 200) {
20+
Array.from(xhr.response.head.children).forEach((child) => {
21+
if (child.nodeType === Node.ELEMENT_NODE && child.nodeName === "SCRIPT") {
22+
child.remove();
23+
}
24+
});
25+
document.head.innerHTML = xhr.response.head;
26+
document.body = xhr.response.body;
27+
28+
if (modifyHistory) {
29+
const path = xhr.responseURL;
30+
window.history.pushState(path, null, path);
31+
}
32+
}
33+
});
34+
35+
xhr.open(type, url);
36+
37+
// WAActionCallback per default are disabled for AJAX requests
38+
// Detection happens with X-Requested-With so we override it
39+
xhr.setRequestHeader("X-Requested-With", "Ajaxifier");
40+
xhr.send(data);
41+
}
42+
43+
// click handler
44+
document.addEventListener("click", (event) => {
45+
46+
// links
47+
const anchor = event.target.closest("a");
48+
if (anchor !== null) {
49+
load("GET", anchor.getAttribute("href"), null, true);
50+
event.preventDefault();
51+
return;
52+
}
53+
54+
// submit
55+
const submit = event.target.closest("input[type=submit], button[type=submit]");
56+
if (submit !== null) {
57+
const form = submit.closest("form");
58+
if (form !== null) {
59+
const formData = new FormData(form);
60+
formData.append(submit.getAttribute("name"), "");
61+
load("POST", form.getAttribute("action"), formData, true);
62+
event.preventDefault();
63+
}
64+
}
65+
66+
});
67+
68+
// check for changes in the hash
69+
setInterval(() => {
70+
const currentHash = window.location.hash.substr(1);
71+
if (currentHash !== activeHash)
72+
load("GET", "?" + (activeHash = currentHash), null, true);
73+
}, 250);
74+
75+
// We assume nobody else will override onpopstate... since we are LIKELY the only ones to use pushstate etc.
76+
window.onpopstate = (event) => {
77+
load("GET", event.state, null, false);
78+
}
79+
80+
});'
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"commentStamp" : "",
2+
"commentStamp" : "pmm 8/25/2022 15:03",
33
"super" : "WAFileLibrary",
4-
"category" : "JQuery-Core-Libraries",
4+
"category" : "Seaside-Ajaxifier-Core",
55
"classinstvars" : [ ],
66
"pools" : [ ],
77
"classvars" : [ ],
88
"instvars" : [ ],
9-
"name" : "JQAjaxifierLibrary",
9+
"name" : "WAAjaxifierLibrary",
1010
"type" : "normal"
1111
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SystemOrganization addCategory: #'Seaside-Ajaxifier-Core'!

0 commit comments

Comments
 (0)