Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 975a2f9

Browse files
author
Marcin Szamotulski
committed
Merge branch 'master' into popstate-event
2 parents d75aad0 + 9174791 commit 975a2f9

File tree

17 files changed

+284
-193
lines changed

17 files changed

+284
-193
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "PHANTOM_TEST_PATH=$(pwd) pulp test --runtime phantomjs"
6+
"test": "pulp test --runtime phantomjs"
77
},
88
"devDependencies": {
99
"eslint": "^3.19.0",

src/DOM/Event/EventTarget.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import DOM (DOM)
77
import DOM.Event.Types (EventTarget, Event, EventType)
88

99
-- | A boxed function that can be used as an event listener. This is necessary
10-
-- | due to the underling implementation of Eff functions.
10+
-- | due to the underlying implementation of Eff functions.
1111
foreign import data EventListener :: # Effect -> Type
1212

1313
-- | Creates an EventListener from a normal PureScript Eff function.

src/DOM/File/Blob.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@
33
exports.typeImpl = function (blob) { return blob.type; };
44

55
exports.size = function (blob) { return blob.size; };
6+
7+
exports.slice = function (contentType) {
8+
return function (start) {
9+
return function (end) {
10+
return function (blob) {
11+
return blob.slice(start, end, contentType);
12+
};
13+
};
14+
};
15+
};

src/DOM/File/Blob.purs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
module DOM.File.Blob
22
( type_
33
, size
4+
, StartByte(..)
5+
, EndByte(..)
6+
, idxFromInt
7+
, idxFromNumber
8+
, ByteIdx
9+
, slice
10+
, slice'
411
) where
512

6-
import Prelude ((==))
13+
import DOM.File.Types (Blob)
14+
import Data.Int (toNumber)
715
import Data.Maybe (Maybe(..))
816
import Data.MediaType (MediaType(..))
9-
import DOM.File.Types (Blob)
17+
import Math (round)
18+
import Prelude ((==), (>>>))
19+
import Unsafe.Coerce (unsafeCoerce)
1020

1121
foreign import typeImpl :: Blob -> String
1222

@@ -23,3 +33,36 @@ type_ blob =
2333

2434
-- | The size (in bytes) of the data contained in the `Blob`.
2535
foreign import size :: Blob -> Number
36+
37+
-- | An index into the Blob indicating the first byte to include in the new Blob.
38+
-- | If you specify a negative value, it's treated as an offset from the end of the
39+
-- | string toward the beginning. For example, -10 would be the 10th from last byte
40+
-- | in the Blob. If you specify a value for start that is larger than the size
41+
-- | of the source Blob, the returned Blob has size 0 and contains no data.
42+
newtype StartByte = StartByte ByteIdx
43+
44+
-- | An index into the Blob indicating the first byte that will *not* be included
45+
-- | in the new Blob (i.e. the byte exactly at this index is not included).
46+
-- | If you specify a negative value, it's treated as an offset from the end of
47+
-- | the string toward the beginning. For example, -10 would be the 10th from
48+
-- | last byte in the Blob. The default value is size.
49+
newtype EndByte = EndByte ByteIdx
50+
51+
foreign import data ByteIdx :: Type
52+
53+
-- | Creates `ByteIdx` from `Int` value
54+
idxFromInt :: Int -> ByteIdx
55+
idxFromInt = toNumber >>> unsafeCoerce
56+
57+
-- | Creates `ByteIdx` from `Number` value using `Math.round`.
58+
idxFromNumber :: Number -> ByteIdx
59+
idxFromNumber = round >>> unsafeCoerce
60+
61+
-- | Creates a new `Blob` object (with specified `MediaType`), containing the
62+
-- | data in the specified range of bytes of the source Blob, by setting .
63+
foreign import slice MediaType -> StartByte -> EndByte -> Blob -> Blob
64+
65+
-- | Creates a new `Blob` object containing the data in the specified range
66+
-- | of bytes of the source Blob.
67+
slice' StartByte -> EndByte -> Blob -> Blob
68+
slice' = slice (MediaType "")

src/DOM/HTML/Document.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ exports._body = function (doc) {
55
return doc.body;
66
};
77
};
8+
9+
exports._readyState = function (doc) {
10+
return function () {
11+
return doc.readyState;
12+
};
13+
};

src/DOM/HTML/Document.purs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
module DOM.HTML.Document
22
( body
3+
, readyState
4+
, module Exports
35
) where
46

57
import Prelude
8+
69
import Control.Monad.Eff (Eff)
7-
import Data.Maybe (Maybe)
8-
import Data.Nullable (Nullable, toMaybe)
910
import DOM (DOM)
11+
import DOM.HTML.Document.ReadyState (ReadyState(..)) as Exports
12+
import DOM.HTML.Document.ReadyState (ReadyState, parseReadyState)
1013
import DOM.HTML.Types (HTMLElement, HTMLDocument)
14+
import Data.Maybe (Maybe, fromJust)
15+
import Data.Nullable (Nullable, toMaybe)
16+
import Partial.Unsafe (unsafePartial)
1117

1218
foreign import _body :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) (Nullable HTMLElement)
1319

1420
body :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) (Maybe HTMLElement)
1521
body = map toMaybe <<< _body
22+
23+
foreign import _readyState :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) String
24+
25+
readyState :: forall eff. HTMLDocument -> Eff (dom :: DOM | eff) ReadyState
26+
readyState = map (unsafePartial fromJust <<< parseReadyState) <<< _readyState

