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

Convert to external version of Snowboard #980

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
17 changes: 17 additions & 0 deletions modules/backend/assets/ui/js/ajax/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { delegate } from 'jquery-events-to-dom-events';
* Functions:
* - Adds the "render" jQuery event to Snowboard requests that widgets use to initialise.
* - Ensures the CSRF token is included in requests.
* - Initialises controls within AJAX-changed partials.
*
* @copyright 2021 Winter.
* @author Ben Thomson <[email protected]>
Expand All @@ -23,6 +24,7 @@ export default class Handler extends Snowboard.Singleton {
listens() {
return {
ready: 'ready',
ajaxUpdate: 'onAjaxUpdate',
ajaxFetchOptions: 'ajaxFetchOptions',
ajaxUpdateComplete: 'ajaxUpdateComplete',
};
Expand All @@ -43,6 +45,10 @@ export default class Handler extends Snowboard.Singleton {
document.addEventListener('$render', () => {
this.snowboard.globalEvent('render');
});
delegate('ajaxUpdate', ['event', 'context', 'data', 'status', 'xhr']);
document.addEventListener('$ajaxUpdate', (event) => {
this.snowboard.globalEvent('ajaxUpdate', event.target, event.detail.data);
});

// Add "render" event for backwards compatibility
window.jQuery(document).trigger('render');
Expand Down Expand Up @@ -121,4 +127,15 @@ export default class Handler extends Snowboard.Singleton {
getToken() {
return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
}

/**
* AJAX update handler.
*
* Initializes widgets inside an update element from an AJAX response.
*
* @param {HTMLElement} element
*/
onAjaxUpdate(element) {
this.snowboard['backend.ui.controls']().initializeControls(element);
}
}
4 changes: 3 additions & 1 deletion modules/backend/assets/ui/js/build/backend.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/backend/assets/ui/js/build/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion modules/backend/assets/ui/js/build/vendor.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions modules/backend/assets/ui/js/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import * as Vue from 'vue';
import { Control, ControlHandler } from '@wintercms/snowboard-controls';
import BackendAjaxHandler from './ajax/Handler';
import BackendUiEventHandler from './ui/EventHandler';
import BackendUiWidgetHandler from './ui/WidgetHandler';

if (window.Snowboard === undefined) {
throw new Error('Snowboard must be loaded in order to use the Backend UI.');
}

((Snowboard) => {
Snowboard.addPlugin('backend.ajax.handler', BackendAjaxHandler);
Snowboard.addPlugin('backend.ui.eventHandler', BackendUiEventHandler);
Snowboard.addPlugin('backend.ui.widgetHandler', BackendUiWidgetHandler);
Snowboard.addPlugin('backend.ui.controls', ControlHandler);
Snowboard.addAbstract('WinterControl', Control);

// Add the pre-filter immediately
Snowboard['backend.ajax.handler']().addPrefilter();
Expand Down
116 changes: 0 additions & 116 deletions modules/backend/assets/ui/js/ui/EventHandler.js

This file was deleted.

181 changes: 0 additions & 181 deletions modules/backend/assets/ui/js/ui/WidgetHandler.js

This file was deleted.

Large diffs are not rendered by default.

Loading
Loading