Skip to content

Commit

Permalink
* xover.listener.dispatcher
Browse files Browse the repository at this point in the history
  - added support !! operator
  - bugs fixed
* xover.listener.Event - reallocated srcElement and defaults to target
  • Loading branch information
uriel-online committed Aug 12, 2024
1 parent e88c55c commit 618c571
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions xo.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ xover.listener.Event = function (event_name, params = {}, context = (event || {}
}
})
if (_event.detail) {
_event.detail["srcElement"] = _event.detail["srcElement"] || (event || {}).srcElement;
_event.detail["designMode"] = _event.detail.hasOwnProperty("designMode") ? _event.detail["designMode"] : document.designMode == 'on';
if (context instanceof Attr) {
_event.detail["element"] = _event.detail["element"] || context.parentNode;
Expand Down Expand Up @@ -1016,6 +1015,7 @@ xover.listener.Event = function (event_name, params = {}, context = (event || {}
_event.detail["previousNode"] = _event.detail.hasOwnProperty("previousNode") ? _event.detail["previousNode"] : context.previousNode;
_event.detail["node"] = _event.detail["node"] || context;
_event.detail["target"] = _event.detail["target"] || context;
_event.detail["srcElement"] = _event.detail["srcElement"] || (event || {}).srcElement || _event.detail["target"];
_event.detail["document"] = _event.detail["document"] || context.ownerDocument;
node = context
}
Expand Down Expand Up @@ -1206,16 +1206,17 @@ Object.defineProperty(xover.listener, 'dispatcher', {
operator = key[key.length - 1];
key = key.slice(0, -1);
} else if (!condition && ["*", "!"].includes(key[0])) {
operator = key[0];
key = key.slice(1);
operator = key.match(/^[!|*]*/)[0];
key = key.slice(operator.length);
}
let [arg, ...props] = key.split(/(?<=[\w\d])\./g);
let context = event.detail[arg];
if (context === undefined && arg in window) {
context = window[arg]
context = window;
props.unshift(arg);
}
try {
if (props.length) {
if (context && props.length) {
with (context) {
context = eval(props.join('.'))
}
Expand All @@ -1229,15 +1230,20 @@ Object.defineProperty(xover.listener, 'dispatcher', {
if (context instanceof Document) {
context = (context.href || '').replace(/^\//, '')
}
if (context == undefined) return false;
if (!condition) {
switch (operator) {
case "!!":
return !!context
case "!":
return !context
default:
return context
}
} else {
switch (operator) {
case "!!":
return !!(context instanceof Node ? context : `${context}`).matches(`${condition}`)
case "!":
return !(context instanceof Node ? context : `${context}`).matches(`${condition}`)
case "*":
Expand Down Expand Up @@ -1360,7 +1366,14 @@ Object.defineProperty(xover.listener, 'on', {
handler.scope = scope && eval(scope) || undefined;
handler.conditions = handler.conditions || conditions && [] || undefined;
for (let condition of conditions) {
handler.conditions.push(new URLSearchParams("?" + condition));
let params;
if ('!'.includes(condition[0])) {
params = new URLSearchParams("?")
params.set(condition,"")
} else {
params = new URLSearchParams("?" + condition)
}
handler.conditions.push(params);
}

let event_array = xover.listener.get(base_event) || new Map();
Expand Down

0 comments on commit 618c571

Please sign in to comment.