Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE EmptyDataDecls #-}
- {-# OPTIONS -Wall -fno-warn-name-shadowing -fno-warn-unused-do-bind #-}
- module Index where
- import FFI
- import Prelude
- -- Import Logikujo.SharedTypes
- -- | Fay Only Modules
- import Dom
- import JQuery
- -- | Some Useful functions
- -- | ---------------------
- void :: Fay f -> Fay ()
- void f = f >> return ()
- -- >>= :: m a -> (a -> m b) -> m b
- (=<<) :: (a -> Fay b) -> Fay a -> Fay b
- (=<<) = flip (>>=)
- currentTarget :: Event -> Fay JQuery.Element
- currentTarget = ffi "%1['currentTarget']"
- -- | Carousel Bootstrap
- -- | ------------------
- data Carousel = Carousel {carouselSelector :: String}
- data CarouselAction = Next | Prev | Cycle | Pause | ByIndex Int
- carousel :: String -> Fay Carousel
- carousel s = return $ Carousel s
- carouselAction :: String -> JQuery -> Fay ()
- carouselAction = ffi "%2['carousel'](%1)"
- carouselActionByIndex :: Int -> JQuery -> Fay ()
- carouselActionByIndex = ffi "%2['carousel'](%1)"
- (<~) :: Carousel -> CarouselAction -> Fay ()
- (<~) c act = do
- e <- select $ carouselSelector c
- case act of
- Next -> do carouselAction "next" e
- Prev -> do carouselAction "prev" e
- Cycle -> do carouselAction "cycle" e
- Pause -> do carouselAction "pause" e
- ByIndex i -> do carouselActionByIndex i e
- (~>) :: CarouselAction -> Carousel -> Fay ()
- (~>) = flip (<~)
- alert :: String -> Fay ()
- alert = ffi "alert(%1)"
- alertEvent :: Event -> Fay ()
- alertEvent e = currentTarget e >>= selectElement >>= getAttr "id" >>= alert
- imageButtonOnHover :: Event -> Fay ()
- imageButtonOnHover e = void $ currentTarget e >>= selectElement >>= getAttr "id" >>= f
- where f "FlaskButton" = indexCarousel >>= (~>) (ByIndex 0)
- f "ShieldButton" = indexCarousel >>= (~>) (ByIndex 1)
- f "StudyButton" = indexCarousel >>= (~>) (ByIndex 2)
- f x = alert x
- imageButtonsOnLoad :: Fay ()
- imageButtonsOnLoad = void $ select "#ServicesButtons" >>= hover alertEvent --(hover imageButtonOnHover)
- indexCarousel :: Fay Carousel
- indexCarousel = carousel ".carousel"
- carouselOnLoad :: Fay ()
- carouselOnLoad = indexCarousel >>= (~>) Cycle
- --servicesButtonsOnload :: Fay ()
- --servicesButtonsOnload = select "#ServicesButtons" >>= click set
- main :: Fay ()
- main = mapM_ addOnload [carouselOnLoad, imageButtonsOnLoad]
Advertisement
Add Comment
Please, Sign In to add comment