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

Commit 49bafde

Browse files
committed
Merge pull request #34 from jonsterling/issue-33
Add binding for the Location object (resolve #33)
2 parents f024729 + 42eccf0 commit 49bafde

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

src/DOM/HTML/Location.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module DOM.HTML.Location
5+
6+
exports.hash = function (location) {
7+
return function () {
8+
return location.hash;
9+
};
10+
};
11+
12+
exports.host = function (location) {
13+
return function () {
14+
return location.host;
15+
};
16+
};
17+
18+
exports.hostname = function (location) {
19+
return function () {
20+
return location.hostname;
21+
};
22+
};
23+
24+
exports.href = function (location) {
25+
return function () {
26+
return location.href;
27+
};
28+
};
29+
30+
exports.origin = function (location) {
31+
return function () {
32+
return location.origin;
33+
};
34+
};
35+
36+
exports.pathname = function (location) {
37+
return function () {
38+
return location.pathname;
39+
};
40+
};
41+
42+
exports.port = function (location) {
43+
return function () {
44+
return location.port;
45+
};
46+
};
47+
48+
exports.protocol = function (location) {
49+
return function () {
50+
return location.protocol;
51+
};
52+
};
53+
54+
exports.search = function (location) {
55+
return function () {
56+
return location.search;
57+
};
58+
};

src/DOM/HTML/Location.purs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module DOM.HTML.Location where
2+
3+
import Control.Monad.Eff (Eff())
4+
5+
import DOM
6+
import DOM.HTML.Types
7+
8+
foreign import hash :: forall eff. Location -> Eff (dom :: DOM | eff) String
9+
foreign import host :: forall eff. Location -> Eff (dom :: DOM | eff) String
10+
foreign import hostname :: forall eff. Location -> Eff (dom :: DOM | eff) String
11+
foreign import href :: forall eff. Location -> Eff (dom :: DOM | eff) String
12+
foreign import origin :: forall eff. Location -> Eff (dom :: DOM | eff) String
13+
foreign import pathname :: forall eff. Location -> Eff (dom :: DOM | eff) String
14+
foreign import port :: forall eff. Location -> Eff (dom :: DOM | eff) String
15+
foreign import protocol :: forall eff. Location -> Eff (dom :: DOM | eff) String
16+
foreign import search :: forall eff. Location -> Eff (dom :: DOM | eff) String

src/DOM/HTML/Types.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module DOM.HTML.Types
1717
, htmlElementToNode
1818
, htmlElementToEventTarget
1919
, readHTMLElement
20+
, Location()
2021
) where
2122

2223
import Prelude
@@ -84,3 +85,5 @@ readHTMLElement = _readHTMLElement (Left <<< TypeMismatch "HTMLElement") Right
8485

8586
instance isForeignHTMLElement :: IsForeign HTMLElement where
8687
read = readHTMLElement
88+
89+
foreign import data Location :: *

src/DOM/HTML/Window.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ exports.navigator = function (window) {
1414
return window.navigator;
1515
};
1616
};
17+
18+
exports.location = function (window) {
19+
return function () {
20+
return window.location;
21+
};
22+
};

src/DOM/HTML/Window.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ import DOM.HTML.Types
88
foreign import document :: forall eff. Window -> Eff (dom :: DOM | eff) HTMLDocument
99

1010
foreign import navigator :: forall eff. Window -> Eff (dom :: DOM | eff) Navigator
11+
12+
foreign import location :: forall eff. Window -> Eff (dom :: DOM | eff) Location

0 commit comments

Comments
 (0)