You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An easy to use library for dealing with the DOM and general javascript APIs.
Minimal dependencies, and aiming to be as close to the javascript API as possible.
Change all a href's on a page and add the original link as a data attribute
modifyLinkTarget link = do
attr <- getAttribute "href" link -- attr = link.getAttribute("href")
setAttribute "href""#" link -- link.setAttribute("href", "#")
setAttribute "data-target" attr link -- link.setAttribute("data-target", attr)
return link
modifyLinks page = do
links <- querySelectorAll "a" page -- links = [HTMLElement]
sequence $ A.map modifyLinkTarget links -- links.map(modifyLinkTarget)
Place some content from an API call into a div
-- Convert the evt content into text for the callback
handleRequest callback evt = do
target <- eventTarget event
text <- responseText target
callback text
-- Construct and perform AJAX request for the specified url
makeGetRequest url callback = do
req <- makeXMLHttpRequest
addEventListener "load" (handleRequest callback) req
open GET url req
setRequestHeader "Content-Type""application/json" req
send NoData req
-- retrieve the content and place it inside the div
requestContent = dolet url = "https://myendpoint.com/"
doc <- document globalWindow
makeGetRequest url $ \resp ->do
querySelector "#myDiv" doc >>= setInnerHtml resp