ATuin

Untitled

Jul 3rd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE EmptyDataDecls #-}
  2. {-# OPTIONS -Wall -fno-warn-name-shadowing -fno-warn-unused-do-bind #-}
  3.  
  4. module Index where
  5.  
  6. import FFI
  7. import Prelude
  8.  
  9. -- Import Logikujo.SharedTypes
  10.  
  11. -- | Fay Only Modules
  12. import Dom
  13. import JQuery
  14.  
  15. -- | Some Useful functions
  16. -- | ---------------------
  17. void :: Fay f -> Fay ()
  18. void f = f >> return ()
  19.  
  20. -- >>= :: m a -> (a -> m b) -> m b
  21. (=<<) :: (a -> Fay b) -> Fay a -> Fay b
  22. (=<<) = flip (>>=)
  23.  
  24. currentTarget :: Event -> Fay JQuery.Element
  25. currentTarget = ffi "%1['currentTarget']"
  26.  
  27. -- | Carousel Bootstrap
  28. -- | ------------------
  29. data Carousel = Carousel {carouselSelector :: String}
  30. data CarouselAction = Next | Prev | Cycle | Pause | ByIndex Int
  31.  
  32. carousel :: String -> Fay Carousel
  33. carousel s = return $ Carousel s
  34.  
  35. carouselAction :: String -> JQuery -> Fay ()
  36. carouselAction = ffi "%2['carousel'](%1)"
  37. carouselActionByIndex :: Int -> JQuery -> Fay ()
  38. carouselActionByIndex = ffi "%2['carousel'](%1)"
  39.  
  40. (<~) :: Carousel -> CarouselAction -> Fay ()
  41. (<~) c act = do
  42.   e <- select $ carouselSelector c
  43.   case act of
  44.     Next -> do carouselAction "next" e
  45.     Prev -> do carouselAction "prev" e
  46.     Cycle -> do carouselAction "cycle" e
  47.     Pause -> do carouselAction "pause" e
  48.     ByIndex i -> do carouselActionByIndex i e
  49.  
  50. (~>) :: CarouselAction -> Carousel -> Fay ()
  51. (~>) = flip (<~)
  52.  
  53. alert :: String -> Fay ()
  54. alert = ffi "alert(%1)"
  55.  
  56. alertEvent :: Event -> Fay ()
  57. alertEvent e = currentTarget e >>= selectElement >>= getAttr "id" >>= alert
  58.  
  59. imageButtonOnHover :: Event -> Fay ()
  60. imageButtonOnHover e = void $ currentTarget e >>= selectElement >>= getAttr "id" >>= f
  61.   where f "FlaskButton" = indexCarousel >>= (~>) (ByIndex 0)
  62.         f "ShieldButton" = indexCarousel >>= (~>) (ByIndex 1)
  63.         f "StudyButton" = indexCarousel >>= (~>) (ByIndex 2)
  64.         f x = alert x
  65.  
  66. imageButtonsOnLoad :: Fay ()
  67. imageButtonsOnLoad = void $ select "#ServicesButtons" >>= hover alertEvent --(hover imageButtonOnHover)
  68.  
  69. indexCarousel :: Fay Carousel
  70. indexCarousel = carousel ".carousel"
  71. carouselOnLoad :: Fay ()
  72. carouselOnLoad = indexCarousel >>= (~>) Cycle
  73.  
  74. --servicesButtonsOnload :: Fay ()
  75. --servicesButtonsOnload = select "#ServicesButtons" >>= click set
  76.  
  77. main :: Fay ()
  78. main = mapM_ addOnload [carouselOnLoad, imageButtonsOnLoad]
Advertisement
Add Comment
Please, Sign In to add comment