on develop help sign in
Add resizeDetectorWithAttrs
commit76d1e7c73abc55d20acfed3024d856a7a4d14542 authorAli Abrar <aliabrar@gmail.com> dateMon 16 May 2016, 15:44 (10 years ago) parentf3f2f26
1 file changed+11−2
src/Reflex/Dom/Widget/Resize.hs+11−2
src/Reflex/Dom/Widget/Resize.hs+11−2
@@ -7,9 +7,11 @@ import Reflex.Dom.Widget.Basic
77
88import Control.Monad
99import Control.Monad.IO.Class
10+import Data.Map (Map)
1011import Data.Monoid
1112import GHCJS.DOM.Element hiding (reset)
1213import GHCJS.DOM.EventM (on)
14+import qualified Data.Map as Map
1315
1416-- | A widget that wraps the given widget in a div and fires an event when resized.
1517-- Adapted from github.com/marcj/css-element-queries
@@ -20,10 +22,16 @@ resizeDetectorWithStyle :: MonadWidget t m
2022 => String -- ^ A css style string. Warning: It should not contain the "position" style attribute.
2123 -> m a -- ^ The embedded widget
2224 -> m (Event t (), a) -- ^ An 'Event' that fires on resize, and the result of the embedded widget
23−resizeDetectorWithStyle styleString w = do
25+resizeDetectorWithStyle styleString w = resizeDetectorWithAttrs ("style" =: styleString) w
26+
27+resizeDetectorWithAttrs :: MonadWidget t m
28+ => Map String String -- ^ A map of attributes. Warning: It should not modify the "position" style attribute.
29+ -> m a -- ^ The embedded widget
30+ -> m (Event t (), a) -- ^ An 'Event' that fires on resize, and the result of the embedded widget
31+resizeDetectorWithAttrs attrs w = do
2432 let childStyle = "position: absolute; left: 0; top: 0;"
2533 containerAttrs = "style" =: "position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;"
26− (parent, (expand, expandChild, shrink, w')) <- elAttr' "div" ("style" =: ("position: relative;" <> styleString)) $ do
34+ (parent, (expand, expandChild, shrink, w')) <- elAttr' "div" (Map.unionWith (<>) attrs ("style" =: "position: relative;")) $ do
2735 w' <- w
2836 elAttr "div" containerAttrs $ do
2937 (expand, (expandChild, _)) <- elAttr' "div" containerAttrs $ elAttr' "div" ("style" =: childStyle) $ return ()
@@ -61,3 +69,4 @@ resizeDetectorWithStyle styleString w = do
6169 rec resize <- performEventAsync $ fmap (\d cb -> liftIO $ cb =<< resetIfChanged d) $ tag (current dimensions) $ leftmost [expandScroll, shrinkScroll]
6270 dimensions <- holdDyn (Nothing, Nothing) $ leftmost [ size0, fmapMaybe id resize ]
6371 return (fmap (const ()) $ fmapMaybe id resize, w')
72+