src/DOM/HTML/Document/ReadyState.purs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module DOM.HTML.Document.ReadyState where
2+
3+
import Prelude
4+
import Data.Enum (class Enum, class BoundedEnum, Cardinality(..), defaultSucc, defaultPred)
5+
import Data.Maybe (Maybe(..))
6+
7+
data ReadyState
8+
= Loading
9+
| Interactive
10+
| Complete
11+
12+
derive instance eqReadyState :: Eq ReadyState
13+
derive instance ordReadyState :: Ord ReadyState
14+
15+
instance showReadyState :: Show ReadyState where
16+
show = case _ of
17+
Loading -> "Loading"
18+
Interactive -> "Interactive"
19+
Complete -> "Complete"
20+
21+
printReadyState :: ReadyState -> String
22+
printReadyState = case _ of
23+
Loading -> "loading"
24+
Interactive -> "interactive"
25+
Complete -> "complete"
26+
27+
parseReadyState :: String -> Maybe ReadyState
28+
parseReadyState = case _ of
29+
"loading" -> Just Loading
30+
"interactive" -> Just Interactive
31+
"complete" -> Just Complete
32+
_ -> Nothing
33+
34+
instance boundedReadyState :: Bounded ReadyState where
35+
bottom = Loading
36+
top = Complete
37+
38+
instance enumReadyState :: Enum ReadyState where
39+
succ = defaultSucc toEnumReadyState fromEnumReadyState
40+
pred = defaultPred toEnumReadyState fromEnumReadyState
41+
42+
instance boundedEnumReadyState :: BoundedEnum ReadyState where
43+
cardinality = Cardinality 3
44+
toEnum = toEnumReadyState
45+
fromEnum = fromEnumReadyState
46+
47+
toEnumReadyState :: Int -> Maybe ReadyState
48+
toEnumReadyState =
49+
case _ of
50+
0 -> Just Loading
51+
1 -> Just Interactive
52+
2 -> Just Complete
53+
_ -> Nothing
54+
55+
fromEnumReadyState :: ReadyState -> Int
56+
fromEnumReadyState =
57+
case _ of
58+
Loading -> 0
59+
Interactive -> 1
60+
Complete -> 2

src/DOM/HTML/HTMLElement.js

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ exports.setHidden = function (hidden) {
9393

9494
// ----------------------------------------------------------------------------
9595

96-
exports.click = function (elt) {
97-
return function () {
98-
return elt.click();
99-
};
100-
};
101-
102-
// ----------------------------------------------------------------------------
103-
10496
exports.tabIndex = function (elt) {
10597
return function () {
10698
return elt.tabIndex;
@@ -118,39 +110,6 @@ exports.setTabIndex = function (tabIndex) {
118110

119111
// ----------------------------------------------------------------------------
120112

121-
exports.hidden = function (elt) {
122-
return function () {
123-
return elt.hidden;
124-
};
125-
};
126-
127-
exports.setHidden = function (hidden) {
128-
return function (elt) {
129-
return function () {
130-
elt.hidden = hidden;
131-
return {};
132-
};
133-
};
134-
};
135-
136-
// ----------------------------------------------------------------------------
137-
138-
exports.focus = function (elt) {
139-
return function () {
140-
return elt.focus();
141-
};
142-
};
143-
144-
// ----------------------------------------------------------------------------
145-
146-
exports.blur = function (elt) {
147-
return function () {
148-
return elt.blur();
149-
};
150-
};
151-
152-
// ----------------------------------------------------------------------------
153-
154113
exports.draggable = function (elt) {
155114
return function () {
156115
return elt.draggable;
@@ -206,6 +165,26 @@ exports.setSpellcheck = function (spellcheck) {
206165
};
207166
};
208167

168+
// ----------------------------------------------------------------------------
169+
170+
exports.click = function (elt) {
171+
return function () {
172+
return elt.click();
173+
};
174+
};
175+
176+
exports.focus = function (elt) {
177+
return function () {
178+
return elt.focus();
179+
};
180+
};
181+
182+
exports.blur = function (elt) {
183+
return function () {
184+
return elt.blur();
185+
};
186+
};
187+
209188
// - CSSOM ---------------------------------------------------------------------
210189

211190
exports.getBoundingClientRect = function (el) {

src/DOM/HTML/Location.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ foreign import hostname :: forall eff. Location -> Eff (dom :: DOM | eff) String
3838
foreign import setHostname :: forall eff. String -> Location -> Eff (dom :: DOM | eff) Unit
3939

4040
foreign import href :: forall eff. Location -> Eff (dom :: DOM | eff) String
41-
foreign import setHref :: forall eff. String -> Location -> Eff (dom :: DOM | eff) String
41+
foreign import setHref :: forall eff. String -> Location -> Eff (dom :: DOM | eff) Unit
4242

4343
foreign import origin :: forall eff. Location -> Eff (dom :: DOM | eff) String
4444
foreign import setOrigin :: forall eff. String -> Location -> Eff (dom :: DOM | eff) Unit

src/DOM/HTML/Window.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ foreign import moveBy :: forall eff. Int -> Int -> Window -> Eff (window :: WIND
6666
foreign import moveTo :: forall eff. Int -> Int -> Window -> Eff (window :: WINDOW | eff) Unit
6767

6868
open :: forall eff. String -> String -> String -> Window -> Eff (window :: WINDOW | eff) (Maybe Window)
69-
open window url' name features = toMaybe <$> _open window url' name features
69+
open url' name features window = toMaybe <$> _open url' name features window
7070

7171
foreign import _open
7272
:: forall eff

0 commit comments

Comments
 (0)