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

Add HTMLHyperlinkElementUtils. #144

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions src/DOM/HTML/HTMLHyperlinkElementUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
"use strict";

exports.href = function (u) {
return function () {
return u.href;
};
};

exports.setHref = function (href) {
return function (u) {
return function () {
u.href = href;
};
};
};

// ----------------------------------------------------------------------------

exports.origin = function (u) {
return function () {
return u.origin;
};
};

// ----------------------------------------------------------------------------

exports.protocol = function (u) {
return function () {
return u.protocol;
};
};

exports.setProtocol = function (protocol) {
return function (u) {
return function () {
u.protocol = protocol;
};
};
};

// ----------------------------------------------------------------------------

exports.username = function (u) {
return function () {
return u.username;
};
};

exports.setUsername = function (username) {
return function (u) {
return function () {
u.username = username;
};
};
};

// ----------------------------------------------------------------------------

exports.password = function (u) {
return function () {
return u.password;
};
};

exports.setPassword = function (password) {
return function (u) {
return function () {
u.password = password;
};
};
};

// ----------------------------------------------------------------------------

exports.host = function (u) {
return function () {
return u.host;
};
};

exports.setHost = function (host) {
return function (u) {
return function () {
u.host = host;
};
};
};

// ----------------------------------------------------------------------------

exports.hostname = function (u) {
return function () {
return u.hostname;
};
};

exports.setHostname = function (hostname) {
return function (u) {
return function () {
u.hostname = hostname;
};
};
};

// ----------------------------------------------------------------------------

exports.port = function (u) {
return function () {
return u.port;
};
};

exports.setPort = function (port) {
return function (u) {
return function () {
u.port = port;
};
};
};

// ----------------------------------------------------------------------------

exports.pathname = function (u) {
return function () {
return u.pathname;
};
};

exports.setPathname = function (pathname) {
return function (u) {
return function () {
u.pathname = pathname;
};
};
};

// ----------------------------------------------------------------------------

exports.search = function (u) {
return function () {
return u.search;
};
};

exports.setSearch = function (search) {
return function (u) {
return function () {
u.search = search;
};
};
};

// ----------------------------------------------------------------------------

exports.hash = function (u) {
return function () {
return u.hash;
};
};

exports.setHash = function (hash) {
return function (u) {
return function () {
u.hash = hash;
};
};
};
41 changes: 41 additions & 0 deletions src/DOM/HTML/HTMLHyperlinkElementUtils.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- https://html.spec.whatwg.org/multipage/links.html#htmlhyperlinkelementutils
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extend this comment a bit futher - the specs used in this library are generally from the w3c not the whatwg... however, in this case, after doing some research it turns out this might be the only place the IDL is actually stated for this API.

It's called URLUtils in the HTML5 spec, which points to a URL standard document, which now points to a whatwg document, which doesn't have the interface listed. As far as I can tell from the non-IDL descriptions in the w3c spec though, this HTMLHyperlinkElementUtils IDL has all the same elements as the now-missing URLUtils API.

So I'd suggest something like:

The `URLUtils` interface referenced in https://www.w3.org/TR/html50/infrastructure.html#urlutils, now documented at https://html.spec.whatwg.org/multipage/links.html#htmlhyperlinkelementutils

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder which name we should use for this module and type, between "URLUtils" and "HTMLHyperlinkElementUtils". I feel like the latter term actually has a specification, which is good enough reason to choose this name rather than "URLUtils", and also it better fits the names of other types in this lib, like "HTMLAnchorElement".

Yeah, I was curious the relationship between w3 and whatwg's specs.
BTW, I chose the whatwg spec because that's the one MDN references:

Specifications
HTML Living Standard
The definition of 'HTMLHyperlinkElementUtils.href' in that specification.

Source: https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/href

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand it, the whatwg/living standard stuff is basically "encode what is commonly available in a spec" 😄 (rather than the w3c specs that describe how things are intended to work, before an implementation exists). I said in the readme we were going off the w3c specs, but maybe the living standard(s) would be more practical.

Really I was just hoping to avoid implementing browser quirks in the API / experimental stuff that is not widely implemented and agreed upon yet. LS would probably also satisfy that.

module DOM.HTML.HTMLHyperlinkElementUtils where

import Prelude (Unit)

import Control.Monad.Eff (Eff)

import DOM (DOM)
import DOM.HTML.Types (HTMLHyperlinkElementUtils)

foreign import href :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setHref :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import origin :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String

foreign import protocol :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setProtocol :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import username :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setUsername :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import password :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setPassword :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import host :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setHost :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import hostname :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setHostname :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import port :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setPort :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import pathname :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setPathname :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import search :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setSearch :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit

foreign import hash :: forall eff. HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) String
foreign import setHash :: forall eff. String -> HTMLHyperlinkElementUtils -> Eff (dom :: DOM | eff) Unit
7 changes: 7 additions & 0 deletions src/DOM/HTML/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ module DOM.HTML.Types
, HTMLAnchorElement
, htmlAnchorElementToHTMLElement
, readHTMLAnchorElement
, HTMLHyperlinkElementUtils
, htmlAnchorElementToHTMLHyperlinkElementUtils
, HTMLDataElement
, htmlDataElementToHTMLElement
, readHTMLDataElement
Expand Down Expand Up @@ -457,6 +459,11 @@ htmlAnchorElementToHTMLElement = U.unsafeCoerce
readHTMLAnchorElement :: Foreign -> F HTMLAnchorElement
readHTMLAnchorElement = unsafeReadTagged "HTMLAnchorElement"

foreign import data HTMLHyperlinkElementUtils :: Type

htmlAnchorElementToHTMLHyperlinkElementUtils :: HTMLAnchorElement -> HTMLHyperlinkElementUtils
htmlAnchorElementToHTMLHyperlinkElementUtils = U.unsafeCoerce

foreign import data HTMLDataElement :: Type

htmlDataElementToHTMLElement :: HTMLDataElement -> HTMLElement
Expand Down