Skip to content

Commit b53ebdb

Browse files
author
Philip Roberts
committed
Split action attribute by last : instead of first
This allows for colons in event names
1 parent d75ab83 commit b53ebdb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

catalyst/src/bind.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ export function bind(controller: HTMLElement) {
1111
// Match the pattern of `eventName:constructor#method`.
1212
for (const binding of (el.getAttribute('data-action') || '').split(' ')) {
1313
const [rest, method] = binding.split('#')
14-
const [eventName, handler] = rest.split(':')
14+
15+
// eventName may contain `:` so account for that
16+
// by splitting by the last instance of `:`
17+
const colonIndex = rest.lastIndexOf(':')
18+
if (colonIndex < 0) continue
19+
20+
const handler = rest.slice(colonIndex + 1)
1521
if (handler !== tag) continue
1622

23+
const eventName = rest.slice(0, colonIndex)
24+
1725
// Check the `method` is present on the prototype
1826
const methodDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(controller), method)
1927
if (methodDescriptor && typeof methodDescriptor.value == 'function') {

0 commit comments

Comments
 (0)