Skip to content

Commit

Permalink
Fix parseAndCacheTrigger indentation as discussed in bigskysoftware#1540
Browse files Browse the repository at this point in the history
  • Loading branch information
Telroshan committed Dec 14, 2023
1 parent 7866258 commit 06c3ced
Showing 1 changed file with 76 additions and 76 deletions.
152 changes: 76 additions & 76 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,89 +1259,89 @@ return (function () {
*/
function parseAndCacheTrigger(elt, explicitTrigger, cache) {
var triggerSpecs = [];
var tokens = tokenizeString(explicitTrigger);
do {
consumeUntil(tokens, NOT_WHITESPACE);
var initialLength = tokens.length;
var trigger = consumeUntil(tokens, /[,\[\s]/);
if (trigger !== "") {
if (trigger === "every") {
var every = {trigger: 'every'};
consumeUntil(tokens, NOT_WHITESPACE);
every.pollInterval = parseInterval(consumeUntil(tokens, /[,\[\s]/));
consumeUntil(tokens, NOT_WHITESPACE);
var eventFilter = maybeGenerateConditional(elt, tokens, "event");
if (eventFilter) {
every.eventFilter = eventFilter;
}
triggerSpecs.push(every);
} else if (trigger.indexOf("sse:") === 0) {
triggerSpecs.push({trigger: 'sse', sseEvent: trigger.substr(4)});
} else {
var triggerSpec = {trigger: trigger};
var eventFilter = maybeGenerateConditional(elt, tokens, "event");
if (eventFilter) {
triggerSpec.eventFilter = eventFilter;
}
while (tokens.length > 0 && tokens[0] !== ",") {
consumeUntil(tokens, NOT_WHITESPACE)
var token = tokens.shift();
if (token === "changed") {
triggerSpec.changed = true;
} else if (token === "once") {
triggerSpec.once = true;
} else if (token === "consume") {
triggerSpec.consume = true;
} else if (token === "delay" && tokens[0] === ":") {
tokens.shift();
triggerSpec.delay = parseInterval(consumeUntil(tokens, WHITESPACE_OR_COMMA));
} else if (token === "from" && tokens[0] === ":") {
tokens.shift();
if (COMBINED_SELECTOR_START.test(tokens[0])) {
var from_arg = consumeCSSSelector(tokens);
} else {
var from_arg = consumeUntil(tokens, WHITESPACE_OR_COMMA);
if (from_arg === "closest" || from_arg === "find" || from_arg === "next" || from_arg === "previous") {
tokens.shift();
var selector = consumeCSSSelector(tokens);
// `next` and `previous` allow a selector-less syntax
if (selector.length > 0) {
from_arg += " " + selector;
}
var tokens = tokenizeString(explicitTrigger);
do {
consumeUntil(tokens, NOT_WHITESPACE);
var initialLength = tokens.length;
var trigger = consumeUntil(tokens, /[,\[\s]/);
if (trigger !== "") {
if (trigger === "every") {
var every = {trigger: 'every'};
consumeUntil(tokens, NOT_WHITESPACE);
every.pollInterval = parseInterval(consumeUntil(tokens, /[,\[\s]/));
consumeUntil(tokens, NOT_WHITESPACE);
var eventFilter = maybeGenerateConditional(elt, tokens, "event");
if (eventFilter) {
every.eventFilter = eventFilter;
}
triggerSpecs.push(every);
} else if (trigger.indexOf("sse:") === 0) {
triggerSpecs.push({trigger: 'sse', sseEvent: trigger.substr(4)});
} else {
var triggerSpec = {trigger: trigger};
var eventFilter = maybeGenerateConditional(elt, tokens, "event");
if (eventFilter) {
triggerSpec.eventFilter = eventFilter;
}
while (tokens.length > 0 && tokens[0] !== ",") {
consumeUntil(tokens, NOT_WHITESPACE)
var token = tokens.shift();
if (token === "changed") {
triggerSpec.changed = true;
} else if (token === "once") {
triggerSpec.once = true;
} else if (token === "consume") {
triggerSpec.consume = true;
} else if (token === "delay" && tokens[0] === ":") {
tokens.shift();
triggerSpec.delay = parseInterval(consumeUntil(tokens, WHITESPACE_OR_COMMA));
} else if (token === "from" && tokens[0] === ":") {
tokens.shift();
if (COMBINED_SELECTOR_START.test(tokens[0])) {
var from_arg = consumeCSSSelector(tokens);
} else {
var from_arg = consumeUntil(tokens, WHITESPACE_OR_COMMA);
if (from_arg === "closest" || from_arg === "find" || from_arg === "next" || from_arg === "previous") {
tokens.shift();
var selector = consumeCSSSelector(tokens);
// `next` and `previous` allow a selector-less syntax
if (selector.length > 0) {
from_arg += " " + selector;
}
}
triggerSpec.from = from_arg;
} else if (token === "target" && tokens[0] === ":") {
tokens.shift();
triggerSpec.target = consumeCSSSelector(tokens);
} else if (token === "throttle" && tokens[0] === ":") {
tokens.shift();
triggerSpec.throttle = parseInterval(consumeUntil(tokens, WHITESPACE_OR_COMMA));
} else if (token === "queue" && tokens[0] === ":") {
tokens.shift();
triggerSpec.queue = consumeUntil(tokens, WHITESPACE_OR_COMMA);
} else if (token === "root" && tokens[0] === ":") {
tokens.shift();
triggerSpec[token] = consumeCSSSelector(tokens);
} else if (token === "threshold" && tokens[0] === ":") {
tokens.shift();
triggerSpec[token] = consumeUntil(tokens, WHITESPACE_OR_COMMA);
} else {
triggerErrorEvent(elt, "htmx:syntax:error", {token:tokens.shift()});
}
triggerSpec.from = from_arg;
} else if (token === "target" && tokens[0] === ":") {
tokens.shift();
triggerSpec.target = consumeCSSSelector(tokens);
} else if (token === "throttle" && tokens[0] === ":") {
tokens.shift();
triggerSpec.throttle = parseInterval(consumeUntil(tokens, WHITESPACE_OR_COMMA));
} else if (token === "queue" && tokens[0] === ":") {
tokens.shift();
triggerSpec.queue = consumeUntil(tokens, WHITESPACE_OR_COMMA);
} else if (token === "root" && tokens[0] === ":") {
tokens.shift();
triggerSpec[token] = consumeCSSSelector(tokens);
} else if (token === "threshold" && tokens[0] === ":") {
tokens.shift();
triggerSpec[token] = consumeUntil(tokens, WHITESPACE_OR_COMMA);
} else {
triggerErrorEvent(elt, "htmx:syntax:error", {token:tokens.shift()});
}
triggerSpecs.push(triggerSpec);
}
triggerSpecs.push(triggerSpec);
}
if (tokens.length === initialLength) {
triggerErrorEvent(elt, "htmx:syntax:error", {token:tokens.shift()});
}
consumeUntil(tokens, NOT_WHITESPACE);
} while (tokens[0] === "," && tokens.shift())
if (cache) {
cache[explicitTrigger] = triggerSpecs
}
return triggerSpecs
if (tokens.length === initialLength) {
triggerErrorEvent(elt, "htmx:syntax:error", {token:tokens.shift()});
}
consumeUntil(tokens, NOT_WHITESPACE);
} while (tokens[0] === "," && tokens.shift())
if (cache) {
cache[explicitTrigger] = triggerSpecs
}
return triggerSpecs
}

/**
Expand Down

0 comments on commit 06c3ced

Please sign in to comment.