Skip to content

The anchor Element

theRealProHacker edited this page Feb 21, 2023 · 2 revisions

The HTML anchor element

Description

The anchor element can be clicked by the user. When it is clicked, it navigates to href.

Attributes

href: A hyper reference, aka URL

Usage

This link will navigate to google.com when it is clicked.

<a href = "google.com"></a>

Default Style

"a": {
    "color": "blue",
    "cursor": "pointer",
    # "text-decoration": "underline"
}
a:visited {
    color: purple
}

Default Event handlers

click: Pushes the href attribute onto the Navigator if given

auxclick: Same as click

def on_click(self):
    if href := self.attrs.get("href"):
        Navigator.push(href)
    else:
        log_error("Anchor without href clicked")

Further Development

Context Menu

The Element will get a custom context menu. The content is not determined yet, but should be configurable by the user by setting some attribute of the positron.Element.AnchorElement class.

Make draggable

For this, a Draggable API needs to be designed first.

download or download = filename

The linked document will be downloaded instead of being navigated to. The options of what happens are:

  1. The file is downloaded and the default file explorer will just open up at the location of the already saved file.
  2. Or it could open a save dialogue and suggest the filename given by the download attribute or derived from the href.

disabled

The link is disabled, its default color becomes more of a gray instead of blue, the anchor element generally behaves more like a "normal" element, has no drag, no pointer cursor and has no default click behavior. The context menu is also the default context menu.

Maybe the type attribute

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-type