{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Glazier.React.Notice.Internal
( Notice(..)
, preventDefault
, isDefaultPrevented
, stopPropagation
, isPropagationStopped
, unsafeGetProperty
, unsafeGetModifierState
)
where
import qualified GHC.Generics as G
import qualified GHCJS.Foreign as J
import qualified GHCJS.Marshal.Pure as J
import qualified GHCJS.Types as J
import qualified JavaScript.Extras as JE
newtype Notice = Notice JE.JSRep
deriving (G.Generic, Show)
instance JE.FromJS Notice where
fromJS a | js_isNotice a = Just $ Notice $ JE.JSRep a
fromJS _ = Nothing
preventDefault :: Notice -> IO ()
preventDefault = js_preventDefault
isDefaultPrevented :: Notice -> Bool
isDefaultPrevented = js_isDefaultPrevented
stopPropagation :: Notice -> IO ()
stopPropagation = js_stopPropagation
isPropagationStopped :: Notice -> Bool
isPropagationStopped = js_isPropagationStopped
unsafeGetProperty :: J.PFromJSVal a => J.JSVal -> J.JSString -> a
unsafeGetProperty v = J.pFromJSVal . js_unsafeGetProperty v
unsafeGetModifierState :: J.JSVal -> J.JSString -> Bool
unsafeGetModifierState obj k = J.fromJSBool $ js_unsafeGetModifierState obj k
#ifdef __GHCJS__
foreign import javascript unsafe
"$1 && $1['nativeEvent'] && $1['nativeEvent'] instanceof Event"
js_isNotice :: J.JSVal -> Bool
foreign import javascript unsafe
"$1['preventDefault']()"
js_preventDefault :: Notice -> IO ()
foreign import javascript unsafe
"$1['isDefaultPrevented']()"
js_isDefaultPrevented :: Notice -> Bool
foreign import javascript unsafe
"$1['stopPropagation']()"
js_stopPropagation :: Notice -> IO ()
foreign import javascript unsafe
"$1['isPropagationStopped']()"
js_isPropagationStopped :: Notice -> Bool
foreign import javascript unsafe "$1[$2]"
js_unsafeGetProperty :: J.JSVal -> J.JSString -> J.JSVal
foreign import javascript unsafe
"$1['getModifierState']($2)"
js_unsafeGetModifierState :: J.JSVal -> J.JSString -> J.JSVal
#else
js_isNotice :: J.JSVal -> Bool
js_isNotice _ = False
js_preventDefault :: Notice -> IO ()
js_preventDefault _ = pure ()
js_isDefaultPrevented :: Notice -> Bool
js_isDefaultPrevented _ = False
js_stopPropagation :: Notice -> IO ()
js_stopPropagation _ = pure ()
js_isPropagationStopped :: Notice -> Bool
js_isPropagationStopped _ = False
js_unsafeGetProperty :: J.JSVal -> J.JSString -> J.JSVal
js_unsafeGetProperty _ _ = J.nullRef
js_unsafeGetModifierState :: J.JSVal -> J.JSString -> J.JSVal
js_unsafeGetModifierState _ _ = J.nullRef
#endif