Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Ajaxifier to modern JavaScript #1337

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
jbrichau marked this conversation as resolved.
Show resolved Hide resolved
"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