45 Commits

Author SHA1 Message Date
MichaelWest22
d528c9d94d
Handle Space before comma in Trigger Spec (#2903)
* strip space after trigger spec

* Add test

* handle addiional case
2024-09-25 13:12:37 -06:00
Kyungmin Bae
27412551a5
fix: Fire htmx:trigger event on delayed triggers (#2411)
* Add test on htmx:trigger for delayed triggers

* Fire htmx:trigger event on delayed triggers
2024-08-05 13:47:58 -06:00
Igor Berlenko
49b5dae073
fixed typo in hx-trigger.js (#2728)
Update hx-trigger.js
2024-07-26 00:27:22 -04:00
Alexander Petros
0e67ac8081 Format tests 2024-01-18 10:20:34 -05:00
Carson Gross
8c61e71940 support revealed paired w/ other events 2023-12-26 16:42:16 -07:00
Alexander Petros
4b890ce72d Run linter on the tests too 2023-12-21 13:22:10 -05:00
Carson Gross
b4080e71da remove psychotic test 2023-12-20 15:48:31 -07:00
Thomas Cowart
078d5da5b4
Update parseInterval to handle "0" correctly (#1835)
* Update parseInterval to handle "0" correctly

When a parameter like "0ms" is passed in to parseInterval it gets parsed to 0.
Previously this would result in a return value of "undefined" because 0 is falsy
and thus the `return 0 || undefined` statements return undefined.

The purpose of the form `parseFloat(str) || undefined` was to return "undefined" if
parseFloat failed (parseFloat returns NaN, a falsy value, if it can't parse its
argument). Unfortunately, as mentioned, parseFloat can also succeed and return a
falsy value -- when the argument is "0" (or "0.0", etc.). So the new code, rather
than depending on the falsiness of the result of parseFloat, explicitly checks for
a NaN.

* Adds some semicolons

Adds some semicolons to parseInterval (and tests) for consistency.

* Add one more parseInterval test for "0"

Adds test test to make sure parseInterval works on "0".

* Adds functional tests for every, swap, settle, throttle, and delay

* Explcitly check that setTimeout values are > 0

These values come from user settings that are read from parseInterval,
so they could be a number or undefined.

If the value being checked is > 0 setTimeout will be called with some
associated function. If the value is 0 or 'undefined' the associated function
will be called immediately ('undefined' is not greater than 0).

* Change '!== undefined' to '> 0'

`pollInterval !== undefined` is a subtly different conditional than just `pollInterval` or `pollInterval > 0` (which are equivalent). Changes the conditional to `pollInterval > 0` so as to not change the behavior but also be more explicit in the test.
2023-12-20 15:46:04 -07:00
Vincent
4057f9c465
Trigger specs cache indentation fix + documentation & tests (#2094)
* Fix parseAndCacheTrigger indentation as discussed in #1540

https://github.com/bigskysoftware/htmx/pull/1540#issuecomment-1834651800

* Trigger specs cache documentation + tests
2023-12-14 11:44:11 -07:00
Jonathan Rietveld
7ef95e8963
Allow CSS selectors with whitespace in hx-trigger (#1913)
* Allow CSS selectors with whitespace in `hx-trigger`

Parsing of `hx-trigger` scans for whitespace, so if a CSS selector is used that contains whitespace, e.g. `form input`, a syntax error is raised.
A workaround is implemented by allowing such a CSS selector to be wrapped in either curly braces or parentheses.

* Add explanation whitespace in CSS selector to docs

* Tests for CSS selectors containing whitespace

* Use faster RegEx test, remove redundant variable declarations

* Added Descendant Combinator support to `root` and `target` modifiers

* Add missing semicolon

* Tests for descendant combinators in `root` and `target` modifiers

* Improve descendant combinator test coverage
2023-11-16 13:45:46 -07:00
Vincent
7274454360
[New feature] selector-less next and previous targets (#1478)
* nextElementSibling and previousElementSibling target selectors

* Renamed nextElementSibling => next, previousElementSibling => previous
2023-10-06 22:25:03 -06:00
Vincent
6d1adc853f
[Bugfix] Fix hx-trigger changed modifier along from clause (#1571)
Fix hx-trigger changed modifier along from clause #1565
2023-07-22 08:39:28 -06:00
Viktor Szépe
b085d89459
Fix assorted comment typos (#1590) 2023-07-17 11:36:04 -04:00
Carson Gross
c96f01e81e bump verison + add this symbol in filter expressions 2023-05-02 14:52:54 -06:00
Alexander Petros
5a5ebd7693
Add support for "naked" triggers and htmx:trigger event (#1327)
The `htmx:trigger` event is fired whenever an HTMX AJAX request would
be. Now, `hx-trigger` can also be specified on an element without an
AJAX request, which will simply fire the `htmx:trigger` event on the
action specified by the attribute, and do nothing else.

This pattern allows for specifying client-side actions that don't
require a network request, while remaining within the HTMX control
paradigm.
2023-03-28 09:14:16 -06:00
Carson Gross
bed3d25d2c fix https://github.com/bigskysoftware/htmx/issues/1259
store initial value on init of event listener so first trigger has correct value to compare against
2023-02-23 13:48:05 -07:00
Carson Gross
85338f4435 fix revealed issue 2022-10-30 13:05:03 -06:00
Carson Gross
9af34ce0e3 fix revealed bug 2022-10-12 22:46:02 -06:00
Carson Gross
8b9585f439 flip revealed to be a normal event
this fixes an ugly bug introduced when the trigger logic was pulled out, where the handler of the first revealed element was used over and over again for any future elements that also were revealed.  many braincells lost mmm.
2022-07-08 13:54:25 -06:00
Carson Gross
742f05b9bd support filters on load event
fixes https://github.com/bigskysoftware/htmx/issues/752
2022-05-13 08:44:41 -06:00
carson
3ee3739b4b add tests 2021-11-17 16:19:37 -07:00
Frankie Robertson
4a59263d40 Allow listening to events from:window 2021-08-29 14:07:17 +03:00
carson
bbf2ae4412 support document as an extended query selector and plug it in for the from: clause in triggers 2021-07-06 15:27:51 -06:00
carson
40ed7b0827 allow filters for polling 2021-07-06 10:24:55 -06:00
carson
e15c5d99e3 support a queue modifier for queueing events in different ways
fixes https://github.com/bigskysoftware/htmx/issues/470
2021-05-20 09:07:56 -06:00
carson
9f04b85a9f tests for hx-trigger delay and throttle modifiers 2021-05-10 09:46:40 -06:00
carson
835436a99b Multiple trigger issue - fix https://github.com/bigskysoftware/htmx/issues/392 and https://github.com/bigskysoftware/htmx/issues/390
Mark handling by element, rather than by event
introduce `consume` keyword on trigger to allow for preventing it from bubbling to parent
2021-02-27 20:01:39 -07:00
carson
02d637785b support target option on hx-trigger, fixes https://github.com/bigskysoftware/htmx/issues/376#issuecomment-786821075 2021-02-26 15:05:40 -07:00
carson
e0018b6d44 Remove event listeners on other elements when an element is removed from the DOM 2021-01-23 16:29:13 -07:00
carson
afa6658648 test case for equality expression in conditional 2021-01-01 20:09:43 -07:00
carson
79038d62e3 support from clause for triggers
also fixed pretty ugly bugs when parsing multple trigger definitions
2021-01-01 18:52:15 -07:00
carson
f7617a4653 do not fire requests when element is no longer in DOM
fixes https://github.com/bigskysoftware/htmx/issues/222
2020-11-05 08:39:33 -07:00
carson
d67634e678 test scrolledIntoView 2020-10-19 09:49:55 -06:00
carson
165586b777 docs and tests for trigger filters 2020-10-17 13:21:15 -06:00
carson
18220b3283 hook in tokenizer implementation 2020-10-04 18:26:17 -06:00
carson
296f354fef fix throttle and make the trigger spec test actually work 2020-06-11 09:45:42 -07:00
carson
96c9623a3d test fix 2020-06-11 06:55:50 -07:00
carson
1f62541094 support throttle modifier in trigger definition
https://github.com/bigskysoftware/htmx/issues/88
2020-06-11 06:21:49 -07:00
carson
cbe8cd9fce fix triggers test 2020-05-24 21:57:20 -07:00
carson
8a6a6f8016 web socket support 2020-05-24 21:41:44 -07:00
Robert Schroll
2ad1202978 Handle multiple triggers
Triggers are separated by commas, and each will get handled with its
own options.  If we are unable to parse any triggers, the default
trigger for each element is used.
2020-05-23 18:08:54 -07:00
Robert Schroll
0b0be4193a Change trigger spec for repeated and SSE events 2020-05-23 18:08:54 -07:00
Robert Schroll
9437e6c0a8 Add tests of trigger spec parsing 2020-05-23 18:08:54 -07:00
carson
ba6d38e9dd Fix https://github.com/bigskysoftware/htmx/issues/19
clean up uses of getRawAttribute() and add a `data-*` test for all attribute tests.
2020-05-23 04:52:52 -07:00
carson
3aa8c64754 le big re-rename 2020-05-17 05:22:19 -07:00