forked from wintercms/winter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attach original AJAX framework events to Snowboard in Backend (winter…
…cms#1235) Replaces wintercms#1234, fixes wintercms#1233. Instead of loading framework.extras.css, which appears to be excluded from the Backend, this PR hooks the necessary original AJAX framework events into Snowboard's events, allowing the applicable events to execute UI functionality such as data-attach-loading and the Stripe loader. This is technically a stop-gap solution for now, since it doesn't emulate a full Snowboard request, so there's the potential for custom Snowboard event listeners to break if they are relying on Snowboard request information, but I'm not aware of that happening yet in core.
- Loading branch information
1 parent
7bf56db
commit 4ff066f
Showing
13 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,20 @@ import { delegate } from 'jquery-events-to-dom-events'; | |
* | ||
* Functions: | ||
* - Adds the "render" jQuery event to Snowboard requests that widgets use to initialise. | ||
* - Hooks into the main jQuery AJAX workflow events of the original AJAX framework (`ajaxPromise` at the beginning | ||
* of an AJAX request, `ajaxDone`/`ajaxRedirected`/`ajaxFail` at the end of the beginning of an AJAX requests) | ||
* and simulates comparable Snowboard events to allow Snowboard functionality that acts on AJAX events to | ||
* to function in the Backend (Flash messages, loader bar) | ||
* - Ensures the CSRF token is included in requests. | ||
* | ||
* @copyright 2021 Winter. | ||
* @author Ben Thomson <[email protected]> | ||
*/ | ||
export default class Handler extends Snowboard.Singleton { | ||
construct() { | ||
this.requests = []; | ||
} | ||
|
||
/** | ||
* Event listeners. | ||
* | ||
|
@@ -46,6 +54,42 @@ export default class Handler extends Snowboard.Singleton { | |
|
||
// Add "render" event for backwards compatibility | ||
window.jQuery(document).trigger('render'); | ||
|
||
// Add global events for AJAX queries and route them to the Snowboard global events and | ||
// necessary UI functionality | ||
delegate('ajaxPromise', ['event', 'context']); | ||
delegate('ajaxDone', ['event', 'context', 'data']); | ||
delegate('ajaxRedirected', ['event']); | ||
delegate('ajaxFail', ['event', 'context', 'textStatus']); | ||
|
||
document.addEventListener('$ajaxPromise', (event) => { | ||
this.requests[event.target] = Promise.withResolvers(); | ||
this.snowboard.globalEvent('ajaxStart', this.requests[event.target].promise, { | ||
element: event.target, | ||
options: {}, | ||
}); | ||
}); | ||
document.addEventListener('$ajaxDone', (event) => { | ||
this.requests[event.target].resolve(event.detail.data); | ||
this.snowboard.globalEvent('ajaxDone', event.detail.data, { | ||
element: event.target, | ||
options: {}, | ||
}); | ||
}); | ||
document.addEventListener('$ajaxRedirected', (event) => { | ||
this.requests[event.target].resolve(); | ||
this.snowboard.globalEvent('ajaxDone', event.detail.data, { | ||
element: event.target, | ||
options: {}, | ||
}); | ||
}); | ||
document.addEventListener('$ajaxFail', (event) => { | ||
this.requests[event.target].reject(event.detail.textStatus); | ||
this.snowboard.globalEvent('ajaxDone', event.detail.data, { | ||
element: event.target, | ||
options: {}, | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
modules/backend/formwidgets/codeeditor/assets/js/build-min.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
modules/backend/formwidgets/fileupload/assets/css/fileupload.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.