From 42eccf04683818bde2a0b1b14e3ea3c03b69f195 Mon Sep 17 00:00:00 2001 From: Jonathan Sterling Date: Tue, 5 Jan 2016 12:14:17 -0800 Subject: [PATCH] Add binding for the Location object (resolve #33) --- src/DOM/HTML/Location.js | 58 ++++++++++++++++++++++++++++++++++++++ src/DOM/HTML/Location.purs | 16 +++++++++++ src/DOM/HTML/Types.purs | 3 ++ src/DOM/HTML/Window.js | 6 ++++ src/DOM/HTML/Window.purs | 2 ++ 5 files changed, 85 insertions(+) create mode 100644 src/DOM/HTML/Location.js create mode 100644 src/DOM/HTML/Location.purs diff --git a/src/DOM/HTML/Location.js b/src/DOM/HTML/Location.js new file mode 100644 index 0000000..5e66a52 --- /dev/null +++ b/src/DOM/HTML/Location.js @@ -0,0 +1,58 @@ +/* global exports */ +"use strict"; + +// module DOM.HTML.Location + +exports.hash = function (location) { + return function () { + return location.hash; + }; +}; + +exports.host = function (location) { + return function () { + return location.host; + }; +}; + +exports.hostname = function (location) { + return function () { + return location.hostname; + }; +}; + +exports.href = function (location) { + return function () { + return location.href; + }; +}; + +exports.origin = function (location) { + return function () { + return location.origin; + }; +}; + +exports.pathname = function (location) { + return function () { + return location.pathname; + }; +}; + +exports.port = function (location) { + return function () { + return location.port; + }; +}; + +exports.protocol = function (location) { + return function () { + return location.protocol; + }; +}; + +exports.search = function (location) { + return function () { + return location.search; + }; +}; diff --git a/src/DOM/HTML/Location.purs b/src/DOM/HTML/Location.purs new file mode 100644 index 0000000..175d767 --- /dev/null +++ b/src/DOM/HTML/Location.purs @@ -0,0 +1,16 @@ +module DOM.HTML.Location where + +import Control.Monad.Eff (Eff()) + +import DOM +import DOM.HTML.Types + +foreign import hash :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import host :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import hostname :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import href :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import origin :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import pathname :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import port :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import protocol :: forall eff. Location -> Eff (dom :: DOM | eff) String +foreign import search :: forall eff. Location -> Eff (dom :: DOM | eff) String diff --git a/src/DOM/HTML/Types.purs b/src/DOM/HTML/Types.purs index d6a7e6b..0a104da 100644 --- a/src/DOM/HTML/Types.purs +++ b/src/DOM/HTML/Types.purs @@ -17,6 +17,7 @@ module DOM.HTML.Types , htmlElementToNode , htmlElementToEventTarget , readHTMLElement + , Location() ) where import Prelude @@ -84,3 +85,5 @@ readHTMLElement = _readHTMLElement (Left <<< TypeMismatch "HTMLElement") Right instance isForeignHTMLElement :: IsForeign HTMLElement where read = readHTMLElement + +foreign import data Location :: * diff --git a/src/DOM/HTML/Window.js b/src/DOM/HTML/Window.js index ec4e72c..6b2a924 100644 --- a/src/DOM/HTML/Window.js +++ b/src/DOM/HTML/Window.js @@ -14,3 +14,9 @@ exports.navigator = function (window) { return window.navigator; }; }; + +exports.location = function (window) { + return function () { + return window.location; + }; +}; diff --git a/src/DOM/HTML/Window.purs b/src/DOM/HTML/Window.purs index b5e2649..fbf67b3 100644 --- a/src/DOM/HTML/Window.purs +++ b/src/DOM/HTML/Window.purs @@ -8,3 +8,5 @@ import DOM.HTML.Types 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