This repository was 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
/
Copy pathWindow.purs
147 lines (104 loc) · 5.69 KB
/
Window.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
module DOM.HTML.Window
( document
, navigator
, location
, history
, innerWidth
, innerHeight
, alert
, confirm
, moveBy
, moveTo
, open
, outerHeight
, outerWidth
, print
, prompt
, promptDefault
, resizeBy
, resizeTo
, screenX
, screenY
, scroll
, scrollBy
, scrollX
, scrollY
, url
, localStorage
, sessionStorage
, requestAnimationFrame
, cancelAnimationFrame
, RequestAnimationFrameId
, requestIdleCallback
, cancelIdleCallback
, RequestIdleCallbackId
) where
import Control.Monad.Eff (Eff)
import DOM (DOM)
import DOM.HTML.Types (ALERT, CONFIRM, HISTORY, HTMLDocument, History, Location, Navigator, PROMPT, SELECTION, Selection, WINDOW, Window, URL)
import DOM.WebStorage.Types (Storage)
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe)
import Data.Newtype (class Newtype, unwrap)
import Prelude (class Eq, class Ord, Unit, (<$>), (<<<), map)
foreign import document :: forall eff. Window -> Eff (dom :: DOM | eff) HTMLDocument
foreign import navigator :: forall eff. Window -> Eff (dom :: DOM | eff) Navigator
foreign import location :: forall eff. Window -> Eff (dom :: DOM | eff) Location
foreign import history :: forall e. Window -> Eff (history :: HISTORY | e) History
foreign import url :: forall eff. Window -> Eff (dom :: DOM | eff) URL
foreign import innerWidth :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import innerHeight :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import alert :: forall eff. String -> Window -> Eff (alert :: ALERT | eff) Unit
foreign import confirm :: forall eff. String -> Window -> Eff (confirm :: CONFIRM | eff) Boolean
foreign import moveBy :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
foreign import moveTo :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
open :: forall eff. String -> String -> String -> Window -> Eff (window :: WINDOW | eff) (Maybe Window)
open window url' name features = toMaybe <$> _open window url' name features
foreign import _open
:: forall eff
. String
-> String
-> String
-> Window
-> Eff (window :: WINDOW | eff) (Nullable Window)
foreign import outerHeight :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import outerWidth :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import print :: forall eff. Window -> Eff (window :: WINDOW | eff) Unit
prompt :: forall eff. String -> Window -> Eff (prompt :: PROMPT | eff) (Maybe String)
prompt msg window = toMaybe <$> _prompt msg "" window
promptDefault :: forall eff. String -> String -> Window -> Eff (prompt :: PROMPT | eff) (Maybe String)
promptDefault msg defaultText window = toMaybe <$> _prompt msg defaultText window
foreign import _prompt :: forall eff. String -> String -> Window -> Eff (prompt :: PROMPT | eff) (Nullable String)
foreign import resizeBy :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
foreign import resizeTo :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
foreign import screenX :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import screenY :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import scroll :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
foreign import scrollBy :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
foreign import scrollX :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import scrollY :: forall eff. Window -> Eff (dom :: DOM | eff) Int
foreign import localStorage :: forall eff. Window -> Eff (dom :: DOM | eff) Storage
foreign import sessionStorage :: forall eff. Window -> Eff (dom :: DOM | eff) Storage
newtype RequestAnimationFrameId = RequestAnimationFrameId Int
derive instance newtypeRequestAnimationFrameId :: Newtype RequestAnimationFrameId _
derive instance eqRequestAnimationFrameId :: Eq RequestAnimationFrameId
derive instance ordRequestAnimationFrameId :: Ord RequestAnimationFrameId
foreign import _requestAnimationFrame :: forall eff. Eff (dom :: DOM | eff) Unit -> Window -> Eff (dom :: DOM | eff) Int
requestAnimationFrame :: forall eff. Eff (dom :: DOM | eff) Unit -> Window -> Eff (dom :: DOM | eff ) RequestAnimationFrameId
requestAnimationFrame fn = map RequestAnimationFrameId <<< _requestAnimationFrame fn
foreign import _cancelAnimationFrame :: forall eff. Int -> Window -> Eff (dom :: DOM | eff) Unit
cancelAnimationFrame :: forall eff. RequestAnimationFrameId -> Window -> Eff (dom :: DOM | eff) Unit
cancelAnimationFrame idAF = _cancelAnimationFrame (unwrap idAF)
newtype RequestIdleCallbackId = RequestIdleCallbackId Int
derive instance newtypeRequestIdleCallbackId :: Newtype RequestIdleCallbackId _
derive instance eqRequestIdleCallbackId :: Eq RequestIdleCallbackId
derive instance ordRequestIdleCallbackId :: Ord RequestIdleCallbackId
foreign import _requestIdleCallback :: forall eff. { timeout :: Int } -> Eff (dom :: DOM | eff) Unit -> Window -> Eff (dom :: DOM | eff) Int
-- | Set timeout to `0` to get the same behaviour as when it is `undefined` in
-- | [JavaScript](https://w3c.github.io/requestidlecallback/#h-the-requestidle-callback-method).
requestIdleCallback :: forall eff. { timeout :: Int } -> Eff (dom :: DOM | eff) Unit -> Window -> Eff (dom :: DOM | eff ) RequestIdleCallbackId
requestIdleCallback opts fn = map RequestIdleCallbackId <<< _requestIdleCallback opts fn
foreign import _cancelIdleCallback :: forall eff. Int -> Window -> Eff (dom :: DOM | eff) Unit
cancelIdleCallback :: forall eff. RequestIdleCallbackId -> Window -> Eff (dom :: DOM | eff) Unit
cancelIdleCallback idAF = _cancelIdleCallback (unwrap idAF)
foreign import getSelection :: forall eff. Window -> Eff (selection :: SELECTION | eff) Selection