blob: 7e8558b56081f442ac007d4e654e3e4611967a55 (
plain)
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
|
module Component.Link
( link
) where
import Data.Map (Map)
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
link :: forall t m a. MonadWidget t m => Text -> Dynamic t (Map Text Text) -> Text -> m ()
link href inputAttrs content =
R.elDynAttr "a" attrs (R.text content)
where
onclickHandler =
T.intercalate ";"
[ "history.pushState(0, '', event.target.href)"
, "dispatchEvent(new PopStateEvent('popstate', {cancelable: true, bubbles: true, view: window}))"
, "return false"
]
attrs =
R.ffor inputAttrs (\as ->
(M.union
(M.fromList
[ ("onclick", onclickHandler)
, ("href", href)
]
)
as)
)
|