Skip to content

Commit

Permalink
Add 'getWindow' function. #24
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed Jul 16, 2013
1 parent 0dcb3e7 commit a98e51e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Graphics/UI/Threepenny/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Graphics.UI.Threepenny.Core (

-- * DOM elements
-- | Create and manipulate DOM elements.
Element, mkElement, delete, (#+), string,
Element, mkElement, getWindow, delete, (#+), string,
getHead, getBody,
children, text, html, attr, style, value,
getValuesList,
Expand Down Expand Up @@ -197,6 +197,21 @@ mkElement
-> IO Element
mkElement tag = Element <$> newMVar (Limbo "" $ \w -> Core.newElement w tag)

-- | Retreive the browser 'Window' in which the element resides.
--
-- Note that elements do not reside in any browser window when they are first created.
-- To move the element to a particular browser window,
-- you have to append it to a parent, for instance with the `(#+)` operator.
--
-- WARNING: The ability to move elements from one browser window to another
-- is currently not implemented yet.
getWindow :: Element -> IO (Maybe Window)
getWindow (Element ref) = do
e1 <- readMVar ref
return $ case e1 of
Alive e -> Just $ Core.getWindow e
Limbo _ _ -> Nothing

-- | Delete the given element.
delete :: Element -> IO ()
delete = updateElement (Core.delete)
Expand Down

0 comments on commit a98e51e

Please sign in to comment.