Skip to content

Commit

Permalink
fixes #413
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Sep 10, 2024
1 parent f9b0944 commit f4cb56f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions fasthtml/xtend.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ def StyleX(fname, **kw):

# %% ../nbs/api/02_xtend.ipynb
def On(code:str, event:str='click', sel:str='', me=True):
"An async surreal.js script block event handler for `event` on selector `sel`"
"An async surreal.js script block event handler for `event` on selector `sel`, making available parent `p`, event `ev`, and target `e`"
func = 'me' if me else 'any'
if sel: sel=f'"{sel}"'
return Script(f'{func}({sel}).on("{event}", async ev=>{{\nlet e = me(ev);\n{code}\n}});\n')
return Script(f'{{let p=me(); {func}({sel}).on("{event}", async ev=>{{\nlet e = me(ev);\n{code}\n}});}}')

# %% ../nbs/api/02_xtend.ipynb
def Prev(code:str, event:str='click'):
"An async surreal.js script block event handler for `event` on previous sibling"
"An async surreal.js script block event handler for `event` on previous sibling, with same vars as `On`"
return On(code, event=event, sel='-')

# %% ../nbs/api/02_xtend.ipynb
Expand Down
6 changes: 3 additions & 3 deletions nbs/api/02_xtend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@
"source": [
"#| export\n",
"def On(code:str, event:str='click', sel:str='', me=True):\n",
" \"An async surreal.js script block event handler for `event` on selector `sel`\"\n",
" \"An async surreal.js script block event handler for `event` on selector `sel`, making available parent `p`, event `ev`, and target `e`\"\n",
" func = 'me' if me else 'any'\n",
" if sel: sel=f'\"{sel}\"'\n",
" return Script(f'{func}({sel}).on(\"{event}\", async ev=>{{\\nlet e = me(ev);\\n{code}\\n}});\\n')"
" return Script(f'{{let p=me(); {func}({sel}).on(\"{event}\", async ev=>{{\\nlet e = me(ev);\\n{code}\\n}});}}')"
]
},
{
Expand All @@ -362,7 +362,7 @@
"source": [
"#| export\n",
"def Prev(code:str, event:str='click'):\n",
" \"An async surreal.js script block event handler for `event` on previous sibling\"\n",
" \"An async surreal.js script block event handler for `event` on previous sibling, with same vars as `On`\"\n",
" return On(code, event=event, sel='-')"
]
},
Expand Down

0 comments on commit f4cb56f

Please sign in to comment.