diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-27 20:21:07 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-27 20:27:42 +0530 |
| commit | 8604765c3660dbea9cae6996d5750bfb985e6751 (patch) | |
| tree | 3a90f68dd07f8eb6a9c92d1f322162ac3b345383 /lua | |
| parent | c95ee83c24b79e64a91a6d3a55addcb6e7ebd11b (diff) | |
| download | null-browser-8604765c3660dbea9cae6996d5750bfb985e6751.tar.gz null-browser-8604765c3660dbea9cae6996d5750bfb985e6751.zip | |
Add web.view.run_js + change rpc js api
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/null-browser/api.lua | 17 | ||||
| -rw-r--r-- | lua/null-browser/extras/tabline.lua | 2 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua index 07b7072..5475beb 100644 --- a/lua/null-browser/api.lua +++ b/lua/null-browser/api.lua @@ -129,6 +129,21 @@ function web.view.set_url(url, view_id) return __internals.view_set_url(url, vie --- ``` function web.view.set_html(html, opts) return __internals.view_set_html(html, (opts or {}).view) end +--- @class RunJSOpts +--- @field view? number View id + +--- Set html in a given view +--- +--- @param js string HTML string +--- @param opts? RunJSOpts Options +--- +--- @example +--- ```lua +--- web.view.run_js('console.log(42)') +--- web.view.run_js('console.log(42)', 3) -- Set html for view with id 3 +--- ``` +function web.view.run_js(js, opts) return __internals.view_run_js(js, (opts or {}).view) end + --- @class ExposeOpts --- @field view? number View id @@ -146,7 +161,7 @@ function web.view.set_html(html, opts) return __internals.view_set_html(html, (o --- ``` --- then in js --- ```js ---- __nullbrowser.tab_select({ view: 5 }) +--- _nullbrowser.rpc.tab_select({ view: 5 }) --- ``` function web.view.expose(name, action, opts) return __internals.view_expose(name, action, (opts or {}).view) end diff --git a/lua/null-browser/extras/tabline.lua b/lua/null-browser/extras/tabline.lua index b9156f5..e265940 100644 --- a/lua/null-browser/extras/tabline.lua +++ b/lua/null-browser/extras/tabline.lua @@ -47,7 +47,7 @@ function tabline.tabs_html() for index, view in ipairs(web.view.list()) do local tab = html.button({ class = 'tab' .. (web.view.current() == view.id and ' current' or ''), - onclick = '__nullbrowser.tab_select({ view: ' .. view.id .. ' })', + onclick = '_nullbrowser.rpc.tab_select({ view: ' .. view.id .. ' })', }, { index .. ': ' .. view.title .. ' (' .. view.url .. ')', }) |
