Skip to content

Commit

Permalink
Merge pull request #1337 from marschall/ajaxifier
Browse files Browse the repository at this point in the history
Port Ajaxifier to modern JavaScript
  • Loading branch information
Johan Brichau authored Sep 16, 2022
2 parents ede65a3 + 262d49c commit 8e1003c
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ baselinejavascript: spec
package: 'Javascript-Core' with: [
spec requires: #('Seaside-Core' 'Seaside-Canvas' ) ];
package: 'Javascript-Tests-Core' with: [
spec requires: #('Javascript-Core' 'Seaside-Tests-Core' ) ].
spec requires: #('Javascript-Core' 'Seaside-Tests-Core' ) ];
package: 'Seaside-Ajaxifier-Core' with: [
spec requires: #('Seaside-Core') ].
spec
group: 'Javascript' with: #('Javascript-Core');
group: 'Javascript Tests' with: #('Javascript-Tests-Core' );
group: 'Tests' with: #( 'Javascript Tests' ) ].
group: 'Tests' with: #( 'Javascript Tests' );
group: 'Ajaxifier' with: #( 'Seaside-Ajaxifier-Core' ) ].

spec for: #squeak do: [
spec
Expand Down Expand Up @@ -47,4 +50,4 @@ baselinejavascript: spec
package: 'Javascript-Core'
with: [ spec includes: #('Javascript-GemStone-Core') ];
package: 'Javascript-GemStone-Core'
with: [ spec requires: #('Javascript-Core') ] ].
with: [ spec requires: #('Javascript-Core') ] ].
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ baselinejquery: spec
package: 'JQuery-Core' with: [
spec requires: #('Javascript-Core' ) ];
package: 'JQuery-Tests-Core' with: [
spec requires: #('JQuery-Core' 'Javascript-Tests-Core' 'Seaside-Development' 'Seaside-Tests-Functional') ];
spec requires: #('JQuery-Core' 'Javascript-Tests-Core' 'Seaside-Development' 'Seaside-Tests-Functional' 'Seaside-Ajaxifier-Core') ];
package: 'JQuery-JSON' with: [
spec requires: #('JQuery-Core' 'Seaside-JSON-Core') ];
package: 'JQuery-Tests-JSON' with: [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ initialize
application
preferenceAt: #sessionClass put: WAExpirySession;
addLibrary: JQDeploymentLibrary;
addLibrary: JQAjaxifierLibrary
addLibrary: WAAjaxifierLibrary
5 changes: 5 additions & 0 deletions repository/Seaside-Ajaxifier-Core.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I ajaxify a web application by turning full page requests into background AJAX requests.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
uploads
ajaxifierJs
^ '/* JavaScript based Ajaxifier
* Copyright (c) 2008 Lukas Renggli, [email protected]
* Copyright (c) 2022 Philippe Marschall, [email protected]
*/
"use strict";
window.addEventListener("DOMContentLoaded", (loadEvent) => {
// variables
let activeHash = "";
// ajax action
function load(type, url, data, modifyHistory) {
const xhr = new XMLHttpRequest();
xhr.responseType = "document"
xhr.addEventListener("load", (event) => {
if (xhr.status === 200) {
Array.from(xhr.response.head.children).forEach((child) => {
if (child.nodeType === Node.ELEMENT_NODE && child.nodeName === "SCRIPT") {
child.remove();
}
});
document.head.innerHTML = xhr.response.head.innerHTML;
document.body = xhr.response.body;
if (modifyHistory) {
const path = xhr.responseURL;
window.history.pushState(path, null, path);
}
}
});
xhr.open(type, url);
// WAActionCallback per default are disabled for AJAX requests
// Detection happens with X-Requested-With so we override it
xhr.setRequestHeader("X-Requested-With", "Ajaxifier");
xhr.send(data);
}
// click handler
document.addEventListener("click", (event) => {
// links
const anchor = event.target.closest("a");
if (anchor !== null) {
load("GET", anchor.getAttribute("href"), null, true);
event.preventDefault();
return;
}
// submit
const submit = event.target.closest("input[type=submit], button[type=submit]");
if (submit !== null) {
const form = submit.closest("form");
if (form !== null) {
const formData = new FormData(form);
formData.append(submit.getAttribute("name"), "");
load("POST", form.getAttribute("action"), formData, true);
event.preventDefault();
}
}
});
// check for changes in the hash
setInterval(() => {
const currentHash = window.location.hash.substr(1);
if (currentHash !== activeHash)
load("GET", "?" + (activeHash = currentHash), null, true);
}, 250);
// We assume nobody else will override onpopstate... since we are LIKELY the only ones to use pushstate etc.
window.onpopstate = (event) => {
load("GET", event.state, null, false);
}
});'
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commentStamp" : "",
"commentStamp" : "pmm 8/25/2022 15:03",
"super" : "WAFileLibrary",
"category" : "JQuery-Core-Libraries",
"category" : "Seaside-Ajaxifier-Core",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "JQAjaxifierLibrary",
"name" : "WAAjaxifierLibrary",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SystemOrganization addCategory: #'Seaside-Ajaxifier-Core'!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'Seaside-Ajaxifier-Core')
1 change: 1 addition & 0 deletions repository/Seaside-Ajaxifier-Core.package/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ }

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
handling
handleFiltered: aRequestContext
self addRedirectedToHeader: aRequestContext.
self respond: [ :response | self processRendering: response ].

"The render phase should have returned a response"
Expand Down

0 comments on commit 8e1003c

Please sign in to comment.