diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-07-01 21:30:59 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-07-01 21:50:08 +0200 |
| commit | 06263ef351281cb27b2cbdb46e2a39d57d084ae4 (patch) | |
| tree | 716c6d713590bad7c8ceeb950f8c2ffd7a884c63 /src/JavaScript/Element.hs | |
| parent | 2573b8a2cae5bf2f3f58aff4135876da7152081d (diff) | |
Add class for conversations with unread messages
Diffstat (limited to 'src/JavaScript/Element.hs')
| -rw-r--r-- | src/JavaScript/Element.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/JavaScript/Element.hs b/src/JavaScript/Element.hs index 60f5c65..925b90e 100644 --- a/src/JavaScript/Element.hs +++ b/src/JavaScript/Element.hs @@ -1,5 +1,6 @@ module JavaScript.Element ( Element, IsElement(..), + module JavaScript.Node, getElementById, documentQuerySelector, @@ -10,9 +11,13 @@ module JavaScript.Element ( firstElementChild, lastElementChild, + + getAttribute, setAttribute, removeAttribute, + addClass, removeClass, toggleClass, ) where import JavaScript.Event +import JavaScript.Node import JavaScript.Val @@ -25,6 +30,9 @@ class IsElement a where instance IsElement Element where toElement = id +instance IsNode Element where + toNode = fromJSValUnchecked . toJSVal + instance IsEventTarget Element where toEventTarget = fromJSValUnchecked . toJSVal @@ -63,3 +71,34 @@ lastElementChild :: IsElement e => e -> IO (Maybe Element) lastElementChild = fmap nullToNothing . js_element_lastElementChild . toJSVal . toElement foreign import javascript unsafe "$1.lastElementChild" js_element_lastElementChild :: JSVal -> IO JSVal + + +getAttribute :: IsElement e => String -> e -> IO String +getAttribute name e = fromJSString <$> js_getAttribute (toJSVal $ toElement e) (toJSString name) +foreign import javascript unsafe "$1.getAttribute($2)" + js_getAttribute :: JSVal -> JSString -> IO JSString + +setAttribute :: IsElement e => String -> String -> e -> IO () +setAttribute name value e = js_setAttribute (toJSVal $ toElement e) (toJSString name) (toJSString value) +foreign import javascript unsafe "$1.setAttribute($2, $3)" + js_setAttribute :: JSVal -> JSString -> JSString -> IO () + +removeAttribute :: IsElement e => String -> e -> IO () +removeAttribute name e = js_removeAttribute (toJSVal $ toElement e) (toJSString name) +foreign import javascript unsafe "$1.removeAttribute($2)" + js_removeAttribute :: JSVal -> JSString -> IO () + +addClass :: IsElement e => String -> e -> IO () +addClass cls e = js_classList_add (toJSVal $ toElement e) (toJSString cls) +foreign import javascript unsafe "$1.classList.add($2)" + js_classList_add :: JSVal -> JSString -> IO () + +removeClass :: IsElement e => String -> e -> IO () +removeClass cls e = js_classList_remove (toJSVal $ toElement e) (toJSString cls) +foreign import javascript unsafe "$1.classList.remove($2)" + js_classList_remove :: JSVal -> JSString -> IO () + +toggleClass :: IsElement e => String -> e -> IO () +toggleClass cls e = js_classList_toggle (toJSVal $ toElement e) (toJSString cls) +foreign import javascript unsafe "$1.classList.toggle($2)" + js_classList_toggle :: JSVal -> JSString -> IO () |