forked from luakit/luakit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_css_wm.lua
33 lines (24 loc) · 909 Bytes
/
image_css_wm.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Customize how single images are displayed in the browser.
--
-- @submodule image_css
-- @copyright 2017 Aidan Holm
local ui = ipc_channel("image_css_wm")
local recalc_funcs = setmetatable({}, { __mode = "k" })
ui:add_signal("image", function (_, page)
local body = page.document.body
-- do nothing if loaded document is not HTML
if not body then return end
local img = body:query("img")[1]
if not img then return end
recalc_funcs[page] = function ()
local body_height = body.rect.height
local img_height = img.rect.height
local vert_overflow = img_height > body_height
img.attr.class = vert_overflow and "verticalOverflow" or ""
end
img:add_event_listener("click", true, recalc_funcs[page])
end)
ui:add_signal("recalc", function (_, page)
return recalc_funcs[page] and recalc_funcs[page]();
end)
-- vim: et:sw=4:ts=8:sts=4:tw=80