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

Rewrite and expand input trigger functionality #1163

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
16e2d20
WIP rewrite
bennothommo Jul 14, 2024
399bc5b
Add initial conditions and actions
bennothommo Jul 15, 2024
97bcd09
Add event prioritisation, refactor connecting of elements to triggers…
bennothommo Jul 15, 2024
385f43e
Minor
bennothommo Jul 15, 2024
6b19152
Allow for multiple conditions and actions in a single trigger
bennothommo Jul 16, 2024
377ef22
Support data-trigger-do
bennothommo Jul 16, 2024
2ddafc6
Allow upper limit for checked/unchecked condition, minor docs tweaks
bennothommo Jul 16, 2024
0894e7b
Refactor actions to allow targeted elements for actions
bennothommo Jul 16, 2024
12294bb
Merge remote-tracking branch 'origin/develop' into wip/trigger-rewrite
bennothommo Jul 17, 2024
a73cfc5
Add focused condition
bennothommo Jul 17, 2024
bb95ba7
Add extensibility (mainly for actions), use a friendly show/hide func…
bennothommo Jul 17, 2024
3d2274f
Add a trigger handler for the backend to bridge between old and new T…
bennothommo Jul 17, 2024
64ec3dd
Remove old trigger functionality
bennothommo Jul 17, 2024
e6f0029
Rebuild assets
bennothommo Jul 17, 2024
14f4b59
Fix code style issues and missing variable
bennothommo Jul 17, 2024
b455840
One comma, man, one comma
bennothommo Jul 17, 2024
2e3cab6
Merge branch 'develop' into wip/trigger-rewrite
bennothommo Jul 19, 2024
7635ca3
Allow upper checked limit to be 1 as well
bennothommo Jul 19, 2024
1319d58
Allow trigger actions to be one-way
bennothommo Jul 19, 2024
0107abb
Initial work on within/notWithin triggers
bennothommo Jul 19, 2024
b5afa3b
Merge remote-tracking branch 'origin/develop' into wip/trigger-rewrite
bennothommo Jul 30, 2024
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
2 changes: 1 addition & 1 deletion modules/backend/assets/ui/js/build/backend.js

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

15 changes: 8 additions & 7 deletions modules/backend/assets/ui/js/build/vendor.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions modules/backend/assets/ui/js/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Vue from 'vue';
import BackendAjaxHandler from './ajax/Handler';
import BackendUiEventHandler from './ui/EventHandler';
import BackendInputTriggerHandler from './input/TriggerHandler';
import BackendUiWidgetHandler from './ui/WidgetHandler';

if (window.Snowboard === undefined) {
Expand All @@ -10,6 +11,7 @@ if (window.Snowboard === undefined) {
((Snowboard) => {
Snowboard.addPlugin('backend.ajax.handler', BackendAjaxHandler);
Snowboard.addPlugin('backend.ui.eventHandler', BackendUiEventHandler);
Snowboard.addPlugin('backend.input.triggerHandler', BackendInputTriggerHandler);
Snowboard.addPlugin('backend.ui.widgetHandler', BackendUiWidgetHandler);

// Add the pre-filter immediately
Expand Down
89 changes: 89 additions & 0 deletions modules/backend/assets/ui/js/input/TriggerHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { delegate } from 'jquery-events-to-dom-events';

/**
* Backend trigger handler.
*
* Registers the usage of the new Trigger functionality, whilst mapping the old jQuery-style events
* to the new functionality.
*
* @copyright 2024 Winter.
* @author Ben Thomson <git@alfreido.com>
*/
export default class TriggerHandler extends Snowboard.Singleton {
construct() {
this.changedElements = new Set();
}

/**
* Listeners.
*
* @returns {Object}
*/
listens() {
return {
ready: 'onReady',
render: 'setUpTriggers',
'trigger.action': 'onTriggerAction',
};
}

onReady() {
delegate('oc.triggerOn.update');

/**
* A number of widgets trigger a change event on a hidden element when they are updated,
* however, this change event is a jQuery "change" event, not the native DOM "change" event.
*
* The following intercepts the jQuery event and dispatches a native event as well.
*/
delegate('change');
document.addEventListener('$change', (event) => {
if (event.throughTrigger) {
return;
}

const newEvent = new InputEvent('change');
newEvent.throughTrigger = true;
event.target.dispatchEvent(newEvent);
});

this.setUpTriggers();
}

setUpTriggers() {
// Scan for triggers
Array
.from(document.querySelectorAll('*'))
.filter(
(element) => [...element.attributes].filter(
({ name }) => name.startsWith('data-trigger-'),
).length > 0,
).forEach((element) => {
const trigger = this.snowboard.trigger(element);
element.addEventListener('$oc.triggerOn.update', () => {
trigger.runEvents(element);
});
});
}

onTriggerAction(element, trigger, action, conditionMet) {
if (action.name === 'show' || action.name === 'hide') {
this.actionShow(
(action.parameters[0])
? Array.from(element.querySelectorAll(action.parameters[0]))
: [element],
(action.name === 'show') ? conditionMet : !conditionMet,
);
}
}

actionShow(elements, show) {
elements.forEach((element) => {
if (show && element.classList.contains('hide')) {
element.classList.remove('hide');
} else if (!show && !element.classList.contains('hide')) {
element.classList.add('hide');
}
});
}
}
6 changes: 3 additions & 3 deletions 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.

Large diffs are not rendered by default.

Loading
Loading