Skip to content

Instantly share code, notes, and snippets.

@Wizek

Wizek/.hs Secret

Last active March 26, 2018 18:46
Show Gist options
  • Save Wizek/aa0641aa7b22e54c69b971d1aca0828b to your computer and use it in GitHub Desktop.
Save Wizek/aa0641aa7b22e54c69b971d1aca0828b to your computer and use it in GitHub Desktop.
mouseDownEvPrevDef :: MW t m => El t m -> m (E t ())
mouseDownEvPrevDef el = do
(event, trigger) <- newTriggerEvent
DOM.liftJSM $ do
jsFun <- JSA.eval [q|(function(el, cb) {
try {
el.addEventListener('mousedown', function(e) {
e.preventDefault()
cb()
})
} catch (e) {
console.error(e)
}
})|]
JSA.call jsFun JSA.global
( _element_raw el
, JSA.asyncFunction $ \_ _ _ -> do
io $ trigger ()
)
pure event
-- enterEvPrevDef :: MW t m => TextAreaElement () t m -> m (E t ())
enterEvPrevDef inp = do
(entersNoShift, entersNoShiftTrigger) <- newTriggerEvent
DOM.liftJSM $ do
jsFun <- JSA.eval [q|(function(el, cb) {
try {
el.addEventListener('keypress', function(e) {
if (e.keyCode == 13 && !e.shiftKey) {
e.preventDefault()
cb()
} else {
}
})
} catch (e) {
console.error(e)
}
})|]
JSA.call jsFun JSA.global
( _textAreaElement_raw inp
, JSA.asyncFunction $ \_ _ _ -> do
io $ entersNoShiftTrigger ()
)
noop
pure entersNoShift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment