This repository has been archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into popstate-event
- Loading branch information
Showing
17 changed files
with
284 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
module DOM.HTML.Document | ||
( body | ||
, readyState | ||
, module Exports | ||
) where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff (Eff) | ||
import Data.Maybe (Maybe) | ||
import Data.Nullable (Nullable, toMaybe) | ||
import DOM (DOM) | ||
import DOM.HTML.Document.ReadyState (ReadyState(..)) as Exports | ||
import DOM.HTML.Document.ReadyState (ReadyState, parseReadyState) | ||
import DOM.HTML.Types (HTMLElement, HTMLDocument) | ||
import Data.Maybe (Maybe, fromJust) | ||
import Data.Nullable (Nullable, toMaybe) | ||
import Partial.Unsafe (unsafePartial) | ||
|
||
foreign import _body :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) (Nullable HTMLElement) | ||
|
||
body :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) (Maybe HTMLElement) | ||
body = map toMaybe <<< _body | ||
|
||
foreign import _readyState :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) String | ||
|
||
readyState :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) ReadyState | ||
readyState = map (unsafePartial fromJust <<< parseReadyState) <<< _readyState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module DOM.HTML.Document.ReadyState where | ||
|
||
import Prelude | ||
import Data.Enum (class Enum, class BoundedEnum, Cardinality(..), defaultSucc, defaultPred) | ||
import Data.Maybe (Maybe(..)) | ||
|
||
data ReadyState | ||
= Loading | ||
| Interactive | ||
| Complete | ||
|
||
derive instance eqReadyState :: Eq ReadyState | ||
derive instance ordReadyState :: Ord ReadyState | ||
|
||
instance showReadyState :: Show ReadyState where | ||
show = case _ of | ||
Loading -> "Loading" | ||
Interactive -> "Interactive" | ||
Complete -> "Complete" | ||
|
||
printReadyState :: ReadyState -> String | ||
printReadyState = case _ of | ||
Loading -> "loading" | ||
Interactive -> "interactive" | ||
Complete -> "complete" | ||
|
||
parseReadyState :: String -> Maybe ReadyState | ||
parseReadyState = case _ of | ||
"loading" -> Just Loading | ||
"interactive" -> Just Interactive | ||
"complete" -> Just Complete | ||
_ -> Nothing | ||
|
||
instance boundedReadyState :: Bounded ReadyState where | ||
bottom = Loading | ||
top = Complete | ||
|
||
instance enumReadyState :: Enum ReadyState where | ||
succ = defaultSucc toEnumReadyState fromEnumReadyState | ||
pred = defaultPred toEnumReadyState fromEnumReadyState | ||
|
||
instance boundedEnumReadyState :: BoundedEnum ReadyState where | ||
cardinality = Cardinality 3 | ||
toEnum = toEnumReadyState | ||
fromEnum = fromEnumReadyState | ||
|
||
toEnumReadyState :: Int -> Maybe ReadyState | ||
toEnumReadyState = | ||
case _ of | ||
0 -> Just Loading | ||
1 -> Just Interactive | ||
2 -> Just Complete | ||
_ -> Nothing | ||
|
||
fromEnumReadyState :: ReadyState -> Int | ||
fromEnumReadyState = | ||
case _ of | ||
Loading -> 0 | ||
Interactive -> 1 | ||
Complete -> 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Test.DOM.HTML.Document where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff.Class (liftEff) | ||
import DOM (DOM) | ||
import DOM.HTML (window) | ||
import DOM.HTML.Document (ReadyState(..), readyState) | ||
import DOM.HTML.Window (document) | ||
import Test.Unit (TestSuite, describe, it) | ||
import Test.Unit.Assert (shouldEqual) | ||
|
||
domHtmlDocumentTests :: forall eff. TestSuite (dom :: DOM | eff) | ||
domHtmlDocumentTests = do | ||
describe "readyState" do | ||
it "should return a sensible readyState" do | ||
rs <- liftEff $ readyState =<< document =<< window | ||
rs `shouldEqual` Complete |
Oops, something went wrong.